Re: [EXT4 set 8][PATCH 1/1]Add journal checksums

2007-08-06 Thread Mingming Cao
On Wed, 2007-08-01 at 12:34 +0530, Girish Shilamkar wrote:
 On Wed, 2007-07-11 at 17:16 +0530, Girish Shilamkar wrote:
 
  I will make the changes and send an incremental patch.
  
 Hi,
   I have made the changes and attached the incremental patch as per the
 review.

Thanks,

I merged your changes to ext4-patch-queue.

Mingming

-
To unsubscribe from this list: send the line unsubscribe linux-fsdevel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [EXT4 set 8][PATCH 1/1]Add journal checksums

2007-08-01 Thread Girish Shilamkar
On Wed, 2007-07-11 at 17:16 +0530, Girish Shilamkar wrote:

 I will make the changes and send an incremental patch.
 
Hi,
I have made the changes and attached the incremental patch as per the
review.

This is the actual changelog which was missing in the original patch.

--
The journal checksum feature adds two new flags i.e 
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT and JBD2_FEATURE_COMPAT_CHECKSUM.

JBD2_FEATURE_CHECKSUM flag indicates that the commit block contains the
checksum for the blocks described by the descriptor blocks.
Due to checksums, writing of the commit record no longer needs to be
synchronous. Now commit record can be sent to disk without waiting for
descriptor blocks to be written to disk. This behavior is controlled
using JBD2_FEATURE_ASYNC_COMMIT flag. Older kernels/e2fsck should not be
able to recover the journal with _ASYNC_COMMIT hence it is made
incompat.
The commit header has been extended to hold the checksum along with the
type of the checksum.

For recovery in pass scan checksums are verified to ensure the sanity
and completeness(in case of _ASYNC_COMMIT) of every transaction.
-

Thanks  Regards,
Girish. 

Signed-off-by: Andreas Dilger [EMAIL PROTECTED]
Signed-off-by: Girish Shilamkar [EMAIL PROTECTED]

Index: linux-2.6.22/Documentation/filesystems/ext4.txt
===
--- linux-2.6.22.orig/Documentation/filesystems/ext4.txt
+++ linux-2.6.22/Documentation/filesystems/ext4.txt
@@ -89,6 +89,16 @@ When mounting an ext4 filesystem, the fo
 extents			ext4 will use extents to address file data.  The
 			file system will no longer be mountable by ext3.
 
+journal_checksum	Enable checksumming of the journal transactions.
+			This will allow the recovery code in e2fsck and the
+			kernel to detect corruption in the kernel.  It is a 
+			compatible change and will be ignored by older kernels.
+
+journal_async_commit	Commit block can be written to disk without waiting 
+			for descriptor blocks. If enabled older kernels cannot
+			mount the device. This will enable 'journal_checksum'
+			internally.
+
 journal=update		Update the ext4 file system's journal to the current
 			format.
 
Index: linux-2.6.22/fs/Kconfig
===
--- linux-2.6.22.orig/fs/Kconfig
+++ linux-2.6.22/fs/Kconfig
@@ -235,6 +235,7 @@ config JBD_DEBUG
 
 config JBD2
 	tristate
+	select CRC32
 	help
 	  This is a generic journaling layer for block devices that support
 	  both 32-bit and 64-bit block numbers.  It is currently used by
Index: linux-2.6.22/fs/jbd2/commit.c
===
--- linux-2.6.22.orig/fs/jbd2/commit.c
+++ linux-2.6.22/fs/jbd2/commit.c
@@ -108,8 +108,9 @@ static int journal_submit_commit_record(
 	__u32 crc32_sum)
 {
 	struct journal_head *descriptor;
+	struct commit_header *tmp;
 	struct buffer_head *bh;
-	int i, ret;
+	int ret;
 	int barrier_done = 0;
 
 	if (is_journal_aborted(journal))
@@ -121,19 +122,16 @@ static int journal_submit_commit_record(
 
 	bh = jh2bh(descriptor);
 
-	for (i = 0; i  bh-b_size; i += 512) {
-		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] 	= cpu_to_be32(crc32_sum);
-		}
+	tmp = (struct commit_header *)bh-b_data;
+	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] 	= cpu_to_be32(crc32_sum);
 	}
 
 	JBUFFER_TRACE(descriptor, submit commit block);
