From patchwork Wed Jan 25 17:42:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9537667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6416D6042B for ; Wed, 25 Jan 2017 17:49:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5299328334 for ; Wed, 25 Jan 2017 17:49:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44D1928339; Wed, 25 Jan 2017 17:49:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ACB1128334 for ; Wed, 25 Jan 2017 17:49:48 +0000 (UTC) Received: from localhost ([::1]:33485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWRhb-00031E-JX for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Jan 2017 12:49:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWRaN-0004UB-9o for qemu-devel@nongnu.org; Wed, 25 Jan 2017 12:42:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cWRaM-0005hI-2j for qemu-devel@nongnu.org; Wed, 25 Jan 2017 12:42:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cWRaG-0005do-U6; Wed, 25 Jan 2017 12:42:13 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 090A0C054900; Wed, 25 Jan 2017 17:42:13 +0000 (UTC) Received: from localhost (ovpn-116-248.phx2.redhat.com [10.3.116.248]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0PHgCBm013938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 25 Jan 2017 12:42:12 -0500 From: Jeff Cody To: qemu-devel@nongnu.org Date: Wed, 25 Jan 2017 12:42:03 -0500 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 25 Jan 2017 17:42:13 +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] [PATCH v2 2/7] 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: kwolf@redhat.com, pbonzini@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Kevin Wolf Signed-off-by: Jeff Cody Reviewed-by: Fam Zheng --- block/iscsi.c | 78 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 97cff30..fc91d0f 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1236,29 +1236,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; @@ -1587,6 +1572,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://[%@][:]// @@ -1625,6 +1645,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); @@ -1659,6 +1682,10 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_STRING, }, { + .name = "password-secret", + .type = QEMU_OPT_STRING, + }, + { .name = "lun", .type = QEMU_OPT_NUMBER, }, @@ -1678,7 +1705,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 @@ -1695,8 +1721,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) { @@ -1704,11 +1728,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) @@ -1747,17 +1766,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;