Skip to contentSkip to conversation

Updated patches for journal checksums.

PATCH Girish Shilamkar 3 participants 6 messages Jun 19, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,
The journal checksums patches for ext4 and e2fsprogs sent on 30th May
had run into problems on big-endian machines. I have made the required changes.
The major updates are:
1. Checksum was written in little endian format in the commit header, changed it to big-endian.
2. The crc32 code ported to userspace (which is used by e2fsprogs) had problem with #ifdef, fixed that.
3. The crc32 user space code used i386 assembly code for swabbing changed it to generic one.
4. Removed various #includes, which caused compilation errors on ppc machine.

Any comments/suggestions are always welcome.

Thanks,
Girish.

fs/jbd2/commit.c +135 -46
Index: linux-2.6.20/fs/jbd2/commit.c
===================================================================
@@ -21,6 +21,7 @@
 #include <linux/mm.h>
 #include <linux/pagemap.h>
 #include <linux/smp_lock.h>
+#include <linux/crc32.h>
 
 /*
  * Default IO end handler for temporary BJ_IO buffer_heads.
@@ -93,15 +94,18 @@ static int inverted_lock(journal_t *jour
 	return 1;
 }
 
-/* Done it all: now write the commit record.  We should have
+/*
+ * Done it all: now submit the commit record.  We should have
  * cleaned up our previous buffers by now, so if we are in abort
  * mode we can now just skip the rest of the journal write
  * entirely.
  *
  * Returns 1 if the journal needs to be aborted or 0 on success
  */
-static int journal_write_commit_record(journal_t *journal,
-					transaction_t *commit_transaction)
+static int journal_submit_commit_record(journal_t *journal,
+					transaction_t *commit_transaction,
+					struct buffer_head **cbh,
+					__u32 crc32_sum)
 {
 	struct journal_head *descriptor;
 	struct buffer_head *bh;
@@ -117,21 +121,36 @@ static int journal_write_commit_record(j
 
 	bh = jh2bh(descriptor);
 
-	/* AKPM: buglet - add `i' to tmp! */
 	for (i = 0; i < bh->b_size; i += 512) {
-		journal_header_t *tmp = (journal_header_t*)bh->b_data;
+ 		struct commit_header *tmp = (struct commit_header*)bh->b_data +
+					    i;
 		tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
 		tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK);
 		tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);
-	}
+		 		
+ 		if (JBD2_HAS_COMPAT_FEATURE(journal,
+					    JBD2_FEATURE_COMPAT_CHECKSUM)) {
+ 			tmp->h_chksum_type 	= JBD2_CRC32_CHKSUM;
+ 			tmp->h_chksum_size 	= JBD2_CRC32_CHKSUM_SIZE;
+ 			tmp->h_chksum[0] 	= crc32_sum;
+ 		}
+  	}
+
+ 	JBUFFER_TRACE(descriptor, "submit commit block");
+ 	lock_buffer(bh);
 
-	JBUFFER_TRACE(descriptor, "write commit block");
 	set_buffer_dirty(bh);
-	if (journal->j_flags & JBD2_BARRIER) {
+ 	set_buffer_uptodate(bh);
+ 	bh->b_end_io = journal_end_buffer_io_sync;
+
+ 	if (journal->j_flags & JBD2_BARRIER &&
+ 		!JBD2_HAS_COMPAT_FEATURE(journal,
+					 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
 		set_buffer_ordered(bh);
 		barrier_done = 1;
-	}
-	ret = sync_dirty_buffer(bh);
+ 	}	
+ 	ret = submit_bh(WRITE, bh);
+
 	/* is it possible for another commit to fail at roughly
 	 * the same time as this one?  If so, we don't want to
 	 * trust the barrier flag in the super, but instead want
@@ -152,14 +171,72 @@ static int journal_write_commit_record(j
 		clear_buffer_ordered(bh);
 		set_buffer_uptodate(bh);
 		set_buffer_dirty(bh);
-		ret = sync_dirty_buffer(bh);
+		ret = submit_bh(WRITE, bh);
 	}
-	put_bh(bh);		/* One for getblk() */
-	jbd2_journal_put_journal_head(descriptor);
+	*cbh = bh;
+	return ret;
+}
+
+/*
+ * This function along with journal_submit_commit_record
+ * allows to write the commit record asynchronously.
+ */
+static int journal_wait_on_commit_record(struct buffer_head *bh)
+{
+	int ret = 0;
 
-	return (ret == -EIO);
+	if (buffer_locked(bh))
+		wait_on_buffer(bh);
+	
+	if (unlikely(!buffer_uptodate(bh)))
+		ret = -EIO;
+	put_bh(bh);            /* One for getblk() */
+	jbd2_journal_put_journal_head(bh2jh(bh));
+	
+	return ret;
 }
 
+/*
+ * Wait for all submitted IO to complete.
+ */
+static int journal_wait_on_locked_list(journal_t *journal,
+				       transaction_t *commit_transaction)
+{
+	int ret = 0;
+	struct journal_head *jh;
+
+	while (commit_transaction->t_locked_list) {
+		struct buffer_head *bh;
+
+		jh = commit_transaction->t_locked_list->b_tprev;
+		bh = jh2bh(jh);
+		get_bh(bh);
+		if (buffer_locked(bh)) {
+			spin_unlock(&journal->j_list_lock);
+			wait_on_buffer(bh);
+			if (unlikely(!buffer_uptodate(bh)))
+				ret = -EIO;
+			spin_lock(&journal->j_list_lock);
+		}
+		if (!inverted_lock(journal, bh)) {
+			put_bh(bh);
+			spin_lock(&journal->j_list_lock);
+			continue;
+		}
+		if (buffer_jbd(bh) && jh->b_jlist == BJ_Locked) {
+			__jbd2_journal_unfile_buffer(jh);
+			jbd_unlock_bh_state(bh);
+			jbd2_journal_remove_journal_head(bh);
+			put_bh(bh);
+		} else {
+			jbd_unlock_bh_state(bh);
+		}
+		put_bh(bh);
+		cond_resched_lock(&journal->j_list_lock);
+	}
+	return ret;
+  }
+
 static void journal_do_submit_data(struct buffer_head **wbuf, int bufs)
 {
 	int i;
@@ -306,6 +383,8 @@ void jbd2_journal_commit_transaction(jou
 	int tag_flag;
 	int i;
 	int tag_bytes = journal_tag_bytes(journal);
+	struct buffer_head *cbh = NULL; /* For transactional checksums */
+	__u32 crc32_sum = ~0;
 
 	/*
 	 * First job: lock down the current transaction and wait for
@@ -441,38 +520,15 @@ void jbd2_journal_commit_transaction(jou
 	journal_submit_data_buffers(journal, commit_transaction);
 
 	/*
-	 * Wait for all previously submitted IO to complete.
+	 * Wait for all previously submitted IO to complete if commit
+	 * record is to be written synchronously.
 	 */
 	spin_lock(&journal->j_list_lock);
-	while (commit_transaction->t_locked_list) {
-		struct buffer_head *bh;
+	if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
+		JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT))
+		err = journal_wait_on_locked_list(journal,
+						commit_transaction);
 
-		jh = commit_transaction->t_locked_list->b_tprev;
-		bh = jh2bh(jh);
-		get_bh(bh);
-		if (buffer_locked(bh)) {
-			spin_unlock(&journal->j_list_lock);
-			wait_on_buffer(bh);
-			if (unlikely(!buffer_uptodate(bh)))
-				err = -EIO;
-			spin_lock(&journal->j_list_lock);
-		}
-		if (!inverted_lock(journal, bh)) {
-			put_bh(bh);
-			spin_lock(&journal->j_list_lock);
-			continue;
-		}
-		if (buffer_jbd(bh) && jh->b_jlist == BJ_Locked) {
-			__jbd2_journal_unfile_buffer(jh);
-			jbd_unlock_bh_state(bh);
-			jbd2_journal_remove_journal_head(bh);
-			put_bh(bh);
-		} else {
-			jbd_unlock_bh_state(bh);
-		}
-		put_bh(bh);
-		cond_resched_lock(&journal->j_list_lock);
-	}
 	spin_unlock(&journal->j_list_lock);
 
 	if (err)
