Blame 0032-virtiofsd-Poll-kick_fd-for-queue.patch

1d442b
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:01:01 +0000
1d442b
Subject: [PATCH] virtiofsd: Poll kick_fd for queue
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
In the queue thread poll the kick_fd we're passed.
1d442b
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@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 5dcd1f56141378226d33dc3df68ec57913e0aa04)
1d442b
---
1d442b
 tools/virtiofsd/fuse_virtio.c | 40 ++++++++++++++++++++++++++++++++++-
1d442b
 1 file changed, 39 insertions(+), 1 deletion(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
1d442b
index 2a94bb3cca..05e7258712 100644
1d442b
--- a/tools/virtiofsd/fuse_virtio.c
1d442b
+++ b/tools/virtiofsd/fuse_virtio.c
1d442b
@@ -24,6 +24,7 @@
1d442b
 #include <stdio.h>
1d442b
 #include <stdlib.h>
1d442b
 #include <string.h>
1d442b
+#include <sys/eventfd.h>
1d442b
 #include <sys/socket.h>
1d442b
 #include <sys/types.h>
1d442b
 #include <sys/un.h>
1d442b
@@ -100,13 +101,50 @@ static void fv_panic(VuDev *dev, const char *err)
1d442b
     exit(EXIT_FAILURE);
1d442b
 }
1d442b
 
1d442b
+/* Thread function for individual queues, created when a queue is 'started' */
1d442b
 static void *fv_queue_thread(void *opaque)
1d442b
 {
1d442b
     struct fv_QueueInfo *qi = opaque;
1d442b
     fuse_log(FUSE_LOG_INFO, "%s: Start for queue %d kick_fd %d\n", __func__,
1d442b
              qi->qidx, qi->kick_fd);
1d442b
     while (1) {
1d442b
-        /* TODO */
1d442b
+        struct pollfd pf[1];
1d442b
+        pf[0].fd = qi->kick_fd;
1d442b
+        pf[0].events = POLLIN;
1d442b
+        pf[0].revents = 0;
1d442b
+
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "%s: Waiting for Queue %d event\n", __func__,
1d442b
+                 qi->qidx);
1d442b
+        int poll_res = ppoll(pf, 1, NULL, NULL);
1d442b
+
1d442b
+        if (poll_res == -1) {
1d442b
+            if (errno == EINTR) {
1d442b
+                fuse_log(FUSE_LOG_INFO, "%s: ppoll interrupted, going around\n",
1d442b
+                         __func__);
1d442b
+                continue;
1d442b
+            }
1d442b
+            fuse_log(FUSE_LOG_ERR, "fv_queue_thread ppoll: %m\n");
1d442b
+            break;
1d442b
+        }
1d442b
+        assert(poll_res == 1);
1d442b
+        if (pf[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
1d442b
+            fuse_log(FUSE_LOG_ERR, "%s: Unexpected poll revents %x Queue %d\n",
1d442b
+                     __func__, pf[0].revents, qi->qidx);
1d442b
+            break;
1d442b
+        }
1d442b
+        assert(pf[0].revents & POLLIN);
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "%s: Got queue event on Queue %d\n", __func__,
1d442b
+                 qi->qidx);
1d442b
+
1d442b
+        eventfd_t evalue;
1d442b
+        if (eventfd_read(qi->kick_fd, &evalue)) {
1d442b
+            fuse_log(FUSE_LOG_ERR, "Eventfd_read for queue: %m\n");
1d442b
+            break;
1d442b
+        }
1d442b
+        if (qi->virtio_dev->se->debug) {
1d442b
+            fprintf(stderr, "%s: Queue %d gave evalue: %zx\n", __func__,
1d442b
+                    qi->qidx, (size_t)evalue);
1d442b
+        }
1d442b
     }
1d442b
 
1d442b
     return NULL;