Skip to content

Conversation

@intelfx
Copy link

@intelfx intelfx commented Dec 6, 2025

Expand vng's capabilities for configuring emulated disk drives. This has two meaningful parts.

First, this PR adds support to the vng wrapper for connecting both types of emulated disks to the VM. Originally, vng only accepted a --disk argument (which was internally translated to vng --blk-disk), with no option to attach a SCSI disk using the vng wrapper. This PR adds support for both vng --disk and vng --blk-disk, which now map 1:1 to virtme-ng options.

(Note: this is a behavior change. If this is not desired, this can be done any other way around — like adding a vng --scsi-disk for SCSI disks and keeping vng --disk for virtio-blk disks, or anything else. I don't feel strongly about it.)

Second, this PR adds support to both vng and virtme-run for passing extended options in both --disk and --blk-disk arguments. Each value is now treated as a comma-separated list with a number of I/O driver options and disk topology options available.

There are several I/O driver options:

  • format=(raw|qcow2)
  • cache=(...) corresponds to QEMU's -blockdev cache.*, or -drive cache=...
  • aio=(...) corresponds to QEMU's -blockdev aio=..., or -drive aio=...
  • discard=(on|off) corresponds to QEMU's -blockdev discard=(ignore|unmap) or -drive discard=...
  • detect-zeroes=(on|off) corresponds to QEMU's -blockdev detect-zeroes=(on|off|unmap) or -drive detect-zeroes=...
  • queues=(int) corresponds to QEMU's -device num_queues=... on virtio-blk-device or virtio-scsi-device nodes

Then, there are topology options which change the characteristics and limits of the disk reported to the guest OS:

  • log-sec=(bytes) sets the logical sector (LBA) size, e.g. to emulate 4Kn disks
  • phy-sec=(bytes) sets the physical (underlying) sector size
  • min-io=(bytes) sets the advisory minimum I/O size
  • opt-io=(bytes) sets the advisory optimal I/O size
  • disc-gran=(bytes) sets the advisory TRIM/UNMAP request granularity
  • rota=(on|off) indicates whether the emulated drive is reported as rotational medium

Finally, there are two metaoptions:

  • iothread=(on|off) adds a dedicated I/O thread for the disk and/or SCSI controller, and
  • topology=(on|off) extracts host device topology data from sysfs and translates that into the values of the options above (naturally, this only works when the path points to a block device).

…sk options

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
The scsi-hd `serial=` parameter is used by QEMU as a default for the
`device_id=` parameter (which is what in fact ends up in the by-id
path).

The `serial=` parameter is set by `virtme-run` using the disk "name"
provided in the `--{,blk-}disk` argument, which is in turn set by `vng`
to the disk path, when not explicitly provided.

When all of this is chained, the full path to disk image ends up being
used as the SCSI device_id:

1. `vng --disk /path/to/disk` leads to
2. `virtme-run --disk /path/to/disk=/path/to/disk` leads to
3. `qemu -device scsi-hd,serial=/path/to/disk` leads to (internally)
4. `qemu -device scsi-hd,serial=/path/to/disk,device_id=/path/to/disk`

However, QEMU (or perhaps it is SCSI) limits the device_id to
20 characters:

```
qemu-system-x86_64: -device scsi-hd,drive=disk0,vendor=virtme,product=disk,serial=/long/path/to/image/file: The serial number can't be longer than 20 characters when it is also used as the default for device_id
```

This problem is indirectly exposed since the previous commit, because
`vng --disk` is now a shorthand for a SCSI disk, not a virtio-blk disk.

Fix this by truncating the SCSI serial manually and using the truncated
value as the SCSI device_id.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
This is a behavioral change (although one that brings the behavior
_in line_ with the documentation). Previously, `vng --disk` was
converted to `virtme-run --blk-disk` internally, contrary to the
`vng` help which is saying that `--disk` adds a virtio-scsi disk.

Support both `vng --disk` (which is converted to `virtme-run --disk`)
and `vng --blk-disk` (which is converted to `virtme-run --blk-disk`).

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Not specifying a disk image file format leads to QEMU issuing a warning
and write-protecting block 0. This is seldom desirable:

```
WARNING: Image format was not specified for '/path/to/file' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
```

To squelch the warning, specify `format=raw` explicitly. This will be
made configurable in the next commit.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
This implements support for various disk topology and I/O driver options
for both `--disk` and `--blk-disk` arguments.

Options are accepted as a comma-separated list after the image file path
e.g., `--disk /path/to/file,format=qcow2,...`.

In addition to general QEMU options (format=), I/O driver options
(cache=, aio=, discard=, detect-zeroes=, queues=) and topology options
(log-sec=, phy-sec=, min-io=, opt-io=, disc-gran=) a "topology="
metaoption is accepted to pass through host device queue limits.

The names for these options were chosen to match `lsblk` columns
rather than QEMU's own -drive/-device options, because the latter are
underdocumented and non-uniform.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Copy link
Collaborator

@marcosps marcosps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me. (I saw that this commit is also present on your patchset to add blk-disk, but this one is easier merged here :) )

