]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0005-virtiofsd-optionally-return-inode-pointer-from-lo_do.patch
713bcc028b9974ab50f3ca9d37ffe815004be1f6
[pve-qemu.git] / debian / patches / extra / 0005-virtiofsd-optionally-return-inode-pointer-from-lo_do.patch
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
5 lo_do_lookup()
6
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
9 releases it.
10
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
13 commit will need it.
14
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>
20 ---
21 tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++--------
22 1 file changed, 21 insertions(+), 8 deletions(-)
23
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,
29 }
30
31 /*
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().
37 */
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)
42 {
43 int newfd;
44 int res;
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);
48
49 + if (inodep) {
50 + *inodep = NULL;
51 + }
52 +
53 /*
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);
58 }
59 e->ino = inode->fuse_ino;
60 - lo_inode_put(lo, &inode);
61 +
62 + /* Transfer ownership of inode pointer to caller or drop it */
63 + if (inodep) {
64 + *inodep = inode;
65 + } else {
66 + lo_inode_put(lo, &inode);
67 + }
68 +
69 lo_inode_put(lo, &dir);
70
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)
73 return;
74 }
75
76 - err = lo_do_lookup(req, parent, name, &e);
77 + err = lo_do_lookup(req, parent, name, &e, NULL);
78 if (err) {
79 fuse_reply_err(req, err);
80 } else {
81 @@ -1067,7 +1080,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
82 goto out;
83 }
84
85 - saverr = lo_do_lookup(req, parent, name, &e);
86 + saverr = lo_do_lookup(req, parent, name, &e, NULL);
87 if (saverr) {
88 goto out;
89 }
90 @@ -1544,7 +1557,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
91
92 if (plus) {
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);
96 if (err) {
97 goto error;
98 }
99 @@ -1742,7 +1755,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
100 }
101
102 fi->fh = fh;
103 - err = lo_do_lookup(req, parent, name, &e);
104 + err = lo_do_lookup(req, parent, name, &e, NULL);
105 }
106 if (lo->cache == CACHE_NONE) {
107 fi->direct_io = 1;