From nobody Fri May 16 12:51:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1497627016087862.2975722279067; Fri, 16 Jun 2017 08:30:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7473723B4; Fri, 16 Jun 2017 15:30:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B4E991284; Fri, 16 Jun 2017 15:30:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 32BA24A495; Fri, 16 Jun 2017 15:30:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5GFTuGH013503 for ; Fri, 16 Jun 2017 11:29:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6A2AC7D4C7; Fri, 16 Jun 2017 15:29:56 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD79A7D4A5; Fri, 16 Jun 2017 15:29:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A7473723B4 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A7473723B4 From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 16 Jun 2017 17:29:43 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 06/10] util: storage: Add JSON parser for new options in iSCSI protocol X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 16 Jun 2017 15:30:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Starting from qemu 2.9, more granular options are supported. Add parser for the relevant bits. With this patch libvirt is able to parse the host and target IQN of from the JSON pseudo-protocol specification. This corresponds to BlockdevOptionsIscsi in qemu qapi. --- src/util/virstoragefile.c | 53 +++++++++++++++++++++++++++++++++++++++++++= ---- tests/virstoragetest.c | 10 +++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index c0aa4e4c6..4f063e7f2 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2941,18 +2941,63 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSou= rcePtr src, virJSONValuePtr json, int opaque ATTRIBUTE_UNUSED) { + const char *transport =3D virJSONValueObjectGetString(json, "transport= "); + const char *portal =3D virJSONValueObjectGetString(json, "portal"); + const char *target =3D virJSONValueObjectGetString(json, "target"); const char *uri; + const char *lun; + char *fulltarget =3D NULL; + int ret =3D -1; /* legacy URI based syntax passed via 'filename' option */ if ((uri =3D virJSONValueObjectGetString(json, "filename"))) return virStorageSourceParseBackingJSONUriStr(src, uri, VIR_STORAGE_NET_PROT= OCOL_ISCSI); - /* iSCSI currently supports only URI syntax passed in as filename */ - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing iSCSI URI in JSON backing volume definition"= )); + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_ISCSI; - return -1; + if (VIR_ALLOC(src->hosts) < 0) + goto cleanup; + + src->nhosts =3D 1; + + if (STRNEQ_NULLABLE(transport, "tcp")) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("only TCP transport is supported for iSCSI volume= s")); + goto cleanup; + } + + src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + + if (!portal) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'portal' address in iSCSI backing defini= tion")); + goto cleanup; + } + + if (!target) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'target' in iSCSI backing definition")); + goto cleanup; + } + + if (VIR_STRDUP(src->hosts->name, portal) < 0) + goto cleanup; + + if (!(lun =3D virJSONValueObjectGetString(json, "lun"))) + lun =3D "0"; + + if (virAsprintf(&fulltarget, "%s/%s", target, lun) < 0) + goto cleanup; + + VIR_STEAL_PTR(src->path, fulltarget); + + ret =3D 0; + + cleanup: + VIR_FREE(fulltarget); + return ret; } diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 70e24a1b7..c31f4fc54 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1502,6 +1502,16 @@ mymain(void) "\"driver\": \"file\"," "\"filename\": \"/path/to/file\" } } }= ", "\n"); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\"," + "\"transport\":\"tcp\"," + "\"portal\":\"test.org\"," + "\"target\":\"iqn.2016-12.com.virtt= est:emulated-iscsi-noauth.target\"," + "\"lun\":\"6\"" + "}" + "}", + "\n" + " \n" + "\n"); cleanup: /* Final cleanup */ --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list