fs/9p: simplify inode lookup operations
Eric Van Hensbergen
maintainerv2 cover fs/9p: simplify inode lookup operations
This patch series takes a pass on the inode lookup-related operations and attempts to simplify the code path, eliminating unnecessary and/or redundant code and/or protocol operations.
---
Changes in v2:
- Fixed whitespace issues
- Switched QID2INO to use BITS_PER_LONG macro
- Fixed some vestigial inconsistency in inode number assignment between legacy and .L
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Eric Van Hensbergen (8):
fs/9p: switch vfsmount to use v9fs_get_new_inode fs/9p: convert mkdir to use get_new_inode fs/9p: remove walk and inode allocation from symlink fs/9p: Eliminate redundant non-cache path in mknod fs/9p: Eliminate now unused v9fs_get_inode fs/9p: rework qid2ino logic
fs/9p: simplify iget to remove unnecessary paths fs/9p: fix dups even in uncached mode
fs/9p/v9fs.h | 31 ++------ fs/9p/v9fs_vfs.h | 11 ++- fs/9p/vfs_dir.c | 4 +- fs/9p/vfs_inode.c | 149 ++++++------------------------------- fs/9p/vfs_inode_dotl.c | 194 +++++++++---------------------------------------- fs/9p/vfs_super.c | 45 +----------- 6 files changed, 71 insertions(+), 363 deletions(-)
---
base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a
change-id: 20240103-ericvh-fix-cache-dups-f0925afbbd21
Best regards,
Signature · 1 line
Eric Van Hensbergen <[email protected]>
Eric Van Hensbergen
maintainerPATCH v2 1/8 fs/9p: switch vfsmount to use v9fs_get_new_inode
In the process of cleaning up inode number allocation, I noticed several functions which didn't use the standard helper allocators. This patch fixes the allocation in the mount entrypoint.
--- fs/9p/vfs_super.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-)
fs/9p/vfs_super.c +1 -28
@@ -110,7 +110,6 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,struct inode *inode =NULL ;struct dentry *root =NULL ;struct v9fs_session_info *v9ses =NULL ; -umode_t mode =0777 |S_ISVTX ;struct p9_fid *fid;int retval =0 ;
@@ -140,7 +139,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,else sb->s_d_op = &v9fs_dentry_operations; - inode =v9fs_get_inode (sb,S_IFDIR | mode,0 ); + inode =v9fs_get_new_inode_from_fid (v9ses, fid, sb);if (IS_ERR (inode)) { retval =PTR_ERR (inode); goto release_sb;
@@ -152,32 +151,6 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags, goto release_sb; } sb->s_root = root; -if (v9fs_proto_dotl (v9ses)) { -struct p9_stat_dotl *st =NULL ; - - st =p9_client_getattr_dotl (fid,P9_STATS_BASIC ); -if (IS_ERR (st)) { - retval =PTR_ERR (st); - goto release_sb; - } -d_inode (root)->i_ino =v9fs_qid2ino (&st->qid); -v9fs_stat2inode_dotl (st,d_inode (root),0 ); -kfree (st); - }else { -struct p9_wstat *st =NULL ; - - st =p9_client_stat (fid); -if (IS_ERR (st)) { - retval =PTR_ERR (st); - goto release_sb; - } - -d_inode (root)->i_ino =v9fs_qid2ino (&st->qid); -v9fs_stat2inode (st,d_inode (root), sb,0 ); - -p9stat_free (st); -kfree (st); - } retval =v9fs_get_acl (inode, fid);if (retval) goto release_sb;
Signature · 1 line
2.41.0
Eric Van Hensbergen
maintainerPATCH v2 2/8 fs/9p: convert mkdir to use get_new_inode
In reply to Eric Van Hensbergenmkdir had different code paths for inode creation, cache used the get_new_inode_from_fid helper, but non-cached used v9fs_get_inode. Collapsed into a single implementation across both as there should be no difference.
--- fs/9p/vfs_inode_dotl.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-)
fs/9p/vfs_inode_dotl.c +10 -25
@@ -401,32 +401,17 @@ static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap, }/* instantiate inode and assign the unopened fid to the dentry */ -if (v9ses->cache & (CACHE_META |CACHE_LOOSE )) { - inode =v9fs_get_new_inode_from_fid (v9ses, fid, dir->i_sb); -if (IS_ERR (inode)) { - err =PTR_ERR (inode); -p9_debug (P9_DEBUG_VFS ,"inode creation failed %d\n" , - err); - goto error; - } -v9fs_fid_add (dentry, &fid); -v9fs_set_create_acl (inode, fid, dacl, pacl); -d_instantiate (dentry, inode); - err =0 ; - }else { -/* -* Not in cached mode. No need to populate -* inode with stat. We need to get an inode -* so that we can set the acl with dentry -*/ - inode =v9fs_get_inode (dir->i_sb, mode,0 ); -if (IS_ERR (inode)) { - err =PTR_ERR (inode); - goto error; - } -v9fs_set_create_acl (inode, fid, dacl, pacl); -d_instantiate (dentry, inode); + inode =v9fs_get_new_inode_from_fid (v9ses, fid, dir->i_sb); +if (IS_ERR (inode)) { + err =PTR_ERR (inode); +p9_debug (P9_DEBUG_VFS ,"inode creation failed %d\n" , + err); + goto error; } +v9fs_fid_add (dentry, &fid); +v9fs_set_create_acl (inode, fid, dacl, pacl); +d_instantiate (dentry, inode); + err =0 ;inc_nlink (dir);v9fs_invalidate_inode_attr (dir); error:
Signature · 1 line
2.41.0
Eric Van Hensbergen
maintainerPATCH v2 3/8 fs/9p: remove walk and inode allocation from symlink
In reply to Eric Van HensbergenSymlink had a bunch of extra operations which essentially end up discarded. It was walking the fid to the new file and creating an inode for it, but those semantics are part of tsymlink. This did prepopulate the cache, but that also seems potentially unnecessary and frought with peril.
--- fs/9p/vfs_inode_dotl.c | 33 --------------------------------- 1 file changed, 33 deletions(-)
fs/9p/vfs_inode_dotl.c +0 -33
@@ -690,14 +690,11 @@ v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct inode *dir,kgid_t gid;const unsigned char *name;struct p9_qid qid; -struct inode *inode;struct p9_fid *dfid;struct p9_fid *fid =NULL ; -struct v9fs_session_info *v9ses; name = dentry->d_name.name;p9_debug (P9_DEBUG_VFS ,"%lu,%s,%s\n" , dir->i_ino, name, symname); - v9ses =v9fs_inode2v9ses (dir); dfid =v9fs_parent_fid (dentry);if (IS_ERR (dfid)) {
@@ -717,36 +714,6 @@ v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct inode *dir, }v9fs_invalidate_inode_attr (dir); -if (v9ses->cache & (CACHE_META |CACHE_LOOSE )) { -/* Now walk from the parent so we can get an unopened fid. */ - fid =p9_client_walk (dfid,1 , &name,1 ); -if (IS_ERR (fid)) { - err =PTR_ERR (fid); -p9_debug (P9_DEBUG_VFS ,"p9_client_walk failed %d\n" , - err); - goto error; - } - -/* instantiate inode and assign the unopened fid to dentry */ - inode =v9fs_get_new_inode_from_fid (v9ses, fid, dir->i_sb); -if (IS_ERR (inode)) { - err =PTR_ERR (inode); -p9_debug (P9_DEBUG_VFS ,"inode creation failed %d\n" , - err); - goto error; - } -v9fs_fid_add (dentry, &fid); -d_instantiate (dentry, inode); - err =0 ; - }else { -/* Not in cached mode. No need to populate inode with stat */ - inode =v9fs_get_inode (dir->i_sb,S_IFLNK ,0 ); -if (IS_ERR (inode)) { - err =PTR_ERR (inode); - goto error; - } -d_instantiate (dentry, inode); - } error:p9_fid_put (fid);
Signature · 1 line
2.41.0
Eric Van Hensbergen
maintainerPATCH v2 4/8 fs/9p: Eliminate redundant non-cache path in mknod
In reply to Eric Van HensbergenLike symlink, mknod had a seperate path with different inode allocation -- but this seems unnecessary, so eliminating this path.
--- fs/9p/vfs_inode_dotl.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-)
fs/9p/vfs_inode_dotl.c +10 -26
@@ -836,33 +836,17 @@ v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir, err); goto error; } - -/* instantiate inode and assign the unopened fid to the dentry */ -if (v9ses->cache & (CACHE_META |CACHE_LOOSE )) { - inode =v9fs_get_new_inode_from_fid (v9ses, fid, dir->i_sb); -if (IS_ERR (inode)) { - err =PTR_ERR (inode); -p9_debug (P9_DEBUG_VFS ,"inode creation failed %d\n" , - err); - goto error; - } -v9fs_set_create_acl (inode, fid, dacl, pacl); -v9fs_fid_add (dentry, &fid); -d_instantiate (dentry, inode); - err =0 ; - }else { -/* -* Not in cached mode. No need to populate inode with stat. -* socket syscall returns a fd, so we need instantiate -*/ - inode =v9fs_get_inode (dir->i_sb, mode, rdev); -if (IS_ERR (inode)) { - err =PTR_ERR (inode); - goto error; - } -v9fs_set_create_acl (inode, fid, dacl, pacl); -d_instantiate (dentry, inode); + inode =v9fs_get_new_inode_from_fid (v9ses, fid, dir->i_sb); +if (IS_ERR (inode)) { + err =PTR_ERR (inode); +p9_debug (P9_DEBUG_VFS ,"inode creation failed %d\n" , + err); + goto error; } +v9fs_set_create_acl (inode, fid, dacl, pacl); +v9fs_fid_add (dentry, &fid); +d_instantiate (dentry, inode); + err =0 ; error:p9_fid_put (fid);v9fs_put_acl (dacl, pacl);
Signature · 1 line
2.41.0
Eric Van Hensbergen
maintainerPATCH v2 5/8 fs/9p: Eliminate now unused v9fs_get_inode
In reply to Eric Van HensbergenNow with all inode allocation going through get_from_fid functions we can remove v9fs_get_inode and reduce us down to a single inode allocation path.
--- fs/9p/v9fs_vfs.h | 2 -- fs/9p/vfs_inode.c | 29 ----------------------------- 2 files changed, 31 deletions(-)
fs/9p/v9fs_vfs.h +0 -2
@@ -40,8 +40,6 @@ extern struct kmem_cache *v9fs_inode_cache;struct inode *v9fs_alloc_inode (struct super_block *sb);void v9fs_free_inode (struct inode *inode); -struct inode *v9fs_get_inode (struct super_block *sb,umode_t mode, -dev_t rdev);int v9fs_init_inode (struct v9fs_session_info *v9ses,struct inode *inode,umode_t mode,dev_t rdev);void v9fs_evict_inode (struct inode *inode);
fs/9p/vfs_inode.c +0 -29
@@ -333,35 +333,6 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses, } -/** -* v9fs_get_inode - helper function to setup an inode -* @sb: superblock -* @mode: mode to setup inode with -* @rdev: The device numbers to set -*/ - -struct inode *v9fs_get_inode (struct super_block *sb,umode_t mode,dev_t rdev) -{ -int err; -struct inode *inode; -struct v9fs_session_info *v9ses = sb->s_fs_info; - -p9_debug (P9_DEBUG_VFS ,"super block: %p mode: %ho\n" , sb, mode); - - inode =new_inode (sb); -if (!inode) { -pr_warn ("%s (%d): Problem allocating inode\n" , - __func__,task_pid_nr (current)); -return ERR_PTR (-ENOMEM ); - } - err =v9fs_init_inode (v9ses, inode, mode, rdev); -if (err) { -iput (inode); -return ERR_PTR (err); - } -return inode; -} -/** * v9fs_evict_inode - Remove an inode from the inode cache * @inode: inode to release
Signature · 1 line
2.41.0
Eric Van Hensbergen
maintainerPATCH v2 6/8 fs/9p: rework qid2ino logic
In reply to Eric Van HensbergenThis changes from a function to a macro because we can figure out if we are 32 or 64 bit at compile time.
--- fs/9p/v9fs_vfs.h | 7 ++++++- fs/9p/vfs_dir.c | 4 ++-- fs/9p/vfs_inode.c | 26 ++------------------------ fs/9p/vfs_inode_dotl.c | 6 ++---- 4 files changed, 12 insertions(+), 31 deletions(-)
fs/9p/v9fs_vfs.h +6 -1
@@ -43,7 +43,12 @@ void v9fs_free_inode(struct inode *inode);int v9fs_init_inode (struct v9fs_session_info *v9ses,struct inode *inode,umode_t mode,dev_t rdev);void v9fs_evict_inode (struct inode *inode); -ino_t v9fs_qid2ino (struct p9_qid *qid); +#if (BITS_PER_LONG ==32 ) +#define QID2INO (q) ((ino_t) (((q)->path+2) ^ (((q)->path) >> 32))) +#else +#define QID2INO (q) ((ino_t) ((q)->path+2)) +#endif +void v9fs_stat2inode (struct p9_wstat *stat,struct inode *inode,struct super_block *sb,unsigned int flags); void v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
fs/9p/vfs_dir.c +2 -2
@@ -127,7 +127,7 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) } over = !dir_emit (ctx, st.name,strlen (st.name), -v9fs_qid2ino (&st.qid),dt_type (&st)); +QID2INO (&st.qid),dt_type (&st));p9stat_free (&st);if (over)return 0 ;
@@ -184,7 +184,7 @@ static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx)if (!dir_emit (ctx, curdirent.d_name,strlen (curdirent.d_name), -v9fs_qid2ino (&curdirent.qid), +QID2INO (&curdirent.qid), curdirent.d_type))return 0 ;
fs/9p/vfs_inode.c +2 -24
@@ -407,7 +407,6 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,dev_t rdev;int retval;umode_t umode; -unsigned long i_ino;struct inode *inode;struct v9fs_session_info *v9ses = sb->s_fs_info;int (*test)(struct inode *inode,void *data);
@@ -417,8 +416,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,else test = v9fs_test_inode; - i_ino =v9fs_qid2ino (qid); - inode =iget5_locked (sb, i_ino, test, v9fs_set_inode, st); + inode =iget5_locked (sb,QID2INO (qid), test, v9fs_set_inode, st);if (!inode)return ERR_PTR (-ENOMEM );if (!(inode->i_state &I_NEW ))
@@ -428,7 +426,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,* FIXME!! we may need support for stale inodes * later. */ - inode->i_ino = i_ino; + inode->i_ino =QID2INO (qid); umode =p9mode2unixmode (v9ses, st, &rdev); retval =v9fs_init_inode (v9ses, inode, umode, rdev);if (retval)
@@ -1159,26 +1157,6 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR ; } -/** -* v9fs_qid2ino - convert qid into inode number -* @qid: qid to hash -* -* BUG: potential for inode number collisions? -*/ - -ino_t v9fs_qid2ino (struct p9_qid *qid) -{ -u64 path = qid->path +2 ; -ino_t i =0 ; - -if (sizeof (ino_t) ==sizeof (path)) -memcpy (&i, &path,sizeof (ino_t)); -else - i = (ino_t) (path ^ (path >>32 )); - -return i; -} -/** * v9fs_vfs_get_link - follow a symlink path * @dentry: dentry for symlink
fs/9p/vfs_inode_dotl.c +2 -4
@@ -100,7 +100,6 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, int new) {int retval; -unsigned long i_ino;struct inode *inode;struct v9fs_session_info *v9ses = sb->s_fs_info;int (*test)(struct inode *inode,void *data);
@@ -110,8 +109,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,else test = v9fs_test_inode_dotl; - i_ino =v9fs_qid2ino (qid); - inode =iget5_locked (sb, i_ino, test, v9fs_set_inode_dotl, st); + inode =iget5_locked (sb,QID2INO (qid), test, v9fs_set_inode_dotl, st);if (!inode)return ERR_PTR (-ENOMEM );if (!(inode->i_state &I_NEW ))
@@ -121,7 +119,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,* FIXME!! we may need support for stale inodes * later. */ - inode->i_ino = i_ino; + inode->i_ino =QID2INO (qid); retval =v9fs_init_inode (v9ses, inode, st->st_mode,new_decode_dev (st->st_rdev));if (retval)
Signature · 1 line
2.41.0
Eric Van Hensbergen
maintainerPATCH v2 7/8 fs/9p: simplify iget to remove unnecessary paths
In reply to Eric Van HensbergenRemove the additional comparison operators and switch to simply lookup by inode number (aka qid.path).
--- fs/9p/v9fs.h | 31 +++------------- fs/9p/v9fs_vfs.h | 2 +- fs/9p/vfs_inode.c | 98 +++++++++++--------------------------------------- fs/9p/vfs_inode_dotl.c | 92 +++++++++-------------------------------------- fs/9p/vfs_super.c | 2 +- 5 files changed, 45 insertions(+), 180 deletions(-)
fs/9p/v9fs.h +5 -26
@@ -179,16 +179,13 @@ extern int v9fs_vfs_rename(struct mnt_idmap *idmap, struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags); -extern struct inode *v9fs_inode_from_fid (struct v9fs_session_info *v9ses, -struct p9_fid *fid, -struct super_block *sb,int new); +extern struct inode *v9fs_fid_iget (struct super_block *sb,struct p9_fid *fid);extern const struct inode_operations v9fs_dir_inode_operations_dotl;extern const struct inode_operations v9fs_file_inode_operations_dotl;extern const struct inode_operations v9fs_symlink_inode_operations_dotl;extern const struct netfs_request_ops v9fs_req_ops; -extern struct inode *v9fs_inode_from_fid_dotl (struct v9fs_session_info *v9ses, -struct p9_fid *fid, -struct super_block *sb,int new); +extern struct inode *v9fs_fid_iget_dotl (struct super_block *sb, +struct p9_fid *fid);/* other default globals */ #define V9FS_PORT 564
@@ -230,27 +227,9 @@ v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, struct super_block *sb) {if (v9fs_proto_dotl (v9ses)) -return v9fs_inode_from_fid_dotl (v9ses, fid, sb,0 ); +return v9fs_fid_iget_dotl (sb, fid);else -return v9fs_inode_from_fid (v9ses, fid, sb,0 ); -} - -/** -* v9fs_get_new_inode_from_fid - Helper routine to populate an inode by -* issuing a attribute request -* @v9ses: session information -* @fid: fid to issue attribute request for -* @sb: superblock on which to create inode -* -*/ -static inline struct inode * -v9fs_get_new_inode_from_fid (struct v9fs_session_info *v9ses,struct p9_fid *fid, -struct super_block *sb) -{ -if (v9fs_proto_dotl (v9ses)) -return v9fs_inode_from_fid_dotl (v9ses, fid, sb,1 ); -else -return v9fs_inode_from_fid (v9ses, fid, sb,1 ); +return v9fs_fid_iget (sb, fid); }#endif
fs/9p/v9fs_vfs.h +1 -1
@@ -41,7 +41,7 @@ extern struct kmem_cache *v9fs_inode_cache;struct inode *v9fs_alloc_inode (struct super_block *sb);void v9fs_free_inode (struct inode *inode);int v9fs_init_inode (struct v9fs_session_info *v9ses, -struct inode *inode,umode_t mode,dev_t rdev); +struct inode *inode,struct p9_qid *qid,umode_t mode,dev_t rdev);void v9fs_evict_inode (struct inode *inode);#if (BITS_PER_LONG ==32 )#define QID2INO (q) ((ino_t) (((q)->path+2) ^ (((q)->path) >> 32)))
fs/9p/vfs_inode.c +21 -77
150 lines not on this page · raw message
fs/9p/vfs_inode_dotl.c +17 -75
142 lines not on this page · raw message
fs/9p/vfs_super.c +1 -1
@@ -139,7 +139,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,else sb->s_d_op = &v9fs_dentry_operations; - inode =v9fs_get_new_inode_from_fid (v9ses, fid, sb); + inode =v9fs_get_inode_from_fid (v9ses, fid, sb);if (IS_ERR (inode)) { retval =PTR_ERR (inode); goto release_sb;
Signature · 1 line
2.41.0
Eric Van Hensbergen
maintainerPATCH v2 8/8 fs/9p: fix dups even in uncached mode
In reply to Eric Van HensbergenIn uncached mode we were still seeing duplicate getattr requests because of aggressive dropping of inodes. Inode "freshness" is guarded by other mechanisms when caches are disabled so this is unnecessary and increases overhead of almost every operation.
--- fs/9p/vfs_super.c | 16 ---------------- 1 file changed, 16 deletions(-)
fs/9p/vfs_super.c +0 -16
@@ -244,21 +244,6 @@ static int v9fs_statfs(struct dentry *dentry, struct kstatfs *buf)return res; } -static int v9fs_drop_inode (struct inode *inode) -{ -struct v9fs_session_info *v9ses; - - v9ses =v9fs_inode2v9ses (inode); -if (v9ses->cache & (CACHE_META |CACHE_LOOSE )) -return generic_drop_inode (inode); -/* -* in case of non cached mode always drop the -* inode because we want the inode attribute -* to always match that on the server. -*/ -return 1 ; -} -static int v9fs_write_inode (struct inode *inode,struct writeback_control *wbc) {
@@ -303,7 +288,6 @@ static const struct super_operations v9fs_super_ops_dotl = { .alloc_inode = v9fs_alloc_inode, .free_inode = v9fs_free_inode, .statfs = v9fs_statfs, - .drop_inode = v9fs_drop_inode, .evict_inode = v9fs_evict_inode, .show_options = v9fs_show_options, .umount_begin = v9fs_umount_begin,
Signature · 1 line
2.41.0