virt.kvm_vm: Add virtio-scsi support
PATCH 1/1 virt.kvm_vm: Add virtio-scsi support
In reply to Lukas DoktorThis patch adds support for virtio-scsi devices.
Tested targets are scsi-hd, scsi-cd, scsi-disk, scsi-block and scsi-generic where scsi-hd and scsi-cd are default virtio-scsi variant.
It's possible to use other targets in specific tests by forcing drive_format_$DISKNAME = "scsi-generic".
NOTE: scsi-block and scsi-generic are passthrough devices and can
be used only with physical HW (/dev/sd*, resp. /dev/sg*)
--- client/virt/guest-hw.cfg.sample | 8 ++++++++ client/virt/kvm_vm.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-)
client/virt/guest-hw.cfg.sample +8 -0
@@ -58,6 +58,14 @@ variants: # Some older qemu might need image_boot=yes for virtio images to work. # Please uncomment the below if that is the case. #image_boot=yes + - virtio_scsi: + # supported formats are: scsi-hd, scsi-cd, scsi-disk, scsi-block, + # scsi-generic + # Use drive_format_$DISKNAME = "scsi-generic" to force disk driver + # for single disk. + # NOTE: scsi-block and scsi-generic are pass-through physical dev only + drive_format=scsi-hd + cd_format=scsi-cd - ahci: drive_format=ahci cd_format=ahci
client/virt/kvm_vm.py +29 -0
@@ -281,6 +281,13 @@ class VM(virt_vm.BaseVM): dev += ",port=%d" % (int(index) + 1) format = "none" index = None + if format.startswith("scsi-"): + # handles scsi-{hd, cd, disk, block, generic} targets + name = "virtio-scsi-cd%s" % index + dev += (" -device %s,drive=%s,bus=virtio_scsi_pci.0" % + (format, name)) + format = "none" + index = None cmd = " -drive file='%s',media=cdrom" % filename if index is not None: cmd += ",index=%s" % index
@@ -320,6 +327,20 @@ class VM(virt_vm.BaseVM): dev += _add_option("drive", name) format = "none" index = None + if format.startswith("scsi-"): + # handles scsi-{hd, cd, disk, block, generic} targets + name = "virtio-scsi%s" % index + dev += " -device %s,bus=virtio_scsi_pci.0" % format + dev += _add_option("drive", name) + dev += _add_option("logical_block_size", logical_block_size) + dev += _add_option("physical_block_size", physical_block_size) + dev += _add_option("min_io_size", min_io_size) + dev += _add_option("opt_io_size", opt_io_size) + dev += _add_option("bootindex", bootindex) + dev += _add_option("serial", serial) + dev += _add_option("removable", removable) + format = "none" + index = None if blkdebug is not None: cmd = " -drive file=blkdebug:%s:%s" % (blkdebug, filename)
@@ -538,6 +559,7 @@ class VM(virt_vm.BaseVM): root_dir = self.root_dir have_ahci = False + have_virtio_scsi = False # Clone this VM using the new params vm = self.clone(name, params, root_dir, copy_state=True)
@@ -607,6 +629,10 @@ class VM(virt_vm.BaseVM): if image_params.get("drive_format") == "ahci" and not have_ahci: qemu_cmd += " -device ahci,id=ahci" have_ahci = True + if (image_params.get("drive_format").startswith("scsi-") + and not have_virtio_scsi): + qemu_cmd += " -device virtio-scsi,id=virtio_scsi_pci" + have_virtio_scsi = True bus = None port = None
@@ -697,6 +723,9 @@ class VM(virt_vm.BaseVM): if cdrom_params.get("cd_format") == "ahci" and not have_ahci: qemu_cmd += " -device ahci,id=ahci" have_ahci = True + if (cdrom_params.get("cd_format").startswith("scsi-") + and not have_virtio_scsi): + qemu_cmd += " -device virtio-scsi,id=virtio_scsi_pci" if iso: qemu_cmd += add_cdrom(help, virt_utils.get_path(root_dir, iso), cdrom_params.get("drive_index"),
Signature · 1 line
1.7.7.4
This patch adds support for virtio-scsi devices.
Added block variants:
* virtio_scsi (default)
* virtio_scsi_disk (legacy scsi)
* virtio_scsi_block (only raw /dev/sd* files)
* virtio_scsi_generic (only raw /dev/sg* files)
Please keep in mind that virtio-scsi is not yet upstream. To test this patch you have to:
1) have a guest OS with virtio-scsi support ( https://github.com/bonzini/virtio-scsi/commits/master )
2) qemu support for virtio-scsi devices ( git://github.com/bonzini/qemu.git )
3) qemu bios support (http://people.redhat.com/pbonzini/virtio-scsi/ )
NOTE: you can download testing rpm packages for all of the above on Paolo Bonzini's page http://people.redhat.com/pbonzini/virtio-scsi/
NOTE2: without modified qemu bios you won't be able to boot from virtio-scsi device
NOTE3: currently only boot from lun0 is supported
NOTE4: automatic hotplug that doesn't work. You have to initialize the device (echo "scsi add-single-device" 2 0 1 0 > /proc/scsi/scsi )
Also please be aware that virtio_scsi_block and virtio_scsi_generic devices are pass-through targets thus you can specify only /dev/sg (resp. /dev/sd*) devices. Also in my version of qemu it was impossible to set those targets directly from cmd-line, although hot-plug worked fine.
Pull request:
https://github.com/autotest/autotest/pull/170
Regards,
Lukáš Doktor