Re: [PATCH] ext2: Prototype: Add JDB2 binary compliant journal

2026-01-21 Thread Samuel Thibault
Hello,

Milos Nikic, le mer. 21 janv. 2026 14:58:01 -0800, a ecrit:
> Over the past week, I have been working on creating a prototype for a journal
> inside ext2fs which is fully Linux compatible (binary JBD2 compatible). This
> enables standard Linux tools (e2fsck, tune2fs, debugfs, etc.) to work
> seamlessly with Hurd partitions.

Great :D

It'll take me some time to get a look at it, people are welcome to
provide feedback of course!

Samuel

> This means one can mount a Hurd image from Linux and fix any issues with the
> drive using standard journaling tools if the need arises. While this is
> currently a prototype with polish still required, it is functional.
> 
> Key Features:
>     Log Replay: The driver writes JBD2-compliant transactions. I have verified
> that after a hard crash of the Hurd guest, a Linux host running e2fsck
> correctly replays the journal and restores filesystem metadata consistency.
>     Continuous Operation: The driver handles ring-buffer wrap-around and
> checkpoints correctly. I have tested it with sustained loads (50,000+
> transaction loops) without deadlocks or corruption.
>     Crash Safety: I have verified via "sabotage tests" (modifying the disk
> offline after a crash) that the journal accurately restores the correct
> metadata state.
>     Lightweight: The implementation consists of only a few new files and ~800
> lines of code.
> 
> Implementation Details: I had to add one weak symbol in diskfs.h. For this
> prototype, I am using a "safe sync" strategy (flushing the pager buckets)
> because there is no explicit write barrier RPC in Mach to ensure strict
> ordering between transaction commits and superblock updates.
> 
> If there is interest from the Hurd community in integrating this, I am willing
> to work on adding a proper write barrier RPC into Mach and productionizing the
> code adding whatever else is needed. There is a path to a safer, more atomic
> Hurd and also retiring fsck fully if we integrate a version of this.
> 
> How to Test It: To test this on your own images, you simply need to create the
> journal using tune2fs. You will need the byte offset of your ext2 partition.
> (WARNING: Please apply the patch first, otherwise your ext2 will refuse to 
> work
> with your image!!!)
> 
> The easiest way (for me) to get the offset is this:
> )> parted debian-hurd-amd64-20251105.img unit B print
> Output example:
> Number  Start        End          Size         Type      File system     Flags
>  1      1048576B     1000341503B  999292928B   primary   linux-swap(v1)  swap
>  2      1001389056B  9564061695B  8562672640B  extended                  lba
>  5      1001390080B  9564061695B  8562671616B  logical   ext2
> (the 1001390080B is the ext2 partition for me.)
> 
> now armed with that knowledge i do:
> > sudo modprobe nbd max_part=8
> > sudo qemu-nbd --connect=/dev/nbd0 --offset=1001390080 --format=raw
> debian-hurd-amd64-20251105.img
> > sudo tune2fs -j /dev/nbd0
> > sudo qemu-nbd --disconnect /dev/nbd0
> 
> That's it! tune2fs has now allocated an empty journal inside your Hurd
> filesystem.
> 
> The next time you boot into Hurd, you might notice a warning: ext2fs:
> part:5:device:wd0: warning: mounting ext3 filesystem as ext2. This is normal.
> 
> All tools will now recognize the partition as ext3. Even mounting the image
> inside Linux will automatically replay the journal and fix any issues if
> needed. Besides that everything should work seamlessly.
> 
> Let me know if this is something the community would like to see developed
> further.
> 
> Thanks,
> Milos
> 

> From e77b197789ee72be42304e705254abd4f35c0aa4 Mon Sep 17 00:00:00 2001
> From: Milos Nikic 
> Date: Sat, 17 Jan 2026 22:49:00 -0800
> Subject: [PATCH] ext2: Prototype: Add JDB2 binary compliant journal
> 
> This prototype adds journal driver that captures some node
> metadata inside a binary compliant place with binary
> compliant content of the JBD2.
> 
> This way standard linux tools (e2fsck, debugfs, tune2fs etc)
> all work and can understand and replay ext2 journal.
> In fact all of them now recognize ext2 as ext3.
> ---
>  ext2fs/Makefile   |   2 +-
>  ext2fs/ext2_fs.h  |   3 +-
>  ext2fs/ext2fs.c   |  24 ++
>  ext2fs/ext2fs.h   |   4 +
>  ext2fs/hyper.c|   9 +
>  ext2fs/inode.c|  41 +-
>  ext2fs/jbd2_format.h  | 101 +
>  ext2fs/journal.c  | 843 ++
>  ext2fs/journal.h  |  62 +++
>  ext2fs/pager.c|  31 ++
>  libdiskfs/diskfs.h|   5 +
>  libdiskfs/node-modified.c |  28 ++
>  libdiskfs/priv.h  |   6 +
>  13 files changed, 1153

[PATCH] ext2: Prototype: Add JDB2 binary compliant journal

2026-01-21 Thread Milos Nikic
Hello everyone,

Over the past week, I have been working on creating a prototype for a
journal inside ext2fs which is fully Linux compatible (binary JBD2
compatible). This enables standard Linux tools (e2fsck, tune2fs, debugfs,
etc.) to work seamlessly with Hurd partitions.

This means one can mount a Hurd image from Linux and fix any issues with
the drive using standard journaling tools if the need arises. While this is
currently a prototype with polish still required, it is functional.

Key Features:
Log Replay: The driver writes JBD2-compliant transactions. I have
verified that after a hard crash of the Hurd guest, a Linux host running
e2fsck correctly replays the journal and restores filesystem metadata
consistency.
Continuous Operation: The driver handles ring-buffer wrap-around and
checkpoints correctly. I have tested it with sustained loads (50,000+
transaction loops) without deadlocks or corruption.
Crash Safety: I have verified via "sabotage tests" (modifying the disk
offline after a crash) that the journal accurately restores the correct
metadata state.
Lightweight: The implementation consists of only a few new files and
~800 lines of code.

Implementation Details: I had to add one weak symbol in diskfs.h. For this
prototype, I am using a "safe sync" strategy (flushing the pager buckets)
because there is no explicit write barrier RPC in Mach to ensure strict
ordering between transaction commits and superblock updates.

If there is interest from the Hurd community in integrating this, I am
willing to work on adding a proper write barrier RPC into Mach and
productionizing the code adding whatever else is needed. There is a path to
a safer, more atomic Hurd and also retiring fsck fully if we integrate a
version of this.

How to Test It: To test this on your own images, you simply need to create
the journal using tune2fs. You will need the byte offset of your ext2
partition.
(WARNING: Please apply the patch first, otherwise your ext2 will refuse to
work with your image!!!)

The easiest way (for me) to get the offset is this:
)> parted debian-hurd-amd64-20251105.img unit B print
Output example:
Number  StartEnd  Size Type  File system
Flags
 1  1048576B 1000341503B  999292928B   primary   linux-swap(v1)
 swap
 2  1001389056B  9564061695B  8562672640B  extended  lba
 5  1001390080B  9564061695B  8562671616B  logical   ext2
(the 1001390080B is the ext2 partition for me.)

now armed with that knowledge i do:
> sudo modprobe nbd max_part=8
> sudo qemu-nbd --connect=/dev/nbd0 --offset=1001390080 --format=raw
debian-hurd-amd64-20251105.img
> sudo tune2fs -j /dev/nbd0
> sudo qemu-nbd --disconnect /dev/nbd0

That's it! tune2fs has now allocated an empty journal inside your Hurd
filesystem.

The next time you boot into Hurd, you might notice a warning: ext2fs:
part:5:device:wd0: warning: mounting ext3 filesystem as ext2. This is
normal.

All tools will now recognize the partition as ext3. Even mounting the image
inside Linux will automatically replay the journal and fix any issues if
needed. Besides that everything should work seamlessly.

Let me know if this is something the community would like to see developed
further.

Thanks,
Milos
From e77b197789ee72be42304e705254abd4f35c0aa4 Mon Sep 17 00:00:00 2001
From: Milos Nikic 
Date: Sat, 17 Jan 2026 22:49:00 -0800
Subject: [PATCH] ext2: Prototype: Add JDB2 binary compliant journal

This prototype adds journal driver that captures some node
metadata inside a binary compliant place with binary
compliant content of the JBD2.

This way standard linux tools (e2fsck, debugfs, tune2fs etc)
all work and can understand and replay ext2 journal.
In fact all of them now recognize ext2 as ext3.
---
 ext2fs/Makefile   |   2 +-
 ext2fs/ext2_fs.h  |   3 +-
 ext2fs/ext2fs.c   |  24 ++
 ext2fs/ext2fs.h   |   4 +
 ext2fs/hyper.c|   9 +
 ext2fs/inode.c|  41 +-
 ext2fs/jbd2_format.h  | 101 +
 ext2fs/journal.c  | 843 ++
 ext2fs/journal.h  |  62 +++
 ext2fs/pager.c|  31 ++
 libdiskfs/diskfs.h|   5 +
 libdiskfs/node-modified.c |  28 ++
 libdiskfs/priv.h  |   6 +
 13 files changed, 1153 insertions(+), 6 deletions(-)
 create mode 100644 ext2fs/jbd2_format.h
 create mode 100644 ext2fs/journal.c
 create mode 100644 ext2fs/journal.h
 create mode 100644 libdiskfs/node-modified.c

diff --git a/ext2fs/Makefile b/ext2fs/Makefile
index 0c2f4a24..a2b0f1ee 100644
--- a/ext2fs/Makefile
+++ b/ext2fs/Makefile
@@ -22,7 +22,7 @@ makemode := server
 target = ext2fs
 SRCS = balloc.c dir.c ext2fs.c getblk.c hyper.c ialloc.c \
inode.c pager.c pokel.c truncate.c storeinfo.c msg.c xinl.c \
-   xattr.c
+   xattr.c journal.c
 OBJS = $(SRCS:.c=.o)
 HURDLIBS = diskfs pager iohelp fshelp store ports ihash shouldbeinlibc
 LDLIBS = -lp