Blame 0029-virtiofsd-Add-main-virtio-loop.patch

1d442b
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:00:58 +0000
1d442b
Subject: [PATCH] virtiofsd: Add main virtio loop
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
Processes incoming requests on the vhost-user fd.
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 204d8ae57b3c57098642c79b3c03d42495149c09)
1d442b
---
1d442b
 tools/virtiofsd/fuse_virtio.c | 42 ++++++++++++++++++++++++++++++++---
1d442b
 1 file changed, 39 insertions(+), 3 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
1d442b
index 2ae3c764dd..1928a2025c 100644
1d442b
--- a/tools/virtiofsd/fuse_virtio.c
1d442b
+++ b/tools/virtiofsd/fuse_virtio.c
1d442b
@@ -11,12 +11,14 @@
1d442b
  * See the file COPYING.LIB
1d442b
  */
1d442b
 
1d442b
+#include "fuse_virtio.h"
1d442b
 #include "fuse_i.h"
1d442b
 #include "standard-headers/linux/fuse.h"
1d442b
 #include "fuse_misc.h"
1d442b
 #include "fuse_opt.h"
1d442b
-#include "fuse_virtio.h"
1d442b
 
1d442b
+#include <assert.h>
1d442b
+#include <errno.h>
1d442b
 #include <stdint.h>
1d442b
 #include <stdio.h>
1d442b
 #include <stdlib.h>
1d442b
@@ -80,15 +82,49 @@ static const VuDevIface fv_iface = {
1d442b
     .queue_is_processed_in_order = fv_queue_order,
1d442b
 };
1d442b
 
1d442b
+/*
1d442b
+ * Main loop; this mostly deals with events on the vhost-user
1d442b
+ * socket itself, and not actual fuse data.
1d442b
+ */
1d442b
 int virtio_loop(struct fuse_session *se)
1d442b
 {
1d442b
     fuse_log(FUSE_LOG_INFO, "%s: Entry\n", __func__);
1d442b
 
1d442b
-    while (1) {
1d442b
-        /* TODO: Add stuffing */
1d442b
+    while (!fuse_session_exited(se)) {
1d442b
+        struct pollfd pf[1];
1d442b
+        pf[0].fd = se->vu_socketfd;
1d442b
+        pf[0].events = POLLIN;
1d442b
+        pf[0].revents = 0;
1d442b
+
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "%s: Waiting for VU event\n", __func__);
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, "virtio_loop 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\n", __func__,
1d442b
+                     pf[0].revents);
1d442b
+            break;
1d442b
+        }
1d442b
+        assert(pf[0].revents & POLLIN);
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "%s: Got VU event\n", __func__);
1d442b
+        if (!vu_dispatch(&se->virtio_dev->dev)) {
1d442b
+            fuse_log(FUSE_LOG_ERR, "%s: vu_dispatch failed\n", __func__);
1d442b
+            break;
1d442b
+        }
1d442b
     }
1d442b
 
1d442b
     fuse_log(FUSE_LOG_INFO, "%s: Exit\n", __func__);
1d442b
+
1d442b
+    return 0;
1d442b
 }
1d442b
 
1d442b
 int virtio_session_mount(struct fuse_session *se)