iSCSI: generate default initiator-name from vm-name
PATCH 1/1 iSCSI: generate default initiator-name from vm-name
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
PATCH 1/1 ISCSI: Pick default initiator-name based on the name of the VM
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 | 16 +++++++++++++--- qemu-doc.texi | 5 +++++ qemu-options.hx | 8 ++++++++ vl.c | 7 +++++++ 4 files changed, 33 insertions(+), 3 deletions(-)
block/iscsi.c +13 -3
@@ -28,6 +28,7 @@#include <arpa/inet.h> #include "qemu-common.h" #include "qemu-error.h" +#include "sysemu.h" #include "block_int.h" #include "trace.h" #include "hw/scsi-defs.h"
@@ -40,6 +41,8 @@#include <hw/scsi-defs.h> #endif +const char *iscsi_name; + typedef struct IscsiLun { struct iscsi_context *iscsi; int lun;
@@ -896,23 +899,30 @@ static char *parse_initiator_name(const char *target)QemuOptsList *list;QemuOpts *opts;const char *name =NULL ; +char *default_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-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.
vl.c +7 -0
@@ -169,6 +169,10 @@ int main(int argc, char **argv)#define MAX_VIRTIO_CONSOLES 1 +#ifdef CONFIG_LIBISCSI +extern const char *iscsi_name; +#endif +static const char *data_dir;const char *bios_name =NULL ;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;
@@ -3074,6 +3078,9 @@ int main(int argc, char **argv, char **envp)os_set_proc_name (p); } } +#ifdef CONFIG_LIBISCSI + iscsi_name = qemu_name; +#endif break ;case QEMU_OPTION_prom_env:if (nb_prom_envs >=MAX_PROM_ENVS ) {
Signature · 1 line
1.7.3.1
Re: [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM
Il 28/07/2012 02:44, Ronnie Sahlberg ha scritto:
Quoted 39 lines
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_namepointer gtomblock/iscsi.cThis 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>
Signed-off-by Ronnie Sahlberg <[email protected]>--- block/iscsi.c | 16 +++++++++++++--- qemu-doc.texi | 5 +++++ qemu-options.hx | 8 ++++++++ vl.c | 7 +++++++ 4 files changed, 33 insertions(+), 3 deletions(-)block/iscsi.c +1
-0@@ -28,6 +28,7 @@#include <arpa/inet.h> #include "qemu-common.h" #include "qemu-error.h" +#include "sysemu.h" #include "block_int.h" #include "trace.h" #include "hw/scsi-defs.h"
block/iscsi.c line 44
Quoted 4 lines
block/iscsi.c +1
-0@@ -40,6 +41,8 @@#include <hw/scsi-defs.h> #endif +const char *iscsi_name;
As a rule of thumb, every #ifdef CONFIG_* increases the chances that your patch is rejected. :)
Please add instead a qemu_get_vm_name() function and make it return NULL in qemu-tool.c.
Paolo
Quoted 105 lines
block/iscsi.c +10
-3typedef struct IscsiLun { struct iscsi_context *iscsi; int lun;@@ -896,23 +899,30 @@ static char *parse_initiator_name(const char *target)QemuOptsList *list;QemuOpts *opts;const char *name =NULL ; +char *default_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-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-initiatorqemu-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.vl.c +7
-0@@ -169,6 +169,10 @@ int main(int argc, char **argv)#define MAX_VIRTIO_CONSOLES 1 +#ifdef CONFIG_LIBISCSI +extern const char *iscsi_name; +#endif +static const char *data_dir;const char *bios_name =NULL ;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;@@ -3074,6 +3078,9 @@ int main(int argc, char **argv, char **envp)os_set_proc_name (p); } } +#ifdef CONFIG_LIBISCSI + iscsi_name = qemu_name; +#endif break ;case QEMU_OPTION_prom_env:if (nb_prom_envs >=MAX_PROM_ENVS ) {