render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0097-virtiofsd-make-lo_release-atomic.patch

1d442b
From: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:02:06 +0000
1d442b
Subject: [PATCH] virtiofsd: make lo_release() atomic
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
Hold the lock across both lo_map_get() and lo_map_remove() to prevent
1d442b
races between two FUSE_RELEASE requests.  In this case I don't see a
1d442b
serious bug but it's safer to do things atomically.
1d442b
1d442b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit baed65c060c0e524530bc243eec427fb408bd477)
1d442b
---
1d442b
 tools/virtiofsd/passthrough_ll.c | 12 ++++++++----
1d442b
 1 file changed, 8 insertions(+), 4 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
1d442b
index 9414935b52..690edbc4c5 100644
1d442b
--- a/tools/virtiofsd/passthrough_ll.c
1d442b
+++ b/tools/virtiofsd/passthrough_ll.c
1d442b
@@ -1772,14 +1772,18 @@ static void lo_release(fuse_req_t req, fuse_ino_t ino,
1d442b
                        struct fuse_file_info *fi)
1d442b
 {
1d442b
     struct lo_data *lo = lo_data(req);
1d442b
-    int fd;
1d442b
+    struct lo_map_elem *elem;
1d442b
+    int fd = -1;
1d442b
 
1d442b
     (void)ino;
1d442b
 
1d442b
-    fd = lo_fi_fd(req, fi);
1d442b
-
1d442b
     pthread_mutex_lock(&lo->mutex);
1d442b
-    lo_map_remove(&lo->fd_map, fi->fh);
1d442b
+    elem = lo_map_get(&lo->fd_map, fi->fh);
1d442b
+    if (elem) {
1d442b
+        fd = elem->fd;
1d442b
+        elem = NULL;
1d442b
+        lo_map_remove(&lo->fd_map, fi->fh);
1d442b
+    }
1d442b
     pthread_mutex_unlock(&lo->mutex);
1d442b
 
1d442b
     close(fd);