Skip to content

Commit b48dbb9

Browse files
committed
9p fid refcount: add p9_fid_get/put wrappers
I was recently reminded that it is not clear that p9_client_clunk() was actually just decrementing refcount and clunking only when that reaches zero: make it clear through a set of helpers. This will also allow instrumenting refcounting better for debugging next patch Link: https://lkml.kernel.org/r/20220612085330.1451496-5-asmadeus@codewreck.org Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent b296d05 commit b48dbb9

12 files changed

Lines changed: 100 additions & 81 deletions

File tree

fs/9p/fid.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static struct p9_fid *v9fs_fid_find_inode(struct inode *inode, kuid_t uid)
5656
h = (struct hlist_head *)&inode->i_private;
5757
hlist_for_each_entry(fid, h, ilist) {
5858
if (uid_eq(fid->uid, uid)) {
59-
refcount_inc(&fid->count);
59+
p9_fid_get(fid);
6060
ret = fid;
6161
break;
6262
}
@@ -104,7 +104,7 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any)
104104
hlist_for_each_entry(fid, h, dlist) {
105105
if (any || uid_eq(fid->uid, uid)) {
106106
ret = fid;
107-
refcount_inc(&ret->count);
107+
p9_fid_get(ret);
108108
break;
109109
}
110110
}
@@ -172,7 +172,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
172172
old_fid = fid;
173173

174174
fid = p9_client_walk(old_fid, 1, &dentry->d_name.name, 1);
175-
p9_client_clunk(old_fid);
175+
p9_fid_put(old_fid);
176176
goto fid_out;
177177
}
178178
up_read(&v9ses->rename_sem);
@@ -194,7 +194,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
194194
if (IS_ERR(root_fid))
195195
return root_fid;
196196

197-
refcount_inc(&root_fid->count);
197+
p9_fid_get(root_fid);
198198
v9fs_fid_add(dentry->d_sb->s_root, root_fid);
199199
}
200200
/* If we are root ourself just return that */
@@ -225,7 +225,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
225225
old_fid == root_fid /* clone */);
226226
/* non-cloning walk will return the same fid */
227227
if (fid != old_fid) {
228-
p9_client_clunk(old_fid);
228+
p9_fid_put(old_fid);
229229
old_fid = fid;
230230
}
231231
if (IS_ERR(fid)) {
@@ -240,11 +240,11 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
240240
spin_lock(&dentry->d_lock);
241241
if (d_unhashed(dentry)) {
242242
spin_unlock(&dentry->d_lock);
243-
p9_client_clunk(fid);
243+
p9_fid_put(fid);
244244
fid = ERR_PTR(-ENOENT);
245245
} else {
246246
__add_fid(dentry, fid);
247-
refcount_inc(&fid->count);
247+
p9_fid_get(fid);
248248
spin_unlock(&dentry->d_lock);
249249
}
250250
}
@@ -301,7 +301,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry)
301301
fid = clone_fid(ofid);
302302
if (IS_ERR(fid))
303303
goto error_out;
304-
p9_client_clunk(ofid);
304+
p9_fid_put(ofid);
305305
/*
306306
* writeback fid will only be used to write back the
307307
* dirty pages. We always request for the open fid in read-write
@@ -310,7 +310,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry)
310310
*/
311311
err = p9_client_open(fid, O_RDWR);
312312
if (err < 0) {
313-
p9_client_clunk(fid);
313+
p9_fid_put(fid);
314314
fid = ERR_PTR(err);
315315
goto error_out;
316316
}

fs/9p/fid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static inline struct p9_fid *v9fs_fid_clone(struct dentry *dentry)
2929
return fid;
3030

3131
nfid = clone_fid(fid);
32-
p9_client_clunk(fid);
32+
p9_fid_put(fid);
3333
return nfid;
3434
}
3535
#endif

fs/9p/vfs_addr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
7373
BUG_ON(!fid);
7474
}
7575

76-
refcount_inc(&fid->count);
76+
p9_fid_get(fid);
7777
rreq->netfs_priv = fid;
7878
return 0;
7979
}
@@ -86,7 +86,7 @@ static void v9fs_free_request(struct netfs_io_request *rreq)
8686
{
8787
struct p9_fid *fid = rreq->netfs_priv;
8888

89-
p9_client_clunk(fid);
89+
p9_fid_put(fid);
9090
}
9191

