Set iscsi initiator name based on vm name. version 2
PATCH 1/1 Set iscsi initiator name based on vm name. version 2
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
PATCH 1/1 ISCSI: Pick default initiator-name based on the name of the VM
Version 2 based on suggestions from Paolo B.
Use a function 'qemu_get_vm_name()' to pass the -name from qemu to block/iscsi.c instead of #ifdefs
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.
Save the -name of the vm so that we can use it in the default iscsi name.
Add a new variable that holds the name for the vm as specified by -name and assign this name to the iscsi_name pointer gtom block/iscsi.c
This way we can thus create default names to use as the initiator name based on the guest session.
If -name is not specified, iscsi will use a default initiator-name of iqn.2008-11.org.linux-kvm
If -name is specified, then iscsi will use a default initiatorname of iqn.2008-11.org.linux-kvm:<name>
--- 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(-)
block/iscsi.c +11 -3
@@ -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);
qemu-common.h +1 -0
@@ -358,6 +358,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
qemu-doc.texi +5 -0
@@ -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
qemu-options.hx +8 -0
@@ -1893,6 +1893,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 \
@@ -1922,6 +1927,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.
qemu-tool.c +5 -0
@@ -30,6 +30,11 @@ struct QEMUBHvoid *opaque; }; +const char *qemu_get_vm_name (void ) +{ +return NULL ; +} +Monitor *cur_mon;int monitor_cur_is_qmp (void )
vl.c +5 -0
@@ -291,6 +291,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 ) {
Signature · 1 line
1.7.3.1
Re: [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM
Il 30/07/2012 11:03, Ronnie Sahlberg ha scritto:
Quoted 1 line
Version 2 based on suggestions from Paolo B.
This text goes after "---" so it doesn't become part of the commit message.
Quoted 4 lines
Save the -name of the vm so that we can use it in the default iscsi name.
Add a new variable that holds the name for the vm as specified by -name and assign this name to the
iscsi_namepointer gtomblock/iscsi.c
This text is obsolete, and what is "gtom"? :)
Paolo