Skip to content

Commit a74ac32

Browse files
committed
Btrfs: Make sure i_nlink doesn't hit zero too soon during log replay
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>
1 parent a4b6e07 commit a74ac32

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/btrfs/tree-log.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,17 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
15321532
root, inode, inode->i_size,
15331533
BTRFS_EXTENT_DATA_KEY);
15341534
BUG_ON(ret);
1535+
1536+
/* if the nlink count is zero here, the iput
1537+
* will free the inode. We bump it to make
1538+
* sure it doesn't get freed until the link
1539+
* count fixup is done
1540+
*/
1541+
if (inode->i_nlink == 0) {
1542+
btrfs_inc_nlink(inode);
1543+
btrfs_update_inode(wc->trans,
1544+
root, inode);
1545+
}
15351546
iput(inode);
15361547
}
15371548
ret = link_to_fixup_dir(wc->trans, root,

0 commit comments

Comments
 (0)