conf: simplify functions virDomainSCSIDriveAddressIsUsedBy*()
Pass the virDomainDeviceDriveAddress as a struct instead of individual arguments. Reworked the function descriptions. Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
3b004cc72d
commit
c344d4b73f
@ -4016,16 +4016,19 @@ virDomainDefPostParseGraphics(virDomainDef *def)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Check if a drive type address $controller:$bus:$target:$unit is already
|
/**
|
||||||
* taken by a disk or not.
|
* virDomainDriveAddressIsUsedByDisk:
|
||||||
|
* @def: domain definition containing the disks to check
|
||||||
|
* @type: bus type
|
||||||
|
* @addr: address to check for duplicates
|
||||||
|
*
|
||||||
|
* Return true if any disk is already using the given address on the
|
||||||
|
* given bus, false otherwise.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
virDomainDriveAddressIsUsedByDisk(const virDomainDef *def,
|
virDomainDriveAddressIsUsedByDisk(const virDomainDef *def,
|
||||||
virDomainDiskBus type,
|
virDomainDiskBus type,
|
||||||
unsigned int controller,
|
const virDomainDeviceDriveAddress *addr)
|
||||||
unsigned int bus,
|
|
||||||
unsigned int target,
|
|
||||||
unsigned int unit)
|
|
||||||
{
|
{
|
||||||
virDomainDiskDefPtr disk;
|
virDomainDiskDefPtr disk;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -4037,10 +4040,10 @@ virDomainDriveAddressIsUsedByDisk(const virDomainDef *def,
|
|||||||
disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
|
disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (disk->info.addr.drive.controller == controller &&
|
if (disk->info.addr.drive.controller == addr->controller &&
|
||||||
disk->info.addr.drive.unit == unit &&
|
disk->info.addr.drive.unit == addr->unit &&
|
||||||
disk->info.addr.drive.bus == bus &&
|
disk->info.addr.drive.bus == addr->bus &&
|
||||||
disk->info.addr.drive.target == target)
|
disk->info.addr.drive.target == addr->target)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4048,16 +4051,19 @@ virDomainDriveAddressIsUsedByDisk(const virDomainDef *def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Check if a drive type address $controller:$target:$bus:$unit is already
|
/**
|
||||||
* taken by a host device or not.
|
* virDomainDriveAddressIsUsedByHostdev:
|
||||||
|
* @def: domain definition containing the hostdevs to check
|
||||||
|
* @type: bus type
|
||||||
|
* @addr: address to check for duplicates
|
||||||
|
*
|
||||||
|
* Return true if any hostdev is already using the given address on the
|
||||||
|
* given bus, false otherwise.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def,
|
virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def,
|
||||||
virDomainHostdevSubsysType type,
|
virDomainHostdevSubsysType type,
|
||||||
unsigned int controller,
|
const virDomainDeviceDriveAddress *addr)
|
||||||
unsigned int bus,
|
|
||||||
unsigned int target,
|
|
||||||
unsigned int unit)
|
|
||||||
{
|
{
|
||||||
virDomainHostdevDefPtr hostdev;
|
virDomainHostdevDefPtr hostdev;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -4069,10 +4075,10 @@ virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def,
|
|||||||
hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
|
hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (hostdev->info->addr.drive.controller == controller &&
|
if (hostdev->info->addr.drive.controller == addr->controller &&
|
||||||
hostdev->info->addr.drive.unit == unit &&
|
hostdev->info->addr.drive.unit == addr->unit &&
|
||||||
hostdev->info->addr.drive.bus == bus &&
|
hostdev->info->addr.drive.bus == addr->bus &&
|
||||||
hostdev->info->addr.drive.target == target)
|
hostdev->info->addr.drive.target == addr->target)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4080,24 +4086,29 @@ virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virDomainSCSIDriveAddressIsUsed:
|
||||||
|
* @def: domain definition to check against
|
||||||
|
* @addr: address to check for duplicates
|
||||||
|
*
|
||||||
|
* Return true if the SCSI drive address is already in use, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
static bool
|
static bool
|
||||||
virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
|
virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
|
||||||
unsigned int controller,
|
const virDomainDeviceDriveAddress *addr)
|
||||||
unsigned int bus,
|
|
||||||
unsigned int target,
|
|
||||||
unsigned int unit)
|
|
||||||
{
|
{
|
||||||
/* In current implementation, the maximum unit number of a controller
|
/* In current implementation, the maximum unit number of a controller
|
||||||
* is either 16 or 7 (narrow SCSI bus), and if the maximum unit number
|
* is either 16 or 7 (narrow SCSI bus), and if the maximum unit number
|
||||||
* is 16, the controller itself is on unit 7 */
|
* is 16, the controller itself is on unit 7 */
|
||||||
if (unit == 7)
|
if (addr->unit == 7)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (virDomainDriveAddressIsUsedByDisk(def, VIR_DOMAIN_DISK_BUS_SCSI,
|
if (virDomainDriveAddressIsUsedByDisk(def, VIR_DOMAIN_DISK_BUS_SCSI,
|
||||||
controller, bus, target, unit) ||
|
addr) ||
|
||||||
virDomainDriveAddressIsUsedByHostdev(def,
|
virDomainDriveAddressIsUsedByHostdev(def,
|
||||||
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI,
|
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI,
|
||||||
controller, bus, target, unit))
|
addr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -4114,7 +4125,9 @@ virDomainControllerSCSINextUnit(const virDomainDef *def,
|
|||||||
|
|
||||||
for (i = 0; i < max_unit; i++) {
|
for (i = 0; i < max_unit; i++) {
|
||||||
/* Default to assigning addresses using bus = target = 0 */
|
/* Default to assigning addresses using bus = target = 0 */
|
||||||
if (!virDomainSCSIDriveAddressIsUsed(def, controller, 0, 0, i))
|
const virDomainDeviceDriveAddress addr = {controller, 0, 0, i};
|
||||||
|
|
||||||
|
if (!virDomainSCSIDriveAddressIsUsed(def, &addr))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4270,10 +4283,7 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
|
|||||||
virDomainDeviceDriveAddressPtr addr = &hdev->info->addr.drive;
|
virDomainDeviceDriveAddressPtr addr = &hdev->info->addr.drive;
|
||||||
if (virDomainDriveAddressIsUsedByDisk(def,
|
if (virDomainDriveAddressIsUsedByDisk(def,
|
||||||
VIR_DOMAIN_DISK_BUS_SCSI,
|
VIR_DOMAIN_DISK_BUS_SCSI,
|
||||||
addr->controller,
|
addr)) {
|
||||||
addr->bus,
|
|
||||||
addr->target,
|
|
||||||
addr->unit)) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("SCSI host address controller='%u' "
|
_("SCSI host address controller='%u' "
|
||||||
"bus='%u' target='%u' unit='%u' in "
|
"bus='%u' target='%u' unit='%u' in "
|
||||||
@ -6535,6 +6545,7 @@ virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt,
|
|||||||
|
|
||||||
switch (def->bus) {
|
switch (def->bus) {
|
||||||
case VIR_DOMAIN_DISK_BUS_SCSI: {
|
case VIR_DOMAIN_DISK_BUS_SCSI: {
|
||||||
|
virDomainDeviceDriveAddress addr = {0, 0, 0, 0};
|
||||||
unsigned int controller;
|
unsigned int controller;
|
||||||
unsigned int unit;
|
unsigned int unit;
|
||||||
|
|
||||||
@ -6559,9 +6570,12 @@ virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt,
|
|||||||
unit = idx % 7;
|
unit = idx % 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr.controller = controller;
|
||||||
|
addr.unit = unit;
|
||||||
|
|
||||||
if (virDomainDriveAddressIsUsedByHostdev(vmdef,
|
if (virDomainDriveAddressIsUsedByHostdev(vmdef,
|
||||||
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI,
|
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI,
|
||||||
controller, 0, 0, unit)) {
|
&addr)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("using disk target name '%s' conflicts with "
|
_("using disk target name '%s' conflicts with "
|
||||||
"SCSI host device address controller='%u' "
|
"SCSI host device address controller='%u' "
|
||||||
@ -6570,10 +6584,7 @@ virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
def->info.addr.drive.controller = controller;
|
memcpy(&def->info.addr.drive, &addr, sizeof(addr));
|
||||||
def->info.addr.drive.bus = 0;
|
|
||||||
def->info.addr.drive.target = 0;
|
|
||||||
def->info.addr.drive.unit = unit;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user