@@ -185,8 +183,8 @@ static int journal_wait_on_commit_record
 {
 	int ret = 0;
 
-	if (buffer_locked(bh))
-		wait_on_buffer(bh);
+	clear_buffer_dirty(bh);
+	wait_on_buffer(bh);
 
 	if (unlikely(!buffer_uptodate(bh)))
 		ret = -EIO;
Index: linux-2.6.22/fs/jbd2/recovery.c
===
--- linux-2.6.22.orig/fs/jbd2/recovery.c
+++ linux-2.6.22/fs/jbd2/recovery.c
@@ -318,14 +318,14 @@ static inline unsigned long long read_ta
 }
 
 /*
- * cal_chksums calculates the checksums for the blocks described in the
+ * calc_chksums calculates the checksums for the blocks described in the
  * descriptor block.
  */
-static int cal_chksums(journal_t *journal, struct buffer_head *bh,
-		   unsigned long *next_log_block, __u32 *crc32_sum)
+static int calc_chksums(journal_t *journal, struct buffer_head *bh,
+			unsigned long *next_log_block, 

Re: [EXT4 set 8][PATCH 1/1]Add journal checksums

2007-07-11 Thread Andrew Morton
On Sun, 01 Jul 2007 03:38:25 -0400 Mingming Cao [EMAIL PROTECTED] wrote:

 Journal checksum feature has been added to detect corruption of journal.

That was brief.  No description of what it does, how it does it, why it
does it, how one operates it, why (or why not) one would choose to enable
it nor of the costs of enabling it.

 Signed-off-by: Andreas Dilger [EMAIL PROTECTED]
 Signed-off-by: Girish Shilamkar [EMAIL PROTECTED]
 Signed-off-by: Dave Kleikamp [EMAIL PROTECTED]
 
 diff -Nurp linux024/fs/ext4/super.c linux/fs/ext4/super.c
 --- linux024/fs/ext4/super.c  2007-06-25 16:19:24.0 -0500
 +++ linux/fs/ext4/super.c 2007-06-26 08:35:16.0 -0500
 @@ -721,6 +721,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,

A new user-visible feature should be accompanied by an update to
Documentation/filesystems/ext4.txt?

   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,
 @@ -760,6 +761,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},

What's journal_async_commit?

   {Opt_abort, abort},
   {Opt_data_journal, data=journal},
   {Opt_data_ordered, data=ordered},
 @@ -948,6 +951,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;
 @@ -1817,6 +1827,21 @@ static int ext4_fill_super (struct super
   goto failed_mount4;
   }
  
 + 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);
 + }

