Blame SOURCES/kvm-scsi-prefer-UUID-to-VM-name-for-the-initiator-name.patch

218e99
From ca89af18d37afb4fe9cea6e4ff3e22386d0db5b0 Mon Sep 17 00:00:00 2001
218e99
From: Paolo Bonzini <pbonzini@redhat.com>
218e99
Date: Mon, 23 Sep 2013 17:07:53 +0200
218e99
Subject: [PATCH 2/3] scsi: prefer UUID to VM name for the initiator name
218e99
218e99
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
218e99
Message-id: <1379956073-3496-1-git-send-email-pbonzini@redhat.com>
218e99
Patchwork-id: 54488
218e99
O-Subject: [RHEL 7.0 qemu-kvm PATCH] scsi: prefer UUID to VM name for the initiator name
218e99
Bugzilla: 1006468
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Amos Kong <akong@redhat.com>
218e99
218e99
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1006468
218e99
218e99
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=6317378
218e99
218e99
The UUID is unique even across multiple hosts, thus it is
218e99
better than a VM name even if it is less user-friendly.
218e99
218e99
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
(cherry picked from commit 5accc8408f2dac1e00d888e4fe75e6174ba2a940)
218e99
---
218e99
 block/iscsi.c           | 23 ++++++++++++++++-------
218e99
 include/sysemu/sysemu.h |  2 ++
218e99
 stubs/Makefile.objs     |  1 +
218e99
 stubs/uuid.c            | 12 ++++++++++++
218e99
 4 files changed, 31 insertions(+), 7 deletions(-)
218e99
 create mode 100644 stubs/uuid.c
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block/iscsi.c           |   23 ++++++++++++++++-------
218e99
 include/sysemu/sysemu.h |    2 ++
218e99
 stubs/Makefile.objs     |    1 +
218e99
 stubs/uuid.c            |   12 ++++++++++++
218e99
 4 files changed, 31 insertions(+), 7 deletions(-)
218e99
 create mode 100644 stubs/uuid.c
218e99
218e99
diff --git a/block/iscsi.c b/block/iscsi.c
218e99
index 1294fdf..4ab9edc 100644
218e99
--- a/block/iscsi.c
218e99
+++ b/block/iscsi.c
218e99
@@ -33,6 +33,8 @@
218e99
 #include "trace.h"
218e99
 #include "block/scsi.h"
218e99
 #include "qemu/iov.h"
218e99
+#include "sysemu/sysemu.h"
218e99
+#include "qmp-commands.h"
218e99
 
218e99
 #include <iscsi iscsi.h="">
218e99
 #include <iscsi scsi-lowlevel.h="">
218e99
@@ -923,8 +925,9 @@ static char *parse_initiator_name(const char *target)
218e99
 {
218e99
     QemuOptsList *list;
218e99
     QemuOpts *opts;
218e99
-    const char *name = NULL;
218e99
-    const char *iscsi_name = qemu_get_vm_name();
218e99
+    const char *name;
218e99
+    char *iscsi_name;
218e99
+    UuidInfo *uuid_info;
218e99
 
218e99
     list = qemu_find_opts("iscsi");
218e99
     if (list) {
218e99
@@ -934,16 +937,22 @@ static char *parse_initiator_name(const char *target)
218e99
         }
218e99
         if (opts) {
218e99
             name = qemu_opt_get(opts, "initiator-name");
218e99
+            if (name) {
218e99
+                return g_strdup(name);
218e99
+            }
218e99
         }
218e99
     }
218e99
 
218e99
-    if (name) {
218e99
-        return g_strdup(name);
218e99
+    uuid_info = qmp_query_uuid(NULL);
218e99
+    if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
218e99
+        name = qemu_get_vm_name();
218e99
     } else {
218e99
-        return g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
218e99
-                               iscsi_name ? ":" : "",
218e99
-                               iscsi_name ? iscsi_name : "");
218e99
+        name = uuid_info->UUID;
218e99
     }
218e99
+    iscsi_name = g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
218e99
+                                 name ? ":" : "", name ? name : "");
218e99
+    qapi_free_UuidInfo(uuid_info);
218e99
+    return iscsi_name;
218e99
 }
218e99
 
218e99
 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
218e99
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
218e99
index d7a77b6..76c5b64 100644
218e99
--- a/include/sysemu/sysemu.h
218e99
+++ b/include/sysemu/sysemu.h
218e99
@@ -17,7 +17,9 @@ extern const char *bios_name;
218e99
 extern const char *qemu_name;
218e99
 extern uint8_t qemu_uuid[];
218e99
 int qemu_uuid_parse(const char *str, uint8_t *uuid);
218e99
+
218e99
 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
218e99
+#define UUID_NONE "00000000-0000-0000-0000-000000000000"
218e99
 
218e99
 bool runstate_check(RunState state);
218e99
 void runstate_set(RunState new_state);
218e99
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
218e99
index 9b701b4..4b2cb7d 100644
218e99
--- a/stubs/Makefile.objs
218e99
+++ b/stubs/Makefile.objs
218e99
@@ -21,6 +21,7 @@ stub-obj-y += reset.o
218e99
 stub-obj-y += set-fd-handler.o
218e99
 stub-obj-y += slirp.o
218e99
 stub-obj-y += sysbus.o
218e99
+stub-obj-y += uuid.o
218e99
 stub-obj-y += vm-stop.o
218e99
 stub-obj-y += vmstate.o
218e99
 stub-obj-$(CONFIG_WIN32) += fd-register.o
218e99
diff --git a/stubs/uuid.c b/stubs/uuid.c
218e99
new file mode 100644
218e99
index 0000000..ffc0ed4
218e99
--- /dev/null
218e99
+++ b/stubs/uuid.c
218e99
@@ -0,0 +1,12 @@
218e99
+#include "qemu-common.h"
218e99
+#include "sysemu/sysemu.h"
218e99
+#include "qmp-commands.h"
218e99
+
218e99
+UuidInfo *qmp_query_uuid(Error **errp)
218e99
+{
218e99
+    UuidInfo *info = g_malloc0(sizeof(*info));
218e99
+
218e99
+    info->UUID = g_strdup(UUID_NONE);
218e99
+    return info;
218e99
+}
218e99
+
218e99
-- 
218e99
1.7.1
218e99