From patchwork Fri Apr 22 10:24:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8909011 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E71049F1D3 for ; Fri, 22 Apr 2016 10:25:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 178B7201EF for ; Fri, 22 Apr 2016 10:25:29 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id F285820221 for ; Fri, 22 Apr 2016 10:25:27 +0000 (UTC) Received: from localhost ([::1]:58729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atYH9-0008Tj-1x for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Apr 2016 06:25:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atYGs-0008Dg-HZ for qemu-devel@nongnu.org; Fri, 22 Apr 2016 06:25:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1atYGr-0006KL-2g for qemu-devel@nongnu.org; Fri, 22 Apr 2016 06:25:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59441) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atYGn-0006GD-CT; Fri, 22 Apr 2016 06:25:05 -0400 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 06C9C3DD47; Fri, 22 Apr 2016 10:25:05 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-4-194.ams2.redhat.com [10.36.4.194]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3MAOx1o032571; Fri, 22 Apr 2016 06:25:02 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 22 Apr 2016 11:24:55 +0100 Message-Id: <1461320695-31372-2-git-send-email-berrange@redhat.com> In-Reply-To: <1461320695-31372-1-git-send-email-berrange@redhat.com> References: <1461320695-31372-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.6] block: add an 'iscsi-id' value to match -drive with -iscsi opts 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: Kevin Wolf , qemu-block@nongnu.org, Peter Lieven , Pino Toscano , Ronnie Sahlberg , John Ferlan , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The iSCSI block driver has ability to lookup various options, in particular authentication info, specified by the separate -iscsi argument. It currently uses the iSCSI IQN as the ID value for this lookup, however, this does not work for common iSCSI IQNs as they contain characters such as ':' which are invalid for use as IDs. This adds an optional 'iscsi-id' parameter to the iSCSI block driver to allow an explicit ID string to be used to reference the -iscsi arg. For example $QEMU \ -iscsi id=my_initiator,user=fred,password-secret=sec0 \ -drive driver=iscsi,iscsi-id=my_initiator,file=iscsi://somehost/iqn/1 Signed-off-by: Daniel P. Berrange --- block/iscsi.c | 35 +++++++++++++++++++++++------------ qemu-doc.texi | 12 +++++++++--- qemu-options.hx | 4 ++-- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 302baf8..4b7aa91 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1070,7 +1070,7 @@ retry: return 0; } -static void parse_chap(struct iscsi_context *iscsi, const char *target, +static void parse_chap(struct iscsi_context *iscsi, const char *id, Error **errp) { QemuOptsList *list; @@ -1085,7 +1085,7 @@ static void parse_chap(struct iscsi_context *iscsi, const char *target, return; } - opts = qemu_opts_find(list, target); + opts = qemu_opts_find(list, id); if (opts == NULL) { opts = QTAILQ_FIRST(&list->head); if (!opts) { @@ -1123,7 +1123,7 @@ static void parse_chap(struct iscsi_context *iscsi, const char *target, g_free(secret); } -static void parse_header_digest(struct iscsi_context *iscsi, const char *target, +static void parse_header_digest(struct iscsi_context *iscsi, const char *id, Error **errp) { QemuOptsList *list; @@ -1135,7 +1135,7 @@ static void parse_header_digest(struct iscsi_context *iscsi, const char *target, return; } - opts = qemu_opts_find(list, target); + opts = qemu_opts_find(list, id); if (opts == NULL) { opts = QTAILQ_FIRST(&list->head); if (!opts) { @@ -1161,7 +1161,7 @@ static void parse_header_digest(struct iscsi_context *iscsi, const char *target, } } -static char *parse_initiator_name(const char *target) +static char *parse_initiator_name(const char *id) { QemuOptsList *list; QemuOpts *opts; @@ -1171,7 +1171,7 @@ static char *parse_initiator_name(const char *target) list = qemu_find_opts("iscsi"); if (list) { - opts = qemu_opts_find(list, target); + opts = qemu_opts_find(list, id); if (!opts) { opts = QTAILQ_FIRST(&list->head); } @@ -1195,7 +1195,7 @@ static char *parse_initiator_name(const char *target) return iscsi_name; } -static int parse_timeout(const char *target) +static int parse_timeout(const char *id) { QemuOptsList *list; QemuOpts *opts; @@ -1203,7 +1203,7 @@ static int parse_timeout(const char *target) list = qemu_find_opts("iscsi"); if (list) { - opts = qemu_opts_find(list, target); + opts = qemu_opts_find(list, id); if (!opts) { opts = QTAILQ_FIRST(&list->head); } @@ -1314,6 +1314,11 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_STRING, .help = "URL to the iscsi image", }, + { + .name = "iscsi-id", + .type = QEMU_OPT_STRING, + .help = "ID of the -iscsi argument" + }, { /* end of list */ } }, }; @@ -1452,6 +1457,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, QemuOpts *opts; Error *local_err = NULL; const char *filename; + const char *iscsi_arg_id; int i, ret = 0, timeout = 0; opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); @@ -1473,7 +1479,12 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, memset(iscsilun, 0, sizeof(IscsiLun)); - initiator_name = parse_initiator_name(iscsi_url->target); + iscsi_arg_id = qdict_get_try_str(bs->options, "iscsi-id"); + if (!iscsi_arg_id) { + iscsi_arg_id = iscsi_url->target; + } + + initiator_name = parse_initiator_name(iscsi_arg_id); iscsi = iscsi_create_context(initiator_name); if (iscsi == NULL) { @@ -1499,7 +1510,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, } /* check if we got CHAP username/password via the options */ - parse_chap(iscsi, iscsi_url->target, &local_err); + parse_chap(iscsi, iscsi_arg_id, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); ret = -EINVAL; @@ -1515,7 +1526,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C); /* check if we got HEADER_DIGEST via the options */ - parse_header_digest(iscsi, iscsi_url->target, &local_err); + parse_header_digest(iscsi, iscsi_arg_id, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); ret = -EINVAL; @@ -1523,7 +1534,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, } /* timeout handling is broken in libiscsi before 1.15.0 */ - timeout = parse_timeout(iscsi_url->target); + timeout = parse_timeout(iscsi_arg_id); #if defined(LIBISCSI_API_VERSION) && LIBISCSI_API_VERSION >= 20150621 iscsi_set_timeout(iscsi, timeout); #else diff --git a/qemu-doc.texi b/qemu-doc.texi index 79141d3..ecfd277 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -1018,7 +1018,7 @@ These can also be set via a configuration file Setting the target name allows different options for different targets @example -[iscsi "iqn.target.name"] +[iscsi "someid"] user = "CHAP username" password = "CHAP password" initiator-name = "iqn.qemu.test:my-initiator" @@ -1026,18 +1026,24 @@ Setting the target name allows different options for different targets header-digest = "CRC32C" @end example +The ``someid'' string is referenced from the -drive argument +using the ``iscsi-id'' parameter. If ``iscsi-id'' is not set +then it will try to use the iSCSI IQN value as the ID, however, +since this often contains invalid characters, using an explicit +ID is recommended. Howto use a configuration file to set iSCSI configuration options: @example cat >iscsi.conf <