* [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; 3+ 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] 3+ messages in thread
* [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM 2012-07-28 0:44 [Qemu-devel] [PATCH] iSCSI: generate default initiator-name from vm-name Ronnie Sahlberg @ 2012-07-28 0:44 ` Ronnie Sahlberg 2012-07-30 7:41 ` Paolo Bonzini 0 siblings, 1 reply; 3+ messages in thread From: Ronnie Sahlberg @ 2012-07-28 0:44 UTC (permalink / raw) To: qemu-devel, pbonzini; +Cc: Ronnie Sahlberg 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> Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com> --- block/iscsi.c | 16 +++++++++++++--- qemu-doc.texi | 5 +++++ qemu-options.hx | 8 ++++++++ vl.c | 7 +++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 993a86d..abf60ee 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -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); diff --git a/qemu-doc.texi b/qemu-doc.texi index 84dad19..2360f7b 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 dc68e15..3335bcc 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -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. diff --git a/vl.c b/vl.c index 8904db1..3320b7a 100644 --- a/vl.c +++ b/vl.c @@ -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) { -- 1.7.3.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM 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 0 siblings, 0 replies; 3+ messages in thread From: Paolo Bonzini @ 2012-07-30 7:41 UTC (permalink / raw) To: Ronnie Sahlberg; +Cc: qemu-devel Il 28/07/2012 02:44, Ronnie Sahlberg ha scritto: > 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> > > Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com> > --- > block/iscsi.c | 16 +++++++++++++--- > qemu-doc.texi | 5 +++++ > qemu-options.hx | 8 ++++++++ > vl.c | 7 +++++++ > 4 files changed, 33 insertions(+), 3 deletions(-) > > diff --git a/block/iscsi.c b/block/iscsi.c > index 993a86d..abf60ee 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -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; 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 > 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); > diff --git a/qemu-doc.texi b/qemu-doc.texi > index 84dad19..2360f7b 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 dc68e15..3335bcc 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -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. > diff --git a/vl.c b/vl.c > index 8904db1..3320b7a 100644 > --- a/vl.c > +++ b/vl.c > @@ -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) { > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-30 7:42 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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).