From patchwork Wed Sep 7 21:23:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9319967 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 C8C66607D3 for ; Wed, 7 Sep 2016 21:34:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D58B62942E for ; Wed, 7 Sep 2016 21:34:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA84729433; Wed, 7 Sep 2016 21:34:53 +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 66AF52942E for ; Wed, 7 Sep 2016 21:34:53 +0000 (UTC) Received: from localhost ([::1]:43194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhkUe-000724-Dq for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Sep 2016 17:34:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhkJi-0004DY-Lp for qemu-devel@nongnu.org; Wed, 07 Sep 2016 17:23:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhkJh-00055P-Ar for qemu-devel@nongnu.org; Wed, 07 Sep 2016 17:23:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhkJh-00054r-3Z for qemu-devel@nongnu.org; Wed, 07 Sep 2016 17:23:33 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 8FAF83F725; Wed, 7 Sep 2016 21:23:32 +0000 (UTC) Received: from localhost (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u87LNTnA002309; Wed, 7 Sep 2016 17:23:31 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Wed, 7 Sep 2016 17:23:12 -0400 Message-Id: <1473283392-31292-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1473283392-31292-1-git-send-email-stefanha@redhat.com> References: <1473283392-31292-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 07 Sep 2016 21:23:32 +0000 (UTC) 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 3/3] iscsi: add iscsi= option 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: ronniesahlberg@gmail.com, pl@kamp.de, Stefan Hajnoczi , Paolo Bonzini , jferlan@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP An iSCSI block driver instance is implicitly matched with an -iscsi object that has id=. If no -iscsi object with that id exists then the first -iscsi object is used. This patch adds a -drive ...,iscsi= option so the relationship between the block driver instance and an -iscsi object can be specified explicitly. When the iscsi= parameter is used there is no fallback to the first -iscsi option (which is weird legacy behavior). This makes it possible to connect to multiple LUNs on the same target with different credentials whereas previously the same -iscsi object would be associated with all block driver instances for that iSCSI target. Example: $ qemu-system-x86_64 -iscsi id=test,user=foo,password=x,\ initiator-name=iqn.2001-04.com.example:my-initiator \ -drive driver=iscsi,filename=iscsi://127.0.0.1/iqn.2003-01.org.linux-iscsi.test.x8664:sn.d964cc832811/0,iscsi=test Signed-off-by: Stefan Hajnoczi --- block/iscsi.c | 21 ++++++++++++++------- qemu-options.hx | 8 ++++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 4eb9a36..b5a813f 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1199,7 +1199,7 @@ retry: } /* Look up the -iscsi command-line option */ -static QemuOpts *find_iscsi_opts(const char *id) +static QemuOpts *find_iscsi_opts(const char *id, bool default_to_first) { QemuOptsList *list; QemuOpts *opts; @@ -1210,13 +1210,9 @@ static QemuOpts *find_iscsi_opts(const char *id) } opts = qemu_opts_find(list, id); - if (opts == NULL) { + if (opts == NULL && default_to_first) { opts = QTAILQ_FIRST(&list->head); - if (!opts) { - return NULL; - } } - return opts; } @@ -1411,6 +1407,11 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_STRING, .help = "URL to the iscsi image", }, + { + .name = "iscsi", + .type = QEMU_OPT_STRING, + .help = "id of iscsi object", + }, { /* end of list */ } }, }; @@ -1550,6 +1551,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, QemuOpts *iscsi_opts; Error *local_err = NULL; const char *filename; + const char *iscsi_opts_id; int i, ret = 0, timeout = 0; opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); @@ -1571,7 +1573,12 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, memset(iscsilun, 0, sizeof(IscsiLun)); - iscsi_opts = find_iscsi_opts(iscsi_url->target); + iscsi_opts_id = qemu_opt_get(opts, "iscsi"); + if (iscsi_opts_id) { + iscsi_opts = find_iscsi_opts(iscsi_opts_id, false); + } else { + iscsi_opts = find_iscsi_opts(iscsi_url->target, true); + } initiator_name = parse_initiator_name(iscsi_opts); diff --git a/qemu-options.hx b/qemu-options.hx index a71aaf8..89da93d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2515,14 +2515,18 @@ LIBISCSI_CHAP_PASSWORD="password" \ qemu-system-i386 -drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1 @end example +An iSCSI drive is associated with an -iscsi option as follows. If -drive +...,iscsi= is present then the -iscsi option with that id is used. +Otherwise an -iscsi option whose id matches the drive's target IQN is searched +and if the search fails the first -iscsi option is used. + iSCSI support is an optional feature of QEMU and only available when compiled and linked against libiscsi. ETEXI DEF("iscsi", HAS_ARG, QEMU_OPTION_iscsi, "-iscsi [user=user][,password=password]\n" " [,header-digest=CRC32C|CR32C-NONE|NONE-CRC32C|NONE\n" - " [,initiator-name=initiator-iqn][,id=target-iqn]\n" - " [,timeout=timeout]\n" + " [,initiator-name=initiator-iqn][,id=id][,timeout=timeout]\n" " iSCSI session parameters\n", QEMU_ARCH_ALL) STEXI