Skip to content

Commit c442a42

Browse files
committed
Merge tag '9p-for-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs
Pull 9p updates from Eric Van Hensbergen: "This includes a number of patches addressing improvements in the cache portions of the 9p client. The biggest improvements have to do with fixing handling of inodes and eliminating duplicate structures and unnecessary allocation/release of inode structures and many associated unnecessary protocol traffic. This also dramatically reduced code complexity across the code and sets us up to add proper temporal cache capabilities" * tag '9p-for-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs: fs/9p: fix dups even in uncached mode fs/9p: simplify iget to remove unnecessary paths fs/9p: rework qid2ino logic fs/9p: Eliminate now unused v9fs_get_inode fs/9p: Eliminate redundant non-cache path in mknod fs/9p: remove walk and inode allocation from symlink fs/9p: convert mkdir to use get_new_inode fs/9p: switch vfsmount to use v9fs_get_new_inode
2 parents 6ce8b2c + be57855 commit c442a42

File tree

6 files changed

+71
-364
lines changed

6 files changed

+71
-364
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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ extern struct kmem_cache *v9fs_inode_cache;
4040

4141
struct inode *v9fs_alloc_inode(struct super_block *sb);
4242
void v9fs_free_inode(struct inode *inode);
43-
struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode,
44-
dev_t rdev);
4543
void v9fs_set_netfs_context(struct inode *inode);
4644
int v9fs_init_inode(struct v9fs_session_info *v9ses,
47-
struct inode *inode, umode_t mode, dev_t rdev);
45+
struct inode *inode, struct p9_qid *qid, umode_t mode, dev_t rdev);
4846
void v9fs_evict_inode(struct inode *inode);
49-
ino_t v9fs_qid2ino(struct p9_qid *qid);
47+
#if (BITS_PER_LONG == 32)
48+
#define QID2INO(q) ((ino_t) (((q)->path+2) ^ (((q)->path) >> 32)))
49+
#else
50+
#define QID2INO(q) ((ino_t) ((q)->path+2))
51+
#endif
52+
5053
void v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
5154
struct super_block *sb, unsigned int flags);
5255
void v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,

fs/9p/vfs_dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
127127
}
128128

129129
over = !dir_emit(ctx, st.name, strlen(st.name),
130-
v9fs_qid2ino(&st.qid), dt_type(&st));
130+
QID2INO(&st.qid), dt_type(&st));
131131
p9stat_free(&st);
132132
if (over)
133133
return 0;
@@ -184,7 +184,7 @@ static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx)
184184

185185
if (!dir_emit(ctx, curdirent.d_name,
186186
strlen(curdirent.d_name),
187-
v9fs_qid2ino(&curdirent.qid),
187+
QID2INO(&curdirent.qid),
188188
curdirent.d_type))
189189
return 0;
190190

fs/9p/vfs_inode.c

Lines changed: 21 additions & 129 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;
@@ -331,36 +334,6 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
331334

332335
}
333336

