Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -570,6 +570,10 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -570,6 +570,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if boot_network: if boot_network:
kvm_cmd.extend(["-boot", "n"]) 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] disk_type = hvp[constants.HV_DISK_TYPE]
if disk_type == constants.HT_DISK_PARAVIRTUAL: if disk_type == constants.HT_DISK_PARAVIRTUAL:
if_val = ",if=virtio" if_val = ",if=virtio"
...@@ -597,7 +601,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -597,7 +601,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if boot_disk: if boot_disk:
kvm_cmd.extend(["-boot", "c"]) kvm_cmd.extend(["-boot", "c"])
boot_disk = False 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" boot_val = ",boot=on"
drive_val = "file=%s,format=raw%s%s%s" % (dev_path, if_val, boot_val, drive_val = "file=%s,format=raw%s%s%s" % (dev_path, if_val, boot_val,
...@@ -612,19 +616,22 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -612,19 +616,22 @@ class KVMHypervisor(hv_base.BaseHypervisor):
iso_image = hvp[constants.HV_CDROM_IMAGE_PATH] iso_image = hvp[constants.HV_CDROM_IMAGE_PATH]
if iso_image: if iso_image:
options = ",format=raw,media=cdrom" options = ",format=raw,media=cdrom"
# set cdrom 'if' type
if boot_cdrom: if boot_cdrom:
kvm_cmd.extend(["-boot", "d"]) actual_cdrom_type = constants.HT_DISK_IDE
if cdrom_disk_type != constants.HT_DISK_IDE: elif cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL:
options = "%s,boot=on,if=%s" % (options, constants.HT_DISK_IDE) actual_cdrom_type = "virtio"
else:
options = "%s,boot=on" % options
else: else:
if cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL: actual_cdrom_type = cdrom_disk_type
if_val = ",if=virtio" if_val = ",if=%s" % actual_cdrom_type
else: # set boot flag, if needed
if_val = ",if=%s" % cdrom_disk_type boot_val = ""
options = "%s%s" % (options, if_val) if boot_cdrom:
drive_val = "file=%s%s" % (iso_image, options) 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]) kvm_cmd.extend(["-drive", drive_val])
iso_image2 = hvp[constants.HV_KVM_CDROM2_IMAGE_PATH] iso_image2 = hvp[constants.HV_KVM_CDROM2_IMAGE_PATH]
...@@ -634,8 +641,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -634,8 +641,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if_val = ",if=virtio" if_val = ",if=virtio"
else: else:
if_val = ",if=%s" % cdrom_disk_type if_val = ",if=%s" % cdrom_disk_type
options = "%s%s" % (options, if_val) drive_val = "file=%s%s%s" % (iso_image2, options, if_val)
drive_val = "file=%s%s" % (iso_image2, options)
kvm_cmd.extend(["-drive", drive_val]) kvm_cmd.extend(["-drive", drive_val])
floppy_image = hvp[constants.HV_KVM_FLOPPY_IMAGE_PATH] floppy_image = hvp[constants.HV_KVM_FLOPPY_IMAGE_PATH]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment