render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From f15a4eb66ecbfb80340bbab65150b22ab3a313fe Mon Sep 17 00:00:00 2001
Message-Id: <f15a4eb66ecbfb80340bbab65150b22ab3a313fe@dist-git>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Wed, 4 Mar 2020 12:42:48 +0100
Subject: [PATCH] qemu: use the vhost-user schemas to find binary
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Look into /usr/share/qemu/vhost-user to see whether we can find
a suitable virtiofsd binary, in case the user did not provide one
in the domain XML.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Tested-by: Andrea Bolognani <abologna@redhat.com>
(cherry picked from commit 071a1ab92fbbd58f68fb4929d004d6155759067e)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
Message-Id: <e422c33d2c825f91b90eb10ef1530406a3492e0e.1583322091.git.jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_extdevice.c  |  9 +++++++++
 src/qemu/qemu_vhost_user.c | 39 ++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_vhost_user.h |  4 ++++
 src/qemu/qemu_virtiofs.c   | 11 +++++++++++
 src/qemu/qemu_virtiofs.h   |  4 ++++
 5 files changed, 67 insertions(+)

diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
index f66bafb62f..07b9117f57 100644
--- a/src/qemu/qemu_extdevice.c
+++ b/src/qemu/qemu_extdevice.c
@@ -105,6 +105,15 @@ qemuExtDevicesPrepareDomain(virQEMUDriverPtr driver,
         }
     }
 
+    for (i = 0; i < vm->def->nfss; i++) {
+        virDomainFSDefPtr fs = vm->def->fss[i];
+
+        if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
+            if (qemuVirtioFSPrepareDomain(driver, fs) < 0)
+                return -1;
+        }
+    }
+
     return ret;
 }
 
diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c
index 4c25b30664..a3d5ac0fc7 100644
--- a/src/qemu/qemu_vhost_user.c
+++ b/src/qemu/qemu_vhost_user.c
@@ -416,3 +416,42 @@ qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver,
     VIR_FREE(vus);
     return ret;
 }
+
+
+int
+qemuVhostUserFillDomainFS(virQEMUDriverPtr driver,
+                          virDomainFSDefPtr fs)
+{
+    qemuVhostUserPtr *vus = NULL;
+    ssize_t nvus = 0;
+    ssize_t i;
+    int ret = -1;
+
+    if ((nvus = qemuVhostUserFetchParsedConfigs(driver->privileged,
+                                                &vus, NULL)) < 0)
+        goto end;
+
+    for (i = 0; i < nvus; i++) {
+        qemuVhostUserPtr vu = vus[i];
+
+        if (vu->type != QEMU_VHOST_USER_TYPE_FS)
+            continue;
+
+        fs->binary = g_strdup(vu->binary);
+        break;
+    }
+
+    if (i == nvus) {
+        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                       _("Unable to find a satisfying virtiofsd"));
+        goto end;
+    }
+
+    ret = 0;
+
+ end:
+    for (i = 0; i < nvus; i++)
+        qemuVhostUserFree(vus[i]);
+    g_free(vus);
+    return ret;
+}
diff --git a/src/qemu/qemu_vhost_user.h b/src/qemu/qemu_vhost_user.h
index 369ba00caa..e505c8a473 100644
--- a/src/qemu/qemu_vhost_user.h
+++ b/src/qemu/qemu_vhost_user.h
@@ -45,3 +45,7 @@ qemuVhostUserFetchConfigs(char ***configs,
 int
 qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver,
                            virDomainVideoDefPtr video);
+
+int
+qemuVhostUserFillDomainFS(virQEMUDriverPtr driver,
+                          virDomainFSDefPtr fs);
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
index 194855ece8..d579ce1d33 100644
--- a/src/qemu/qemu_virtiofs.c
+++ b/src/qemu/qemu_virtiofs.c
@@ -28,6 +28,7 @@
 #include "qemu_conf.h"
 #include "qemu_extdevice.h"
 #include "qemu_security.h"
+#include "qemu_vhost_user.h"
 #include "qemu_virtiofs.h"
 #include "virpidfile.h"
 #include "virqemu.h"
@@ -325,3 +326,13 @@ qemuVirtioFSSetupCgroup(virDomainObjPtr vm,
 
     return 0;
 }
+
+int
+qemuVirtioFSPrepareDomain(virQEMUDriverPtr driver,
+                          virDomainFSDefPtr fs)
+{
+    if (fs->binary)
+        return 0;
+
+    return qemuVhostUserFillDomainFS(driver, fs);
+}
diff --git a/src/qemu/qemu_virtiofs.h b/src/qemu/qemu_virtiofs.h
index 1db59917c6..7de4ea6190 100644
--- a/src/qemu/qemu_virtiofs.h
+++ b/src/qemu/qemu_virtiofs.h
@@ -40,3 +40,7 @@ int
 qemuVirtioFSSetupCgroup(virDomainObjPtr vm,
                         virDomainFSDefPtr fs,
                         virCgroupPtr cgroup);
+
+int
+qemuVirtioFSPrepareDomain(virQEMUDriverPtr driver,
+                          virDomainFSDefPtr fs);
-- 
2.25.1