334-
/**
335-
* v9fs_get_inode - helper function to setup an inode
336-
* @sb: superblock
337-
* @mode: mode to setup inode with
338-
* @rdev: The device numbers to set
339-
*/
340-
341-
struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode, dev_t rdev)
342-
{
343-
int err;
344-
struct inode *inode;
345-
struct v9fs_session_info *v9ses = sb->s_fs_info;
346-
347-
p9_debug(P9_DEBUG_VFS, "super block: %p mode: %ho\n", sb, mode);
348-
349-
inode = new_inode(sb);
350-
if (!inode) {
351-
pr_warn("%s (%d): Problem allocating inode\n",
352-
__func__, task_pid_nr(current));
353-
return ERR_PTR(-ENOMEM);
354-
}
355-
err = v9fs_init_inode(v9ses, inode, mode, rdev);
356-
if (err) {
357-
iput(inode);
358-
return ERR_PTR(err);
359-
}
360-
v9fs_set_netfs_context(inode);
361-
return inode;
362-
}
363-
364337
/**
365338
* v9fs_evict_inode - Remove an inode from the inode cache
366339
* @inode: inode to release
@@ -384,82 +357,40 @@ void v9fs_evict_inode(struct inode *inode)
384357
#endif
385358
}
386359

387-
static int v9fs_test_inode(struct inode *inode, void *data)
388-
{
389-
int umode;
390-
dev_t rdev;
391-
struct v9fs_inode *v9inode = V9FS_I(inode);
392-
struct p9_wstat *st = (struct p9_wstat *)data;
393-
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
394-
395-
umode = p9mode2unixmode(v9ses, st, &rdev);
396-
/* don't match inode of different type */
397-
if (inode_wrong_type(inode, umode))
398-
return 0;
399-
400-
/* compare qid details */
401-
if (memcmp(&v9inode->qid.version,
402-
&st->qid.version, sizeof(v9inode->qid.version)))
403-
return 0;
404-
405-
if (v9inode->qid.type != st->qid.type)
406-
return 0;
407-
408-
if (v9inode->qid.path != st->qid.path)
409-
return 0;
410-
return 1;
411-
}
412-
413-
static int v9fs_test_new_inode(struct inode *inode, void *data)
414-
{
415-
return 0;
416-
}
417-
418-
static int v9fs_set_inode(struct inode *inode, void *data)
419-
{
420-
struct v9fs_inode *v9inode = V9FS_I(inode);
421-
struct p9_wstat *st = (struct p9_wstat *)data;
422-
423-
memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
424-
return 0;
425-
}
426-
427-
static struct inode *v9fs_qid_iget(struct super_block *sb,
428-
struct p9_qid *qid,
429-
struct p9_wstat *st,
430-
int new)
360+
struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid)
431361
{
432362
dev_t rdev;
433363
int retval;
434364
umode_t umode;
435-
unsigned long i_ino;
436365
struct inode *inode;
366+
struct p9_wstat *st;
437367
struct v9fs_session_info *v9ses = sb->s_fs_info;
438-
int (*test)(struct inode *inode, void *data);
439368

440-
if (new)
441-
test = v9fs_test_new_inode;
442-
else
443-
test = v9fs_test_inode;
444-
445-
i_ino = v9fs_qid2ino(qid);
446-
inode = iget5_locked(sb, i_ino, test, v9fs_set_inode, st);
447-
if (!inode)
369+
inode = iget_locked(sb, QID2INO(&fid->qid));
370+
if (unlikely(!inode))
448371
return ERR_PTR(-ENOMEM);
449372
if (!(inode->i_state & I_NEW))
450373
return inode;
374+
451375
/*
452376
* initialize the inode with the stat info
453377
* FIXME!! we may need support for stale inodes
454378
* later.
455379
*/
456-
inode->i_ino = i_ino;
380+
st = p9_client_stat(fid);
381+
if (IS_ERR(st)) {
382+
retval = PTR_ERR(st);
383+
goto error;
384+
}
385+
457386
umode = p9mode2unixmode(v9ses, st, &rdev);
458-
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);
459391
if (retval)
460392
goto error;
461393

462-
v9fs_stat2inode(st, inode, sb, 0);
463394
v9fs_set_netfs_context(inode);
464395
v9fs_cache_inode_get_cookie(inode);
465396
unlock_new_inode(inode);
@@ -470,23 +401,6 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
470401

471402
}
472403

473-
struct inode *
474-
v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
475-
struct super_block *sb, int new)
476-
{
477-
struct p9_wstat *st;
478-
struct inode *inode = NULL;
479-
480-
st = p9_client_stat(fid);
481-
if (IS_ERR(st))
482-
return ERR_CAST(st);
483-
484-
inode = v9fs_qid_iget(sb, &st->qid, st, new);
485-
p9stat_free(st);
486-
kfree(st);
487-
return inode;
488-
}
489-
490404
/**
491405
* v9fs_at_to_dotl_flags- convert Linux specific AT flags to
492406
* plan 9 AT flag.
@@ -633,7 +547,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
633547
/*
634548
* instantiate inode and assign the unopened fid to the dentry
635549
*/
636-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
550+
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
637551
if (IS_ERR(inode)) {
638552
err = PTR_ERR(inode);
639553
p9_debug(P9_DEBUG_VFS,
@@ -761,10 +675,8 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
761675
inode = NULL;
762676
else if (IS_ERR(fid))
763677
inode = ERR_CAST(fid);
764-
else if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
765-
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
766678
else
767-
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
679+
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
768680
/*
769681
* If we had a rename on the server and a parallel lookup
770682
* for the new name, then make sure we instantiate with
@@ -1186,26 +1098,6 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
11861098
v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
11871099
}
11881100

1189-
/**
1190-
* v9fs_qid2ino - convert qid into inode number
1191-
* @qid: qid to hash
1192-
*
1193-
* BUG: potential for inode number collisions?
1194-
*/
1195-
1196-
ino_t v9fs_qid2ino(struct p9_qid *qid)
1197-
{
1198-
u64 path = qid->path + 2;
1199-
ino_t i = 0;
1200-
1201-
if (sizeof(ino_t) == sizeof(path))
1202-
memcpy(&i, &path, sizeof(ino_t));
1203-
else
1204-
i = (ino_t) (path ^ (path >> 32));
1205-
1206-
return i;
1207-
}
1208-
12091101
/**
12101102
* v9fs_vfs_get_link - follow a symlink path
12111103
* @dentry: dentry for symlink

0 commit comments

Comments
 (0)