blockdev: Make drive_add() take explicit type, index parameters

Before, type & index were hidden in printf-like fmt, ... parameters,
which get expanded into an option string.  Rather inconvenient for
uses later in this series.

New IF_DEFAULT to ask for the machine's default interface.  Before,
that was done by having no option "if" in the option string.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Markus Armbruster 2011-01-28 11:21:41 +01:00 committed by Kevin Wolf
parent 27d6bf40ed
commit 2292ddaeab
4 changed files with 48 additions and 25 deletions

View file

@ -75,20 +75,34 @@ void blockdev_auto_del(BlockDriverState *bs)
}
}
QemuOpts *drive_add(const char *file, const char *fmt, ...)
QemuOpts *drive_def(const char *optstr)
{
return qemu_opts_parse(qemu_find_opts("drive"), optstr, 0);
}
QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
const char *fmt, ...)
{
va_list ap;
char optstr[1024];
QemuOpts *opts;
char buf[32];
va_start(ap, fmt);
vsnprintf(optstr, sizeof(optstr), fmt, ap);
va_end(ap);
opts = qemu_opts_parse(qemu_find_opts("drive"), optstr, 0);
opts = drive_def(optstr);
if (!opts) {
return NULL;
}
if (type != IF_DEFAULT) {
qemu_opt_set(opts, "if", if_name[type]);
}
if (index >= 0) {
snprintf(buf, sizeof(buf), "%d", index);
qemu_opt_set(opts, "index", buf);
}
if (file)
qemu_opt_set(opts, "file", file);
return opts;
@ -473,7 +487,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
if (devaddr)
qemu_opt_set(opts, "addr", devaddr);
break;
case IF_COUNT:
default:
abort();
}
if (!file || !*file) {