Skip to content

Commit 724a084

Browse files
committed
fs/9p: simplify iget to remove unnecessary paths
Remove the additional comparison operators and switch to simply lookup by inode number (aka qid.path). Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
1 parent b91a266 commit 724a084

File tree

5 files changed

+45
-180
lines changed

5 files changed

+45
-180
lines changed

fs/9p/v9fs.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,13 @@ extern int v9fs_vfs_rename(struct mnt_idmap *idmap,
179179
struct inode *old_dir, struct dentry *old_dentry,
180180
struct inode *new_dir, struct dentry *new_dentry,
181181
unsigned int flags);
182-
extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
183-
struct p9_fid *fid,
184-
struct super_block *sb, int new);
182+
extern struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid);
185183
extern const struct inode_operations v9fs_dir_inode_operations_dotl;
186184
extern const struct inode_operations v9fs_file_inode_operations_dotl;
187185
extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
188186
extern const struct netfs_request_ops v9fs_req_ops;
189-
extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,
190-
struct p9_fid *fid,
191-
struct super_block *sb, int new);
187+
extern struct inode *v9fs_fid_iget_dotl(struct super_block *sb,
188+
struct p9_fid *fid);
192189

193190
/* other default globals */
194191
#define V9FS_PORT 564
@@ -230,27 +227,9 @@ v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
230227
struct super_block *sb)
231228
{
232229
if (v9fs_proto_dotl(v9ses))
233-
return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0);
230+
return v9fs_fid_iget_dotl(sb, fid);
234231
else
235-
return v9fs_inode_from_fid(v9ses, fid, sb, 0);
236-
}
237-
238-
/**
239-
* v9fs_get_new_inode_from_fid - Helper routine to populate an inode by
240-
* issuing a attribute request
241-
* @v9ses: session information
242-
* @fid: fid to issue attribute request for
243-
* @sb: superblock on which to create inode
244-
*
245-
*/
246-
static inline struct inode *
247-
v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
248-
struct super_block *sb)
249-
{
250-
if (v9fs_proto_dotl(v9ses))
251-
return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);
252-
else
253-
return v9fs_inode_from_fid(v9ses, fid, sb, 1);
232+
return v9fs_fid_iget(sb, fid);
254233
}
255234

256235
#endif

fs/9p/v9fs_vfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct inode *v9fs_alloc_inode(struct super_block *sb);
4242
void v9fs_free_inode(struct inode *inode);
4343
void v9fs_set_netfs_context(struct inode *inode);
4444
int v9fs_init_inode(struct v9fs_session_info *v9ses,
45-
struct inode *inode, umode_t mode, dev_t rdev);
45+
struct inode *inode, struct p9_qid *qid, umode_t mode, dev_t rdev);
4646
void v9fs_evict_inode(struct inode *inode);
4747
#if (BITS_PER_LONG == 32)
4848
#define QID2INO(q) ((ino_t) (((q)->path+2) ^ (((q)->path) >> 32)))

fs/9p/vfs_inode.c

Lines changed: 21 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,12 @@ void v9fs_set_netfs_context(struct inode *inode)
253253
}
254254

255255
int v9fs_init_inode(struct v9fs_session_info *v9ses,
256-
struct inode *inode, umode_t mode, dev_t rdev)
256+
struct inode *inode, struct p9_qid *qid, umode_t mode, dev_t rdev)
257257
{
258258
int err = 0;
259+
struct v9fs_inode *v9inode = V9FS_I(inode);
260+
261+
memcpy(&v9inode->qid, qid, sizeof(struct p9_qid));
259262

260263
inode_init_owner(&nop_mnt_idmap, inode, NULL, mode);
261264
inode->i_blocks = 0;
@@ -354,80 +357,40 @@ void v9fs_evict_inode(struct inode *inode)
354357
#endif
355358
}
356359

