diff options
author | Markus Armbruster <armbru@redhat.com> | 2011-01-28 11:21:41 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-01-31 10:59:09 +0100 |
commit | 2292ddaeab3467c68efd9e07e17ca0c9fc510fdc (patch) | |
tree | 7977bb2762dc972c8bbf4e2f20d0c034a6772839 /blockdev.c | |
parent | 27d6bf40edc346a61ade6d4c5d4f27f6b40acc81 (diff) |
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>
Diffstat (limited to 'blockdev.c')
-rw-r--r-- | blockdev.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/blockdev.c b/blockdev.c index fba53f913a..6d828f202d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -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) { |