Add a single boolean function to handle whether the hostdev is shared or not. Use the new function for the qemu{Add|Remove}SharedHostdev calls as well as qemuSetUnprivSGIO. NB: This second usage fixes a possible bug where if this feature is enabled at some time in the future and the shareable flag wasn't set, the sgio would have been erroneously set. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_conf.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index d521886..48fb74a 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1201,6 +1201,19 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, } +static bool +qemuIsSharedHostdev(virDomainHostdevDefPtr hostdev) +{ + if (hostdev->shareable && + (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && + hostdev->source.subsys.u.scsi.protocol != + VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)) + return true; + return false; +} + + static char * qemuGetSharedHostdevKey(virDomainHostdevDefPtr hostdev) { @@ -1238,10 +1251,7 @@ qemuAddSharedHostdev(virQEMUDriverPtr driver, char *key = NULL; int ret = -1; - if (!hostdev->shareable || - !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && - hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)) + if (!qemuIsSharedHostdev(hostdev)) return 0; if (!(key = qemuGetSharedHostdevKey(hostdev))) @@ -1342,10 +1352,7 @@ qemuRemoveSharedHostdev(virQEMUDriverPtr driver, char *key = NULL; int ret; - if (!hostdev->shareable || - !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && - hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)) + if (!qemuIsSharedHostdev(hostdev)) return 0; if (!(key = qemuGetSharedHostdevKey(hostdev))) @@ -1407,11 +1414,10 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev) } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) { hostdev = dev->data.hostdev; + if (!qemuIsSharedHostdev(hostdev)) + return 0; - if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type == - VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && - hostdev->source.subsys.u.scsi.sgio) { + if (hostdev->source.subsys.u.scsi.sgio) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("'sgio' is not supported for SCSI " "generic device yet ")); -- 2.1.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list