]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
nilfs2: use checkpoint number instead of timestamp to select super block
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Sat, 1 May 2010 02:54:21 +0000 (11:54 +0900)
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Mon, 10 May 2010 02:32:32 +0000 (11:32 +0900)
Nilfs maintains two super blocks, and selects the new one on mount
time if they both have valid checksums and their timestamps differ.

However, this has potential for mis-selection since the system clock
may be rewinded and the resolution of the timestamps is not high.

Usually this doesn't become an issue because both super blocks are
updated at the same time when the file system is unmounted.  Even if
the file system wasn't unmounted cleanly, the roll-forward recovery
will find the proper log which stores the latest super root.  Thus,
the issue can appear only if update of one super block fails and the
clock happens to be rewinded.

This fixes the issue by using checkpoint numbers instead of timestamps
to pick the super block storing the location of the latest log.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
fs/nilfs2/the_nilfs.c

index 33871f7e4f013b2113547a4de2639685be007aae..a756168a21c21e00cdf096f2f1a99b5719e313f6 100644 (file)
@@ -486,11 +486,15 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
                printk(KERN_WARNING
                       "NILFS warning: unable to read secondary superblock\n");
 
+       /*
+        * Compare two super blocks and set 1 in swp if the secondary
+        * super block is valid and newer.  Otherwise, set 0 in swp.
+        */
        valid[0] = nilfs_valid_sb(sbp[0]);
        valid[1] = nilfs_valid_sb(sbp[1]);
-       swp = valid[1] &&
-               (!valid[0] ||
-                le64_to_cpu(sbp[1]->s_wtime) > le64_to_cpu(sbp[0]->s_wtime));
+       swp = valid[1] && (!valid[0] ||
+                          le64_to_cpu(sbp[1]->s_last_cno) >
+                          le64_to_cpu(sbp[0]->s_last_cno));
 
        if (valid[swp] && nilfs_sb2_bad_offset(sbp[swp], sb2off)) {
                brelse(sbh[1]);