1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Stefan Hajnoczi <stefanha@redhat.com>
3 Date: Thu, 4 Feb 2021 18:34:36 +0000
4 Subject: [PATCH] virtiofsd: optionally return inode pointer from
7 lo_do_lookup() finds an existing inode or allocates a new one. It
8 increments nlookup so that the inode stays alive until the client
11 Existing callers don't need the struct lo_inode so the function doesn't
12 return it. Extend the function to optionally return the inode. The next
15 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16 Reviewed-by: Greg Kurz <groug@kaod.org>
17 Message-Id: <20210204150208.367837-3-stefanha@redhat.com>
18 Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
19 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
21 tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++--------
22 1 file changed, 21 insertions(+), 8 deletions(-)
24 diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
25 index 218e20e9d7..2bd050b620 100644
26 --- a/tools/virtiofsd/passthrough_ll.c
27 +++ b/tools/virtiofsd/passthrough_ll.c
28 @@ -843,11 +843,13 @@ static int do_statx(struct lo_data *lo, int dirfd, const char *pathname,
32 - * Increments nlookup and caller must release refcount using
33 - * lo_inode_put(&parent).
34 + * Increments nlookup on the inode on success. unref_inode_lolocked() must be
35 + * called eventually to decrement nlookup again. If inodep is non-NULL, the
36 + * inode pointer is stored and the caller must call lo_inode_put().
38 static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
39 - struct fuse_entry_param *e)
40 + struct fuse_entry_param *e,
41 + struct lo_inode **inodep)
45 @@ -857,6 +859,10 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
46 struct lo_inode *inode = NULL;
47 struct lo_inode *dir = lo_inode(req, parent);
54 * name_to_handle_at() and open_by_handle_at() can reach here with fuse
55 * mount point in guest, but we don't have its inode info in the
56 @@ -924,7 +930,14 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
57 pthread_mutex_unlock(&lo->mutex);
59 e->ino = inode->fuse_ino;
60 - lo_inode_put(lo, &inode);
62 + /* Transfer ownership of inode pointer to caller or drop it */
66 + lo_inode_put(lo, &inode);
69 lo_inode_put(lo, &dir);
71 fuse_log(FUSE_LOG_DEBUG, " %lli/%s -> %lli\n", (unsigned long long)parent,
72 @@ -959,7 +972,7 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
76 - err = lo_do_lookup(req, parent, name, &e);
77 + err = lo_do_lookup(req, parent, name, &e, NULL);
79 fuse_reply_err(req, err);
81 @@ -1067,7 +1080,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
85 - saverr = lo_do_lookup(req, parent, name, &e);
86 + saverr = lo_do_lookup(req, parent, name, &e, NULL);
90 @@ -1544,7 +1557,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
93 if (!is_dot_or_dotdot(name)) {
94 - err = lo_do_lookup(req, ino, name, &e);
95 + err = lo_do_lookup(req, ino, name, &e, NULL);
99 @@ -1742,7 +1755,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
103 - err = lo_do_lookup(req, parent, name, &e);
104 + err = lo_do_lookup(req, parent, name, &e, NULL);
106 if (lo->cache == CACHE_NONE) {