Skip to contentSkip to conversation

Btrfs: set the i_nlink to 2 for an initial dir inode

PATCH In review Jeff Liu 4 participants 6 messages Nov 28, 2011 – Nov 30, 2011 Btrfs file system

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

PATCH 2/2 Btrfs: set the i_nlink to 2 for an initial dir inode

For an initial dir inode, stat(1) show it links as 1, IMHO it should be 2 by default.

---
 fs/btrfs/inode.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/btrfs/inode.c +0 -0
index 116ab67..92b3cb9 100644
@@ -4734,6 +4734,7 @@ static int btrfs_mkdir(struct inode *dir, struct

dentry *dentry, int mode)
inode->i_op = &btrfs_dir_inode_operations; inode->i_fop = &btrfs_dir_file_operations;

+ set_nlink(inode, 2);
btrfs_i_size_write(inode, 0);
err = btrfs_update_inode(trans, root, inode); if (err)

Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 2 lines · Jeff Liu

For an initial dir inode, stat(1) show it links as 1, IMHO it should be 2 by default.

Yes, this is correct for directories. And newly created subvolumes should have nlink == 2 as well, can you please add it to your patch? (I have tested your patch + the proposed change.)

Thanks,
david

author
#2 lore raw
In reply to Jeff Liu

Please ignore this patch for now, it can cause the file system corrupted and failed to mount again, sorry for the noise!

-Jeff

Quoted 22 lines · Jeff Liu

For an initial dir inode, stat(1) show it links as 1, IMHO it should be 2 by default.

---
 fs/btrfs/inode.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/btrfs/inode.c +1 -0
index 116ab67..92b3cb9 100644
@@ -4734,6 +4734,7 @@ static int btrfs_mkdir(struct inode *dir, struct
 dentry *dentry, int mode)
 	inode->i_op = &btrfs_dir_inode_operations;
 	inode->i_fop = &btrfs_dir_file_operations;
 
+	set_nlink(inode, 2);
 	btrfs_i_size_write(inode, 0);
 	err = btrfs_update_inode(trans, root, inode);

if (err)

#3 lore raw
Quoted 2 lines · Jeff Liu

Please ignore this patch for now, it can cause the file system corrupted and failed to mount again, sorry for the noise!

Directories always have a link count of 1 in btrfs. This tells find not to use the link count as the count of subdirectories in the directory.

-chris

#4 lore raw
Quoted 6 lines · Chris Mason
Quoted 2 lines · Jeff Liu

Please ignore this patch for now, it can cause the file system corrupted and failed to mount again, sorry for the noise!

Directories always have a link count of 1 in btrfs. This tells find not to use the link count as the count of subdirectories in the directory.

I'm surprised.

Now I see why my thread "Creation of pseudo items leads to (seemingly) duplicate inodes (BUG inside)" suffered from little attention :-)

-Jan

author
#5 lore raw
In reply to Chris Mason
Quoted 6 lines · Chris Mason
Quoted 2 lines · Jeff Liu

Please ignore this patch for now, it can cause the file system corrupted and failed to mount again, sorry for the noise!

Directories always have a link count of 1 in btrfs. This tells find not to use the link count as the count of subdirectories in the directory.

Thank you for your clarification!

-Jeff

Quoted 6 lines

-chris
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html