a41c76
From 3366d4df5aac258013848cf5df7c95d45693c1e0 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <3366d4df5aac258013848cf5df7c95d45693c1e0@dist-git>
a41c76
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
a41c76
Date: Wed, 4 Mar 2020 12:42:44 +0100
a41c76
Subject: [PATCH] qemu: validate virtiofs filesystems
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Reject unsupported configurations.
a41c76
a41c76
Signed-off-by: Ján Tomko <jtomko@redhat.com>
a41c76
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Tested-by: Andrea Bolognani <abologna@redhat.com>
a41c76
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
a41c76
(cherry picked from commit efaf46811c909ee5333360fba1d75ae82352964a)
a41c76
Signed-off-by: Ján Tomko <jtomko@redhat.com>
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
a41c76
Message-Id: <1fcb6b7d58c3791799c5d436edaa2faa07e92305.1583322091.git.jtomko@redhat.com>
a41c76
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_domain.c | 82 +++++++++++++++++++++++++++++++++++++++---
a41c76
 1 file changed, 77 insertions(+), 5 deletions(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
a41c76
index 402b079b09..79d8de2e42 100644
a41c76
--- a/src/qemu/qemu_domain.c
a41c76
+++ b/src/qemu/qemu_domain.c
a41c76
@@ -8329,11 +8329,52 @@ qemuDomainDeviceDefValidateIOMMU(const virDomainIOMMUDef *iommu,
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
+static int
a41c76
+qemuDomainDefValidateVirtioFSSharedMemory(const virDomainDef *def)
a41c76
+{
a41c76
+    size_t numa_nodes = virDomainNumaGetNodeCount(def->numa);
a41c76
+    size_t i;
a41c76
+
a41c76
+    if (numa_nodes == 0) {
a41c76
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                       _("virtiofs requires one or more NUMA nodes"));
a41c76
+        return -1;
a41c76
+    }
a41c76
+
a41c76
+    for (i = 0; i < numa_nodes; i++) {
a41c76
+        virDomainMemoryAccess node_access =
a41c76
+            virDomainNumaGetNodeMemoryAccessMode(def->numa, i);
a41c76
+
a41c76
+        switch (node_access) {
a41c76
+        case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT:
a41c76
+            if (def->mem.access != VIR_DOMAIN_MEMORY_ACCESS_SHARED) {
a41c76
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                               _("virtiofs requires shared memory"));
a41c76
+                return -1;
a41c76
+            }
a41c76
+            break;
a41c76
+        case VIR_DOMAIN_MEMORY_ACCESS_SHARED:
a41c76
+            break;
a41c76
+        case VIR_DOMAIN_MEMORY_ACCESS_PRIVATE:
a41c76
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                           _("virtiofs requires shared memory"));
a41c76
+            return -1;
a41c76
+
a41c76
+        case VIR_DOMAIN_MEMORY_ACCESS_LAST:
a41c76
+        default:
a41c76
+            virReportEnumRangeError(virDomainMemoryAccess, node_access);
a41c76
+            return -1;
a41c76
+
a41c76
+        }
a41c76
+    }
a41c76
+    return 0;
a41c76
+}
a41c76
 
a41c76
 static int
a41c76
 qemuDomainDeviceDefValidateFS(virDomainFSDefPtr fs,
a41c76
-                              const virDomainDef *def G_GNUC_UNUSED,
a41c76
-                              virQEMUCapsPtr qemuCaps G_GNUC_UNUSED)
a41c76
+                              const virDomainDef *def,
a41c76
+                              virQEMUDriverPtr driver,
a41c76
+                              virQEMUCapsPtr qemuCaps)
a41c76
 {
a41c76
     if (fs->type != VIR_DOMAIN_FS_TYPE_MOUNT) {
a41c76
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
@@ -8362,8 +8403,39 @@ qemuDomainDeviceDefValidateFS(virDomainFSDefPtr fs,
a41c76
         return -1;
a41c76
 
a41c76
     case VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS:
a41c76
-        /* TODO: vhost-user-fs-pci */
a41c76
-        return 0;
a41c76
+        if (!virQEMUDriverIsPrivileged(driver)) {
a41c76
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                           _("virtiofs is not yet supported in session mode"));
a41c76
+            return -1;
a41c76
+        }
a41c76
+        if (fs->accessmode != VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH) {
a41c76
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                           _("virtiofs only supports passthrough accessmode"));
a41c76
+            return -1;
a41c76
+        }
a41c76
+        if (fs->wrpolicy != VIR_DOMAIN_FS_WRPOLICY_DEFAULT) {
a41c76
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                           _("virtiofs does not support wrpolicy"));
a41c76
+            return -1;
a41c76
+        }
a41c76
+        if (fs->model != VIR_DOMAIN_FS_MODEL_DEFAULT) {
a41c76
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                           _("virtiofs does not support model"));
a41c76
+            return -1;
a41c76
+        }
a41c76
+        if (fs->format != VIR_STORAGE_FILE_NONE) {
a41c76
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                           _("virtiofs does not support format"));
a41c76
+            return -1;
a41c76
+        }
a41c76
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_FS)) {
a41c76
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
a41c76
+                           _("virtiofs is not supported with this QEMU binary"));
a41c76
+            return -1;
a41c76
+        }
a41c76
+        if (qemuDomainDefValidateVirtioFSSharedMemory(def) < 0)
a41c76
+            return -1;
a41c76
+        break;
a41c76
 
a41c76
     case VIR_DOMAIN_FS_DRIVER_TYPE_LAST:
a41c76
     default:
a41c76
@@ -8542,7 +8614,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
a41c76
         break;
a41c76
 
a41c76
     case VIR_DOMAIN_DEVICE_FS:
a41c76
-        ret = qemuDomainDeviceDefValidateFS(dev->data.fs, def, qemuCaps);
a41c76
+        ret = qemuDomainDeviceDefValidateFS(dev->data.fs, def, driver, qemuCaps);
a41c76
         break;
a41c76
 
a41c76
     case VIR_DOMAIN_DEVICE_NVRAM:
a41c76
-- 
a41c76
2.25.1
a41c76