Some discussion of the forward- and backward- compatibility design would be
appropriate.  Also a description of whether and how fsck can be used to fix
up these feature flags.

   /* We have now updated the journal if required, so we can
* validate the data journaling mode. */
   switch (test_opt(sb, DATA_FLAGS)) {
 diff -Nurp linux024/fs/jbd2/commit.c linux/fs/jbd2/commit.c
 --- linux024/fs/jbd2/commit.c 2007-06-25 16:19:25.0 -0500
 +++ linux/fs/jbd2/commit.c2007-06-26 08:40:03.0 -0500
 @@ -21,6 +21,7 @@
  #include linux/mm.h
  #include linux/pagemap.h
  #include linux/jiffies.h
 +#include linux/crc32.h

I think we just broke CONFIG_EXT4=y, CONFIG_CRC32=n builds.

  /*
   * 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 

Re: [EXT4 set 8][PATCH 1/1]Add journal checksums

2007-07-11 Thread Girish Shilamkar
On Tue, 2007-07-10 at 23:16 -0700, Andrew Morton wrote:
 On Sun, 01 Jul 2007 03:38:25 -0400 Mingming Cao [EMAIL PROTECTED] wrote:
 
  Journal checksum feature has been added to detect corruption of journal.
 
 That was brief.  No description of what it does, how it does it, why it
 does it, how one operates it, why (or why not) one would choose to enable
 it nor of the costs of enabling it.
Somehow the description was lost due to the way the original patchset
was sent to ext4 list.

Here is the original description:

The journal checksum feature adds two new flags i.e 
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT and JBD2_FEATURE_COMPAT_CHECKSUM.

JBD2_FEATURE_CHECKSUM flag indicates that the commit block contains the
checksum for the blocks described by the descriptor blocks.
Due to checksums, writing of the commit record no longer needs to be
synchronous. Now commit record can be sent to disk without waiting for
descriptor blocks to be written to disk. This behavior is controlled
using JBD2_FEATURE_ASYNC_COMMIT flag. Older kernels/e2fsck should not be
able to recover the journal with _ASYNC_COMMIT hence it is made
incompat.
The commit header has been extended to hold the checksum along with the
type of the checksum.

For recovery in pass scan checksums are verified to ensure the sanity
and completeness(in case of _ASYNC_COMMIT) of every transaction.


 
  Signed-off-by: Andreas Dilger [EMAIL PROTECTED]
  Signed-off-by: Girish Shilamkar [EMAIL PROTECTED]
  Signed-off-by: Dave Kleikamp [EMAIL PROTECTED]
  
  diff -Nurp linux024/fs/ext4/super.c linux/fs/ext4/super.c
  --- linux024/fs/ext4/super.c2007-06-25 16:19:24.0 -0500
  +++ linux/fs/ext4/super.c   2007-06-26 08:35:16.0 -0500
  @@ -721,6 +721,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,
 
 A new user-visible feature should be accompanied by an update to
 Documentation/filesystems/ext4.txt?
Ok.

  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,
  @@ -760,6 +761,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},
 
 What's journal_async_commit?
I hope the description has answered this question.

  {Opt_abort, abort},
  {Opt_data_journal, data=journal},
  {Opt_data_ordered, data=ordered},
  @@ -948,6 +951,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;
  @@ -1817,6 +1827,21 @@ static int ext4_fill_super (struct super
  goto failed_mount4;
  }
   
  +   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);
  +   }
 
 Some discussion of the forward- and backward- compatibility design would be
 appropriate.  Also a description of whether and how fsck can be used to fix
 up these feature flags.
  /* We have now updated the journal if required, so we can
   * validate the data journaling mode. */
  switch (test_opt(sb, DATA_FLAGS)) {
  diff -Nurp linux024/fs/jbd2/commit.c linux/fs/jbd2/commit.c
  --- linux024/fs/jbd2/commit.c   2007-06-25 16:19:25.0 -0500
  +++ linux/fs/jbd2/commit.c  2007-06-26 08:40:03.0 -0500
  @@ -21,6 +21,7 @@
   #include linux/mm.h
   #include linux/pagemap.h
   #include linux/jiffies.h
  +#include linux/crc32.h
 
 I think we just broke 

Re: [EXT4 set 8][PATCH 1/1]Add journal checksums

2007-07-11 Thread Andreas Dilger
On Jul 11, 2007  17:16 +0530, Girish Shilamkar wrote:
   + 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);
   + }
  
  Some discussion of the forward- and backward- compatibility design would be
  appropriate.  Also a description of whether and how fsck can be used to fix
  up these feature flags.

It is forward  backward compatible to enable COMPAT_CHECKSUM.  That just
means the commit blocks will have checksums in them, but older kernels
will just ignore them.  Hmm, I suppose there might be an issue with upgrade,
downgrade, upgrade in that the commit blocks would not have checksums
even though the superblock says they will...

Does that mean we should accept a checksum == 0 as being valid (which
is not very nice, given that 0 is an oft-hit bad value), or that we need
a flag in every commit block which indicates if it actually has a checksum?

The INCOMPAT_ASYNC_COMMIT can't be handled safely by older kernels, since
they would assume commit block == complete transaction, which isn't
true if the commit block didn't wait for the rest of the blocks to make
it to the disk.

I don't think e2fsck can be used to individually clean up the feature flags,
but it is always possible to remove and recreate the journal...

   - /* AKPM: buglet - add `i' to tmp! */
  
  Damn.  After, what, seven years, someone actually fixed it?
  
 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]= cpu_to_be32(crc32_sum);
   + }
 }
  
  And in doing so, changed the on-disk format of the journal commit blocks.
  
  Surely this was worth a mention in the changelog, if not a standalone patch?
  
  I don't think this is worth doing, really.  Why not just leave the format
  as it was, take the loop out and run this code once rather than eight
  times?

Well, we aren't using the rest of the commit block in any case.  I think
the original intention was that we'd get 8 copies of the commit block so
we would be sure to get a good one.

I don't know whether we'd rather have 8 copies of the commit block, or
more potential to expand the commit block?  I don't personally have any
preference, since the checksum should be a more robust way of checking
validity than having multiple copies, so we may as well remove the loop
and stick with a single copy for now.

   @@ -328,6 +360,7 @@ static int do_one_pass(journal_t *journa
 unsigned intsequence;
 int blocktype;
 int tag_bytes = journal_tag_bytes(journal);
   + __u32   crc32_sum = ~0; /* Transactional Checksums */
  
  We normally use __u32 for visible-to-userspace stuff.  Kernel code would
  use plain old u32.
 Ok.

Since the checksum is saved to disk, it seems more appropriate to use __u32
or maybe even __be32, though I'm not sure if the crc32 functions do that
correctly or not.

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

-
To unsubscribe from this list: send the line unsubscribe linux-fsdevel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [EXT4 set 8][PATCH 1/1]Add journal checksums

2007-07-11 Thread Andrew Morton
On Wed, 11 Jul 2007 07:01:08 -0600 Andreas Dilger [EMAIL PROTECTED] wrote:

-   /* AKPM: buglet - add `i' to tmp! */
   
   Damn.  After, what, seven years, someone actually fixed it?
   
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]= 
cpu_to_be32(crc32_sum);
+   }
}
   
   And in doing so, changed the on-disk format of the journal commit blocks.
   
   Surely this was worth a mention in the changelog, if not a standalone 
   patch?
   
   I don't think this is worth doing, really.  Why not just leave the format
   as it was, take the loop out and run this code once rather than eight
   times?
 
 Well, we aren't using the rest of the commit block in any case.  I think
 the original intention was that we'd get 8 copies of the commit block so
 we would be sure to get a good one.
 
 I don't know whether we'd rather have 8 copies of the commit block, or
 more potential to expand the commit block?  I don't personally have any
 preference, since the checksum should be a more robust way of checking
 validity than having multiple copies, so we may as well remove the loop
 and stick with a single copy for now.

We've never altered any commit block sectors apart from the zeroeth one
(eight times) due to the above bug.  So I'd suggest that we should formalise
the old bug and leave the format as-is.  That'll leave lots of space spare in
the commit block.
-
To unsubscribe from this list: send the line unsubscribe linux-fsdevel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[EXT4 set 8][PATCH 1/1]Add journal checksums

2007-07-01 Thread Mingming Cao
Journal checksum feature has been added to detect corruption of journal.

Signed-off-by: Andreas Dilger [EMAIL PROTECTED]
Signed-off-by: Girish Shilamkar [EMAIL PROTECTED]
Signed-off-by: Dave Kleikamp [EMAIL PROTECTED]

diff -Nurp linux024/fs/ext4/super.c linux/fs/ext4/super.c
--- linux024/fs/ext4/super.c2007-06-25 16:19:24.0 -0500
+++ linux/fs/ext4/super.c   2007-06-26 08:35:16.0 -0500
@@ -721,6 +721,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,
@@ -760,6 +761,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},
@@ -948,6 +951,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;
@@ -1817,6 +1827,21 @@ static int ext4_fill_super (struct super
goto failed_mount4;
}
 
+   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)) {
diff -Nurp linux024/fs/jbd2/commit.c linux/fs/jbd2/commit.c
--- linux024/fs/jbd2/commit.c   2007-06-25 16:19:25.0 -0500
+++ linux/fs/jbd2/commit.c  2007-06-26 08:40:03.0 -0500
@@ -21,6 +21,7 @@
 #include linux/mm.h
 #include linux/pagemap.h
 #include linux/jiffies.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,
+