Commit 24be50e0 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix boot=on flag for CDROMs

This generalises commit 4304964a

 to cdroms too, since they have
somewhat the same logic. We just abstract the needs_boot_flag into a
separate variable, and then reuse it in the cdrom section.

Note that the logic of what 'if=' type to pass to KVM was very
convoluted, and (I think) incorrect; I went and cleaned it to be more
consistent.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 2b846304
......@@ -570,6 +570,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if boot_network:
kvm_cmd.extend(["-boot", "n"])
# whether this is an older KVM version that uses the boot=on flag
# on devices
needs_boot_flag = (v_major, v_min) < (0, 14)
disk_type = hvp[constants.HV_DISK_TYPE]
if disk_type == constants.HT_DISK_PARAVIRTUAL:
if_val = ",if=virtio"
......@@ -597,7 +601,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if boot_disk:
kvm_cmd.extend(["-boot", "c"])
boot_disk = False
if (v_major, v_min) < (0, 14) and disk_type != constants.HT_DISK_IDE:
if needs_boot_flag and disk_type != constants.HT_DISK_IDE:
boot_val = ",boot=on"
drive_val = "file=%s,format=raw%s%s%s" % (dev_path, if_val, boot_val,
......@@ -612,19 +616,22 @@ class KVMHypervisor(hv_base.BaseHypervisor):
iso_image = hvp[constants.HV_CDROM_IMAGE_PATH]
if iso_image:
options = ",format=raw,media=cdrom"
# set cdrom 'if' type
if boot_cdrom:
kvm_cmd.extend(["-boot", "d"])
if cdrom_disk_type != constants.HT_DISK_IDE:
options = "%s,boot=on,if=%s" % (options, constants.HT_DISK_IDE)
else:
options = "%s,boot=on" % options
actual_cdrom_type = constants.HT_DISK_IDE
elif cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL:
actual_cdrom_type = "virtio"
else:
if cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL:
if_val = ",if=virtio"
else:
if_val = ",if=%s" % cdrom_disk_type
options = "%s%s" % (options, if_val)
drive_val = "file=%s%s" % (iso_image, options)
actual_cdrom_type = cdrom_disk_type
if_val = ",if=%s" % actual_cdrom_type
# set boot flag, if needed
boot_val = ""
if boot_cdrom:
kvm_cmd.extend(["-boot", "d"])
if needs_boot_flag:
boot_val = ",boot=on"
# and finally build the entire '-drive' value
drive_val = "file=%s%s%s%s" % (iso_image, options, if_val, boot_val)
kvm_cmd.extend(["-drive", drive_val])
iso_image2 = hvp[constants.HV_KVM_CDROM2_IMAGE_PATH]
......@@ -634,8 +641,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if_val = ",if=virtio"
else:
if_val = ",if=%s" % cdrom_disk_type
options = "%s%s" % (options, if_val)
drive_val = "file=%s%s" % (iso_image2, options)
drive_val = "file=%s%s%s" % (iso_image2, options, if_val)
kvm_cmd.extend(["-drive", drive_val])
floppy_image = hvp[constants.HV_KVM_FLOPPY_IMAGE_PATH]
......
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