Skip to content

Commit

Permalink
fs/9p: rework qid2ino logic
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ericvh committed Jan 26, 2024
1 parent f61c906 commit b91a266
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
7 changes: 6 additions & 1 deletion fs/9p/v9fs_vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ void v9fs_set_netfs_context(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,
Expand Down
4 changes: 2 additions & 2 deletions fs/9p/vfs_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
26 changes: 2 additions & 24 deletions fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,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);
Expand All @@ -412,8 +411,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))
Expand All @@ -423,7 +421,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)
Expand Down Expand Up @@ -1156,26 +1154,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
Expand Down
6 changes: 2 additions & 4 deletions fs/9p/vfs_inode_dotl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit b91a266

Please sign in to comment.