Skip to content

Commit b91a266

Browse files
committed
fs/9p: rework qid2ino logic
This changes from a function to a macro because we can figure out if we are 32 or 64 bit at compile time. Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
1 parent f61c906 commit b91a266

File tree

4 files changed

+12
-31
lines changed

4 files changed

+12
-31
lines changed

fs/9p/v9fs_vfs.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ void v9fs_set_netfs_context(struct inode *inode);
4444
int v9fs_init_inode(struct v9fs_session_info *v9ses,
4545
struct inode *inode, umode_t mode, dev_t rdev);
4646
void v9fs_evict_inode(struct inode *inode);
47-
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+
4853
void v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
4954
struct super_block *sb, unsigned int flags);
5055
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: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
402402
dev_t rdev;
403403
int retval;
404404
umode_t umode;
405-
unsigned long i_ino;
406405
struct inode *inode;
407406
struct v9fs_session_info *v9ses = sb->s_fs_info;
408407
int (*test)(struct inode *inode, void *data);
@@ -412,8 +411,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
412411
else
413412
test = v9fs_test_inode;
414413

415-
i_ino = v9fs_qid2ino(qid);
416-
inode = iget5_locked(sb, i_ino, test, v9fs_set_inode, st);
414+
inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode, st);
417415
if (!inode)
418416
return ERR_PTR(-ENOMEM);
419417
if (!(inode->i_state & I_NEW))
@@ -423,7 +421,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
423421
* FIXME!! we may need support for stale inodes
424422
* later.
425423
*/
426-
inode->i_ino = i_ino;
424+
inode->i_ino = QID2INO(qid);
427425
umode = p9mode2unixmode(v9ses, st, &rdev);
428426
retval = v9fs_init_inode(v9ses, inode, umode, rdev);
429427
if (retval)
@@ -1156,26 +1154,6 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
11561154
v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
11571155
}
11581156

1159-
/**
1160-
* v9fs_qid2ino - convert qid into inode number
1161-
* @qid: qid to hash
1162-
*
1163-
* BUG: potential for inode number collisions?
1164-
*/
1165-
1166-
ino_t v9fs_qid2ino(struct p9_qid *qid)
1167-
{
1168-
u64 path = qid->path + 2;
1169-
ino_t i = 0;
1170-
1171-
if (sizeof(ino_t) == sizeof(path))
1172-
memcpy(&i, &path, sizeof(ino_t));
1173-
else
1174-
i = (ino_t) (path ^ (path >> 32));
1175-
1176-
return i;
1177-
}
1178-
11791157
/**
11801158
* v9fs_vfs_get_link - follow a symlink path
11811159
* @dentry: dentry for symlink

fs/9p/vfs_inode_dotl.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
100100
int new)
101101
{
102102
int retval;
103-
unsigned long i_ino;
104103
struct inode *inode;
105104
struct v9fs_session_info *v9ses = sb->s_fs_info;
106105
int (*test)(struct inode *inode, void *data);
@@ -110,8 +109,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
110109
else
111110
test = v9fs_test_inode_dotl;
112111

113-
i_ino = v9fs_qid2ino(qid);
114-
inode = iget5_locked(sb, i_ino, test, v9fs_set_inode_dotl, st);
112+
inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode_dotl, st);
115113
if (!inode)
116114
return ERR_PTR(-ENOMEM);
117115
if (!(inode->i_state & I_NEW))
@@ -121,7 +119,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
121119
* FIXME!! we may need support for stale inodes
122120
* later.
123121
*/
124-
inode->i_ino = i_ino;
122+
inode->i_ino = QID2INO(qid);
125123
retval = v9fs_init_inode(v9ses, inode,
126124
st->st_mode, new_decode_dev(st->st_rdev));
127125
if (retval)

0 commit comments

Comments
 (0)