357-
static int v9fs_test_inode(struct inode *inode, void *data)
358-
{
359-
int umode;
360-
dev_t rdev;
361-
struct v9fs_inode *v9inode = V9FS_I(inode);
362-
struct p9_wstat *st = (struct p9_wstat *)data;
363-
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
364-
365-
umode = p9mode2unixmode(v9ses, st, &rdev);
366-
/* don't match inode of different type */
367-
if (inode_wrong_type(inode, umode))
368-
return 0;
369-
370-
/* compare qid details */
371-
if (memcmp(&v9inode->qid.version,
372-
&st->qid.version, sizeof(v9inode->qid.version)))
373-
return 0;
374-
375-
if (v9inode->qid.type != st->qid.type)
376-
return 0;
377-
378-
if (v9inode->qid.path != st->qid.path)
379-
return 0;
380-
return 1;
381-
}
382-
383-
static int v9fs_test_new_inode(struct inode *inode, void *data)
384-
{
385-
return 0;
386-
}
387-
388-
static int v9fs_set_inode(struct inode *inode, void *data)
389-
{
390-
struct v9fs_inode *v9inode = V9FS_I(inode);
391-
struct p9_wstat *st = (struct p9_wstat *)data;
392-
393-
memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
394-
return 0;
395-
}
396-
397-
static struct inode *v9fs_qid_iget(struct super_block *sb,
398-
struct p9_qid *qid,
399-
struct p9_wstat *st,
400-
int new)
360+
struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid)
401361
{
402362
dev_t rdev;
403363
int retval;
404364
umode_t umode;
405365
struct inode *inode;
366+
struct p9_wstat *st;
406367
struct v9fs_session_info *v9ses = sb->s_fs_info;
407-
int (*test)(struct inode *inode, void *data);
408-
409-
if (new)
410-
test = v9fs_test_new_inode;
411-
else
412-
test = v9fs_test_inode;
413368

414-
inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode, st);
415-
if (!inode)
369+
inode = iget_locked(sb, QID2INO(&fid->qid));
370+
if (unlikely(!inode))
416371
return ERR_PTR(-ENOMEM);
417372
if (!(inode->i_state & I_NEW))
418373
return inode;
374+
419375
/*
420376
* initialize the inode with the stat info
421377
* FIXME!! we may need support for stale inodes
422378
* later.
423379
*/
424-
inode->i_ino = QID2INO(qid);
380+
st = p9_client_stat(fid);
381+
if (IS_ERR(st)) {
382+
retval = PTR_ERR(st);
383+
goto error;
384+
}
385+
425386
umode = p9mode2unixmode(v9ses, st, &rdev);
426-
retval = v9fs_init_inode(v9ses, inode, umode, rdev);
387+
retval = v9fs_init_inode(v9ses, inode, &fid->qid, umode, rdev);
388+
v9fs_stat2inode(st, inode, sb, 0);
389+
p9stat_free(st);
390+
kfree(st);
427391
if (retval)
428392
goto error;
429393

430-
v9fs_stat2inode(st, inode, sb, 0);
431394
v9fs_set_netfs_context(inode);
432395
v9fs_cache_inode_get_cookie(inode);
433396
unlock_new_inode(inode);
@@ -438,23 +401,6 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
438401

439402
}
440403