@@ -640,6 +696,16 @@ void jbd2_journal_commit_transaction(jou
 start_journal_io:
 			for (i = 0; i < bufs; i++) {
 				struct buffer_head *bh = wbuf[i];
+				/*
+				 * Compute checksum.
+				 */
+				if (JBD2_HAS_COMPAT_FEATURE(journal,
+					JBD2_FEATURE_COMPAT_CHECKSUM)) {
+					crc32_sum = crc32_be(crc32_sum,
+							(void *)bh->b_data,
+							bh->b_size);
+				}
+
 				lock_buffer(bh);
 				clear_buffer_dirty(bh);
 				set_buffer_uptodate(bh);
@@ -655,6 +721,23 @@ start_journal_io:
 		}
 	}
 
+	/* Done it all: now write the commit record asynchronously. */
+
+	if (JBD2_HAS_INCOMPAT_FEATURE(journal,
+		JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
+		err = journal_submit_commit_record(journal, commit_transaction,
+						 &cbh, crc32_sum);
+		if (err)
+			__jbd2_journal_abort_hard(journal);
+
+		spin_lock(&journal->j_list_lock);
+		err = journal_wait_on_locked_list(journal,
+						commit_transaction);
+		spin_unlock(&journal->j_list_lock);
+		if (err)
+			__jbd2_journal_abort_hard(journal);
+	}
+
 	/* Lo and behold: we have just managed to send a transaction to
            the log.  Before we can commit it, wait for the IO so far to
            complete.  Control buffers being written are on the
@@ -753,9 +836,15 @@ wait_for_iobuf:
 	}
 
 	jbd_debug(3, "JBD: commit phase 6\n");
-
-	if (journal_write_commit_record(journal, commit_transaction))
-		err = -EIO;
+	 	
+	if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
+		JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
+		err = journal_submit_commit_record(journal, commit_transaction,
+						&cbh, crc32_sum);
+		if (err)
+			__jbd2_journal_abort_hard(journal);
+	}
+	err = journal_wait_on_commit_record(cbh);
 
 	if (err)
 		__jbd2_journal_abort_hard(journal);
include/linux/jbd2.h +33 -4
Index: linux-2.6.20/include/linux/jbd2.h
===================================================================
@@ -148,6 +148,29 @@ typedef struct journal_header_s
 	__be32		h_sequence;
 } journal_header_t;
 
+/*
+ * Checksum types.
+ */
+#define JBD2_CRC32_CHKSUM   1
+#define JBD2_MD5_CHKSUM     2
+#define JBD2_SHA1_CHKSUM    3
+
+#define JBD2_CRC32_CHKSUM_SIZE 4
+
+#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32))
+/*
+ * Commit block header for storing transactional checksums:
+ */
+struct commit_header
+{
+	__be32		h_magic;
+	__be32          h_blocktype;
+	__be32          h_sequence;
+	unsigned char   h_chksum_type;
+	unsigned char   h_chksum_size;
+	unsigned char 	h_padding[2];
+	__u32 		h_chksum[JBD2_CHECKSUM_BYTES];
+};
 
 /*
  * The block tag: used to describe a single buffer in the journal.
@@ -241,14 +264,18 @@ typedef struct journal_superblock_s
 	((j)->j_format_version >= 2 &&					\
 	 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
 
-#define JBD2_FEATURE_INCOMPAT_REVOKE	0x00000001
-#define JBD2_FEATURE_INCOMPAT_64BIT	0x00000002
+#define JBD2_FEATURE_COMPAT_CHECKSUM	0x00000001
+
+#define JBD2_FEATURE_INCOMPAT_REVOKE		0x00000001
+#define JBD2_FEATURE_INCOMPAT_64BIT		0x00000002
+#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT	0x00000004
 
 /* Features known to this kernel version: */
-#define JBD2_KNOWN_COMPAT_FEATURES	0
+#define JBD2_KNOWN_COMPAT_FEATURES	JBD2_FEATURE_COMPAT_CHECKSUM
 #define JBD2_KNOWN_ROCOMPAT_FEATURES	0
 #define JBD2_KNOWN_INCOMPAT_FEATURES	(JBD2_FEATURE_INCOMPAT_REVOKE | \
-					 JBD2_FEATURE_INCOMPAT_64BIT)
+					JBD2_FEATURE_INCOMPAT_64BIT | \
+ 					JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)
 
 #ifdef __KERNEL__
 
@@ -931,6 +958,8 @@ extern int	   jbd2_journal_check_availab
 		   (journal_t *, unsigned long, unsigned long, unsigned long);
 extern int	   jbd2_journal_set_features
 		   (journal_t *, unsigned long, unsigned long, unsigned long);
