Btrfs: Make sure i_nlink doesn't hit zero too soon during log replay
authorChris Mason <chris.mason@oracle.com>
Tue, 24 Mar 2009 14:24:13 +0000 (10:24 -0400)
committerChris Mason <chris.mason@oracle.com>
Tue, 24 Mar 2009 20:14:51 +0000 (16:14 -0400)
During log replay, inodes are copied from the log to the main filesystem
btrees.  Sometimes they have a zero link count in the log but they actually
gain links during the replay or have some in the main btree.

This patch updates the link count to be at least one after copying the
inode out of the log.  This makes sure the inode is deleted during an
iput while the rest of the replay code is still working on it.

The log replay has fixup code to make sure that link counts are correct
at the end of the replay, so we could use any non-zero number here and
it would work fine.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/tree-log.c

index a93934fc93bd2885846d51a222b3ee7fdf1d8364..405439ca4c452569744617153ce494f93b7244ee 100644 (file)
@@ -1532,6 +1532,17 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
                                        root, inode, inode->i_size,
                                        BTRFS_EXTENT_DATA_KEY);
                                BUG_ON(ret);
+
+                               /* if the nlink count is zero here, the iput
+                                * will free the inode.  We bump it to make
+                                * sure it doesn't get freed until the link
+                                * count fixup is done
+                                */
+                               if (inode->i_nlink == 0) {
+                                       btrfs_inc_nlink(inode);
+                                       btrfs_update_inode(wc->trans,
+                                                          root, inode);
+                               }
                                iput(inode);
                        }
                        ret = link_to_fixup_dir(wc->trans, root,