Blame SOURCES/kvm-blockdev-Separate-ID-generation-from-DriveInfo-creat.patch

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