For any disk controller model which is not "lsilogic", the command
line will be like:
-drive file=/dev/sda,if=none,id=drive-scsi0-0-3-0,format=raw \
-device scsi-disk,bus=scsi0.0,channel=0,scsi-id=3,lun=0,i\
drive=drive-scsi0-0-3-0,id=scsi0-0-3-0
The relationship between the libvirt address attrs and the qdev
properties are (controller model is not "lsilogic"; strings
inside <> represent libvirt adress attrs):
bus=scsi<controller>.0
channel=<bus>
scsi-id=<target>
lun=<unit>
* src/qemu/qemu_command.h: (New param "virDomainDefPtr def"
for function qemuBuildDriveDevStr; new param "virDomainDefPtr
vmdef" for function qemuAssignDeviceDiskAlias. Both for
virDomainDiskFindControllerModel's use).
* src/qemu/qemu_command.c:
- New param "virDomainDefPtr def" for qemuAssignDeviceDiskAliasCustom.
For virDomainDiskFindControllerModel's use, if the disk bus is "scsi"
and the controller model is not "lsilogic", "target" is one part
of
the alias name.
- According change on qemuAssignDeviceDiskAlias and qemuBuildDriveDevStr
* src/qemu/qemu_hotplug.c:
- Changes to be consistent with declarations of qemuAssignDeviceDiskAlias
qemuBuildDriveDevStr, and qemuBuildControllerDevStr.
---
src/qemu/qemu_command.c | 96 ++++++++++++++++++++++++++++++++++++----------
src/qemu/qemu_command.h | 10 +++--
src/qemu/qemu_hotplug.c | 14 +++---
3 files changed, 88 insertions(+), 32 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ba22127..a964a9b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -463,15 +463,35 @@ static int qemuAssignDeviceDiskAliasFixed(virDomainDiskDefPtr disk)
/* Our custom -drive naming scheme used with id= */
-static int qemuAssignDeviceDiskAliasCustom(virDomainDiskDefPtr disk)
+static int
+qemuAssignDeviceDiskAliasCustom(virDomainDefPtr def,
+ virDomainDiskDefPtr disk)
{
const char *prefix = virDomainDiskBusTypeToString(disk->bus);
+ int controllerModel = -1;
+
if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
- if (virAsprintf(&disk->info.alias, "%s%d-%d-%d", prefix,
- disk->info.addr.drive.controller,
- disk->info.addr.drive.bus,
- disk->info.addr.drive.unit) < 0)
- goto no_memory;
+ if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
+ controllerModel =
+ virDomainDiskFindControllerModel(def, disk,
+ VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+ }
+
+ if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
+ controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
+ if (virAsprintf(&disk->info.alias, "%s%d-%d-%d", prefix,
+ disk->info.addr.drive.controller,
+ disk->info.addr.drive.bus,
+ disk->info.addr.drive.unit) < 0)
+ goto no_memory;
+ } else {
+ if (virAsprintf(&disk->info.alias, "%s%d-%d-%d-%d", prefix,
+ disk->info.addr.drive.controller,
+ disk->info.addr.drive.bus,
+ disk->info.addr.drive.target,
+ disk->info.addr.drive.unit) < 0)
+ goto no_memory;
+ }
} else {
int idx = virDiskNameToIndex(disk->dst);
if (virAsprintf(&disk->info.alias, "%s-disk%d", prefix, idx)
< 0)
@@ -487,11 +507,13 @@ no_memory:
int
-qemuAssignDeviceDiskAlias(virDomainDiskDefPtr def, virBitmapPtr qemuCaps)
+qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
+ virDomainDiskDefPtr def,
+ virBitmapPtr qemuCaps)
{
if (qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE)) {
if (qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
- return qemuAssignDeviceDiskAliasCustom(def);
+ return qemuAssignDeviceDiskAliasCustom(vmdef, def);
else
return qemuAssignDeviceDiskAliasFixed(def);
} else {
@@ -602,7 +624,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virBitmapPtr qemuCaps)
int i;
for (i = 0; i < def->ndisks ; i++) {
- if (qemuAssignDeviceDiskAlias(def->disks[i], qemuCaps) < 0)
+ if (qemuAssignDeviceDiskAlias(def, def->disks[i], qemuCaps) < 0)
return -1;
}
if (qemuCapsGet(qemuCaps, QEMU_CAPS_NET_NAME) ||
@@ -2078,13 +2100,15 @@ error:
char *
-qemuBuildDriveDevStr(virDomainDiskDefPtr disk,
+qemuBuildDriveDevStr(virDomainDefPtr def,
+ virDomainDiskDefPtr disk,
int bootindex,
virBitmapPtr qemuCaps)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
int idx = virDiskNameToIndex(disk->dst);
+ int controller_model;
if (idx < 0) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2096,7 +2120,8 @@ qemuBuildDriveDevStr(virDomainDiskDefPtr disk,
/* make sure that both the bus and the qemu binary support
* type='lun' (SG_IO).
*/
- if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) {
+ if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO &&
+ disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk device='lun' is not supported for
bus='%s'"),
bus);
@@ -2123,11 +2148,40 @@ qemuBuildDriveDevStr(virDomainDiskDefPtr disk,
disk->info.addr.drive.unit);
break;
case VIR_DOMAIN_DISK_BUS_SCSI:
- virBufferAddLit(&opt, "scsi-disk");
- virBufferAsprintf(&opt, ",bus=scsi%d.%d,scsi-id=%d",
- disk->info.addr.drive.controller,
- disk->info.addr.drive.bus,
- disk->info.addr.drive.unit);
+ controller_model =
+ virDomainDiskFindControllerModel(def, disk,
+ VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+ if (controller_model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
+ virBufferAddLit(&opt, "scsi-disk");
+ virBufferAsprintf(&opt, ",bus=scsi%d.%d,scsi-id=%d",
+ disk->info.addr.drive.controller,
+ disk->info.addr.drive.bus,
+ disk->info.addr.drive.unit);
+ } else {
+ if (!qemuCapsGet(qemuCaps, QEMU_CAPS_SCSI_DISK_CHANNEL)) {
+ if (disk->info.addr.drive.target > 7) {
+ qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("This QEMU doesn't support target "
+ "greater than 7"));
+ goto error;
+ }
+
+ if ((disk->info.addr.drive.bus != disk->info.addr.drive.unit)
&&
+ (disk->info.addr.drive.bus != 0)) {
+ qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("This QEMU only supports both bus and "
+ "unit are equal to 0"));
+ goto error;
+ }
+ }
+
+ virBufferAddLit(&opt, "scsi-disk");
+ virBufferAsprintf(&opt,
",bus=scsi%d.0,channel=%d,scsi-id=%d,lun=%d",
+ disk->info.addr.drive.controller,
+ disk->info.addr.drive.bus,
+ disk->info.addr.drive.target,
+ disk->info.addr.drive.unit);
+ }
break;
case VIR_DOMAIN_DISK_BUS_SATA:
virBufferAddLit(&opt, "ide-drive");
@@ -2323,6 +2377,7 @@ qemuBuildUSBControllerDevStr(virDomainControllerDefPtr def,
int model, caps;
model = def->model;
+
if (model == -1)
model = VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI;
@@ -2350,8 +2405,7 @@ qemuBuildUSBControllerDevStr(virDomainControllerDefPtr def,
}
char *
-qemuBuildControllerDevStr(virDomainDefPtr domainDef ATTRIBUTE_UNUSED,
- virDomainControllerDefPtr def,
+qemuBuildControllerDevStr(virDomainControllerDefPtr def,
virBitmapPtr qemuCaps,
int *nusbcontroller)
{
@@ -4339,7 +4393,7 @@ qemuBuildCommandLine(virConnectPtr conn,
char *devstr;
virCommandAddArg(cmd, "-device");
- if (!(devstr = qemuBuildControllerDevStr(def, cont, qemuCaps,
NULL)))
+ if (!(devstr = qemuBuildControllerDevStr(cont, qemuCaps, NULL)))
goto error;
virCommandAddArg(cmd, devstr);
@@ -4358,7 +4412,7 @@ qemuBuildCommandLine(virConnectPtr conn,
virCommandAddArg(cmd, "-device");
char *devstr;
- if (!(devstr = qemuBuildControllerDevStr(def, def->controllers[i],
qemuCaps,
+ if (!(devstr = qemuBuildControllerDevStr(def->controllers[i],
qemuCaps,
&usbcontroller)))
goto error;
@@ -4477,7 +4531,7 @@ qemuBuildCommandLine(virConnectPtr conn,
} else {
virCommandAddArg(cmd, "-device");
- if (!(optstr = qemuBuildDriveDevStr(disk, bootindex,
+ if (!(optstr = qemuBuildDriveDevStr(def, disk, bootindex,
qemuCaps)))
goto error;
virCommandAddArg(cmd, optstr);
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 2f8b5ba..4e2f5c0 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -90,14 +90,14 @@ char *qemuBuildFSStr(virDomainFSDefPtr fs,
virBitmapPtr qemuCaps);
/* Current, best practice */
-char * qemuBuildDriveDevStr(virDomainDiskDefPtr disk,
+char * qemuBuildDriveDevStr(virDomainDefPtr def,
+ virDomainDiskDefPtr disk,
int bootindex,
virBitmapPtr qemuCaps);
char * qemuBuildFSDevStr(virDomainFSDefPtr fs,
virBitmapPtr qemuCaps);
/* Current, best practice */
-char * qemuBuildControllerDevStr(virDomainDefPtr domainDef,
- virDomainControllerDefPtr def,
+char * qemuBuildControllerDevStr(virDomainControllerDefPtr def,
virBitmapPtr qemuCaps,
int *nusbcontroller);
@@ -201,7 +201,9 @@ int qemuAssignDevicePCISlots(virDomainDefPtr def,
qemuDomainPCIAddressSetPtr ad
int qemuAssignDeviceAliases(virDomainDefPtr def, virBitmapPtr qemuCaps);
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
-int qemuAssignDeviceDiskAlias(virDomainDiskDefPtr def, virBitmapPtr qemuCaps);
+int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
+ virDomainDiskDefPtr def,
+ virBitmapPtr qemuCaps);
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int
idx);
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev,
int idx);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 3dd7c0a..d7842c6 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -226,13 +226,13 @@ int qemuDomainAttachPciDiskDevice(virConnectPtr conn,
if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, &disk->info) <
0)
goto error;
releaseaddr = true;
- if (qemuAssignDeviceDiskAlias(disk, priv->qemuCaps) < 0)
+ if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
goto error;
if (!(drivestr = qemuBuildDriveStr(conn, disk, false, priv->qemuCaps)))
goto error;
- if (!(devstr = qemuBuildDriveDevStr(disk, 0, priv->qemuCaps)))
+ if (!(devstr = qemuBuildDriveDevStr(NULL, disk, 0, priv->qemuCaps)))
goto error;
}
@@ -336,7 +336,7 @@ int qemuDomainAttachPciControllerDevice(struct qemud_driver *driver,
goto cleanup;
}
- if (!(devstr = qemuBuildControllerDevStr(vm->def, controller,
priv->qemuCaps, NULL))) {
+ if (!(devstr = qemuBuildControllerDevStr(controller, priv->qemuCaps, NULL)))
{
goto cleanup;
}
}
@@ -461,9 +461,9 @@ int qemuDomainAttachSCSIDisk(virConnectPtr conn,
}
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
- if (qemuAssignDeviceDiskAlias(disk, priv->qemuCaps) < 0)
+ if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
goto error;
- if (!(devstr = qemuBuildDriveDevStr(disk, 0, priv->qemuCaps)))
+ if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
goto error;
}
@@ -583,11 +583,11 @@ int qemuDomainAttachUsbMassstorageDevice(virConnectPtr conn,
}
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
- if (qemuAssignDeviceDiskAlias(disk, priv->qemuCaps) < 0)
+ if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
goto error;
if (!(drivestr = qemuBuildDriveStr(conn, disk, false, priv->qemuCaps)))
goto error;
- if (!(devstr = qemuBuildDriveDevStr(disk, 0, priv->qemuCaps)))
+ if (!(devstr = qemuBuildDriveDevStr(NULL, disk, 0, priv->qemuCaps)))
goto error;
}
--
1.7.7.3