summaryrefslogtreecommitdiffstats
path: root/include/net/9p
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2022-06-12 13:42:32 +0900
committerDominique Martinet <dominique.martinet@atmark-techno.com>2022-07-02 18:52:21 +0900
commitb48dbb998d70b7f48c2ec0a15c3cf47136808e4e (patch)
tree30857d1451aa4ff349eb622fd91944d591793dbc /include/net/9p
parentb296d05746b7fa0d663e3b11abf0e03eab6e03e6 (diff)
downloadlinux-stable-b48dbb998d70b7f48c2ec0a15c3cf47136808e4e.tar.gz
linux-stable-b48dbb998d70b7f48c2ec0a15c3cf47136808e4e.tar.bz2
linux-stable-b48dbb998d70b7f48c2ec0a15c3cf47136808e4e.zip
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>
Diffstat (limited to 'include/net/9p')
-rw-r--r--include/net/9p/client.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/net/9p/client.h b/include/net/9p/client.h
index ec1d1706f43c..eabb53992350 100644
--- a/include/net/9p/client.h
+++ b/include/net/9p/client.h
@@ -237,6 +237,34 @@ static inline int p9_req_try_get(struct p9_req_t *r)
int p9_req_put(struct p9_req_t *r);
+/* fid reference counting helpers:
+ * - fids used for any length of time should always be referenced through
+ * p9_fid_get(), and released with p9_fid_put()
+ * - v9fs_fid_lookup() or similar will automatically call get for you
+ * and also require a put
+ * - the *_fid_add() helpers will stash the fid in the inode,
+ * at which point it is the responsibility of evict_inode()
+ * to call the put
+ * - the last put will automatically send a clunk to the server
+ */
+static inline struct p9_fid *p9_fid_get(struct p9_fid *fid)
+{
+ refcount_inc(&fid->count);
+
+ return fid;
+}
+
+static inline int p9_fid_put(struct p9_fid *fid)
+{
+ if (!fid || IS_ERR(fid))
+ return 0;
+
+ if (!refcount_dec_and_test(&fid->count))
+ return 0;
+
+ return p9_client_clunk(fid);
+}
+
void p9_client_cb(struct p9_client *c, struct p9_req_t *req, int status);
int p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type,