9292
/**

fs/9p/vfs_dentry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void v9fs_dentry_release(struct dentry *dentry)
5454
p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
5555
dentry, dentry);
5656
hlist_for_each_safe(p, n, (struct hlist_head *)&dentry->d_fsdata)
57-
p9_client_clunk(hlist_entry(p, struct p9_fid, dlist));
57+
p9_fid_put(hlist_entry(p, struct p9_fid, dlist));
5858
dentry->d_fsdata = NULL;
5959
}
6060

@@ -85,7 +85,7 @@ static int v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
8585
retval = v9fs_refresh_inode_dotl(fid, inode);
8686
else
8787
retval = v9fs_refresh_inode(fid, inode);
88-
p9_client_clunk(fid);
88+
p9_fid_put(fid);
8989

9090
if (retval == -ENOENT)
9191
return 0;

fs/9p/vfs_dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
218218
spin_lock(&inode->i_lock);
219219
hlist_del(&fid->ilist);
220220
spin_unlock(&inode->i_lock);
221-
p9_client_clunk(fid);
221+
p9_fid_put(fid);
222222
}
223223

224224
if ((filp->f_mode & FMODE_WRITE)) {

fs/9p/vfs_file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
6363

6464
err = p9_client_open(fid, omode);
6565
if (err < 0) {
66-
p9_client_clunk(fid);
66+
p9_fid_put(fid);
6767
return err;
6868
}
6969
if ((file->f_flags & O_APPEND) &&
@@ -98,7 +98,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
9898
v9fs_open_fid_add(inode, fid);
9999
return 0;
100100
out_error:
101-
p9_client_clunk(file->private_data);
101+
p9_fid_put(file->private_data);
102102
file->private_data = NULL;
103103
return err;
104104
}

fs/9p/vfs_inode.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ void v9fs_evict_inode(struct inode *inode)
400400
fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false);
401401
/* clunk the fid stashed in writeback_fid */
402402
if (v9inode->writeback_fid) {
403-
p9_client_clunk(v9inode->writeback_fid);
403+
p9_fid_put(v9inode->writeback_fid);
404404
v9inode->writeback_fid = NULL;
405405
}
406406
}
@@ -569,7 +569,7 @@ static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
569569
if (v9fs_proto_dotl(v9ses))
570570
retval = p9_client_unlinkat(dfid, dentry->d_name.name,
571571
v9fs_at_to_dotl_flags(flags));
572-
p9_client_clunk(dfid);
572+
p9_fid_put(dfid);
573573
if (retval == -EOPNOTSUPP) {
574574
/* Try the one based on path */
575575
v9fid = v9fs_fid_clone(dentry);
@@ -633,14 +633,14 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
633633
if (IS_ERR(ofid)) {
634634
err = PTR_ERR(ofid);
635635
p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
636-
p9_client_clunk(dfid);
636+
p9_fid_put(dfid);
637637
return ERR_PTR(err);
638638
}
639639

640640
err = p9_client_fcreate(ofid, name, perm, mode, extension);
641641
if (err < 0) {
642642
p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
643-
p9_client_clunk(dfid);
643+
p9_fid_put(dfid);
644644
goto error;
645645
}
646646

@@ -652,7 +652,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
652652
p9_debug(P9_DEBUG_VFS,
653653
"p9_client_walk failed %d\n", err);
654654
fid = NULL;
655-
p9_client_clunk(dfid);
655+
p9_fid_put(dfid);
656656
goto error;
657657
}
658658
/*
@@ -663,20 +663,20 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
663663
err = PTR_ERR(inode);
664664
p9_debug(P9_DEBUG_VFS,
665665
"inode creation failed %d\n", err);
666-
p9_client_clunk(dfid);
666+
p9_fid_put(dfid);
667667
goto error;
668668
}
669669
v9fs_fid_add(dentry, fid);
670670
d_instantiate(dentry, inode);
671671
}
672-
p9_client_clunk(dfid);
672+
p9_fid_put(dfid);
673673
return ofid;
674674
error:
675675
if (ofid)
676-
p9_client_clunk(ofid);
676+
p9_fid_put(ofid);
677677

678678
if (fid)
679-
p9_client_clunk(fid);
679+
p9_fid_put(fid);
680680

681681
return ERR_PTR(err);
682682
}
@@ -708,7 +708,7 @@ v9fs_vfs_create(struct user_namespace *mnt_userns, struct inode *dir,
708708
return PTR_ERR(fid);
709709

710710
v9fs_invalidate_inode_attr(dir);
711-
p9_client_clunk(fid);
711+
p9_fid_put(fid);
712712

713713
return 0;
714714
}
@@ -744,7 +744,7 @@ static int v9fs_vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
744744
}
745745

746746
if (fid)
747-
p9_client_clunk(fid);
747+
p9_fid_put(fid);
748748

749749
return err;
750750
}
@@ -785,7 +785,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
785785
*/
786786
name = dentry->d_name.name;
787787
fid = p9_client_walk(dfid, 1, &name, 1);
788-
p9_client_clunk(dfid);
788+
p9_fid_put(dfid);
789789
if (fid == ERR_PTR(-ENOENT))
790790
inode = NULL;
791791
else if (IS_ERR(fid))
@@ -808,7 +808,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
808808
else if (!IS_ERR(res))
809809
v9fs_fid_add(res, fid);
810810
else
811-
p9_client_clunk(fid);
811+
p9_fid_put(fid);
812812
}
813813
return res;
814814
}
@@ -891,7 +891,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
891891

