From nobody Thu May 15 04:10:16 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.zohomail.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 1517396961439721.3340567044105; Wed, 31 Jan 2018 03:09:21 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E341FC05B012; Wed, 31 Jan 2018 11:09:19 +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 9E7015DA60; Wed, 31 Jan 2018 11:09:19 +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 1AFB43FC73; Wed, 31 Jan 2018 11:09:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0VB8EkJ009678 for ; Wed, 31 Jan 2018 06:08:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5DBBF5D760; Wed, 31 Jan 2018 11:08:14 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48B635EDEE; Wed, 31 Jan 2018 11:08:13 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 12:07:32 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/2] util: storage: Parse 'lun' for iSCSI protocol from JSON as string or number 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 31 Jan 2018 11:09:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" While the QEMU QAPI schema describes 'lun' as a number, the code dealing with JSON strings does not strictly adhere to this schema and thus formats the number back as a string. Use the new helper to retrieve both possibilities. Note that the formatting code is okay and qemu will accept it as an int. Tweak also one of the test stringst to verify that both formats work with libvirt. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1540290 --- src/util/virstoragefile.c | 13 +++++-------- tests/virstoragetest.c | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5780180a94..5f661c956c 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2976,10 +2976,9 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSour= cePtr src, const char *transport =3D virJSONValueObjectGetString(json, "transport= "); const char *portal =3D virJSONValueObjectGetString(json, "portal"); const char *target =3D virJSONValueObjectGetString(json, "target"); + const char *lun =3D virJSONValueObjectGetStringOrNumber(json, "lun"); const char *uri; char *port; - unsigned int lun =3D 0; - char *fulltarget =3D NULL; int ret =3D -1; /* legacy URI based syntax passed via 'filename' option */ @@ -2990,6 +2989,9 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourc= ePtr src, src->type =3D VIR_STORAGE_TYPE_NETWORK; src->protocol =3D VIR_STORAGE_NET_PROTOCOL_ISCSI; + if (!lun) + lun =3D "0"; + if (VIR_ALLOC(src->hosts) < 0) goto cleanup; @@ -3026,17 +3028,12 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSou= rcePtr src, *port =3D '\0'; } - ignore_value(virJSONValueObjectGetNumberUint(json, "lun", &lun)); - - if (virAsprintf(&fulltarget, "%s/%u", target, lun) < 0) + if (virAsprintf(&src->path, "%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 7a0d4a8260..1dc7608cee 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1572,7 +1572,7 @@ mymain(void) "\"transport\":\"tcp\"," "\"portal\":\"test.org:1234\"," "\"target\":\"iqn.2016-12.com.virtt= est:emulated-iscsi-noauth.target\"," - "\"lun\":6" + "\"lun\":\"6\"" "}" "}", "\n" --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list