From nobody Fri May 16 13:10:25 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 1497880740558287.97917653845116; Mon, 19 Jun 2017 06:59:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AD5280C27; Mon, 19 Jun 2017 13:58:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 759F581EE5; Mon, 19 Jun 2017 13:58:57 +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 16BA41800C8D; Mon, 19 Jun 2017 13:58:57 +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 v5JDwb6W020881 for ; Mon, 19 Jun 2017 09:58:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id A1D3C82746; Mon, 19 Jun 2017 13:58:37 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id A23EB82743; Mon, 19 Jun 2017 13:58:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9AD5280C27 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 9AD5280C27 From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 19 Jun 2017 15:58:33 +0200 Message-Id: <79bbe211171149fbd74de89036753a945dd31594.1497880533.git.pkrempa@redhat.com> 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 v2 6/8] util: storage: adapt to changes in JSON format for ceph/rbd 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 19 Jun 2017 13:58:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since qemu 2.9 the options changed from a monolithic string into fine grained options for the json pseudo-protocol object. --- src/util/virstoragefile.c | 50 +++++++++++++++++++++++++++++++++++++++++++= ---- tests/virstoragetest.c | 19 ++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b0dc92942..220a55d9b 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3122,6 +3122,15 @@ virStorageSourceParseBackingJSONRBD(virStorageSource= Ptr src, int opaque ATTRIBUTE_UNUSED) { const char *filename; + const char *pool =3D virJSONValueObjectGetString(json, "pool"); + const char *image =3D virJSONValueObjectGetString(json, "image"); + const char *conf =3D virJSONValueObjectGetString(json, "conf"); + const char *snapshot =3D virJSONValueObjectGetString(json, "snapshot"); + virJSONValuePtr servers =3D virJSONValueObjectGetArray(json, "server"); + char *fullname =3D NULL; + size_t nservers; + size_t i; + int ret =3D -1; src->type =3D VIR_STORAGE_TYPE_NETWORK; src->protocol =3D VIR_STORAGE_NET_PROTOCOL_RBD; @@ -3130,11 +3139,44 @@ virStorageSourceParseBackingJSONRBD(virStorageSourc= ePtr src, if ((filename =3D virJSONValueObjectGetString(json, "filename"))) return virStorageSourceParseRBDColonString(filename, src); - /* RBD currently supports only URI syntax passed in as filename */ - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing RBD filename in JSON backing volume definiti= on")); + if (!pool || !image) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing pool or image name in ceph backing volum= e " + "JSON specification")); + return -1; + } - return -1; + /* currently we need to store the pool name and image name together, s= ince + * the rest of the code is not prepared for it */ + if (virAsprintf(&fullname, "%s/%s", pool, image) < 0) + return -1; + + if (VIR_STRDUP(src->snapshot, snapshot) < 0 || + VIR_STRDUP(src->configFile, conf) < 0) + goto cleanup; + + VIR_STEAL_PTR(src->path, fullname); + + if (servers) { + nservers =3D virJSONValueArraySize(servers); + + if (VIR_ALLOC_N(src->hosts, nservers) < 0) + goto cleanup; + + src->nhosts =3D nservers; + + for (i =3D 0; i < nservers; i++) { + if (virStorageSourceParseBackingJSONInetSocketAddress(src->hos= ts + i, + virJSONV= alueArrayGet(servers, i)) < 0) + goto cleanup; + } + } + + ret =3D 0; + cleanup: + VIR_FREE(fullname); + + return ret; } static int diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index ca2601de7..9c7314bff 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1507,6 +1507,25 @@ mymain(void) "\n" " \n" "\n"); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"rbd\"," + "\"image\":\"test\"," + "\"pool\":\"libvirt\"," + "\"conf\":\"/path/to/conf\"," + "\"snapshot\":\"snapshotname\"," + "\"server\":[ {\"host\":\"example.c= om\"," + "\"port\":\"1234\"" + "}," + "{\"host\":\"example2.= com\"" + "}" + "]" + "}" + "}", + "\n" + " \n" + " \n" + " \n" + " \n" + "\n"); TEST_BACKING_PARSE("json:{ \"file\": { " "\"driver\": \"raw\"," "\"file\": {" --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list