[libvirt] [PATCH 0/3] qemu_hotplug: dead code removal

Originally posted as a part of https://www.redhat.com/archives/libvir-list/2015-August/msg00521.html Ján Tomko (3): qemu_hotplug: remove qemuDomainAttachDeviceControllerLive Remove dead code from qemuDomainAttachControllerDevice mark virDomainVirtioSerialAddrSetAddController as static. src/conf/domain_addr.c | 23 +---------------------- src/conf/domain_addr.h | 8 -------- src/libvirt_private.syms | 2 -- src/qemu/qemu_driver.c | 23 +---------------------- src/qemu/qemu_hotplug.c | 25 +++++++------------------ 5 files changed, 9 insertions(+), 72 deletions(-) -- 2.4.6

This function calls qemuDomainAttachControllerDevice for SCSI controllers and reports an error for all other controllers. Move the error inside qemuDomainAttachControllerDevice and delete this wrapper. --- src/qemu/qemu_driver.c | 23 +---------------------- src/qemu/qemu_hotplug.c | 7 +++++++ 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 783a7cd..991fff5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7713,27 +7713,6 @@ qemuDomainUndefine(virDomainPtr dom) } static int -qemuDomainAttachDeviceControllerLive(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev) -{ - virDomainControllerDefPtr cont = dev->data.controller; - int ret = -1; - - switch (cont->type) { - case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: - ret = qemuDomainAttachControllerDevice(driver, vm, cont); - break; - default: - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("'%s' controller cannot be hot plugged."), - virDomainControllerTypeToString(cont->type)); - break; - } - return ret; -} - -static int qemuDomainAttachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev, virDomainPtr dom) @@ -7753,7 +7732,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, break; case VIR_DOMAIN_DEVICE_CONTROLLER: - ret = qemuDomainAttachDeviceControllerLive(driver, vm, dev); + ret = qemuDomainAttachControllerDevice(driver, vm, dev->data.controller); if (!ret) { alias = dev->data.controller->info.alias; dev->data.controller = NULL; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1a61701..eae5418 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -444,6 +444,13 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, bool releaseaddr = false; bool addedToAddrSet = false; + if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("'%s' controller cannot be hot plugged."), + virDomainControllerTypeToString(controller->type)); + return -1; + } + if (virDomainControllerFind(vm->def, controller->type, controller->idx) >= 0) { virReportError(VIR_ERR_OPERATION_FAILED, _("target %s:%d already exists"), -- 2.4.6

We only support hotplugging SCSI controllers, USB and virtio-serial related code is useless here. --- src/conf/domain_addr.c | 21 --------------------- src/conf/domain_addr.h | 4 ---- src/libvirt_private.syms | 1 - src/qemu/qemu_hotplug.c | 18 ------------------ 4 files changed, 44 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index ca5803e..c7eab0c 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -884,27 +884,6 @@ virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs return 0; } -/* virDomainVirtioSerialAddrSetRemoveController - * - * Removes a virtio serial controller from the address set. - */ -void -virDomainVirtioSerialAddrSetRemoveController(virDomainVirtioSerialAddrSetPtr addrs, - virDomainControllerDefPtr cont) -{ - ssize_t pos; - - if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL) - return; - - VIR_DEBUG("Removing virtio serial controller index %u " - "from the address set", cont->idx); - - pos = virDomainVirtioSerialAddrFindController(addrs, cont->idx); - - if (pos >= 0) - VIR_DELETE_ELEMENT(addrs->controllers, pos, addrs->ncontrollers); -} void virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr addrs) diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 2220a79..74f414e 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -209,10 +209,6 @@ int virDomainVirtioSerialAddrSetAddController(virDomainVirtioSerialAddrSetPtr addrs, virDomainControllerDefPtr cont) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -void -virDomainVirtioSerialAddrSetRemoveController(virDomainVirtioSerialAddrSetPtr addrs, - virDomainControllerDefPtr cont) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs, virDomainDefPtr def) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 63d8618..536acab 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -115,7 +115,6 @@ virDomainVirtioSerialAddrSetAddController; virDomainVirtioSerialAddrSetAddControllers; virDomainVirtioSerialAddrSetCreate; virDomainVirtioSerialAddrSetFree; -virDomainVirtioSerialAddrSetRemoveController; # conf/domain_audit.h diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index eae5418..9bd4238 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -442,7 +442,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, char *devstr = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; bool releaseaddr = false; - bool addedToAddrSet = false; if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -484,20 +483,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, if (qemuAssignDeviceControllerAlias(vm->def, priv->qemuCaps, controller) < 0) goto cleanup; - if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB && - controller->model == -1 && - !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("USB controller hotplug unsupported in this QEMU binary")); - goto cleanup; - } - - if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL && - virDomainVirtioSerialAddrSetAddController(priv->vioserialaddrs, - controller) < 0) - goto cleanup; - addedToAddrSet = true; - if (!(devstr = qemuBuildControllerDevStr(vm->def, controller, priv->qemuCaps, NULL))) goto cleanup; } @@ -526,9 +511,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, } cleanup: - if (ret != 0 && addedToAddrSet) - virDomainVirtioSerialAddrSetRemoveController(priv->vioserialaddrs, - controller); if (ret != 0 && releaseaddr) qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL); -- 2.4.6