441-
struct inode *
442-
v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
443-
struct super_block *sb, int new)
444-
{
445-
struct p9_wstat *st;
446-
struct inode *inode = NULL;
447-
448-
st = p9_client_stat(fid);
449-
if (IS_ERR(st))
450-
return ERR_CAST(st);
451-
452-
inode = v9fs_qid_iget(sb, &st->qid, st, new);
453-
p9stat_free(st);
454-
kfree(st);
455-
return inode;
456-
}
457-
458404
/**
459405
* v9fs_at_to_dotl_flags- convert Linux specific AT flags to
460406
* plan 9 AT flag.
@@ -601,7 +547,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
601547
/*
602548
* instantiate inode and assign the unopened fid to the dentry
603549
*/
604-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
550+
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
605551
if (IS_ERR(inode)) {
606552
err = PTR_ERR(inode);
607553
p9_debug(P9_DEBUG_VFS,
@@ -729,10 +675,8 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
729675
inode = NULL;
730676
else if (IS_ERR(fid))
731677
inode = ERR_CAST(fid);
732-
else if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
733-
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
734678
else
735-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
679+
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
736680
/*
737681
* If we had a rename on the server and a parallel lookup
738682
* for the new name, then make sure we instantiate with

fs/9p/vfs_inode_dotl.c

Lines changed: 17 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -52,76 +52,33 @@ static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
5252
return current_fsgid();
5353
}
5454

55-
static int v9fs_test_inode_dotl(struct inode *inode, void *data)
56-
{
57-
struct v9fs_inode *v9inode = V9FS_I(inode);
58-
struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
59-
60-
/* don't match inode of different type */
61-
if (inode_wrong_type(inode, st->st_mode))
62-
return 0;
63-
64-
if (inode->i_generation != st->st_gen)
65-
return 0;
66-
67-
/* compare qid details */
68-
if (memcmp(&v9inode->qid.version,
69-
&st->qid.version, sizeof(v9inode->qid.version)))
70-
return 0;
71-
72-
if (v9inode->qid.type != st->qid.type)
73-
return 0;
74-
75-
if (v9inode->qid.path != st->qid.path)
76-
return 0;
77-
return 1;
78-
}
79-
80-
/* Always get a new inode */
81-
static int v9fs_test_new_inode_dotl(struct inode *inode, void *data)
82-
{
83-
return 0;
84-
}
85-
86-
static int v9fs_set_inode_dotl(struct inode *inode, void *data)
87-
{
88-
struct v9fs_inode *v9inode = V9FS_I(inode);
89-
struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
90-
91-
memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
92-
inode->i_generation = st->st_gen;
93-
return 0;
94-
}
95-
96-
static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
97-
struct p9_qid *qid,
98-
struct p9_fid *fid,
99-
struct p9_stat_dotl *st,
100-
int new)
55+
struct inode *v9fs_fid_iget_dotl(struct super_block *sb, struct p9_fid *fid)
10156
{
10257
int retval;
10358
struct inode *inode;
59+
struct p9_stat_dotl *st;
10460
struct v9fs_session_info *v9ses = sb->s_fs_info;
105-
int (*test)(struct inode *inode, void *data);
106-
107-
if (new)
108-
test = v9fs_test_new_inode_dotl;
109-
else
110-
test = v9fs_test_inode_dotl;
11161

112-
inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode_dotl, st);
113-
if (!inode)
62+
inode = iget_locked(sb, QID2INO(&fid->qid));
63+
if (unlikely(!inode))
11464
return ERR_PTR(-ENOMEM);
11565
if (!(inode->i_state & I_NEW))
11666
return inode;
67+
11768
/*
11869
* initialize the inode with the stat info
11970
* FIXME!! we may need support for stale inodes
12071
* later.
12172
*/
122-
inode->i_ino = QID2INO(qid);
123-
retval = v9fs_init_inode(v9ses, inode,
73+
st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
74+
if (IS_ERR(st)) {
75+
retval = PTR_ERR(st);
76+
goto error;
77+
}
78+
79+
retval = v9fs_init_inode(v9ses, inode, &fid->qid,
12480
st->st_mode, new_decode_dev(st->st_rdev));
81+
kfree(st);
12582
if (retval)
12683
goto error;
12784

@@ -133,29 +90,14 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
13390
goto error;
13491

13592
unlock_new_inode(inode);
93+
13694
return inode;
13795
error:
13896
iget_failed(inode);
13997
return ERR_PTR(retval);
14098

14199
}
142100

143-
struct inode *
144-
v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
145-
struct super_block *sb, int new)
146-
{
147-
struct p9_stat_dotl *st;
148-
struct inode *inode = NULL;
149-
150-
st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
151-
if (IS_ERR(st))
152-
return ERR_CAST(st);
153-
154-
inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new);
155-
kfree(st);
156-
return inode;
157-
}
158-
159101
struct dotl_openflag_map {
160102
int open_flag;
161103
int dotl_flag;
@@ -305,7 +247,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
305247
p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
306248
goto out;
307249
}
308-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
250+
inode = v9fs_fid_iget_dotl(dir->i_sb, fid);
309251
if (IS_ERR(inode)) {
310252
err = PTR_ERR(inode);
311253
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
@@ -400,7 +342,7 @@ static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap,
400342
}
401343

402344
/* instantiate inode and assign the unopened fid to the dentry */
403-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
345+
inode = v9fs_fid_iget_dotl(dir->i_sb, fid);
404346
if (IS_ERR(inode)) {
405347
err = PTR_ERR(inode);
406348
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
@@ -838,7 +780,7 @@ v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir,
838780
err);
839781
goto error;
840782
}
841-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
783+
inode = v9fs_fid_iget_dotl(dir->i_sb, fid);
842784
if (IS_ERR(inode)) {
843785
err = PTR_ERR(inode);
844786
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",

fs/9p/vfs_super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
139139
else
140140
sb->s_d_op = &v9fs_dentry_operations;
141141

142-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, sb);
142+
inode = v9fs_get_inode_from_fid(v9ses, fid, sb);
143143
if (IS_ERR(inode)) {
144144
retval = PTR_ERR(inode);
145145
goto release_sb;

0 commit comments

Comments
 (0)