After the previous commits, qemuAddSharedDevice() and qemuRemoveSharedDevice() are now the same code with a different flag to call the internal functions. This patch aggregates the common code into a new function called qemuAddRemoveSharedDeviceInternal() to further reduce code repetition. Both qemuAddSharedDevice() and qemuRemoveSharedDevice() are kept since they are public functions used elsewhere. No functional change was made. Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- src/qemu/qemu_conf.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 422f0d743d..6ce2d10ac7 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1793,6 +1793,26 @@ qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr driver, } +static int +qemuAddRemoveSharedDeviceInternal(virQEMUDriverPtr driver, + virDomainDeviceDefPtr dev, + const char *name, + bool addDevice) +{ + /* Currently the only conflicts we have to care about for + * the shared disk and shared host device is "sgio" setting, + * which is only valid for block disk and scsi host device. + */ + if (dev->type == VIR_DOMAIN_DEVICE_DISK) + return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, + name, addDevice); + else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) + return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev, + name, addDevice); + else + return 0; +} + /* qemuAddSharedDevice: * @driver: Pointer to qemu driver struct @@ -1808,18 +1828,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, const char *name) { - /* Currently the only conflicts we have to care about for - * the shared disk and shared host device is "sgio" setting, - * which is only valid for block disk and scsi host device. - */ - if (dev->type == VIR_DOMAIN_DEVICE_DISK) - return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, - name, true); - else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev, - name, true); - else - return 0; + return qemuAddRemoveSharedDeviceInternal(driver, dev, name, true); } @@ -1846,14 +1855,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, const char *name) { - if (dev->type == VIR_DOMAIN_DEVICE_DISK) - return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, - name, false); - else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev, - name, false); - else - return 0; + return qemuAddRemoveSharedDeviceInternal(driver, dev, name, false); } -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list