From 8d46386bfe01b84982e25e915ad9cfbae5cf4cb1 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Wed, 12 Aug 2015 15:30:45 -0400 Subject: [PATCH] conf: Add SCSI hostdev check for disk drive address already in use https://bugzilla.redhat.com/show_bug.cgi?id=1210587 (partial) If a SCSI subsystem element address is provided, we need to make sure the address provided doesn't conflict with an existing or libvirt generated address for a SCSI element. We can handle this condition in device post processing since we're not generating an address based on some target name - rather it's either generated based on space or provided from the user. If the user provides one that conflicts, then we need to disallow the change. This will fix the issue where the domain XML provided an
for the , but not the element where the address provided ends up being the same address used for the . A address is generated using it's assigned 'dev' name prior to the check/validation of the address value. --- src/conf/domain_conf.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f1e02e3391..7e5a11d589 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4141,12 +4141,33 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev, virDomainHostdevDefPtr hdev = dev->data.hostdev; if (hdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && - hdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && - virDomainHostdevAssignAddress(xmlopt, def, hdev) < 0) { + hdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { + + if (hdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && + virDomainHostdevAssignAddress(xmlopt, def, hdev) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Cannot assign SCSI host device address")); return -1; + } else { + /* Ensure provided address doesn't conflict with existing + * scsi disk drive address + */ + virDomainDeviceDriveAddressPtr addr = &hdev->info->addr.drive; + if (virDomainDriveAddressIsUsedByDisk(def, + VIR_DOMAIN_DISK_BUS_SCSI, + addr->controller, + addr->bus, + addr->target, + addr->unit)) { + virReportError(VIR_ERR_XML_ERROR, + _("SCSI host address controller='%u' " + "bus='%u' target='%u' unit='%u' in " + "use by a SCSI disk"), + addr->controller, addr->bus, + addr->target, addr->unit); + return -1; + } + } } } return 0; -- 2.39.5