qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH] ISCSI: Pick default initiator-name based on the name of the VM
Date: Mon, 30 Jul 2012 09:41:58 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

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 <address@hidden>
> ---
>  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) {
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]