[libvirt] [PATCH V2 0/2] enhance capabilities mode hostdev process

hostdev has mode "capabilities" for LXC, from formatdomain.html: " Block / character devices from the host can be passed through to the guest using the hostdev element. This is only possible with container based virtualization. since after 1.0.1 for LXC " So forbid capabilities mode hostdev if domain is not LXC. Althrough this patch only constrains qemu currently, the more non-container based hypervisor should also apply this rule. V2: move the hyervisor type checking to qemuBuildCommandLine(). Jincheng Miao (2): qemu: forbid define a capabilities mode hostdev docs: fix some typos in formatdomain.html docs/formatdomain.html.in | 4 ++-- src/qemu/qemu_command.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) -- 1.8.3.1

hostdev has mode "capabilities" for LXC, from formatdomain.html: " Block / character devices from the host can be passed through to the guest using the hostdev element. This is only possible with container based virtualization. since after 1.0.1 for LXC " So forbid capabilities mode hostdev if domain is not LXC. The related bug is: https://bugzilla.redhat.com/show_bug.cgi?id=1111044 Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/qemu/qemu_command.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2caee66..338235a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8907,6 +8907,14 @@ qemuBuildCommandLine(virConnectPtr conn, virDomainHostdevDefPtr hostdev = def->hostdevs[i]; char *devstr; + /* forbid capabilities mode hostdev in this type of hypervisor */ + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported capabilities mode hostdev in %s"), + virDomainVirtTypeToString(def->virtType)); + goto error; + } + if (hostdev->info->bootIndex) { if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && -- 1.8.3.1

On 06/19/14 13:05, Jincheng Miao wrote:
hostdev has mode "capabilities" for LXC, from formatdomain.html: " Block / character devices from the host can be passed through to the guest using the hostdev element. This is only possible with container based virtualization. since after 1.0.1 for LXC " So forbid capabilities mode hostdev if domain is not LXC.
The related bug is: https://bugzilla.redhat.com/show_bug.cgi?id=1111044
Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/qemu/qemu_command.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2caee66..338235a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8907,6 +8907,14 @@ qemuBuildCommandLine(virConnectPtr conn, virDomainHostdevDefPtr hostdev = def->hostdevs[i]; char *devstr;
+ /* forbid capabilities mode hostdev in this type of hypervisor */ + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
This apparently doesn't depend on the actual qemu binary nor the state of the system. For such checks we have the domain XML post parse callbacks which point out the error at define time (as it's actually invalid XML from the point of view of the qemu driver) and not when the user attempts to start a VM
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported capabilities mode hostdev in %s"), + virDomainVirtTypeToString(def->virtType)); + goto error; + } + if (hostdev->info->bootIndex) { if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
Peter

----- Original Message -----
On 06/19/14 13:05, Jincheng Miao wrote:
hostdev has mode "capabilities" for LXC, from formatdomain.html: " Block / character devices from the host can be passed through to the guest using the hostdev element. This is only possible with container based virtualization. since after 1.0.1 for LXC " So forbid capabilities mode hostdev if domain is not LXC.
The related bug is: https://bugzilla.redhat.com/show_bug.cgi?id=1111044
Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/qemu/qemu_command.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2caee66..338235a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8907,6 +8907,14 @@ qemuBuildCommandLine(virConnectPtr conn, virDomainHostdevDefPtr hostdev = def->hostdevs[i]; char *devstr;
+ /* forbid capabilities mode hostdev in this type of hypervisor */ + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
This apparently doesn't depend on the actual qemu binary nor the state of the system.
For such checks we have the domain XML post parse callbacks which point out the error at define time (as it's actually invalid XML from the point of view of the qemu driver) and not when the user attempts to start a VM
Yes, I think I can find that callback function .devicesPostParseCallback(). and the function implements are: libxlDomainDeviceDefPostParse(), virLXCDomainDeviceDefPostParse(), openvzDomainDeviceDefPostParse(), qemuDomainDeviceDefPostParse(), umlDomainDeviceDefPostParse(), xenDomainDeviceDefPostParse(), xenapiDomainDeviceDefPostParse() I think I should patch them except LXC.
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported capabilities mode hostdev in %s"), + virDomainVirtTypeToString(def->virtType)); + goto error; + } + if (hostdev->info->bootIndex) { if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
Peter

In section "Block / character devices" of "Host device assignment", the description of hostdev element has some error: For a block device, the type should be "storage", not "block"; For a character device, the type should be "misc", not "char". Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- docs/formatdomain.html.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 79b85d5..3075e16 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2932,8 +2932,8 @@ <dt><code>hostdev</code></dt> <dd>The <code>hostdev</code> element is the main container for describing host devices. For block/character device passthrough <code>mode</code> is - always "capabilities" and <code>type</code> is "block" for a block - device, "char" for a character device and "net" for a host network + always "capabilities" and <code>type</code> is "storage" for a block + device, "misc" for a character device and "net" for a host network interface. </dd> <dt><code>source</code></dt> -- 1.8.3.1
participants (2)
-
Jincheng Miao
-
Peter Krempa