From 2292ddaeab3467c68efd9e07e17ca0c9fc510fdc Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 28 Jan 2011 11:21:41 +0100 Subject: 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 Signed-off-by: Kevin Wolf --- blockdev.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'blockdev.c') 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) { -- cgit v1.2.3-55-g7522