+extern int	   jbd2_journal_clear_features
+		   (journal_t *, unsigned long, unsigned long, unsigned long);
 extern int	   jbd2_journal_create     (journal_t *);
 extern int	   jbd2_journal_load       (journal_t *journal);
 extern void	   jbd2_journal_destroy    (journal_t *);
fs/ext4/super.c +25 -0
Index: linux-2.6.20/fs/ext4/super.c
===================================================================
@@ -724,6 +724,7 @@ enum {
 	Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
 	Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh,
 	Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev,
+	Opt_journal_checksum, Opt_journal_async_commit,
 	Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
 	Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
 	Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
@@ -763,6 +764,8 @@ static match_table_t tokens = {
 	{Opt_journal_update, "journal=update"},
 	{Opt_journal_inum, "journal=%u"},
 	{Opt_journal_dev, "journal_dev=%u"},
+	{Opt_journal_checksum, "journal_checksum"},
+	{Opt_journal_async_commit, "journal_async_commit"},
 	{Opt_abort, "abort"},
 	{Opt_data_journal, "data=journal"},
 	{Opt_data_ordered, "data=ordered"},
@@ -949,6 +952,13 @@ static int parse_options (char *options,
 				return 0;
 			*journal_devnum = option;
 			break;
+		case Opt_journal_checksum:
+			set_opt (sbi->s_mount_opt, JOURNAL_CHECKSUM);
+			break;
+		case Opt_journal_async_commit:
+			set_opt (sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT);
+			set_opt (sbi->s_mount_opt, JOURNAL_CHECKSUM);
+			break;
 		case Opt_noload:
 			set_opt (sbi->s_mount_opt, NOLOAD);
 			break;
@@ -1793,6 +1803,21 @@ static int ext4_fill_super (struct super
 		goto failed_mount3;
 	}
 
+	if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
+		jbd2_journal_set_features(sbi->s_journal,
+				JBD2_FEATURE_COMPAT_CHECKSUM, 0,
+				JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
+	} else if (test_opt(sb, JOURNAL_CHECKSUM)) {
+		jbd2_journal_set_features(sbi->s_journal,
+				JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0);
+		jbd2_journal_clear_features(sbi->s_journal, 0, 0,
+				JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
+	} else {
+		jbd2_journal_clear_features(sbi->s_journal,
+				JBD2_FEATURE_COMPAT_CHECKSUM, 0,
+				JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
+	}
+
 	/* We have now updated the journal if required, so we can
 	 * validate the data journaling mode. */
 	switch (test_opt(sb, DATA_FLAGS)) {
include/linux/ext4_fs.h +2 -0
Index: linux-2.6.20/include/linux/ext4_fs.h
===================================================================
@@ -400,6 +400,8 @@ struct ext4_inode {
 #define EXT4_MOUNT_USRQUOTA		0x100000 /* "old" user quota */
 #define EXT4_MOUNT_GRPQUOTA		0x200000 /* "old" group quota */
 #define EXT4_MOUNT_EXTENTS		0x400000 /* Extents support */
+#define EXT4_MOUNT_JOURNAL_CHECKSUM	0x800000 /* Journal checksums */
+#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT	0x1000000 /* Journal Async Commit */
 
 /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
 #ifndef _LINUX_EXT2_FS_H
fs/jbd2/recovery.c +117 -7

162 lines not on this page · raw message

fs/jbd2/journal.c +27 -0
Index: linux-2.6.20/fs/jbd2/journal.c
===================================================================
@@ -1268,6 +1268,33 @@ int jbd2_journal_set_features (journal_t
 	return 1;
 }
 
+/**
+ * int jbd2_journal_clear_features () - Clear a given journal feature in the superblock
+ * @journal: Journal to act on.
+ * @compat: bitmask of compatible features
+ * @ro: bitmask of features that force read-only mount
+ * @incompat: bitmask of incompatible features
+ *
+ * Clear a given journal feature as present on the
+ * superblock.  Returns true if the requested features could be reset.
+ *
+ */
+int jbd2_journal_clear_features (journal_t *journal, unsigned long compat,
+			  unsigned long ro, unsigned long incompat)
+{
+	journal_superblock_t *sb;
+
+	jbd_debug(1, "Clear features 0x%lx/0x%lx/0x%lx\n",
+		  compat, ro, incompat);
+
+	sb = journal->j_superblock;
+
+	sb->s_feature_compat    &= ~cpu_to_be32(compat);
+	sb->s_feature_ro_compat &= ~cpu_to_be32(ro);
+	sb->s_feature_incompat  &= ~cpu_to_be32(incompat);
+
+	return 1;
+}
 
 /**
  * int jbd2_journal_update_format () - Update on-disk journal structure.
lib/ext2fs/kernel-jbd.h +30 -3
Index: e2fsprogs-1.39/lib/ext2fs/kernel-jbd.h
===================================================================
@@ -108,7 +108,29 @@ typedef struct journal_header_s
 	__u32		h_sequence;
 } journal_header_t;
 
+/*
+ * Checksum types.
+ */
+#define JFS_CRC32_CHKSUM   1
+#define JFS_MD5_CHKSUM     2
+#define JFS_SHA1_CHKSUM    3
+
+#define JFS_CRC32_CHKSUM_SIZE 4
 
+#define JFS_CHECKSUM_BYTES (32 / sizeof(__u32))
+/*
+ * Commit block header for storing transactional checksums:
+ */
+struct commit_header
+{
+	__u32		h_magic;
+	__u32		h_blocktype;
+	__u32		h_sequence;
+	unsigned char   h_chksum_type;
+	unsigned char   h_chksum_size;
+	unsigned char   h_padding[2];
+	__u32		h_chksum[JFS_CHECKSUM_BYTES];
+};
 /* 
  * The block tag: used to describe a single buffer in the journal 
  */
@@ -194,12 +216,17 @@ typedef struct journal_superblock_s
 	((j)->j_format_version >= 2 &&					\
 	 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
 
-#define JFS_FEATURE_INCOMPAT_REVOKE	0x00000001
+#define JFS_FEATURE_COMPAT_CHECKSUM    0x00000001
+
+#define JFS_FEATURE_INCOMPAT_REVOKE		0x00000001
+/*#define JFS_FEATURE_INCOMPAT_64BIT             0x00000002*/
+#define JFS_FEATURE_INCOMPAT_ASYNC_COMMIT	0x00000004
 
 /* Features known to this kernel version: */
-#define JFS_KNOWN_COMPAT_FEATURES	0
+#define JFS_KNOWN_COMPAT_FEATURES	JFS_FEATURE_COMPAT_CHECKSUM
 #define JFS_KNOWN_ROCOMPAT_FEATURES	0
-#define JFS_KNOWN_INCOMPAT_FEATURES	JFS_FEATURE_INCOMPAT_REVOKE
+#define JFS_KNOWN_INCOMPAT_FEATURES	(JFS_FEATURE_INCOMPAT_REVOKE| \
+					JFS_FEATURE_INCOMPAT_ASYNC_COMMIT)
 
 #ifdef __KERNEL__
 
lib/ext2fs/crc32.h new file +28 -0
Index: e2fsprogs-1.39/lib/ext2fs/crc32.h
===================================================================
@@ -0,0 +1,28 @@
+/*
+ * crc32.h
+ * See crc32.c for license and changes
+ */
+#ifndef _LINUX_CRC32_H
+#define _LINUX_CRC32_H
+
+typedef unsigned int u32;
+typedef unsigned char u8;
+
+extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len);
+extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len);
+extern u32 bitreverse(u32 in);
+
+#define crc32(seed, data, length)  crc32_le(seed, (unsigned char const *)data, length)
+
+/*
+ * Helpers for hash table generation of ethernet nics:
+ *
+ * Ethernet sends the least significant bit of a byte first, thus crc32_le
+ * is used. The output of crc32_le is bit reversed [most significant bit
+ * is in bit nr 0], thus it must be reversed before use. Except for
+ * nics that bit swap the result internally...
+ */
+#define ether_crc(length, data)    bitreverse(crc32_le(~0, data, length))
+#define ether_crc_le(length, data) crc32_le(~0, data, length)
+
+#endif /* _LINUX_CRC32_H */
lib/ext2fs/crc32.c new file +519 -0

519 lines not on this page · raw message

lib/ext2fs/crc32defs.h new file +32 -0
Index: e2fsprogs-1.39/lib/ext2fs/crc32defs.h
===================================================================
@@ -0,0 +1,32 @@
+/*
+ * There are multiple 16-bit CRC polynomials in common use, but this is
+ * *the* standard CRC-32 polynomial, first popularized by Ethernet.
+ * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
+ */
+#define CRCPOLY_LE 0xedb88320
+#define CRCPOLY_BE 0x04c11db7
+
+/* How many bits at a time to use.  Requires a table of 4<<CRC_xx_BITS bytes. */
+/* For less performance-sensitive, use 4 */
+#ifndef CRC_LE_BITS
+# define CRC_LE_BITS 8
+#endif
+#ifndef CRC_BE_BITS
+# define CRC_BE_BITS 8
+#endif
+
+/*
+ * Little-endian CRC computation.  Used with serial bit streams sent
+ * lsbit-first.  Be sure to use cpu_to_le32() to append the computed CRC.
+ */
+#if CRC_LE_BITS > 8 || CRC_LE_BITS < 1 || CRC_LE_BITS & CRC_LE_BITS-1
+# error CRC_LE_BITS must be a power of 2 between 1 and 8
+#endif
+
+/*
+ * Big-endian CRC computation.  Used with serial bit streams sent
+ * msbit-first.  Be sure to use cpu_to_be32() to append the computed CRC.
+ */
+#if CRC_BE_BITS > 8 || CRC_BE_BITS < 1 || CRC_BE_BITS & CRC_BE_BITS-1
+# error CRC_BE_BITS must be a power of 2 between 1 and 8
+#endif
lib/ext2fs/crc32table.h new file +135 -0

135 lines not on this page · raw message

lib/ext2fs/crc32_user.h new file +45 -0

45 lines not on this page · raw message

lib/ext2fs/Makefile.in +4 -0
Index: e2fsprogs-1.39/lib/ext2fs/Makefile.in
===================================================================
@@ -68,6 +68,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_O
 	unlink.o \
 	valid_blk.o \
 	version.o \
+	crc32.o \
 	crc16.o \
 	csum.o
 
@@ -141,6 +142,7 @@ SRCS= ext2_err.c \
 	$(srcdir)/tst_types.c \
 	$(srcdir)/tst_iscan.c \
 	$(srcdir)/tst_csum.c \
+	$(srcdir)/crc32.c \
 	$(srcdir)/crc16.c \
 	$(srcdir)/csum.c
 
@@ -382,6 +384,8 @@ cmp_bitmaps.o: $(srcdir)/cmp_bitmaps.c $
  $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/bitops.h
 crc16.o: $(srcdir)/crc16.c $(srcdir)/ext2_fs.h $(srcdir)/crc16.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h
+crc32.o: $(srcdir)/crc32.c $(srcdir)/ext2_fs.h $(srcdir)/crc16.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h
 csum.o: $(srcdir)/csum.c $(srcdir)/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h
 dblist.o: $(srcdir)/dblist.c $(srcdir)/ext2_fs.h \
e2fsck/recovery.c +125 -7

170 lines not on this page · raw message

lib/ext2fs/tst_csum.c +53 -19

97 lines not on this page · raw message

#1 lore raw

say, at mount time we fund transaction logged. this means part of it can be on a disk. what do we do if transaction in the journal is found with wrong checksum? leave partial transaction in-place?

thanks, Alex

Quoted 18 lines · Girish Shilamkar

Hi,
The journal checksums patches for ext4 and e2fsprogs sent on 30th May
had run into problems on big-endian machines. I have made the required changes. The major updates are:
1. Checksum was written in little endian format in the commit header, changed it to big-endian.
2. The crc32 code ported to userspace (which is used by e2fsprogs) had problem with #ifdef, fixed that.
3. The crc32 user space code used i386 assembly code for swabbing changed it to generic one.
4. Removed various #includes, which caused compilation errors on ppc machine.

Any comments/suggestions are always welcome.

Thanks,
Girish.

#2 lore raw
Quoted 2 lines · Alex Tomas

say, at mount time we fund transaction logged. this means part of it can be on a disk.

I am not sure I understand this completely. Still I hope the following answers your question.

Quoted 3 lines

what do we do if transaction in the journal is found with wrong checksum? leave partial transaction in-place?

The sanity of the transaction is checked in PASS_SCAN. And if checksum is found to be incorrect for nth transaction then last transaction which is written to disk is (n - 1).

Regards,
Girish

#3 lore raw
Quoted 6 lines · Girish Shilamkar
Quoted 2 lines · Alex Tomas

say, at mount time we fund transaction logged. this means part of it can be on a disk.

I am not sure I understand this completely. Still I hope the following answers your question.

I _think_ Alex is asking "what happens if during a transaction undergoing checkpoint of blocks to filesystem (not the last one in the journal) is interrupted by a crash and upon restart the partially-checkpointed transaction is found to have a checksum error?"

Quoted 6 lines
Quoted 2 lines

what do we do if transaction in the journal is found with wrong checksum? leave partial transaction in-place?

The sanity of the transaction is checked in PASS_SCAN. And if checksum is found to be incorrect for nth transaction then last transaction which is written to disk is (n - 1).

The recovery.c code (AFAIK) does not do replay for any transaction that does not have a valid checksum, or transactions beyond that. If the bad transaction had already started chekpoint (i.e. isn't the last committed transaction) then the journal _should_ return an error up to the filesystem, so it can call ext4_error() at startup. For e2fsck (which normally does journal replay & recovery) it can do a full filesystem check at this point.

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.

#4 lore raw
Quoted 4 lines · Andreas Dilger

I _think_ Alex is asking "what happens if during a transaction undergoing checkpoint of blocks to filesystem (not the last one in the journal) is interrupted by a crash and upon restart the partially-checkpointed transaction is found to have a checksum error?"

yup, thanks for clarification.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

what do we do if transaction in the journal is found with wrong checksum? leave partial transaction in-place?

The sanity of the transaction is checked in PASS_SCAN. And if checksum is found to be incorrect for nth transaction then last transaction which is written to disk is (n - 1).

Quoted 7 lines

The recovery.c code (AFAIK) does not do replay for any transaction that does not have a valid checksum, or transactions beyond that. If the bad transaction had already started chekpoint (i.e. isn't the last committed transaction) then the journal _should_ return an error up to the filesystem, so it can call ext4_error() at startup. For e2fsck (which normally does journal replay & recovery) it can do a full filesystem check at this point.

hmm. it actually can be last transaction (following no activity?)

thanks, Alex

#5 lore raw
Quoted 22 lines · Alex Tomas
Quoted 4 lines · Andreas Dilger

I _think_ Alex is asking "what happens if during a transaction undergoing checkpoint of blocks to filesystem (not the last one in the journal) is interrupted by a crash and upon restart the partially-checkpointed transaction is found to have a checksum error?"

yup, thanks for clarification.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

what do we do if transaction in the journal is found with wrong checksum? leave partial transaction in-place?

The sanity of the transaction is checked in PASS_SCAN. And if checksum is found to be incorrect for nth transaction then last transaction which is written to disk is (n - 1).

Quoted 7 lines

The recovery.c code (AFAIK) does not do replay for any transaction that does not have a valid checksum, or transactions beyond that. If the bad transaction had already started chekpoint (i.e. isn't the last committed transaction) then the journal _should_ return an error up to the filesystem, so it can call ext4_error() at startup. For e2fsck (which normally does journal replay & recovery) it can do a full filesystem check at this point.

Quoted 1 line

hmm. it actually can be last transaction (following no activity?)

The current implementation is that if you are running with sync commits (i.e. the current 2-phase write {data blocks} {wait} {commit block} {wait}) and you detect a checksum error in the last transaction this SHOULD result in the filesystem being marked in error (I haven't verified this is in the most recent version of the code). This is what JBD_FEATURE_COMPAT_CHECKSUM does - it only adds checksums to the commit blocks.

However, in the case of async commits (JBD_FEATURE_INCOMPAT_ASYNC_COMMIT
- write {data blocks} {commit block} {wait}, which is what gives the performance gain) there isn't any way to tell the difference between a checksum error in the last transaction and the case of an interrupted commit. In the case of an interrupted commit there would not have been any checkpointing into the filesystem yet, so this case shouldn't matter.

This leaves only the "last transaction, finished async commit, started checkpoint, crash, corruption, checksum error" case. I agree this could cause data corruption. One possibility is to limit the corruption to at most a single block by adding checksums to the transaction descriptor blocks (which already hold the transaction ID to verify they are not stale) and cover the block numbers. This would seem to be the only place that we could get error "fan out" and then we would limit the corruption to the block(s) that were actually corrupted. This wouldn't be any different than having random corruption of disk blocks inside the fs. This would probably be a separate INCOMPAT flag.

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.