From c57f3fd2f8999d17e01272246b26d31179ab7b6e Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 5 Sep 2017 16:24:14 +0200 Subject: [PATCH] conf: Validate device on update-device https://bugzilla.redhat.com/show_bug.cgi?id=1439991 Whenever a device is being updated via virDomainUpdateDeviceFlags() API, we parse the device XML and ideally run some generic checks to validate the configuration (e.g. if device defines per-device boot order but the domain has os/boot element already). Well, that's the theory - due to a missing check we've jumped early from that check function. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/conf/domain_conf.c | 6 +----- src/conf/domain_conf.h | 3 +-- src/lxc/lxc_driver.c | 20 ++++---------------- src/qemu/qemu_driver.c | 20 ++++---------------- 4 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6cffe2c953..2fc1fc3402 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26023,14 +26023,10 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr def ATTRIBUTE_UNUSED, int virDomainDefCompatibleDevice(virDomainDefPtr def, - virDomainDeviceDefPtr dev, - virDomainDeviceAction action) + virDomainDeviceDefPtr dev) { virDomainDeviceInfoPtr info = virDomainDeviceGetInfo(dev); - if (action != VIR_DOMAIN_DEVICE_ACTION_ATTACH) - return 0; - if (!virDomainDefHasUSB(def) && def->os.type != VIR_DOMAIN_OSTYPE_EXE && virDomainDeviceIsUSB(dev)) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ca15d1727a..bb3b6f0c3c 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2962,8 +2962,7 @@ typedef enum { } virDomainDeviceAction; int virDomainDefCompatibleDevice(virDomainDefPtr def, - virDomainDeviceDefPtr dev, - virDomainDeviceAction action); + virDomainDeviceDefPtr dev); void virDomainRNGDefFree(virDomainRNGDefPtr def); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 784edad396..5cc392b0ec 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -4806,8 +4806,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, if (!vmdef) goto endjob; - if (virDomainDefCompatibleDevice(vmdef, dev, - VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev) < 0) goto endjob; if ((ret = lxcDomainAttachDeviceConfig(vmdef, dev)) < 0) @@ -4815,8 +4814,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, - VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0) goto endjob; if ((ret = lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_copy)) < 0) @@ -4919,8 +4917,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, if (!vmdef) goto endjob; - if (virDomainDefCompatibleDevice(vmdef, dev, - VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev) < 0) goto endjob; if ((ret = lxcDomainUpdateDeviceConfig(vmdef, dev)) < 0) @@ -4928,8 +4925,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, - VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0) goto endjob; virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", @@ -5016,19 +5012,11 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, if (!vmdef) goto endjob; - if (virDomainDefCompatibleDevice(vmdef, dev, - VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0) - goto endjob; - if ((ret = lxcDomainDetachDeviceConfig(vmdef, dev)) < 0) goto endjob; } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, - VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0) - goto endjob; - if ((ret = lxcDomainDetachDeviceLive(driver, vm, dev_copy)) < 0) goto endjob; /* diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b7824512c9..45a56716ec 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8303,8 +8303,7 @@ qemuDomainAttachDeviceLiveAndConfig(virConnectPtr conn, if (!vmdef) goto cleanup; - if (virDomainDefCompatibleDevice(vmdef, dev, - VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev) < 0) goto cleanup; if ((ret = qemuDomainAttachDeviceConfig(vmdef, dev, conn, caps, parse_flags, @@ -8313,8 +8312,7 @@ qemuDomainAttachDeviceLiveAndConfig(virConnectPtr conn, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, - VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0) goto cleanup; if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, conn, driver)) < 0) @@ -8454,8 +8452,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, if (!vmdef) goto endjob; - if (virDomainDefCompatibleDevice(vmdef, dev, - VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev) < 0) goto endjob; if ((ret = qemuDomainUpdateDeviceConfig(vmdef, dev, caps, @@ -8465,8 +8462,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, - VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0) goto endjob; if ((ret = qemuDomainUpdateDeviceLive(dom->conn, vm, dev_copy, dom, force)) < 0) @@ -8554,10 +8550,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, if (!vmdef) goto cleanup; - if (virDomainDefCompatibleDevice(vmdef, dev, - VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0) - goto cleanup; - if ((ret = qemuDomainDetachDeviceConfig(vmdef, dev, caps, parse_flags, driver->xmlopt)) < 0) @@ -8565,10 +8557,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, - VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0) - goto cleanup; - if ((ret = qemuDomainDetachDeviceLive(vm, dev_copy, driver)) < 0) goto cleanup; /* -- GitLab