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