On 12/09/2015 12:08 PM, Ján Tomko wrote:
We only support hotplugging SCSI controllers, USB and virtio-serial related code is useless here. --- src/conf/domain_addr.c | 21 --------------------- src/conf/domain_addr.h | 4 ---- src/libvirt_private.syms | 1 - src/qemu/qemu_hotplug.c | 18 ------------------ 4 files changed, 44 deletions(-)
Perhaps helpful to add a bit of history: This reverts commit id 'ee0d97a77', part of '16db8d2e', and part of commit id 'd6d54cd1'. Although for that last one, if one goes and checks out the history - there's no way the code ever have been called since the only way into the function where it was added is if the controller type is VIR_DOMAIN_CONTROLLER_TYPE_SCSI
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index ca5803e..c7eab0c 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -884,27 +884,6 @@ virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs return 0; }
-/* virDomainVirtioSerialAddrSetRemoveController - * - * Removes a virtio serial controller from the address set. - */ -void -virDomainVirtioSerialAddrSetRemoveController(virDomainVirtioSerialAddrSetPtr addrs, - virDomainControllerDefPtr cont) -{ - ssize_t pos; - - if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL) - return; - - VIR_DEBUG("Removing virtio serial controller index %u " - "from the address set", cont->idx); - - pos = virDomainVirtioSerialAddrFindController(addrs, cont->idx); - - if (pos >= 0) - VIR_DELETE_ELEMENT(addrs->controllers, pos, addrs->ncontrollers); -}
void virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr addrs) diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 2220a79..74f414e 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -209,10 +209,6 @@ int virDomainVirtioSerialAddrSetAddController(virDomainVirtioSerialAddrSetPtr addrs, virDomainControllerDefPtr cont) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -void -virDomainVirtioSerialAddrSetRemoveController(virDomainVirtioSerialAddrSetPtr addrs, - virDomainControllerDefPtr cont) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs, virDomainDefPtr def) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 63d8618..536acab 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -115,7 +115,6 @@ virDomainVirtioSerialAddrSetAddController; virDomainVirtioSerialAddrSetAddControllers; virDomainVirtioSerialAddrSetCreate; virDomainVirtioSerialAddrSetFree; -virDomainVirtioSerialAddrSetRemoveController;
# conf/domain_audit.h diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index eae5418..9bd4238 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -442,7 +442,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, char *devstr = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; bool releaseaddr = false; - bool addedToAddrSet = false;
if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -484,20 +483,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, if (qemuAssignDeviceControllerAlias(vm->def, priv->qemuCaps, controller) < 0) goto cleanup;
- if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB && - controller->model == -1 && - !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("USB controller hotplug unsupported in this QEMU binary")); - goto cleanup; - } - - if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL && - virDomainVirtioSerialAddrSetAddController(priv->vioserialaddrs, - controller) < 0) - goto cleanup; - addedToAddrSet = true; - if (!(devstr = qemuBuildControllerDevStr(vm->def, controller, priv->qemuCaps, NULL))) goto cleanup; } @@ -526,9 +511,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, }
cleanup: - if (ret != 0 && addedToAddrSet) - virDomainVirtioSerialAddrSetRemoveController(priv->vioserialaddrs, - controller); if (ret != 0 && releaseaddr) qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL);

