summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2013-08-02 17:02:01 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2013-09-12 08:46:21 +0200
commit5accc8408f2dac1e00d888e4fe75e6174ba2a940 (patch)
treeedac711fe67c94fe04af6382b633292195663f7e /block
parent2d1fe1873a984d1c2c89ffa3d12949cafc718551 (diff)
scsi: prefer UUID to VM name for the initiator name
The UUID is unique even across multiple hosts, thus it is better than a VM name even if it is less user-friendly. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/iscsi.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/block/iscsi.c b/block/iscsi.c
index 813abd8fef..60b3967994 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -33,6 +33,8 @@
#include "trace.h"
#include "block/scsi.h"
#include "qemu/iov.h"
+#include "sysemu/sysemu.h"
+#include "qmp-commands.h"
#include <iscsi/iscsi.h>
#include <iscsi/scsi-lowlevel.h>
@@ -922,8 +924,9 @@ static char *parse_initiator_name(const char *target)
{
QemuOptsList *list;
QemuOpts *opts;
- const char *name = NULL;
- const char *iscsi_name = qemu_get_vm_name();
+ const char *name;
+ char *iscsi_name;
+ UuidInfo *uuid_info;
list = qemu_find_opts("iscsi");
if (list) {
@@ -933,16 +936,22 @@ static char *parse_initiator_name(const char *target)
}
if (opts) {
name = qemu_opt_get(opts, "initiator-name");
+ if (name) {
+ return g_strdup(name);
+ }
}
}
- if (name) {
- return g_strdup(name);
+ uuid_info = qmp_query_uuid(NULL);
+ if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
+ name = qemu_get_vm_name();
} else {
- return g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
- iscsi_name ? ":" : "",
- iscsi_name ? iscsi_name : "");
+ name = uuid_info->UUID;
}
+ iscsi_name = g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
+ name ? ":" : "", name ? name : "");
+ qapi_free_UuidInfo(uuid_info);
+ return iscsi_name;
}
#if defined(LIBISCSI_FEATURE_NOP_COUNTER)