22c213
From 23d81ee7564084f29e32fedaed5196ae1a5a3240 Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:01:10 +0100
22c213
Subject: [PATCH 039/116] virtiofsd: add --print-capabilities option
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-36-dgilbert@redhat.com>
22c213
Patchwork-id: 93486
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 035/112] virtiofsd: add --print-capabilities option
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: Stefan Hajnoczi <stefanha@redhat.com>
22c213
22c213
Add the --print-capabilities option as per vhost-user.rst "Backend
22c213
programs conventions".  Currently there are no advertised features.
22c213
22c213
Signed-off-by: Stefan Hajnoczi <stefanha@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 45018fbb0a73ce66fd3dd87ecd2872b45658add4)
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 docs/interop/vhost-user.json     |  4 +++-
22c213
 tools/virtiofsd/fuse_lowlevel.h  |  1 +
22c213
 tools/virtiofsd/helper.c         |  2 ++
22c213
 tools/virtiofsd/passthrough_ll.c | 12 ++++++++++++
22c213
 4 files changed, 18 insertions(+), 1 deletion(-)
22c213
22c213
diff --git a/docs/interop/vhost-user.json b/docs/interop/vhost-user.json
22c213
index da6aaf5..d4ea1f7 100644
22c213
--- a/docs/interop/vhost-user.json
22c213
+++ b/docs/interop/vhost-user.json
22c213
@@ -31,6 +31,7 @@
22c213
 # @rproc-serial: virtio remoteproc serial link
22c213
 # @scsi: virtio scsi
22c213
 # @vsock: virtio vsock transport
22c213
+# @fs: virtio fs (since 4.2)
22c213
 #
22c213
 # Since: 4.0
22c213
 ##
22c213
@@ -50,7 +51,8 @@
22c213
       'rpmsg',
22c213
       'rproc-serial',
22c213
       'scsi',
22c213
-      'vsock'
22c213
+      'vsock',
22c213
+      'fs'
22c213
   ]
22c213
 }
22c213
 
22c213
diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowlevel.h
22c213
index f6b3470..0d61df8 100644
22c213
--- a/tools/virtiofsd/fuse_lowlevel.h
22c213
+++ b/tools/virtiofsd/fuse_lowlevel.h
22c213
@@ -1794,6 +1794,7 @@ struct fuse_cmdline_opts {
22c213
     int nodefault_subtype;
22c213
     int show_version;
22c213
     int show_help;
22c213
+    int print_capabilities;
22c213
     unsigned int max_idle_threads;
22c213
 };
22c213
 
22c213
diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c
22c213
index a3645fc..b8ec5ac 100644
22c213
--- a/tools/virtiofsd/helper.c
22c213
+++ b/tools/virtiofsd/helper.c
22c213
@@ -40,6 +40,7 @@ static const struct fuse_opt fuse_helper_opts[] = {
22c213
     FUSE_HELPER_OPT("--help", show_help),
22c213
     FUSE_HELPER_OPT("-V", show_version),
22c213
     FUSE_HELPER_OPT("--version", show_version),
22c213
+    FUSE_HELPER_OPT("--print-capabilities", print_capabilities),
22c213
     FUSE_HELPER_OPT("-d", debug),
22c213
     FUSE_HELPER_OPT("debug", debug),
22c213
     FUSE_HELPER_OPT("-d", foreground),
22c213
@@ -135,6 +136,7 @@ void fuse_cmdline_help(void)
22c213
 {
22c213
     printf("    -h   --help                print help\n"
22c213
            "    -V   --version             print version\n"
22c213
+           "    --print-capabilities       print vhost-user.json\n"
22c213
            "    -d   -o debug              enable debug output (implies -f)\n"
22c213
            "    -f                         foreground operation\n"
22c213
            "    --daemonize                run in background\n"
22c213
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
22c213
index 037c5d7..cd27c09 100644
22c213
--- a/tools/virtiofsd/passthrough_ll.c
22c213
+++ b/tools/virtiofsd/passthrough_ll.c
22c213
@@ -1298,6 +1298,14 @@ static struct fuse_lowlevel_ops lo_oper = {
22c213
     .lseek = lo_lseek,
22c213
 };
22c213
 
22c213
+/* Print vhost-user.json backend program capabilities */
22c213
+static void print_capabilities(void)
22c213
+{
22c213
+    printf("{\n");
22c213
+    printf("  \"type\": \"fs\"\n");
22c213
+    printf("}\n");
22c213
+}
22c213
+
22c213
 int main(int argc, char *argv[])
22c213
 {
22c213
     struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
22c213
@@ -1328,6 +1336,10 @@ int main(int argc, char *argv[])
22c213
         fuse_lowlevel_version();
22c213
         ret = 0;
22c213
         goto err_out1;
22c213
+    } else if (opts.print_capabilities) {
22c213
+        print_capabilities();
22c213
+        ret = 0;
22c213
+        goto err_out1;
22c213
     }
22c213
 
22c213
     if (fuse_opt_parse(&args, &lo, lo_opts, NULL) == -1) {
22c213
-- 
22c213
1.8.3.1
22c213