Skip to content

Commit

Permalink
Merge pull request #1297 from JoshuaWatt/qemu-disk-opts
Browse files Browse the repository at this point in the history
qemudriver: Add support for additional disk options
  • Loading branch information
Bastian-Krause committed Nov 27, 2023
2 parents b72dc55 + 5864c00 commit ad3d6f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ New Features in 23.1
- A new log level called ``CONSOLE`` has been added between the default
``INFO`` and ``DEBUG`` levels. This level will show all reads and writes made
to the serial console during testing.
- The `QEMUDriver` now has an additional ``disk_opts`` property which can be
used to pass additional options for the disk directly to QEMU

Bug fixes in 23.1
~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,7 @@ Arguments:
- boot_args (str): optional, additional kernel boot argument
- kernel (str): optional, reference to the images key for the kernel
- disk (str): optional, reference to the images key for the disk image
- disk_opts (str): optional, additional QEMU disk options
- flash (str): optional, reference to the images key for the flash image
- rootfs (str): optional, reference to the paths key for use as the virtio-9p filesystem
- dtb (str): optional, reference to the image key for the device tree
Expand Down
13 changes: 10 additions & 3 deletions labgrid/driver/qemudriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol):
boot_args (str): optional, additional kernel boot argument
kernel (str): optional, reference to the images key for the kernel
disk (str): optional, reference to the images key for the disk image
disk_opts (str): optional, additional QEMU disk options
flash (str): optional, reference to the images key for the flash image
rootfs (str): optional, reference to the paths key for use as the virtio-9p filesystem
dtb (str): optional, reference to the image key for the device tree
Expand All @@ -64,6 +65,9 @@ class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol):
disk = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)))
disk_opts = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)))
rootfs = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)))
Expand Down Expand Up @@ -146,20 +150,23 @@ def get_qemu_base_args(self):
disk_format = "raw"
if disk_path.endswith(".qcow2"):
disk_format = "qcow2"
disk_opts = ""
if self.disk_opts:
disk_opts = f",{self.disk_opts}"
if self.machine == "vexpress-a9":
cmd.append("-drive")
cmd.append(
f"if=sd,format={disk_format},file={disk_path},id=mmc0")
f"if=sd,format={disk_format},file={disk_path},id=mmc0{disk_opts}")
boot_args.append("root=/dev/mmcblk0p1 rootfstype=ext4 rootwait")
elif self.machine == "q35":
cmd.append("-drive")
cmd.append(
f"if=virtio,format={disk_format},file={disk_path}")
f"if=virtio,format={disk_format},file={disk_path}{disk_opts}")
boot_args.append("root=/dev/vda rootwait")
elif self.machine == "pc":
cmd.append("-drive")
cmd.append(
f"if=virtio,format={disk_format},file={disk_path}")
f"if=virtio,format={disk_format},file={disk_path}{disk_opts}")
boot_args.append("root=/dev/vda rootwait")
else:
raise NotImplementedError(
Expand Down

0 comments on commit ad3d6f7

Please sign in to comment.