From: Jincheng Miao Date: Wed, 25 Jun 2014 06:45:59 +0000 (+0800) Subject: enhance hostdev mode 'capabilities' process X-Git-Tag: v1.2.6-rc1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01e508f33c3b94bafe3e266bfd45b070fae8c8c0;p=thirdparty%2Flibvirt.git enhance hostdev mode 'capabilities' process Currently, only LXC has hostdev mode 'capabilities' support, so the other drivers should forbid to define it in XML. The hostdev mode check is added to devicesPostParseCallback() for each hypervisor driver. But there are some drivers lack function devicesPostParseCallback(), so only add check for qemu, libxl, openvz, uml, xen, xenapi. Signed-off-by: Jincheng Miao --- diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 73242ac023..da3f2412c1 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -485,6 +485,15 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) { virDomainHostdevDefPtr hostdev = dev->data.hostdev; + /* forbid capabilities mode hostdev in this kind of hypervisor */ + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hostdev mode 'capabilities' is not " + "supported in %s"), + virDomainVirtTypeToString(def->virtType)); + return -1; + } + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 4c815ed41e..baa725629f 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -113,6 +113,16 @@ openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ; + /* forbid capabilities mode hostdev in this kind of hypervisor */ + if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && + dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hostdev mode 'capabilities' is not " + "supported in %s"), + virDomainVirtTypeToString(def->virtType)); + return -1; + } + return 0; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2e55c99193..a09567cc8d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -940,6 +940,16 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, dev->data.chr->source.data.nix.listen = true; } + /* forbid capabilities mode hostdev in this kind of hypervisor */ + if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && + dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hostdev mode 'capabilities' is not " + "supported in %s"), + virDomainVirtTypeToString(def->virtType)); + goto cleanup; + } + ret = 0; cleanup: diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 5ccd44387e..f14cfaa0aa 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -430,6 +430,16 @@ umlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML; + /* forbid capabilities mode hostdev in this kind of hypervisor */ + if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && + dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hostdev mode 'capabilities' is not " + "supported in %s"), + virDomainVirtTypeToString(def->virtType)); + return -1; + } + return 0; } diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index bd51909bc4..8c0050acb2 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -343,6 +343,16 @@ xenDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, STRNEQ(def->os.type, "hvm")) dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN; + /* forbid capabilities mode hostdev in this kind of hypervisor */ + if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && + dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hostdev mode 'capabilities' is not " + "supported in %s"), + virDomainVirtTypeToString(def->virtType)); + return -1; + } + return 0; } diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 908448b497..500b78a1a8 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -55,6 +55,16 @@ xenapiDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, STRNEQ(def->os.type, "hvm")) dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN; + /* forbid capabilities mode hostdev in this kind of hypervisor */ + if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && + dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hostdev mode 'capabilities' is not " + "supported in %s"), + virDomainVirtTypeToString(def->virtType)); + return -1; + } + return 0; }