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