All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, jcody@redhat.com, berrange@redhat.com,
	pl@kamp.de, ptoscano@redhat.com, ronniesahlberg@gmail.com,
	pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 2/6] iscsi: Handle -iscsi user/password in bdrv_parse_filename()
Date: Thu,  8 Dec 2016 14:23:07 +0100	[thread overview]
Message-ID: <1481203391-9523-3-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1481203391-9523-1-git-send-email-kwolf@redhat.com>

This splits the logic in the old parse_chap() function into a part that
parses the -iscsi options into the new driver-specific options, and
another part that actually applies those options (called apply_chap()
now).

Note that this means that username and password specified with -iscsi
only take effect when a URL is provided. This is intentional, -iscsi is
a legacy interface only supported for compatibility, new users should
use the proper driver-specific options.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/iscsi.c | 72 +++++++++++++++++++++++++++++++----------------------------
 1 file changed, 38 insertions(+), 34 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 7a6664e..c5106c1 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1235,29 +1235,14 @@ retry:
     return 0;
 }
 
-static void parse_chap(struct iscsi_context *iscsi, const char *target,
+static void apply_chap(struct iscsi_context *iscsi, QemuOpts *opts,
                        Error **errp)
 {
-    QemuOptsList *list;
-    QemuOpts *opts;
     const char *user = NULL;
     const char *password = NULL;
     const char *secretid;
     char *secret = NULL;
 
-    list = qemu_find_opts("iscsi");
-    if (!list) {
-        return;
-    }
-
-    opts = qemu_opts_find(list, target);
-    if (opts == NULL) {
-        opts = QTAILQ_FIRST(&list->head);
-        if (!opts) {
-            return;
-        }
-    }
-
     user = qemu_opt_get(opts, "user");
     if (!user) {
         return;
@@ -1586,6 +1571,35 @@ out:
     }
 }
 
+static void iscsi_parse_iscsi_option(const char *target, QDict *options)
+{
+    QemuOptsList *list;
+    QemuOpts *opts;
+    const char *user;
+
+    list = qemu_find_opts("iscsi");
+    if (!list) {
+        return;
+    }
+
+    opts = qemu_opts_find(list, target);
+    if (opts == NULL) {
+        opts = QTAILQ_FIRST(&list->head);
+        if (!opts) {
+            return;
+        }
+    }
+
+    user = qemu_opt_get(opts, "user");
+    if (user) {
+        qdict_set_default_str(options, "user", user);
+        qdict_set_default_str(options, "password",
+                              qemu_opt_get(opts, "password"));
+        qdict_set_default_str(options, "password-secret",
+                              qemu_opt_get(opts, "password-secret"));
+    }
+}
+
 /*
  * We support iscsi url's on the form
  * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
@@ -1624,6 +1638,9 @@ static void iscsi_parse_filename(const char *filename, QDict *options,
     qdict_set_default_str(options, "lun", lun_str);
     g_free(lun_str);
 
+    /* User/password from -iscsi take precedence over those from the URL */
+    iscsi_parse_iscsi_option(iscsi_url->target, options);
+
     if (iscsi_url->user[0] != '\0') {
         qdict_set_default_str(options, "user", iscsi_url->user);
         qdict_set_default_str(options, "password", iscsi_url->passwd);
@@ -1658,6 +1675,10 @@ static QemuOptsList runtime_opts = {
             .type = QEMU_OPT_STRING,
         },
         {
+            .name = "password-secret",
+            .type = QEMU_OPT_STRING,
+        },
+        {
             .name = "lun",
             .type = QEMU_OPT_NUMBER,
         },
@@ -1677,7 +1698,6 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     QemuOpts *opts;
     Error *local_err = NULL;
     const char *transport_name, *portal, *target;
-    const char *user, *password;
 #if LIBISCSI_API_VERSION >= (20160603)
     enum iscsi_transport_type transport;
 #endif
@@ -1694,8 +1714,6 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     transport_name = qemu_opt_get(opts, "transport");
     portal = qemu_opt_get(opts, "portal");
     target = qemu_opt_get(opts, "target");
-    user = qemu_opt_get(opts, "user");
-    password = qemu_opt_get(opts, "password");
     lun = qemu_opt_get_number(opts, "lun", 0);
 
     if (!transport_name || !portal || !target) {
@@ -1703,11 +1721,6 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
         ret = -EINVAL;
         goto out;
     }
-    if (user && !password) {
-        error_setg(errp, "If a user name is given, a password is required");
-        ret = -EINVAL;
-        goto out;
-    }
 
     if (!strcmp(transport_name, "tcp")) {
 #if LIBISCSI_API_VERSION >= (20160603)
@@ -1746,17 +1759,8 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
         goto out;
     }
 
-    if (user) {
-        ret = iscsi_set_initiator_username_pwd(iscsi, user, password);
-        if (ret != 0) {
-            error_setg(errp, "Failed to set initiator username and password");
-            ret = -EINVAL;
-            goto out;
-        }
-    }
-
     /* check if we got CHAP username/password via the options */
-    parse_chap(iscsi, target, &local_err);
+    apply_chap(iscsi, opts, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         ret = -EINVAL;
-- 
1.8.3.1

  parent reply	other threads:[~2016-12-08 13:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-08 13:23 [Qemu-devel] [RFC PATCH 0/6] iscsi: Add blockdev-add support Kevin Wolf
2016-12-08 13:23 ` [Qemu-devel] [RFC PATCH 1/6] iscsi: Split URL into individual options Kevin Wolf
2016-12-08 14:10   ` Daniel P. Berrange
2016-12-08 14:31     ` Kevin Wolf
2016-12-08 13:23 ` Kevin Wolf [this message]
2016-12-08 13:42   ` [Qemu-devel] [RFC PATCH 2/6] iscsi: Handle -iscsi user/password in bdrv_parse_filename() Daniel P. Berrange
2016-12-08 13:23 ` [Qemu-devel] [RFC PATCH 3/6] iscsi: Add initiator-name option Kevin Wolf
2016-12-08 14:16   ` Daniel P. Berrange
2016-12-08 13:23 ` [Qemu-devel] [RFC PATCH 4/6] iscsi: Add header-digest option Kevin Wolf
2016-12-08 14:13   ` Daniel P. Berrange
2016-12-08 13:23 ` [Qemu-devel] [RFC PATCH 5/6] iscsi: Add timeout option Kevin Wolf
2016-12-08 14:14   ` Daniel P. Berrange
2016-12-08 13:23 ` [Qemu-devel] [RFC PATCH 6/6] iscsi: Add blockdev-add support Kevin Wolf
2016-12-08 14:15   ` Daniel P. Berrange
2016-12-08 16:31   ` Eric Blake
2016-12-08 13:55 ` [Qemu-devel] [RFC PATCH 0/6] " Daniel P. Berrange
2016-12-08 14:42   ` Kevin Wolf
2017-01-24 11:35 ` Daniel P. Berrange
2017-01-24 13:50   ` Jeff Cody

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1481203391-9523-3-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=berrange@redhat.com \
    --cc=jcody@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --cc=ptoscano@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.