Skip to content

Commit

Permalink
qemu: Switch to -blockdev instead of -drive where possible
Browse files Browse the repository at this point in the history
-drive is considered legacy whereas -blockdev is the new interface.
It's slightly more verbose but not incredibly so, let's switch to it.
  • Loading branch information
DaanDeMeyer committed Feb 26, 2025
1 parent ee3b71b commit 7ff9a89
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions mkosi/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,18 @@ def add_virtiofs_mount(

if want_scratch(config):
scratch = stack.enter_context(generate_scratch_fs(config))
cache = "cache.writeback=on,cache.direct=on,cache.no-flush=yes,aio=io_uring"
blockdev = [
"driver=raw",
"node-name=scratch",
"discard=unmap",
"file.driver=file",
f"file.filename={scratch}",
"file.aio=io_uring",
"cache.direct=on",
"cache.no-flush=on",
]
cmdline += [
"-drive", f"if=none,id=scratch,file={scratch},format=raw,discard=on,{cache}",
"-blockdev", ",".join(blockdev),
"-device", "virtio-blk-pci,drive=scratch",
] # fmt: skip
kcl += [f"systemd.mount-extra=LABEL=scratch:/var/tmp:{config.distribution.filesystem()}"]
Expand All @@ -1434,9 +1443,16 @@ def add_virtiofs_mount(
cmdline += ["-initrd", initrd]

if config.output_format in (OutputFormat.disk, OutputFormat.esp):
direct = fname.stat().st_size % resource.getpagesize() == 0
ephemeral = config.ephemeral
cache = f"cache.writeback=on,cache.direct={yes_no(direct)},cache.no-flush={yes_no(ephemeral)},aio=io_uring" # noqa: E501
blockdev = [
"driver=raw",
"node-name=mkosi",
"discard=unmap",
"file.driver=file",
f"file.filename={fname}",
"file.aio=io_uring",
f"cache.direct={yes_no(fname.stat().st_size % resource.getpagesize() == 0)}",
f"cache.no-flush={yes_no(config.ephemeral)}",
]

device_type = "virtio-blk-pci"
if config.cdrom:
Expand All @@ -1445,7 +1461,7 @@ def add_virtiofs_mount(
device_type = "scsi-hd,removable=on"

cmdline += [
"-drive", f"if=none,id=mkosi,file={fname},format=raw,discard=on,{cache}",
"-blockdev", ",".join(blockdev),
"-device", f"{device_type},drive=mkosi,bootindex=1",
] # fmt: skip

Expand Down Expand Up @@ -1503,11 +1519,20 @@ def add_virtiofs_mount(
file = stack.enter_context(finalize_drive(config, drives[0]))

for drive in drives:
arg = f"if=none,id={drive.id},file={file},format=raw,file.locking=off,cache.writeback=on,cache.direct=on,cache.no-flush=yes,aio=io_uring" # noqa: E501
arg = [
"driver=raw",
f"node-name={drive.id}",
"file.driver=file",
f"file.filename={file}",
"file.aio=io_uring",
"file.locking=off",
"cache.direct=on",
"cache.no-flush=yes",
]
if drive.options:
arg += f",{drive.options}"
arg += [drive.options]

cmdline += ["-drive", arg]
cmdline += ["-blockdev", ",".join(arg)]

cmdline += config.qemu_args
cmdline += args.cmdline
Expand Down

0 comments on commit 7ff9a89

Please sign in to comment.