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

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