1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

qemu_command.c: move LSILOGIC controller validation to qemu_validate.c

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2020-10-08 13:54:42 -03:00
parent c9fbb07bab
commit cd97692000
2 changed files with 38 additions and 25 deletions

View File

@ -1616,35 +1616,11 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
return NULL; return NULL;
if (controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) { if (controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
if (disk->info.addr.drive.target != 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("target must be 0 for controller "
"model 'lsilogic'"));
return NULL;
}
virBufferAsprintf(&opt, ",bus=%s.%d,scsi-id=%d", virBufferAsprintf(&opt, ",bus=%s.%d,scsi-id=%d",
contAlias, contAlias,
disk->info.addr.drive.bus, disk->info.addr.drive.bus,
disk->info.addr.drive.unit); disk->info.addr.drive.unit);
} else { } else {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_DISK_CHANNEL)) {
if (disk->info.addr.drive.target > 7) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU doesn't support target "
"greater than 7"));
return NULL;
}
if (disk->info.addr.drive.bus != 0 &&
disk->info.addr.drive.unit != 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU only supports both bus and "
"unit equal to 0"));
return NULL;
}
}
virBufferAsprintf(&opt, ",bus=%s.0,channel=%d,scsi-id=%d,lun=%d", virBufferAsprintf(&opt, ",bus=%s.0,channel=%d,scsi-id=%d,lun=%d",
contAlias, contAlias,
disk->info.addr.drive.bus, disk->info.addr.drive.bus,

View File

@ -2004,8 +2004,12 @@ qemuValidateDomainDeviceDefDiskSerial(const char *value)
static int static int
qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk, qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
virDomainDeviceInfoPtr diskInfo;
int cModel;
if (disk->geometry.cylinders > 0 && if (disk->geometry.cylinders > 0 &&
disk->geometry.heads > 0 && disk->geometry.heads > 0 &&
disk->geometry.sectors > 0) { disk->geometry.sectors > 0) {
@ -2146,6 +2150,9 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
switch (disk->bus) { switch (disk->bus) {
case VIR_DOMAIN_DISK_BUS_SCSI: case VIR_DOMAIN_DISK_BUS_SCSI:
diskInfo = (virDomainDeviceInfoPtr)&disk->info;
cModel = qemuDomainFindSCSIControllerModel(def, diskInfo);
if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("unexpected address type for scsi disk")); _("unexpected address type for scsi disk"));
@ -2160,6 +2167,36 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
"%s", _("SCSI controller only supports 1 bus")); "%s", _("SCSI controller only supports 1 bus"));
return -1; return -1;
} }
/* We allow hotplug/hotunplug disks without a controller,
* hence we don't error out if cModel is < 0. These
* validations were originally made under the assumption of
* a controller being found though. */
if (cModel > 0) {
if (cModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
if (disk->info.addr.drive.target != 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("target must be 0 for controller "
"model 'lsilogic'"));
return -1;
}
} else if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_DISK_CHANNEL)) {
if (disk->info.addr.drive.target > 7) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU doesn't support target "
"greater than 7"));
return -1;
}
if (disk->info.addr.drive.bus != 0 &&
disk->info.addr.drive.unit != 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU only supports both bus and "
"unit equal to 0"));
return -1;
}
}
}
break; break;
case VIR_DOMAIN_DISK_BUS_IDE: case VIR_DOMAIN_DISK_BUS_IDE:
@ -2433,7 +2470,7 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
int idx; int idx;
int partition; int partition;
if (qemuValidateDomainDeviceDefDiskFrontend(disk, qemuCaps) < 0) if (qemuValidateDomainDeviceDefDiskFrontend(disk, def, qemuCaps) < 0)
return -1; return -1;
if (qemuValidateDomainDeviceDefDiskBlkdeviotune(disk, def, qemuCaps) < 0) if (qemuValidateDomainDeviceDefDiskBlkdeviotune(disk, def, qemuCaps) < 0)