892892
error:
893893
if (fid)
894-
p9_client_clunk(fid);
894+
p9_fid_put(fid);
895895
goto out;
896896
}
897897

@@ -959,7 +959,7 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
959959
dfid = v9fs_parent_fid(old_dentry);
960960
olddirfid = clone_fid(dfid);
961961
if (dfid && !IS_ERR(dfid))
962-
p9_client_clunk(dfid);
962+
p9_fid_put(dfid);
963963

964964
if (IS_ERR(olddirfid)) {
965965
retval = PTR_ERR(olddirfid);
@@ -968,7 +968,7 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
968968

969969
dfid = v9fs_parent_fid(new_dentry);
970970
newdirfid = clone_fid(dfid);
971-
p9_client_clunk(dfid);
971+
p9_fid_put(dfid);
972972

973973
if (IS_ERR(newdirfid)) {
974974
retval = PTR_ERR(newdirfid);
@@ -1020,13 +1020,13 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
10201020
d_move(old_dentry, new_dentry);
10211021
}
10221022
up_write(&v9ses->rename_sem);
1023-
p9_client_clunk(newdirfid);
1023+
p9_fid_put(newdirfid);
10241024

10251025
clunk_olddir:
1026-
p9_client_clunk(olddirfid);
1026+
p9_fid_put(olddirfid);
10271027

10281028
done:
1029-
p9_client_clunk(oldfid);
1029+
p9_fid_put(oldfid);
10301030
return retval;
10311031
}
10321032

@@ -1060,7 +1060,7 @@ v9fs_vfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
10601060
return PTR_ERR(fid);
10611061

10621062
st = p9_client_stat(fid);
1063-
p9_client_clunk(fid);
1063+
p9_fid_put(fid);
10641064
if (IS_ERR(st))
10651065
return PTR_ERR(st);
10661066

@@ -1136,7 +1136,7 @@ static int v9fs_vfs_setattr(struct user_namespace *mnt_userns,
11361136
retval = p9_client_wstat(fid, &wstat);
11371137

11381138
if (use_dentry)
1139-
p9_client_clunk(fid);
1139+
p9_fid_put(fid);
11401140

11411141
if (retval < 0)
11421142
return retval;
@@ -1261,7 +1261,7 @@ static const char *v9fs_vfs_get_link(struct dentry *dentry,
12611261
return ERR_CAST(fid);
12621262

12631263
st = p9_client_stat(fid);
1264-
p9_client_clunk(fid);
1264+
p9_fid_put(fid);
12651265
if (IS_ERR(st))
12661266
return ERR_CAST(st);
12671267

@@ -1308,7 +1308,7 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
13081308
return PTR_ERR(fid);
13091309

13101310
v9fs_invalidate_inode_attr(dir);
1311-
p9_client_clunk(fid);
1311+
p9_fid_put(fid);
13121312
return 0;
13131313
}
13141314

@@ -1364,7 +1364,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
13641364
v9fs_refresh_inode(oldfid, d_inode(old_dentry));
13651365
v9fs_invalidate_inode_attr(dir);
13661366
}
1367-
p9_client_clunk(oldfid);
1367+
p9_fid_put(oldfid);
13681368
return retval;
13691369
}
13701370

0 commit comments

Comments
 (0)