a41c76
From f15a4eb66ecbfb80340bbab65150b22ab3a313fe Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <f15a4eb66ecbfb80340bbab65150b22ab3a313fe@dist-git>
a41c76
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
a41c76
Date: Wed, 4 Mar 2020 12:42:48 +0100
a41c76
Subject: [PATCH] qemu: use the vhost-user schemas to find binary
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Look into /usr/share/qemu/vhost-user to see whether we can find
a41c76
a suitable virtiofsd binary, in case the user did not provide one
a41c76
in the domain XML.
a41c76
a41c76
Signed-off-by: Ján Tomko <jtomko@redhat.com>
a41c76
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
a41c76
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Tested-by: Andrea Bolognani <abologna@redhat.com>
a41c76
(cherry picked from commit 071a1ab92fbbd58f68fb4929d004d6155759067e)
a41c76
Signed-off-by: Ján Tomko <jtomko@redhat.com>
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
a41c76
Message-Id: <e422c33d2c825f91b90eb10ef1530406a3492e0e.1583322091.git.jtomko@redhat.com>
a41c76
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_extdevice.c  |  9 +++++++++
a41c76
 src/qemu/qemu_vhost_user.c | 39 ++++++++++++++++++++++++++++++++++++++
a41c76
 src/qemu/qemu_vhost_user.h |  4 ++++
a41c76
 src/qemu/qemu_virtiofs.c   | 11 +++++++++++
a41c76
 src/qemu/qemu_virtiofs.h   |  4 ++++
a41c76
 5 files changed, 67 insertions(+)
a41c76
a41c76
diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
a41c76
index f66bafb62f..07b9117f57 100644
a41c76
--- a/src/qemu/qemu_extdevice.c
a41c76
+++ b/src/qemu/qemu_extdevice.c
a41c76
@@ -105,6 +105,15 @@ qemuExtDevicesPrepareDomain(virQEMUDriverPtr driver,
a41c76
         }
a41c76
     }
a41c76
 
a41c76
+    for (i = 0; i < vm->def->nfss; i++) {
a41c76
+        virDomainFSDefPtr fs = vm->def->fss[i];
a41c76
+
a41c76
+        if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
a41c76
+            if (qemuVirtioFSPrepareDomain(driver, fs) < 0)
a41c76
+                return -1;
a41c76
+        }
a41c76
+    }
a41c76
+
a41c76
     return ret;
a41c76
 }
a41c76
 
a41c76
diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c
a41c76
index 4c25b30664..a3d5ac0fc7 100644
a41c76
--- a/src/qemu/qemu_vhost_user.c
a41c76
+++ b/src/qemu/qemu_vhost_user.c
a41c76
@@ -416,3 +416,42 @@ qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver,
a41c76
     VIR_FREE(vus);
a41c76
     return ret;
a41c76
 }
a41c76
+
a41c76
+
a41c76
+int
a41c76
+qemuVhostUserFillDomainFS(virQEMUDriverPtr driver,
a41c76
+                          virDomainFSDefPtr fs)
a41c76
+{
a41c76
+    qemuVhostUserPtr *vus = NULL;
a41c76
+    ssize_t nvus = 0;
a41c76
+    ssize_t i;
a41c76
+    int ret = -1;
a41c76
+
a41c76
+    if ((nvus = qemuVhostUserFetchParsedConfigs(driver->privileged,
a41c76
+                                                &vus, NULL)) < 0)
a41c76
+        goto end;
a41c76
+
a41c76
+    for (i = 0; i < nvus; i++) {
a41c76
+        qemuVhostUserPtr vu = vus[i];
a41c76
+
a41c76
+        if (vu->type != QEMU_VHOST_USER_TYPE_FS)
a41c76
+            continue;
a41c76
+
a41c76
+        fs->binary = g_strdup(vu->binary);
a41c76
+        break;
a41c76
+    }
a41c76
+
a41c76
+    if (i == nvus) {
a41c76
+        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
a41c76
+                       _("Unable to find a satisfying virtiofsd"));
a41c76
+        goto end;
a41c76
+    }
a41c76
+
a41c76
+    ret = 0;
a41c76
+
a41c76
+ end:
a41c76
+    for (i = 0; i < nvus; i++)
a41c76
+        qemuVhostUserFree(vus[i]);
a41c76
+    g_free(vus);
a41c76
+    return ret;
a41c76
+}
a41c76
diff --git a/src/qemu/qemu_vhost_user.h b/src/qemu/qemu_vhost_user.h
a41c76
index 369ba00caa..e505c8a473 100644
a41c76
--- a/src/qemu/qemu_vhost_user.h
a41c76
+++ b/src/qemu/qemu_vhost_user.h
a41c76
@@ -45,3 +45,7 @@ qemuVhostUserFetchConfigs(char ***configs,
a41c76
 int
a41c76
 qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver,
a41c76
                            virDomainVideoDefPtr video);
a41c76
+
a41c76
+int
a41c76
+qemuVhostUserFillDomainFS(virQEMUDriverPtr driver,
a41c76
+                          virDomainFSDefPtr fs);
a41c76
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
a41c76
index 194855ece8..d579ce1d33 100644
a41c76
--- a/src/qemu/qemu_virtiofs.c
a41c76
+++ b/src/qemu/qemu_virtiofs.c
a41c76
@@ -28,6 +28,7 @@
a41c76
 #include "qemu_conf.h"
a41c76
 #include "qemu_extdevice.h"
a41c76
 #include "qemu_security.h"
a41c76
+#include "qemu_vhost_user.h"
a41c76
 #include "qemu_virtiofs.h"
a41c76
 #include "virpidfile.h"
a41c76
 #include "virqemu.h"
a41c76
@@ -325,3 +326,13 @@ qemuVirtioFSSetupCgroup(virDomainObjPtr vm,
a41c76
 
a41c76
     return 0;
a41c76
 }
a41c76
+
a41c76
+int
a41c76
+qemuVirtioFSPrepareDomain(virQEMUDriverPtr driver,
a41c76
+                          virDomainFSDefPtr fs)
a41c76
+{
a41c76
+    if (fs->binary)
a41c76
+        return 0;
a41c76
+
a41c76
+    return qemuVhostUserFillDomainFS(driver, fs);
a41c76
+}
a41c76
diff --git a/src/qemu/qemu_virtiofs.h b/src/qemu/qemu_virtiofs.h
a41c76
index 1db59917c6..7de4ea6190 100644
a41c76
--- a/src/qemu/qemu_virtiofs.h
a41c76
+++ b/src/qemu/qemu_virtiofs.h
a41c76
@@ -40,3 +40,7 @@ int
a41c76
 qemuVirtioFSSetupCgroup(virDomainObjPtr vm,
a41c76
                         virDomainFSDefPtr fs,
a41c76
                         virCgroupPtr cgroup);
a41c76
+
a41c76
+int
a41c76
+qemuVirtioFSPrepareDomain(virQEMUDriverPtr driver,
a41c76
+                          virDomainFSDefPtr fs);
a41c76
-- 
a41c76
2.25.1
a41c76