qemu: validate virtiofs filesystems

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>
This commit is contained in:
Ján Tomko 2019-12-18 17:46:54 +01:00
parent f04319a544
commit efaf46811c

View File

@ -8270,11 +8270,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",
@ -8303,8 +8344,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:
@ -8483,7 +8555,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: