|
|
9ae3a8 |
From abc45043366f4031947a55c23ae0533d2409413e Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 5 Nov 2013 14:09:02 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 49/87] blockdev: Separate ID generation from DriveInfo creation
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383660558-32096-9-git-send-email-kwolf@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55387
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 08/24] blockdev: Separate ID generation from DriveInfo creation
|
|
|
9ae3a8 |
Bugzilla: 978402
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
blockdev-add shouldn't automatically generate IDs, but will keep most of
|
|
|
9ae3a8 |
the DriveInfo creation code.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 326642bc7f0ff95a0c08db527861a9a114a109da)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
blockdev.c | 32 +++++++++++++++++---------------
|
|
|
9ae3a8 |
include/qemu/option.h | 1 +
|
|
|
9ae3a8 |
util/qemu-option.c | 6 ++++++
|
|
|
9ae3a8 |
3 files changed, 24 insertions(+), 15 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
blockdev.c | 32 +++++++++++++++++---------------
|
|
|
9ae3a8 |
include/qemu/option.h | 1 +
|
|
|
9ae3a8 |
util/qemu-option.c | 6 ++++++
|
|
|
9ae3a8 |
3 files changed, 24 insertions(+), 15 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/blockdev.c b/blockdev.c
|
|
|
9ae3a8 |
index d4f66db..03ee554 100644
|
|
|
9ae3a8 |
--- a/blockdev.c
|
|
|
9ae3a8 |
+++ b/blockdev.c
|
|
|
9ae3a8 |
@@ -604,23 +604,25 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
|
|
|
9ae3a8 |
return NULL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* init */
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- dinfo = g_malloc0(sizeof(*dinfo));
|
|
|
9ae3a8 |
- if ((buf = qemu_opts_id(opts)) != NULL) {
|
|
|
9ae3a8 |
- dinfo->id = g_strdup(buf);
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- /* no id supplied -> create one */
|
|
|
9ae3a8 |
- dinfo->id = g_malloc0(32);
|
|
|
9ae3a8 |
- if (type == IF_IDE || type == IF_SCSI)
|
|
|
9ae3a8 |
+ /* no id supplied -> create one */
|
|
|
9ae3a8 |
+ if (qemu_opts_id(opts) == NULL) {
|
|
|
9ae3a8 |
+ char *new_id;
|
|
|
9ae3a8 |
+ if (type == IF_IDE || type == IF_SCSI) {
|
|
|
9ae3a8 |
mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
|
|
|
9ae3a8 |
- if (max_devs)
|
|
|
9ae3a8 |
- snprintf(dinfo->id, 32, "%s%i%s%i",
|
|
|
9ae3a8 |
- if_name[type], bus_id, mediastr, unit_id);
|
|
|
9ae3a8 |
- else
|
|
|
9ae3a8 |
- snprintf(dinfo->id, 32, "%s%s%i",
|
|
|
9ae3a8 |
- if_name[type], mediastr, unit_id);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (max_devs) {
|
|
|
9ae3a8 |
+ new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
|
|
|
9ae3a8 |
+ mediastr, unit_id);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ new_id = g_strdup_printf("%s%s%i", if_name[type],
|
|
|
9ae3a8 |
+ mediastr, unit_id);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ qemu_opts_set_id(opts, new_id);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* init */
|
|
|
9ae3a8 |
+ dinfo = g_malloc0(sizeof(*dinfo));
|
|
|
9ae3a8 |
+ dinfo->id = g_strdup(qemu_opts_id(opts));
|
|
|
9ae3a8 |
dinfo->bdrv = bdrv_new(dinfo->id);
|
|
|
9ae3a8 |
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
|
|
9ae3a8 |
dinfo->bdrv->read_only = ro;
|
|
|
9ae3a8 |
diff --git a/include/qemu/option.h b/include/qemu/option.h
|
|
|
9ae3a8 |
index 13f5e72..f5ebb05 100644
|
|
|
9ae3a8 |
--- a/include/qemu/option.h
|
|
|
9ae3a8 |
+++ b/include/qemu/option.h
|
|
|
9ae3a8 |
@@ -139,6 +139,7 @@ void qemu_opts_loc_restore(QemuOpts *opts);
|
|
|
9ae3a8 |
int qemu_opts_set(QemuOptsList *list, const char *id,
|
|
|
9ae3a8 |
const char *name, const char *value);
|
|
|
9ae3a8 |
const char *qemu_opts_id(QemuOpts *opts);
|
|
|
9ae3a8 |
+void qemu_opts_set_id(QemuOpts *opts, char *id);
|
|
|
9ae3a8 |
void qemu_opts_del(QemuOpts *opts);
|
|
|
9ae3a8 |
void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp);
|
|
|
9ae3a8 |
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
|
|
|
9ae3a8 |
diff --git a/util/qemu-option.c b/util/qemu-option.c
|
|
|
9ae3a8 |
index 5d686c8..fcbd1b8 100644
|
|
|
9ae3a8 |
--- a/util/qemu-option.c
|
|
|
9ae3a8 |
+++ b/util/qemu-option.c
|
|
|
9ae3a8 |
@@ -825,6 +825,12 @@ const char *qemu_opts_id(QemuOpts *opts)
|
|
|
9ae3a8 |
return opts->id;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+/* The id string will be g_free()d by qemu_opts_del */
|
|
|
9ae3a8 |
+void qemu_opts_set_id(QemuOpts *opts, char *id)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ opts->id = id;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
void qemu_opts_del(QemuOpts *opts)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
QemuOpt *opt;
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|