Commit dd40330b authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Nikos Skalkotos
Browse files

kvm: Support various target device types

Old QEMU versions used -drive file=<file>,iface=<iface> in order
to define a virtual disk. Until now snf-image was using this
deprecated method and launched the helper using the virtio
interface. Here we use the new interface which goes down to:

 -drive file=<file>,iface=none,id=disk0
 -device <driver>,drive=disk0

Ganeti exports the disk type to be used as INSTANCE_HV_disk_type.
Some of the allowed values are: paravirtual, scsi, scsi-hd,
scsi-generic, scsi-block, etc.

In case of paravirtual device type the <driver> will be
"virtio-blk-pci" and the helper will see the disk as /dev/vdb.

If the disk type is scsi'ish then the helper will see the device as
/dev/sda and the <driver> will be:

  - scsi-hd for scsi
  - the same as disk type otherwise

Note that in case of a scsi'ish disk type an extra SCSI controller
(virtio-scsi-pci) is added to the QEMU command line.
Signed-off-by: default avatarDimitris Aragiorgis <>
parent 766fd6a4
......@@ -126,6 +126,7 @@ get_api10_arguments() {
exit 1
get_api20_arguments() {
......@@ -15,16 +15,40 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
get_img_dev() {
local idx=$1
local letters=( a b c d e f g h e j k l m n )
case $disk_type in
# The helper's root disk is always paravirtual and thus /dev/vda
# will be occupied.
paravirtual) echo /dev/vd${letters[$idx+1]};;
scsi-generic|scsi-block|scsi-hd|scsi) echo /dev/sd${letters[$idx]};;
get_img_driver() {
case $disk_type in
paravirtual) echo virtio-blk-pci;;
scsi|scsi-hd) echo scsi-hd;;
scsi-block) echo scsi-block;;
scsi-generic) echo scsi-generic;;
assign_disk_devices_to() {
local varname
local varname dev i
# This will declare the given variable as an array
eval $varname=\(\)
set -- b c d e f g h e j k l m n
# For DISK_COUNT=3, disk_type=paravirtual, and varname=snf_export_DEV
# this will create snf_export_DEV array of ( /dev/vdb /dev/vdc /dev/vdd )
for ((i = 0; i < DISK_COUNT; i++)); do
eval $varname+=\(\"/dev/vd$1\"\); shift
dev=$(get_img_dev $i)
eval $varname+=\(\"$dev\"\)
......@@ -41,7 +65,8 @@ launch_helper() {
for ((i=0; i < DISK_COUNT; i++)); do
disks+=" -drive file=$(find_disk $i),format=raw,if=virtio,cache=none"
disks+=" -drive file=$(find_disk $i),format=raw,if=none,cache=none,id=drive$i"
disks+=" -device $(get_img_driver),id=disk$i,drive=drive$i"
set +e
......@@ -52,11 +77,16 @@ launch_helper() {
if [[ "$disk_type" =~ ^scsi ]]; then
EXTRA_CONTROLLER_ARG="-device virtio-scsi-pci"
$KVM -runas "$HELPER_USER" \
-drive file="$HELPER_DIR/image",format=raw,if=virtio,readonly \
$disks -m "$HELPER_MEMORY" -boot c -serial stdio \
-drive file="$HELPER_DIR/image",format=raw,if=none,id=helper,readonly \
-device virtio-blk-pci,id=helper,drive=helper \
-m "$HELPER_MEMORY" -boot c -serial stdio \
-serial "file:$(printf "%q" "$result_file")" \
-serial file:>(./ ${MONITOR_FD}) \
-serial pty \
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment