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