qemu: Use scsi-block for lun passthrough instead of scsi-disk

And don't allow to hotplug a usb disk with "device == lun". This
is the missed pieces in previous virtio-scsi patchset:

http://www.redhat.com/archives/libvir-list/2012-February/msg01052.html
This commit is contained in:
Osier Yang
2012-03-12 22:19:56 +08:00
parent 823a27c628
commit 3165602a55
8 changed files with 80 additions and 7 deletions

View File

@@ -154,6 +154,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
"drive-iotune", /* 85 */
"system_wakeup",
"scsi-disk.channel",
"scsi-block",
);
struct qemu_feature_flags {
@@ -1444,6 +1445,8 @@ qemuCapsParseDeviceStr(const char *str, virBitmapPtr flags)
qemuCapsSet(flags, QEMU_CAPS_VIRTIO_BLK_SCSI);
if (strstr(str, "scsi-disk.channel"))
qemuCapsSet(flags, QEMU_CAPS_SCSI_DISK_CHANNEL);
if (strstr(str, "scsi-block"))
qemuCapsSet(flags, QEMU_CAPS_SCSI_BLOCK);
return 0;
}

View File

@@ -122,6 +122,7 @@ enum qemuCapsFlags {
QEMU_CAPS_DRIVE_IOTUNE = 85, /* -drive bps= and friends */
QEMU_CAPS_WAKEUP = 86, /* system_wakeup monitor command */
QEMU_CAPS_SCSI_DISK_CHANNEL = 87, /* Is scsi-disk.channel available? */
QEMU_CAPS_SCSI_BLOCK = 88, /* -device scsi-block */
QEMU_CAPS_LAST, /* this must always be the last item */
};

View File

@@ -2194,6 +2194,15 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
disk->info.addr.drive.unit);
break;
case VIR_DOMAIN_DISK_BUS_SCSI:
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
if (!qemuCapsGet(qemuCaps, QEMU_CAPS_SCSI_BLOCK)) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU doesn't support scsi-block for "
"lun passthrough"));
goto error;
}
}
controllerModel =
virDomainDiskFindControllerModel(def, disk,
VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
@@ -2209,7 +2218,10 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
goto error;
}
virBufferAddLit(&opt, "scsi-disk");
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN)
virBufferAddLit(&opt, "scsi-block");
else
virBufferAddLit(&opt, "scsi-disk");
virBufferAsprintf(&opt, ",bus=scsi%d.%d,scsi-id=%d",
disk->info.addr.drive.controller,
disk->info.addr.drive.bus,
@@ -2232,7 +2244,11 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
}
}
virBufferAddLit(&opt, "scsi-disk");
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
virBufferAddLit(&opt, "scsi-disk");
else
virBufferAddLit(&opt, "scsi-block");
virBufferAsprintf(&opt, ",bus=scsi%d.0,channel=%d,scsi-id=%d,lun=%d",
disk->info.addr.drive.controller,
disk->info.addr.drive.bus,

View File

@@ -5091,17 +5091,23 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
break;
case VIR_DOMAIN_DISK_DEVICE_DISK:
case VIR_DOMAIN_DISK_DEVICE_LUN:
if (disk->bus == VIR_DOMAIN_DISK_BUS_USB)
if (disk->bus == VIR_DOMAIN_DISK_BUS_USB) {
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device='lun' is not supported for usb bus"));
break;
}
ret = qemuDomainAttachUsbMassstorageDevice(conn, driver, vm,
disk);
else if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO)
} else if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
ret = qemuDomainAttachPciDiskDevice(conn, driver, vm, disk);
else if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI)
} else if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
ret = qemuDomainAttachSCSIDisk(conn, driver, vm, disk);
else
} else {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk bus '%s' cannot be hotplugged."),
virDomainDiskBusTypeToString(disk->bus));
}
break;
default:
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,