yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
902636
From 083b944fac29bc3115a19eb38e176f6b23f04938 Mon Sep 17 00:00:00 2001
902636
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
Date: Mon, 27 Jan 2020 19:01:01 +0100
902636
Subject: [PATCH 030/116] virtiofsd: Poll kick_fd for queue
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-27-dgilbert@redhat.com>
902636
Patchwork-id: 93483
902636
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 026/112] virtiofsd: Poll kick_fd for queue
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: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
902636
In the queue thread poll the kick_fd we're passed.
902636
902636
Signed-off-by: Dr. David Alan Gilbert <dgilbert@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 5dcd1f56141378226d33dc3df68ec57913e0aa04)
902636
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
902636
---
902636
 tools/virtiofsd/fuse_virtio.c | 40 +++++++++++++++++++++++++++++++++++++++-
902636
 1 file changed, 39 insertions(+), 1 deletion(-)
902636
902636
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
902636
index 2a94bb3..05e7258 100644
902636
--- a/tools/virtiofsd/fuse_virtio.c
902636
+++ b/tools/virtiofsd/fuse_virtio.c
902636
@@ -24,6 +24,7 @@
902636
 #include <stdio.h>
902636
 #include <stdlib.h>
902636
 #include <string.h>
902636
+#include <sys/eventfd.h>
902636
 #include <sys/socket.h>
902636
 #include <sys/types.h>
902636
 #include <sys/un.h>
902636
@@ -100,13 +101,50 @@ static void fv_panic(VuDev *dev, const char *err)
902636
     exit(EXIT_FAILURE);
902636
 }
902636
 
902636
+/* Thread function for individual queues, created when a queue is 'started' */
902636
 static void *fv_queue_thread(void *opaque)
902636
 {
902636
     struct fv_QueueInfo *qi = opaque;
902636
     fuse_log(FUSE_LOG_INFO, "%s: Start for queue %d kick_fd %d\n", __func__,
902636
              qi->qidx, qi->kick_fd);
902636
     while (1) {
902636
-        /* TODO */
902636
+        struct pollfd pf[1];
902636
+        pf[0].fd = qi->kick_fd;
902636
+        pf[0].events = POLLIN;
902636
+        pf[0].revents = 0;
902636
+
902636
+        fuse_log(FUSE_LOG_DEBUG, "%s: Waiting for Queue %d event\n", __func__,
902636
+                 qi->qidx);
902636
+        int poll_res = ppoll(pf, 1, NULL, NULL);
902636
+
902636
+        if (poll_res == -1) {
902636
+            if (errno == EINTR) {
902636
+                fuse_log(FUSE_LOG_INFO, "%s: ppoll interrupted, going around\n",
902636
+                         __func__);
902636
+                continue;
902636
+            }
902636
+            fuse_log(FUSE_LOG_ERR, "fv_queue_thread ppoll: %m\n");
902636
+            break;
902636
+        }
902636
+        assert(poll_res == 1);
902636
+        if (pf[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
902636
+            fuse_log(FUSE_LOG_ERR, "%s: Unexpected poll revents %x Queue %d\n",
902636
+                     __func__, pf[0].revents, qi->qidx);
902636
+            break;
902636
+        }
902636
+        assert(pf[0].revents & POLLIN);
902636
+        fuse_log(FUSE_LOG_DEBUG, "%s: Got queue event on Queue %d\n", __func__,
902636
+                 qi->qidx);
902636
+
902636
+        eventfd_t evalue;
902636
+        if (eventfd_read(qi->kick_fd, &evalue)) {
902636
+            fuse_log(FUSE_LOG_ERR, "Eventfd_read for queue: %m\n");
902636
+            break;
902636
+        }
902636
+        if (qi->virtio_dev->se->debug) {
902636
+            fprintf(stderr, "%s: Queue %d gave evalue: %zx\n", __func__,
902636
+                    qi->qidx, (size_t)evalue);
902636
+        }
902636
     }
902636
 
902636
     return NULL;
902636
-- 
902636
1.8.3.1
902636