render / rpms / libvirt

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

Reject unsupported configurations.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Tested-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
(cherry picked from commit efaf46811c909ee5333360fba1d75ae82352964a)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
Message-Id: <1fcb6b7d58c3791799c5d436edaa2faa07e92305.1583322091.git.jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 82 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 77 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 402b079b09..79d8de2e42 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8329,11 +8329,52 @@ qemuDomainDeviceDefValidateIOMMU(const virDomainIOMMUDef *iommu,
     return 0;
 }
 
+static int
+qemuDomainDefValidateVirtioFSSharedMemory(const virDomainDef *def)
+{
+    size_t numa_nodes = virDomainNumaGetNodeCount(def->numa);
+    size_t i;
+
+    if (numa_nodes == 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("virtiofs requires one or more NUMA nodes"));
+        return -1;
+    }
+
+    for (i = 0; i < numa_nodes; i++) {
+        virDomainMemoryAccess node_access =
+            virDomainNumaGetNodeMemoryAccessMode(def->numa, i);
+
+        switch (node_access) {
+        case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT:
+            if (def->mem.access != VIR_DOMAIN_MEMORY_ACCESS_SHARED) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("virtiofs requires shared memory"));
+                return -1;
+            }
+            break;
+        case VIR_DOMAIN_MEMORY_ACCESS_SHARED:
+            break;
+        case VIR_DOMAIN_MEMORY_ACCESS_PRIVATE:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("virtiofs requires shared memory"));
+            return -1;
+
+        case VIR_DOMAIN_MEMORY_ACCESS_LAST:
+        default:
+            virReportEnumRangeError(virDomainMemoryAccess, node_access);
+            return -1;
+
+        }
+    }
+    return 0;
+}
 
 static int
 qemuDomainDeviceDefValidateFS(virDomainFSDefPtr fs,
-                              const virDomainDef *def G_GNUC_UNUSED,
-                              virQEMUCapsPtr qemuCaps G_GNUC_UNUSED)
+                              const virDomainDef *def,
+                              virQEMUDriverPtr driver,
+                              virQEMUCapsPtr qemuCaps)
 {
     if (fs->type != VIR_DOMAIN_FS_TYPE_MOUNT) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -8362,8 +8403,39 @@ qemuDomainDeviceDefValidateFS(virDomainFSDefPtr fs,
         return -1;
 
     case VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS:
-        /* TODO: vhost-user-fs-pci */
-        return 0;
+        if (!virQEMUDriverIsPrivileged(driver)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("virtiofs is not yet supported in session mode"));
+            return -1;
+        }
+        if (fs->accessmode != VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("virtiofs only supports passthrough accessmode"));
+            return -1;
+        }
+        if (fs->wrpolicy != VIR_DOMAIN_FS_WRPOLICY_DEFAULT) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("virtiofs does not support wrpolicy"));
+            return -1;
+        }
+        if (fs->model != VIR_DOMAIN_FS_MODEL_DEFAULT) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("virtiofs does not support model"));
+            return -1;
+        }
+        if (fs->format != VIR_STORAGE_FILE_NONE) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("virtiofs does not support format"));
+            return -1;
+        }
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_FS)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("virtiofs is not supported with this QEMU binary"));
+            return -1;
+        }
+        if (qemuDomainDefValidateVirtioFSSharedMemory(def) < 0)
+            return -1;
+        break;
 
     case VIR_DOMAIN_FS_DRIVER_TYPE_LAST:
     default:
@@ -8542,7 +8614,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
         break;
 
     case VIR_DOMAIN_DEVICE_FS:
-        ret = qemuDomainDeviceDefValidateFS(dev->data.fs, def, qemuCaps);
+        ret = qemuDomainDeviceDefValidateFS(dev->data.fs, def, driver, qemuCaps);
         break;
 
     case VIR_DOMAIN_DEVICE_NVRAM:
-- 
2.25.1