yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtiofsd-Convert-lo_destroy-to-take-the-lo-mutex-lo.patch

22c213
From 24f91062f571ad2dd2ac22db3b7d456a2c8bd2cb Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:02:23 +0100
22c213
Subject: [PATCH 112/116] virtiofsd: Convert lo_destroy to take the lo->mutex
22c213
 lock itself
22c213
MIME-Version: 1.0
22c213
Content-Type: text/plain; charset=UTF-8
22c213
Content-Transfer-Encoding: 8bit
22c213
22c213
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Message-id: <20200127190227.40942-109-dgilbert@redhat.com>
22c213
Patchwork-id: 93563
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 108/112] virtiofsd: Convert lo_destroy to take the lo->mutex lock itself
22c213
Bugzilla: 1694164
22c213
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
22c213
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
22c213
lo_destroy was relying on some implicit knowledge of the locking;
22c213
we can avoid this if we create an unref_inode that doesn't take
22c213
the lock and then grab it for the whole of the lo_destroy.
22c213
22c213
Suggested-by: Vivek Goyal <vgoyal@redhat.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit fe4c15798a48143dd6b1f58d2d3cad12206ce211)
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 tools/virtiofsd/passthrough_ll.c | 31 +++++++++++++++++--------------
22c213
 1 file changed, 17 insertions(+), 14 deletions(-)
22c213
22c213
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
22c213
index eb001b9..fc15d61 100644
22c213
--- a/tools/virtiofsd/passthrough_ll.c
22c213
+++ b/tools/virtiofsd/passthrough_ll.c
22c213
@@ -1344,14 +1344,13 @@ static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
22c213
     lo_inode_put(lo, &inode;;
22c213
 }
22c213
 
22c213
-static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
22c213
-                                 uint64_t n)
22c213
+/* To be called with lo->mutex held */
22c213
+static void unref_inode(struct lo_data *lo, struct lo_inode *inode, uint64_t n)
22c213
 {
22c213
     if (!inode) {
22c213
         return;
22c213
     }
22c213
 
22c213
-    pthread_mutex_lock(&lo->mutex);
22c213
     assert(inode->nlookup >= n);
22c213
     inode->nlookup -= n;
22c213
     if (!inode->nlookup) {
22c213
@@ -1362,15 +1361,24 @@ static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
22c213
         }
22c213
         g_hash_table_destroy(inode->posix_locks);
22c213
         pthread_mutex_destroy(&inode->plock_mutex);
22c213
-        pthread_mutex_unlock(&lo->mutex);
22c213
 
22c213
         /* Drop our refcount from lo_do_lookup() */
22c213
         lo_inode_put(lo, &inode;;
22c213
-    } else {
22c213
-        pthread_mutex_unlock(&lo->mutex);
22c213
     }
22c213
 }
22c213
 
22c213
+static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
22c213
+                                 uint64_t n)
22c213
+{
22c213
+    if (!inode) {
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    pthread_mutex_lock(&lo->mutex);
22c213
+    unref_inode(lo, inode, n);
22c213
+    pthread_mutex_unlock(&lo->mutex);
22c213
+}
22c213
+
22c213
 static void lo_forget_one(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
22c213
 {
22c213
     struct lo_data *lo = lo_data(req);
22c213
@@ -2458,13 +2466,7 @@ static void lo_destroy(void *userdata)
22c213
 {
22c213
     struct lo_data *lo = (struct lo_data *)userdata;
22c213
 
22c213
-    /*
22c213
-     * Normally lo->mutex must be taken when traversing lo->inodes but
22c213
-     * lo_destroy() is a serialized request so no races are possible here.
22c213
-     *
22c213
-     * In addition, we cannot acquire lo->mutex since unref_inode() takes it
22c213
-     * too and this would result in a recursive lock.
22c213
-     */
22c213
+    pthread_mutex_lock(&lo->mutex);
22c213
     while (true) {
22c213
         GHashTableIter iter;
22c213
         gpointer key, value;
22c213
@@ -2475,8 +2477,9 @@ static void lo_destroy(void *userdata)
22c213
         }
22c213
 
22c213
         struct lo_inode *inode = value;
22c213
-        unref_inode_lolocked(lo, inode, inode->nlookup);
22c213
+        unref_inode(lo, inode, inode->nlookup);
22c213
     }
22c213
+    pthread_mutex_unlock(&lo->mutex);
22c213
 }
22c213
 
22c213
 static struct fuse_lowlevel_ops lo_oper = {
22c213
-- 
22c213
1.8.3.1
22c213