iscsi: Pick default initiator-name based on the name of the VM
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 6 Aug 2012 08:24:55 +0000 (18:24 +1000)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 9 Aug 2012 13:04:09 +0000 (15:04 +0200)
This patch updates the iscsi layer to automatically pick a 'unique'
initiator-name based on the name of the vm in case the user has not set
an explicit iqn-name to use.

Create a new function qemu_get_vm_name() that returns the name of the VM,
if specified.

This way we can thus create default names to use as the initiator name
based on the guest session.

If the VM is not named via the '-name' command line argument, the iscsi
initiator-name used wiull simply be

    iqn.2008-11.org.linux-kvm

If a name for the VM was specified with the '-name' option, iscsi will
use a default initiatorname of

    iqn.2008-11.org.linux-kvm:<name>

These names are just the default iscsi initiator name that qemu will
generate/use only when the user has not set an explicit initiator name
via the commandlines or config files.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
block/iscsi.c
qemu-common.h
qemu-doc.texi
qemu-options.hx
qemu-tool.c
vl.c

index fd954d4c1f476c7598baf24250f4cef95924e2f5..219f92782380786c693f9c7889a2b3b752461389 100644 (file)
@@ -896,6 +896,7 @@ static char *parse_initiator_name(const char *target)
     QemuOptsList *list;
     QemuOpts *opts;
     const char *name = NULL;
+    const char *iscsi_name = qemu_get_vm_name();
 
     list = qemu_find_opts("iscsi");
     if (list) {
@@ -911,7 +912,9 @@ static char *parse_initiator_name(const char *target)
     if (name) {
         return g_strdup(name);
     } else {
-        return g_strdup("iqn.2008-11.org.linux-kvm");
+        return g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
+                               iscsi_name ? ":" : "",
+                               iscsi_name ? iscsi_name : "");
     }
 }
 
index f16079f432ba07cc5122e697a4a0c347d465435a..f9deca6f8675778ebf5dbb22b97048996e7ab0c4 100644 (file)
@@ -376,6 +376,7 @@ bool buffer_is_zero(const void *buf, size_t len);
 void qemu_progress_init(int enabled, float min_skip);
 void qemu_progress_end(void);
 void qemu_progress_print(float delta, int max);
+const char *qemu_get_vm_name(void);
 
 #define QEMU_FILE_TYPE_BIOS   0
 #define QEMU_FILE_TYPE_KEYMAP 1
index f32e9e2fb9f3e698443f81db9c6e2093cd710910..35cabbcb9e06eba2ae0e108b1ca7ee87d91cc103 100644 (file)
@@ -734,6 +734,11 @@ Various session related parameters can be set via special options, either
 in a configuration file provided via '-readconfig' or directly on the
 command line.
 
+If the initiator-name is not specified qemu will use a default name
+of 'iqn.2008-11.org.linux-kvm[:<name>'] where <name> is the name of the
+virtual machine.
+
+
 @example
 Setting a specific initiator name to use when logging in to the target
 -iscsi initiator-name=iqn.qemu.test:my-initiator
index 5e7d0dc035978945e692efe3ef063b6a69e73b29..47cb5bd311c697ba641175056e44955b10a6d600 100644 (file)
@@ -1897,6 +1897,11 @@ images for the guest storage. Both disk and cdrom images are supported.
 Syntax for specifying iSCSI LUNs is
 ``iscsi://<target-ip>[:<port>]/<target-iqn>/<lun>''
 
+By default qemu will use the iSCSI initiator-name
+'iqn.2008-11.org.linux-kvm[:<name>]' but this can also be set from the command
+line or a configuration file.
+
+
 Example (without authentication):
 @example
 qemu-system-i386 -iscsi initiator-name=iqn.2001-04.com.example:my-initiator \
@@ -1926,6 +1931,9 @@ DEF("iscsi", HAS_ARG, QEMU_OPTION_iscsi,
     "                iSCSI session parameters\n", QEMU_ARCH_ALL)
 STEXI
 
+iSCSI parameters such as username and password can also be specified via
+a configuration file. See qemu-doc for more information and examples.
+
 @item NBD
 QEMU supports NBD (Network Block Devices) both using TCP protocol as well
 as Unix Domain Sockets.
index 318c5fcbca8a943b52fd5e765be9b5c0450db101..64b5e88bc7a684a39625c37cc0ce2c7a299d306d 100644 (file)
@@ -30,6 +30,11 @@ struct QEMUBH
     void *opaque;
 };
 
+const char *qemu_get_vm_name(void)
+{
+    return NULL;
+}
+
 Monitor *cur_mon;
 
 int monitor_cur_is_qmp(void)
diff --git a/vl.c b/vl.c
index e71cb30ecfc09d89d0cbc9e82585f61b44445083..065aec290eb02e5a7bb0974c155e5319b3008b64 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -293,6 +293,11 @@ static struct {
     { .driver = "qxl-vga",              .flag = &default_vga       },
 };
 
+const char *qemu_get_vm_name(void)
+{
+    return qemu_name;
+}
+
 static void res_free(void)
 {
     if (boot_splash_filedata != NULL) {