Skip to content

Commit cba83f4

Browse files
tyhicksmartinetd
authored andcommitted
9p: Track the root fid with its own variable during lookups
Improve readability by using a new variable when dealing with the root fid. The root fid requires special handling in comparison to other fids used during fid lookup. Link: https://lkml.kernel.org/r/20220527000003.355812-3-tyhicks@linux.microsoft.com Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent 03c765b commit cba83f4

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

fs/9p/fid.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
152152
const unsigned char **wnames, *uname;
153153
int i, n, l, clone, access;
154154
struct v9fs_session_info *v9ses;
155-
struct p9_fid *fid, *old_fid;
155+
struct p9_fid *fid, *root_fid, *old_fid;
156156

157157
v9ses = v9fs_dentry2v9ses(dentry);
158158
access = v9ses->flags & V9FS_ACCESS_MASK;
@@ -178,8 +178,8 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
178178
up_read(&v9ses->rename_sem);
179179

180180
/* start from the root and try to do a lookup */
181-
fid = v9fs_fid_find(dentry->d_sb->s_root, uid, any);
182-
if (!fid) {
181+
root_fid = v9fs_fid_find(dentry->d_sb->s_root, uid, any);
182+
if (!root_fid) {
183183
/* the user is not attached to the fs yet */
184184
if (access == V9FS_ACCESS_SINGLE)
185185
return ERR_PTR(-EPERM);
@@ -189,17 +189,18 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
189189
else
190190
uname = v9ses->uname;
191191

192-
fid = p9_client_attach(v9ses->clnt, NULL, uname, uid,
193-
v9ses->aname);
194-
if (IS_ERR(fid))
195-
return fid;
192+
root_fid = p9_client_attach(v9ses->clnt, NULL, uname, uid,
193+
v9ses->aname);
194+
if (IS_ERR(root_fid))
195+
return root_fid;
196196

197-
refcount_inc(&fid->count);
198-
v9fs_fid_add(dentry->d_sb->s_root, fid);
197+
refcount_inc(&root_fid->count);
198+
v9fs_fid_add(dentry->d_sb->s_root, root_fid);
199199
}
200200
/* If we are root ourself just return that */
201201
if (dentry->d_sb->s_root == dentry)
202-
return fid;
202+
return root_fid;
203+
203204
/*
204205
* Do a multipath walk with attached root.
205206
* When walking parent we need to make sure we
@@ -211,7 +212,8 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
211212
fid = ERR_PTR(n);
212213
goto err_out;
213214
}
214-
old_fid = fid;
215+
fid = root_fid;
216+
old_fid = root_fid;
215217
clone = 1;
216218
i = 0;
217219
while (i < n) {
@@ -220,7 +222,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
220222
* We need to hold rename lock when doing a multipath
221223
* walk to ensure none of the patch component change
222224
*/
223-
fid = p9_client_walk(fid, l, &wnames[i], clone);
225+
fid = p9_client_walk(old_fid, l, &wnames[i], clone);
224226
/* non-cloning walk will return the same fid */
225227
if (fid != old_fid) {
226228
p9_client_clunk(old_fid);

0 commit comments

Comments
 (0)