Copy link
Owner

@arighi arighi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for working on this!!

Just one comment, it'd be nice to not change the behavior of --disk (BTW, with the new syntax how do we specify virtio-blk disks?).

Maybe adding a separate --scsi-disk would be nicer, because we don't break the current behavior, someone may currently use --disk expecting to create virtio-blk devices.

@intelfx
Copy link
Author

intelfx commented Dec 15, 2025

BTW, with the new syntax how do we specify virtio-blk disks?

Like I wrote, I made vng options map 1:1 to virtme-run options, while the semantics of the latter is not changed:

  • {vng,virtme-run} --disk /path/to/image,foo=bar → virtio-scsi
  • {vng,virtme-run} --blk-disk /path/to/image,foo=bar → virtio-blk

Just one comment, it'd be nice to not change the behavior of --disk. Maybe adding a separate --scsi-disk would be nicer, because we don't break the current behavior, someone may currently use --disk expecting to create virtio-blk devices.

OK, so you want vng --diskvirtme-run --blk-disk and vng --scsi-diskvirtme-run --disk?

I did not do it this way because I thought that mapping A to B and B to C would be highly confusing, but I'll do whatever you decide on.

@matttbe
Copy link
Collaborator

matttbe commented Dec 15, 2025

Just one comment, it'd be nice to not change the behavior of --disk. Maybe adding a separate --scsi-disk would be nicer, because we don't break the current behavior, someone may currently use --disk expecting to create virtio-blk devices.

OK, so you want vng --diskvirtme-run --blk-disk and vng --scsi-diskvirtme-run --disk?

I did not do it this way originally because I wanted the two CLIs to be consistent, but I'll do whatever you decide on.

Could we eventually use aliases not to change the behaviours?

So having --scsi-disk and --blk-disk in both, and one would have --disk with --scsi-disk as an alias, and the other one with --blk-disk. And from vng, call virtme-run with --blk-disk or --scsi-disk, but not --disk to avoid confusions. WDYT?

@intelfx
Copy link
Author

intelfx commented Dec 15, 2025

So, introduce and prominently document --{blk,scsi}-disk with consistent behavior and leave --disk as a sort of a legacy alias with differing behavior for compatibility? Yep, works for me.

@arighi
Copy link
Owner

arighi commented Dec 15, 2025

BTW, with the new syntax how do we specify virtio-blk disks?

Like I wrote, I made vng options map 1:1 to virtme-run options, while the semantics of the latter is not changed:

  • {vng,virtme-run} --disk /path/to/image,foo=bar → virtio-scsi
  • {vng,virtme-run} --blk-disk /path/to/image,foo=bar → virtio-blk

Ah alright, it makes sense as it is then, thanks for clarifying it. Also I think not many people are using --disk, so let's stick with this syntax, which seems more sane.

Edit: I should read the whole thread before replying. This #389 (comment) would be the best, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants