yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ddf19c
From 4ebabb66f4132186152edf8e1907fce436bf5c69 Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Mon, 27 Jan 2020 19:02:06 +0100
ddf19c
Subject: [PATCH 095/116] virtiofsd: make lo_release() atomic
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-92-dgilbert@redhat.com>
ddf19c
Patchwork-id: 93545
ddf19c
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 091/112] virtiofsd: make lo_release() atomic
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: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
Hold the lock across both lo_map_get() and lo_map_remove() to prevent
ddf19c
races between two FUSE_RELEASE requests.  In this case I don't see a
ddf19c
serious bug but it's safer to do things atomically.
ddf19c
ddf19c
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
ddf19c
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
(cherry picked from commit baed65c060c0e524530bc243eec427fb408bd477)
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
---
ddf19c
 tools/virtiofsd/passthrough_ll.c | 12 ++++++++----
ddf19c
 1 file changed, 8 insertions(+), 4 deletions(-)
ddf19c
ddf19c
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
ddf19c
index 9414935..690edbc 100644
ddf19c
--- a/tools/virtiofsd/passthrough_ll.c
ddf19c
+++ b/tools/virtiofsd/passthrough_ll.c
ddf19c
@@ -1772,14 +1772,18 @@ static void lo_release(fuse_req_t req, fuse_ino_t ino,
ddf19c
                        struct fuse_file_info *fi)
ddf19c
 {
ddf19c
     struct lo_data *lo = lo_data(req);
ddf19c
-    int fd;
ddf19c
+    struct lo_map_elem *elem;
ddf19c
+    int fd = -1;
ddf19c
 
ddf19c
     (void)ino;
ddf19c
 
ddf19c
-    fd = lo_fi_fd(req, fi);
ddf19c
-
ddf19c
     pthread_mutex_lock(&lo->mutex);
ddf19c
-    lo_map_remove(&lo->fd_map, fi->fh);
ddf19c
+    elem = lo_map_get(&lo->fd_map, fi->fh);
ddf19c
+    if (elem) {
ddf19c
+        fd = elem->fd;
ddf19c
+        elem = NULL;
ddf19c
+        lo_map_remove(&lo->fd_map, fi->fh);
ddf19c
+    }
ddf19c
     pthread_mutex_unlock(&lo->mutex);
ddf19c
 
ddf19c
     close(fd);
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c