qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM
@ 2012-08-06  8:24 ronniesahlberg
  2012-08-06  8:51 ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: ronniesahlberg @ 2012-08-06  8:24 UTC (permalink / raw)
  To: pbonzini, qemu-devel; +Cc: Ronnie Sahlberg

From: Ronnie Sahlberg <ronniesahlberg@gmail.com>

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   |   14 +++++++++++---
 qemu-common.h   |    1 +
 qemu-doc.texi   |    5 +++++
 qemu-options.hx |    8 ++++++++
 qemu-tool.c     |    5 +++++
 vl.c            |    5 +++++
 6 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 993a86d..243496b 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -896,23 +896,31 @@ static char *parse_initiator_name(const char *target)
     QemuOptsList *list;
     QemuOpts *opts;
     const char *name = NULL;
+    char *default_name;
+    const char *iscsi_name = qemu_get_vm_name();
+
+    if (asprintf(&default_name, "iqn.2008-11.org.linux-kvm%s%s",
+                 iscsi_name ? ":" : "",
+                 iscsi_name ? iscsi_name : "") == -1) {
+        default_name = (char *)"iqn.2008-11.org.linux-kvm";
+    }
 
     list = qemu_find_opts("iscsi");
     if (!list) {
-        return g_strdup("iqn.2008-11.org.linux-kvm");
+        return g_strdup(default_name);
     }
 
     opts = qemu_opts_find(list, target);
     if (opts == NULL) {
         opts = QTAILQ_FIRST(&list->head);
         if (!opts) {
-            return g_strdup("iqn.2008-11.org.linux-kvm");
+            return g_strdup(default_name);
         }
     }
 
     name = qemu_opt_get(opts, "initiator-name");
     if (!name) {
-        return g_strdup("iqn.2008-11.org.linux-kvm");
+        return g_strdup(default_name);
     }
 
     return g_strdup(name);
diff --git a/qemu-common.h b/qemu-common.h
index f16079f..f9deca6 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -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
diff --git a/qemu-doc.texi b/qemu-doc.texi
index f32e9e2..35cabbc 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -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
diff --git a/qemu-options.hx b/qemu-options.hx
index 5e7d0dc..47cb5bd 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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.
diff --git a/qemu-tool.c b/qemu-tool.c
index 318c5fc..64b5e88 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -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 e71cb30..065aec2 100644
--- 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) {
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH] Set iscsi initiator name based on vm name. version 2
@ 2012-07-30  9:03 Ronnie Sahlberg
  2012-07-30  9:03 ` [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM Ronnie Sahlberg
  0 siblings, 1 reply; 7+ messages in thread
From: Ronnie Sahlberg @ 2012-07-30  9:03 UTC (permalink / raw)
  To: pbonzini, qemu-devel

Paolo, List

Please find an updated patch for setting a default iscsi initiator name based
on the vm name.

This is version 2 of the patch based on suggestions from Paolo to use a 
proper function to pass -name to the block layer instead of using an #ifdef


regards
ronnie sahlberg

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH] iSCSI: generate default initiator-name from vm-name
@ 2012-07-28  0:44 Ronnie Sahlberg
  2012-07-28  0:44 ` [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM Ronnie Sahlberg
  0 siblings, 1 reply; 7+ messages in thread
From: Ronnie Sahlberg @ 2012-07-28  0:44 UTC (permalink / raw)
  To: qemu-devel, pbonzini

List,

Please find a patch that updates the iSCSI block driver to automatically generate a 'unique' initiator-name based on the name given to the virtual machine.

Normally users will always have to set the initiator-name properly since LUN masking on the iscsi targets would almost always require this in common environments, but for test environments it can often be convenient to have the name set automatically and still have the name semi-unique across different VMs.


regards
ronnie sahlberg

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-08-09  1:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-06  8:24 [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM ronniesahlberg
2012-08-06  8:51 ` Paolo Bonzini
2012-08-09  1:34   ` ronnie sahlberg
  -- strict thread matches above, loose matches on Subject: below --
2012-07-30  9:03 [Qemu-devel] [PATCH] Set iscsi initiator name based on vm name. version 2 Ronnie Sahlberg
2012-07-30  9:03 ` [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM Ronnie Sahlberg
2012-07-30  9:21   ` Paolo Bonzini
2012-07-28  0:44 [Qemu-devel] [PATCH] iSCSI: generate default initiator-name from vm-name Ronnie Sahlberg
2012-07-28  0:44 ` [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM Ronnie Sahlberg
2012-07-30  7:41   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).