From patchwork Tue Feb 21 15:40:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 730693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vSRMp5vmtz9s7D for ; Wed, 22 Feb 2017 03:51:02 +1100 (AEDT) Received: from localhost ([::1]:46869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgDeW-0005aZ-95 for incoming@patchwork.ozlabs.org; Tue, 21 Feb 2017 11:51:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCYu-0005tl-PR for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:41:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgCYt-0004MK-FN for qemu-devel@nongnu.org; Tue, 21 Feb 2017 10:41:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48868) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgCYo-0004Ji-RZ; Tue, 21 Feb 2017 10:41:03 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EEEAD6AACA; Tue, 21 Feb 2017 15:41:01 +0000 (UTC) Received: from localhost (ovpn-116-19.phx2.redhat.com [10.3.116.19]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LFf1NA021247 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 21 Feb 2017 10:41:01 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 10:40:50 -0500 Message-Id: <20170221154057.20313-3-jcody@redhat.com> In-Reply-To: <20170221154057.20313-1-jcody@redhat.com> References: <20170221154057.20313-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 15:41:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/9] iscsi: Handle -iscsi user/password in bdrv_parse_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Kevin Wolf 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. Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf Signed-off-by: Jeff Cody --- block/iscsi.c | 78 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index d61d3d8..ec26fc6 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1245,29 +1245,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; @@ -1600,6 +1585,41 @@ out: } } +static void iscsi_parse_iscsi_option(const char *target, QDict *options) +{ + QemuOptsList *list; + QemuOpts *opts; + const char *user, *password, *password_secret; + + 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); + } + + password = qemu_opt_get(opts, "password"); + if (password) { + qdict_set_default_str(options, "password", password); + } + + password_secret = qemu_opt_get(opts, "password-secret"); + if (password_secret) { + qdict_set_default_str(options, "password-secret", password_secret); + } +} + /* * We support iscsi url's on the form * iscsi://[%@][:]// @@ -1642,6 +1662,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); @@ -1676,6 +1699,10 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_STRING, }, { + .name = "password-secret", + .type = QEMU_OPT_STRING, + }, + { .name = "lun", .type = QEMU_OPT_NUMBER, }, @@ -1695,7 +1722,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 @@ -1712,8 +1738,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) { @@ -1721,11 +1745,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) @@ -1764,17 +1783,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;