From nobody Sun Feb 8 21:32:34 2026 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 1490888118635640.8200761386066; Thu, 30 Mar 2017 08:35:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C97BD6AAC4; Thu, 30 Mar 2017 15:21: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 9E217820D4; Thu, 30 Mar 2017 15:21: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 52BCF18523CC; Thu, 30 Mar 2017 15:21:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2UFBt7M004169 for ; Thu, 30 Mar 2017 11:11:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 904567DE2E; Thu, 30 Mar 2017 15:11:55 +0000 (UTC) Received: from angien.brq.redhat.com (dhcp129-47.brq.redhat.com [10.34.129.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4CFC8387A; Thu, 30 Mar 2017 15:11:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C97BD6AAC4 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 C97BD6AAC4 From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 30 Mar 2017 17:12:46 +0200 Message-Id: <2bca845759296131caf8263719e80df6dcc607d3.1490886728.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 2/5] storage: util: Split out the gluster volume extraction code into new function 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 30 Mar 2017 15:21:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" To allow testing of the algorithm, split out the extractor into a separate helper. --- src/storage/storage_util.c | 95 +++++++++++++++++++++++++++---------------= ---- src/storage/storage_util.h | 4 ++ 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index cad706199..3b55bafc0 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2836,6 +2836,60 @@ virStorageBackendDeleteLocal(virConnectPtr conn ATTR= IBUTE_UNUSED, } +int +virStorageUtilGlusterExtractPoolSources(const char *host, + const char *xml, + virStoragePoolSourceListPtr list, + bool netfs) +{ + xmlDocPtr doc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + xmlNodePtr *nodes =3D NULL; + virStoragePoolSource *src =3D NULL; + size_t i; + int nnodes; + int ret =3D -1; + + if (!(doc =3D virXMLParseStringCtxt(xml, _("(gluster_cli_output)"), &c= txt))) + goto cleanup; + + if ((nnodes =3D virXPathNodeSet("//volumes/volume", ctxt, &nodes)) < 0) + goto cleanup; + + for (i =3D 0; i < nnodes; i++) { + ctxt->node =3D nodes[i]; + + if (!(src =3D virStoragePoolSourceListNewSource(list))) + goto cleanup; + + if (!(src->dir =3D virXPathString("string(//name)", ctxt))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to extract gluster volume name")); + goto cleanup; + } + + if (VIR_ALLOC_N(src->hosts, 1) < 0) + goto cleanup; + src->nhost =3D 1; + + if (VIR_STRDUP(src->hosts[0].name, host) < 0) + goto cleanup; + + if (netfs) + src->format =3D VIR_STORAGE_POOL_NETFS_GLUSTERFS; + } + + ret =3D nnodes; + + cleanup: + VIR_FREE(nodes); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); + + return ret; +} + + /** * virStorageBackendFindGlusterPoolSources: * @host: host to detect volumes on @@ -2859,12 +2913,6 @@ virStorageBackendFindGlusterPoolSources(const char *= host, char *glusterpath =3D NULL; char *outbuf =3D NULL; virCommandPtr cmd =3D NULL; - xmlDocPtr doc =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; - xmlNodePtr *nodes =3D NULL; - virStoragePoolSource *src =3D NULL; - size_t i; - int nnodes; int rc; int ret =3D -1; @@ -2895,42 +2943,9 @@ virStorageBackendFindGlusterPoolSources(const char *= host, goto cleanup; } - if (!(doc =3D virXMLParseStringCtxt(outbuf, _("(gluster_cli_output)"), - &ctxt))) - goto cleanup; - - if ((nnodes =3D virXPathNodeSet("//volumes/volume", ctxt, &nodes)) < 0) - goto cleanup; - - for (i =3D 0; i < nnodes; i++) { - ctxt->node =3D nodes[i]; - - if (!(src =3D virStoragePoolSourceListNewSource(list))) - goto cleanup; - - if (!(src->dir =3D virXPathString("string(//name)", ctxt))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to extract gluster volume name")); - goto cleanup; - } - - if (VIR_ALLOC_N(src->hosts, 1) < 0) - goto cleanup; - src->nhost =3D 1; - - if (VIR_STRDUP(src->hosts[0].name, host) < 0) - goto cleanup; - - if (netfs) - src->format =3D VIR_STORAGE_POOL_NETFS_GLUSTERFS; - } - - ret =3D nnodes; + ret =3D virStorageUtilGlusterExtractPoolSources(host, outbuf, list, ne= tfs); cleanup: - VIR_FREE(nodes); - xmlXPathFreeContext(ctxt); - xmlFreeDoc(doc); VIR_FREE(outbuf); virCommandFree(cmd); VIR_FREE(glusterpath); diff --git a/src/storage/storage_util.h b/src/storage/storage_util.h index 741baa78d..ecd67e2fc 100644 --- a/src/storage/storage_util.h +++ b/src/storage/storage_util.h @@ -93,6 +93,10 @@ int virStorageBackendDeleteLocal(virConnectPtr conn, int virStorageBackendRefreshLocal(virConnectPtr conn, virStoragePoolObjPtr pool); +int virStorageUtilGlusterExtractPoolSources(const char *host, + const char *xml, + virStoragePoolSourceListPtr li= st, + bool netfs); int virStorageBackendFindGlusterPoolSources(const char *host, virStoragePoolSourceListPtr li= st, bool netfs, --=20 2.12.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list