提交 6ae6ffd8 编写于 作者: J John Ferlan

qemu: Introduce qemuDomainFindSCSIControllerModel

Rather than repeat multiple steps in order to find the SCSI
controller model, let's combine them into one helper that will
return either the model from the definition or the default
model based on the capabilities.

This patch adds an extra check/error that the controller
that's being found actually exists. This just clarifies that
the error was because the controller doesn't exist rather
than the more generic error that we were unable to determine
the model from qemuDomainSetSCSIControllerModel when a -1
was passed in and the capabilities were unable to find one.
上级 932862b8
......@@ -190,14 +190,10 @@ qemuAssignDeviceDiskAlias(virDomainDefPtr def,
if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
virDomainControllerDefPtr cont;
cont = virDomainDeviceFindSCSIController(def, &disk->info);
if (cont)
controllerModel = cont->model;
if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
&controllerModel)) < 0)
controllerModel = qemuDomainFindSCSIControllerModel(def,
&disk->info,
qemuCaps);
if (controllerModel < 0)
return -1;
}
......
......@@ -1957,7 +1957,6 @@ qemuBuildDriveDevStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
virDomainControllerDefPtr cont;
const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
const char *contAlias;
char *drivealias;
......@@ -2043,11 +2042,9 @@ qemuBuildDriveDevStr(const virDomainDef *def,
goto error;
}
cont = virDomainDeviceFindSCSIController(def, &disk->info);
if (cont)
controllerModel = cont->model;
if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
&controllerModel)) < 0)
controllerModel = qemuDomainFindSCSIControllerModel(def, &disk->info,
qemuCaps);
if (controllerModel < 0)
goto error;
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
......@@ -5143,16 +5140,12 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainControllerDefPtr cont;
int model = -1;
char *driveAlias;
const char *contAlias;
cont = virDomainDeviceFindSCSIController(def, dev->info);
if (cont)
model = cont->model;
if (qemuDomainSetSCSIControllerModel(def, qemuCaps, &model) < 0)
model = qemuDomainFindSCSIControllerModel(def, dev->info, qemuCaps);
if (model < 0)
goto error;
if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
......
......@@ -74,6 +74,37 @@ qemuDomainSetSCSIControllerModel(const virDomainDef *def,
}
/**
* @def: Domain definition
* @info: Domain device info
* @qemuCaps: QEMU capabilities
*
* Using the device info, find the controller related to the
* device by index and use that controller to return the model.
*
* Returns the model if found, -1 if not with an error message set
*/
int
qemuDomainFindSCSIControllerModel(const virDomainDef *def,
virDomainDeviceInfoPtr info,
virQEMUCapsPtr qemuCaps)
{
virDomainControllerDefPtr cont;
int model;
if (!(cont = virDomainDeviceFindSCSIController(def, info))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to find a SCSI controller for idx=%d"),
info->addr.drive.controller);
return -1;
}
model = cont->model;
ignore_value(qemuDomainSetSCSIControllerModel(def, qemuCaps, &model));
return model;
}
static int
qemuDomainAssignVirtioSerialAddresses(virDomainDefPtr def)
{
......
......@@ -32,6 +32,10 @@ int qemuDomainSetSCSIControllerModel(const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
int *model);
int qemuDomainFindSCSIControllerModel(const virDomainDef *def,
virDomainDeviceInfoPtr info,
virQEMUCapsPtr qemuCaps);
int qemuDomainAssignAddresses(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
virQEMUDriverPtr driver,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册