On 03/04/2023 16.55, Markus Armbruster wrote:
Alex Bennée <alex.ben...@linaro.org> writes:
Markus Armbruster <arm...@redhat.com> writes:
Alex Bennée <alex.ben...@linaro.org> writes:
...
I was under the impression things like -hda wouldn't work say on an Arm
machine because you don't know what sort of interface you might be
using and -hda implies IDE. Where is this macro substitution done?
qemu_init() calls drive_add() for all these options.
drive_add(TYPE, INDEX, FILE, OPTSTR) creates a QemuOpts in group
"drive". It sets "if" to if_name[TYPE] unless TYPE is IF_DEFAULT,
"index" to INDEX unless it's negative, and "file" to FILE unless it's
null. Then it parses OPTSTR on top.
For -hdX, the call looks like
drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
HD_OPTS);
We pass IF_DEFAULT, so "if" remains unset. "index" is set to 0 for
-hda, 1, for -hdb and so forth. "file" is set to the option argument.
Since HD_OPTS is "media=disk", we set "media" to "disk".
The QemuOpts in config group "drive" get passed to drive_new() via
drive_init_func(). Unset "if" defaults to the current machine's class's
block_default_type.
If a machine doesn't set this member explicitly, it remains zero, which
is IF_NONE. Documented in blockdev.h:
typedef enum {
IF_DEFAULT = -1, /* for use with drive_add() only */
/*
* IF_NONE must be zero, because we want MachineClass member
---> * block_default_type to default-initialize to IF_NONE
*/
IF_NONE = 0,
IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO,
IF_XEN,
IF_COUNT
} BlockInterfaceType;
Questions?
How's the average user supposed to know that? Our qemu-options.hx just says:
"-hda/-hdb file use 'file' as IDE hard disk 0/1 image"...
Thomas