Skip to contentSkip to conversation

hfsplus: add journal replay

PATCH Superseded Sergei Antonov 2 participants 3 messages Feb 23, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hfsplus: add journal replay

Add journal replay functionality. If filesystem is mounted for read-write and a non-empty journal is found, the replay action will be done. The original behaviour of switching to read-only mode in presense of journal by default is retained since the driver does not support journaled metadata modification anyway. After an attempt to replay has been done, the mount procedure repeats loading volume header to get its updated state. Having performed journal replay we do not run a risk of stumbling on inconsistency when working with the volume, so this functionality adds stability, while not changing any existing behaviour. Mount logic in super.c is changed as conservatively as possible.

The replay code checks the integrity of the whole journal before actually replaying sectors. If any error (e.g. checksum mismatch, invalid/misaligned offsets) is detected, the volume will remain unchanged and the journal will not be cleared.

The code supports checksums for replay data in addition to checksums for header and lists. Checksums for data is a relatively modern feature present on volumes modified by modern OS X versions.

Tested with:
drives with 512 and 4K sector sizes
default (8 MB) and custom (1 MB, 500 MB) journal sizes big-endian (PowerPC) and little-endian (Intel) journal byte sexes

Advantages over a previously presented
"[PATCH v3 00/15] hfsplus: introduce journal replay functionality" by a different author:
support for big-endian journal
no redundant stuff like journal initialization
less intrusive changes
shorter, easier to review

CC Al Viro <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Andrew Morton <[email protected]>
CC Vyacheslav Dubeyko <[email protected]>
CC Hin-Tak Leung <[email protected]>
---
 fs/hfsplus/Makefile      |   3 +-
 fs/hfsplus/hfsplus_fs.h  |   9 +
 fs/hfsplus/hfsplus_raw.h |  65 +++-
 fs/hfsplus/journal.c     | 903 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/hfsplus/super.c       |  30 +-
 5 files changed, 1004 insertions(+), 6 deletions(-)
 create mode 100644 fs/hfsplus/journal.c
fs/hfsplus/Makefile +2 -1
index 683fca2..927e89c 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o
 
 hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
 		bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o \
-		attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
+		attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o \
+		journal.o
 
 hfsplus-$(CONFIG_HFSPLUS_FS_POSIX_ACL)	+= posix_acl.o
fs/hfsplus/hfsplus_fs.h +9 -0
index 08846425b..2edbfd1 100644
@@ -31,6 +31,7 @@
 #define DBG_BITMAP	0x00000040
 #define DBG_ATTR_MOD	0x00000080
 #define DBG_ACL_MOD	0x00000100
+#define DBG_JOURNAL	0x00000200
 
 #if 0
 #define DBG_MASK	(DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
@@ -166,6 +167,11 @@ struct hfsplus_sb_info {
 	u32 total_blocks;
 	u32 data_clump_blocks, rsrc_clump_blocks;
 
+	/* immutable data on the placement of the journal (if there is one) */
+	u64 journal_offset;	/* relative to volume start */
+	u64 journal_size;	/* relative to volume start */
+	bool journal_swab;	/* need swap bytes in journal */
+
 	/* mutable data from the volume header, protected by alloc_mutex */
 	u32 free_blocks;
 	struct mutex alloc_mutex;
@@ -516,6 +522,9 @@ int hfs_part_find(struct super_block *, sector_t *, sector_t *);
 int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
 		void *buf, void **data, int rw);
 
+/* journal.c */
+int hfsplus_jrnl_replay(struct super_block *, u32, bool *);
+
 /* time macros */
 #define __hfsp_mt2ut(t)		(be32_to_cpu(t) - 2082844800U)
 #define __hfsp_ut2mt(t)		(cpu_to_be32(t + 2082844800U))
fs/hfsplus/hfsplus_raw.h +64 -1

77 lines not on this page · raw message

fs/hfsplus/journal.c new file +903 -0

903 lines not on this page · raw message

fs/hfsplus/super.c +26 -4
index 80875aa..84b832e 100644
@@ -403,6 +403,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
 		goto out_unload_nls;
 	}
 
+reread_vhdr:
 	/* Grab the volume header */
 	if (hfsplus_read_wrapper(sb)) {
 		if (!silent)
@@ -447,6 +448,31 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
 	sb->s_op = &hfsplus_sops;
 	sb->s_maxbytes = MAX_LFS_FILESIZE;
 
+	if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) &&
+	    !(sb->s_flags & MS_RDONLY)) {
+		bool journal_was_empty;
+		int replay_error;
+
+		pr_warn("write access to a journaled filesystem is not supported, use the force option at your own risk, mounting read-only.\n");
+		sb->s_flags |= MS_RDONLY;
+
+		replay_error = hfsplus_jrnl_replay(sb,
+			be32_to_cpu(vhdr->jrnl_info_block), &journal_was_empty);
+		if (replay_error)
+			pr_err("journal replay error %d\n", replay_error);
+
+		/*
+		 * Reread volume header after replay, no matter if it succeeded
+		 * or not. We've just set read-only flag, so no further replay
+		 * attempts will happen.
+		 */
+		kfree(sbi->s_vhdr_buf);
+		kfree(sbi->s_backup_vhdr_buf);
+		sbi->s_vhdr_buf = 0;
+		sbi->s_backup_vhdr_buf = 0;
+		goto reread_vhdr;
+	}
+
 	if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
 		pr_warn("Filesystem was not cleanly unmounted, running fsck.hfsplus is recommended.  mounting read-only.\n");
 		sb->s_flags |= MS_RDONLY;
