Skip to contentSkip to conversation

fs/9p: fix inode nlink accounting

PATCH New Eric Van Hensbergen 1 participant 1 message Jan 8, 2024 9P file system

lore
Share & tools
lore

Eric Van Hensbergen

author maintainer
#0 lore raw

PATCH v2 1/1 fs/9p: fix inode nlink accounting

I was running some regressions and noticed a (race-y) kernel warning that happens when nlink becomes less than zero. Looking through the code it looks like we aren't good about protecting the inode lock when manipulating nlink and some code that was added several years ago to protect against bugs in underlying file systems nlink handling didn't look quite right either. I took a look at what NFS was doing and tried to follow similar approaches in the 9p code.

---
Changes in v2:
- add wrappers
- fix checkpatch errors
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 fs/9p/v9fs_vfs.h       |  1 +
 fs/9p/vfs_inode.c      | 49 +++++++++++++++++++++++++++++++++++--------------
 fs/9p/vfs_inode_dotl.c |  2 +-
 3 files changed, 37 insertions(+), 15 deletions(-)
fs/9p/v9fs_vfs.h +1 -0
index 731e3d14b67d..6019909445d4 100644
@@ -37,6 +37,7 @@ extern const struct file_operations v9fs_dir_operations_dotl;
 extern const struct dentry_operations v9fs_dentry_operations;
 extern const struct dentry_operations v9fs_cached_dentry_operations;
 extern struct kmem_cache *v9fs_inode_cache;
+extern void v9fs_inc_nlink(struct inode *inode);
 
 struct inode *v9fs_alloc_inode(struct super_block *sb);
 void v9fs_free_inode(struct inode *inode);
fs/9p/vfs_inode.c +35 -14

87 lines not on this page · raw message

fs/9p/vfs_inode_dotl.c +1 -1
index c7319af2f471..fe0c41d042a1 100644
@@ -427,7 +427,7 @@ static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap,
 		v9fs_set_create_acl(inode, fid, dacl, pacl);
 		d_instantiate(dentry, inode);
 	}
-	inc_nlink(dir);
+	v9fs_inc_nlink(dir);
 	v9fs_invalidate_inode_attr(dir);
 error:
 	p9_fid_put(fid);

---
base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a
change-id: 20240107-fix-nlink-handling-3c0646f5d927

Best regards,

Signature · 1 line
Eric Van Hensbergen <[email protected]>