cryptospore / rpms / qemu-kvm

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