Blame SOURCES/kvm-virtiofsd-optionally-return-inode-pointer-from-lo_do.patch

a19a21
From f2c0b07088966c396ddcee54f4bed97cdb01192f Mon Sep 17 00:00:00 2001
f45498
From: Jon Maloy <jmaloy@redhat.com>
a19a21
Date: Tue, 9 Feb 2021 23:14:55 -0500
f45498
Subject: [PATCH 2/3] virtiofsd: optionally return inode pointer from
f45498
 lo_do_lookup()
f45498
f45498
RH-Author: Jon Maloy <jmaloy@redhat.com>
a19a21
Message-id: <20210209231456.1555472-3-jmaloy@redhat.com>
a19a21
Patchwork-id: 101022
a19a21
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 2/3] virtiofsd: optionally return inode pointer from lo_do_lookup()
a19a21
Bugzilla: 1919111
f45498
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
f45498
RH-Acked-by: Greg Kurz <gkurz@redhat.com>
f45498
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
f45498
f45498
From: Stefan Hajnoczi <stefanha@redhat.com>
f45498
f45498
lo_do_lookup() finds an existing inode or allocates a new one. It
f45498
increments nlookup so that the inode stays alive until the client
f45498
releases it.
f45498
f45498
Existing callers don't need the struct lo_inode so the function doesn't
f45498
return it. Extend the function to optionally return the inode. The next
f45498
commit will need it.
f45498
f45498
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
f45498
Reviewed-by: Greg Kurz <groug@kaod.org>
f45498
Message-Id: <20210204150208.367837-3-stefanha@redhat.com>
f45498
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
f45498
f45498
(cherry-picked from commit 22d2ece71e533310da31f2857ebc4a00d91968b3)
f45498
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
f45498
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
f45498
---
f45498
 tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++--------
f45498
 1 file changed, 21 insertions(+), 8 deletions(-)
f45498
f45498
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
f45498
index 518ba11c47..e5bd3d73e4 100644
f45498
--- a/tools/virtiofsd/passthrough_ll.c
f45498
+++ b/tools/virtiofsd/passthrough_ll.c
f45498
@@ -878,11 +878,13 @@ static void posix_locks_value_destroy(gpointer data)
f45498
 }
f45498
 
f45498
 /*
f45498
- * Increments nlookup and caller must release refcount using
f45498
- * lo_inode_put(&parent).
f45498
+ * Increments nlookup on the inode on success. unref_inode_lolocked() must be
f45498
+ * called eventually to decrement nlookup again. If inodep is non-NULL, the
f45498
+ * inode pointer is stored and the caller must call lo_inode_put().
f45498
  */
f45498
 static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
f45498
-                        struct fuse_entry_param *e)
f45498
+                        struct fuse_entry_param *e,
f45498
+                        struct lo_inode **inodep)
f45498
 {
f45498
     int newfd;
f45498
     int res;
f45498
@@ -891,6 +893,10 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
f45498
     struct lo_inode *inode = NULL;
f45498
     struct lo_inode *dir = lo_inode(req, parent);
f45498
 
f45498
+    if (inodep) {
f45498
+        *inodep = NULL;
f45498
+    }
f45498
+
f45498
     /*
f45498
      * name_to_handle_at() and open_by_handle_at() can reach here with fuse
f45498
      * mount point in guest, but we don't have its inode info in the
f45498
@@ -953,7 +959,14 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
f45498
         pthread_mutex_unlock(&lo->mutex);
f45498
     }
f45498
     e->ino = inode->fuse_ino;
f45498
-    lo_inode_put(lo, &inode;;
f45498
+
f45498
+    /* Transfer ownership of inode pointer to caller or drop it */
f45498
+    if (inodep) {
f45498
+        *inodep = inode;
f45498
+    } else {
f45498
+        lo_inode_put(lo, &inode;;
f45498
+    }
f45498
+
f45498
     lo_inode_put(lo, &dir;;
f45498
 
f45498
     fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n", (unsigned long long)parent,
f45498
@@ -988,7 +1001,7 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
f45498
         return;
f45498
     }
f45498
 
f45498
-    err = lo_do_lookup(req, parent, name, &e);
f45498
+    err = lo_do_lookup(req, parent, name, &e, NULL);
f45498
     if (err) {
f45498
         fuse_reply_err(req, err);
f45498
     } else {
f45498
@@ -1098,7 +1111,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
f45498
         goto out;
f45498
     }
f45498
 
f45498
-    saverr = lo_do_lookup(req, parent, name, &e);
f45498
+    saverr = lo_do_lookup(req, parent, name, &e, NULL);
f45498
     if (saverr) {
f45498
         goto out;
f45498
     }
f45498
@@ -1599,7 +1612,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
f45498
 
f45498
         if (plus) {
f45498
             if (!is_dot_or_dotdot(name)) {
f45498
-                err = lo_do_lookup(req, ino, name, &e);
f45498
+                err = lo_do_lookup(req, ino, name, &e, NULL);
f45498
                 if (err) {
f45498
                     goto error;
f45498
                 }
f45498
@@ -1793,7 +1806,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
f45498
         }
f45498
 
f45498
         fi->fh = fh;
f45498
-        err = lo_do_lookup(req, parent, name, &e);
f45498
+        err = lo_do_lookup(req, parent, name, &e, NULL);
f45498
     }
f45498
     if (lo->cache == CACHE_NONE) {
f45498
         fi->direct_io = 1;
f45498
-- 
f45498
2.18.2
f45498