This function is no longer used outside domain_addr.c --- src/conf/domain_addr.c | 2 +- src/conf/domain_addr.h | 4 ---- src/libvirt_private.syms | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index c7eab0c..9883c4f 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -825,7 +825,7 @@ virDomainVirtioSerialAddrFindController(virDomainVirtioSerialAddrSetPtr addrs, * Adds virtio serial ports of the existing controller * to the address set. */ -int +static int virDomainVirtioSerialAddrSetAddController(virDomainVirtioSerialAddrSetPtr addrs, virDomainControllerDefPtr cont) { diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 74f414e..208635c 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -206,10 +206,6 @@ typedef virDomainVirtioSerialAddrSet *virDomainVirtioSerialAddrSetPtr; virDomainVirtioSerialAddrSetPtr virDomainVirtioSerialAddrSetCreate(void); int -virDomainVirtioSerialAddrSetAddController(virDomainVirtioSerialAddrSetPtr addrs, - virDomainControllerDefPtr cont) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -int virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs, virDomainDefPtr def) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 536acab..91d0e78 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -111,7 +111,6 @@ virDomainVirtioSerialAddrAutoAssign; virDomainVirtioSerialAddrIsComplete; virDomainVirtioSerialAddrRelease; virDomainVirtioSerialAddrReserve; -virDomainVirtioSerialAddrSetAddController; virDomainVirtioSerialAddrSetAddControllers; virDomainVirtioSerialAddrSetCreate; virDomainVirtioSerialAddrSetFree; -- 2.4.6

We only support hotplugging SCSI controllers, USB and virtio-serial related code is useless here. --- src/conf/domain_addr.c | 21 --------------------- src/conf/domain_addr.h | 4 ---- src/libvirt_private.syms | 1 - src/qemu/qemu_hotplug.c | 18 ------------------ 4 files changed, 44 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index ca5803e..c7eab0c 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -884,27 +884,6 @@ virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs return 0; } -/* virDomainVirtioSerialAddrSetRemoveController - * - * Removes a virtio serial controller from the address set. - */ -void -virDomainVirtioSerialAddrSetRemoveController(virDomainVirtioSerialAddrSetPtr addrs, - virDomainControllerDefPtr cont) -{ - ssize_t pos; - - if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL) - return; - - VIR_DEBUG("Removing virtio serial controller index %u " - "from the address set", cont->idx); - - pos = virDomainVirtioSerialAddrFindController(addrs, cont->idx); - - if (pos >= 0) - VIR_DELETE_ELEMENT(addrs->controllers, pos, addrs->ncontrollers); -} void virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr addrs) diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 2220a79..74f414e 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -209,10 +209,6 @@ int virDomainVirtioSerialAddrSetAddController(virDomainVirtioSerialAddrSetPtr addrs, virDomainControllerDefPtr cont) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -void -virDomainVirtioSerialAddrSetRemoveController(virDomainVirtioSerialAddrSetPtr addrs, - virDomainControllerDefPtr cont) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs, virDomainDefPtr def) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 63d8618..536acab 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -115,7 +115,6 @@ virDomainVirtioSerialAddrSetAddController; virDomainVirtioSerialAddrSetAddControllers; virDomainVirtioSerialAddrSetCreate; virDomainVirtioSerialAddrSetFree; -virDomainVirtioSerialAddrSetRemoveController; # conf/domain_audit.h diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index eae5418..9bd4238 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -442,7 +442,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, char *devstr = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; bool releaseaddr = false; - bool addedToAddrSet = false; if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -484,20 +483,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, if (qemuAssignDeviceControllerAlias(vm->def, priv->qemuCaps, controller) < 0) goto cleanup; - if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB && - controller->model == -1 && - !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("USB controller hotplug unsupported in this QEMU binary")); - goto cleanup; - } - - if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL && - virDomainVirtioSerialAddrSetAddController(priv->vioserialaddrs, - controller) < 0) - goto cleanup; - addedToAddrSet = true; - if (!(devstr = qemuBuildControllerDevStr(vm->def, controller, priv->qemuCaps, NULL))) goto cleanup; } @@ -526,9 +511,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, } cleanup: - if (ret != 0 && addedToAddrSet) - virDomainVirtioSerialAddrSetRemoveController(priv->vioserialaddrs, - controller); if (ret != 0 && releaseaddr) qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL); -- 2.4.6

On 12/09/2015 12:08 PM, Ján Tomko wrote:
Originally posted as a part of https://www.redhat.com/archives/libvir-list/2015-August/msg00521.html
Ján Tomko (3): qemu_hotplug: remove qemuDomainAttachDeviceControllerLive Remove dead code from qemuDomainAttachControllerDevice mark virDomainVirtioSerialAddrSetAddController as static.
src/conf/domain_addr.c | 23 +---------------------- src/conf/domain_addr.h | 8 -------- src/libvirt_private.syms | 2 -- src/qemu/qemu_driver.c | 23 +---------------------- src/qemu/qemu_hotplug.c | 25 +++++++------------------ 5 files changed, 9 insertions(+), 72 deletions(-)
ACK series - although a slight adjustment to commit message as I noted in reply to patch 2 would I think be beneficial. John

On Wed, Dec 16, 2015 at 08:19:49AM -0500, John Ferlan wrote:
On 12/09/2015 12:08 PM, Ján Tomko wrote:
Originally posted as a part of https://www.redhat.com/archives/libvir-list/2015-August/msg00521.html
Ján Tomko (3): qemu_hotplug: remove qemuDomainAttachDeviceControllerLive Remove dead code from qemuDomainAttachControllerDevice mark virDomainVirtioSerialAddrSetAddController as static.
src/conf/domain_addr.c | 23 +---------------------- src/conf/domain_addr.h | 8 -------- src/libvirt_private.syms | 2 -- src/qemu/qemu_driver.c | 23 +---------------------- src/qemu/qemu_hotplug.c | 25 +++++++------------------ 5 files changed, 9 insertions(+), 72 deletions(-)
ACK series - although a slight adjustment to commit message as I noted in reply to patch 2 would I think be beneficial.
I have amended the commit message and pushed the series. Thanks, Jan
participants (2)
-
John Ferlan
-
Ján Tomko