@@ -455,10 +481,6 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
 	} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
 		pr_warn("Filesystem is marked locked, mounting read-only.\n");
 		sb->s_flags |= MS_RDONLY;
-	} else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) &&
-			!(sb->s_flags & MS_RDONLY)) {
-		pr_warn("write access to a journaled filesystem is not supported, use the force option at your own risk, mounting read-only.\n");
-		sb->s_flags |= MS_RDONLY;
 	}
 
 	err = -EINVAL;
Signature · 1 line
1.9.0
#1 lore raw
Quoted 24 lines · Sergei Antonov

Add journal replay functionality. If filesystem is mounted for read-write and a non-empty journal is found, the replay action will be done. The original behaviour of switching to read-only mode in presense of journal by default is retained since the driver does not support journaled metadata modification anyway. After an attempt to replay has been done, the mount procedure repeats loading volume header to get its updated state. Having performed journal replay we do not run a risk of stumbling on inconsistency when working with the volume, so this functionality adds stability, while not changing any existing behaviour. Mount logic in super.c is changed as conservatively as possible.

The replay code checks the integrity of the whole journal before actually replaying sectors. If any error (e.g. checksum mismatch, invalid/misaligned offsets) is detected, the volume will remain unchanged and the journal will not be cleared.

The code supports checksums for replay data in addition to checksums for header and lists. Checksums for data is a relatively modern feature present on volumes modified by modern OS X versions.

Tested with:
drives with 512 and 4K sector sizes
default (8 MB) and custom (1 MB, 500 MB) journal sizes big-endian (PowerPC) and little-endian (Intel) journal byte sexes

Quoted 7 lines

Advantages over a previously presented
"[PATCH v3 00/15] hfsplus: introduce journal replay functionality" by a different author:
support for big-endian journal
no redundant stuff like journal initialization
less intrusive changes
shorter, easier to review

I have corrected my code for big-endian support and I am ready to submit it during next several days. I have really bad feelings about your patch because it makes sense to announce your intentions to make such implementation if you know about efforts from another party in this direction. For me it is really dishonest way because I spent my time for this implementation.

I disagree with such way of submitting patch. Because it is likewise cheating, form my point of view.

With the best regards,
Vyacheslav Dubeyko.

#2 lore raw
Quoted 34 lines · Vyacheslav Dubeyko
Quoted 24 lines · Sergei Antonov

Add journal replay functionality. If filesystem is mounted for read-write and a non-empty journal is found, the replay action will be done. The original behaviour of switching to read-only mode in presense of journal by default is retained since the driver does not support journaled metadata modification anyway. After an attempt to replay has been done, the mount procedure repeats loading volume header to get its updated state. Having performed journal replay we do not run a risk of stumbling on inconsistency when working with the volume, so this functionality adds stability, while not changing any existing behaviour. Mount logic in super.c is changed as conservatively as possible.

The replay code checks the integrity of the whole journal before actually replaying sectors. If any error (e.g. checksum mismatch, invalid/misaligned offsets) is detected, the volume will remain unchanged and the journal will not be cleared.

The code supports checksums for replay data in addition to checksums for header and lists. Checksums for data is a relatively modern feature present on volumes modified by modern OS X versions.

Tested with:
drives with 512 and 4K sector sizes
default (8 MB) and custom (1 MB, 500 MB) journal sizes big-endian (PowerPC) and little-endian (Intel) journal byte sexes

Quoted 7 lines

Advantages over a previously presented
"[PATCH v3 00/15] hfsplus: introduce journal replay functionality" by a different author:
support for big-endian journal
no redundant stuff like journal initialization
less intrusive changes
shorter, easier to review

Quoted 6 lines

I have corrected my code for big-endian support and I am ready to submit it during next several days. I have really bad feelings about your patch because it makes sense to announce your intentions to make such implementation if you know about efforts from another party in this direction. For me it is really dishonest way because I spent my time for this implementation.

I disagree with such way of submitting patch. Because it is likewise cheating, form my point of view.

I can say additionally that there are many implementation tasks in HFS+ driver. And if you don't know what to do then you can simply ask about it. It makes sense to cooperate instead of foolish cheating.

As far as I can judge, HFS+ driver needs in such implementation, as minimum:
(1) access to resource forks is broken, currently;
(2) HFS+ compressed files support (I have initial state of code);
(3) richacl support;
(4) full featured journalling support;
(5) FITRIM support (and flash optimizations);
(6) different stabilization and optimization efforts;
(7) O_TMPFILE support.

This is small TODO list. I think that I don't mentioned all necessary implementation in HFS+ driver. But you prefer cheating instead of cooperation in implementation by unknown reasons for me. And it is really upset me.

With the best regards,
Vyacheslav Dubeyko.