aboutsummaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2013-07-11 12:52:34 +0200
committerKevin Wolf <kwolf@redhat.com>2013-10-11 16:50:01 +0200
commit326642bc7f0ff95a0c08db527861a9a114a109da (patch)
treef0bd11e35ced3f2bc251250e69efff7b9dda28b5 /blockdev.c
parentd26c9a15738147a8dccc451c6f6d1ddc2305713d (diff)
blockdev: Separate ID generation from DriveInfo creation
blockdev-add shouldn't automatically generate IDs, but will keep most of the DriveInfo creation code. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/blockdev.c b/blockdev.c
index 9929d781a5..c1fcd3c8d3 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -600,23 +600,25 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
return NULL;
}
- /* init */
-
- dinfo = g_malloc0(sizeof(*dinfo));
- if ((buf = qemu_opts_id(opts)) != NULL) {
- dinfo->id = g_strdup(buf);
- } else {
- /* no id supplied -> create one */
- dinfo->id = g_malloc0(32);
- if (type == IF_IDE || type == IF_SCSI)
+ /* no id supplied -> create one */
+ if (qemu_opts_id(opts) == NULL) {
+ char *new_id;
+ if (type == IF_IDE || type == IF_SCSI) {
mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
- if (max_devs)
- snprintf(dinfo->id, 32, "%s%i%s%i",
- if_name[type], bus_id, mediastr, unit_id);
- else
- snprintf(dinfo->id, 32, "%s%s%i",
- if_name[type], mediastr, unit_id);
+ }
+ if (max_devs) {
+ new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
+ mediastr, unit_id);
+ } else {
+ new_id = g_strdup_printf("%s%s%i", if_name[type],
+ mediastr, unit_id);
+ }
+ qemu_opts_set_id(opts, new_id);
}
+
+ /* init */
+ dinfo = g_malloc0(sizeof(*dinfo));
+ dinfo->id = g_strdup(qemu_opts_id(opts));
dinfo->bdrv = bdrv_new(dinfo->id);
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
dinfo->bdrv->read_only = ro;