From nobody Mon Feb 9 01:47:23 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 1490793976044861.8704076942092; Wed, 29 Mar 2017 06:26:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3124E61BAD; Wed, 29 Mar 2017 13:26:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 026CFB23EC; Wed, 29 Mar 2017 13:26: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 F173D5EC63; Wed, 29 Mar 2017 13:26:12 +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 v2TDMiad014944 for ; Wed, 29 Mar 2017 09:22:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D73FC189EB; Wed, 29 Mar 2017 13:22:44 +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 355B318992; Wed, 29 Mar 2017 13:22:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3124E61BAD Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 3124E61BAD From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 29 Mar 2017 15:23:38 +0200 Message-Id: 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 1/3] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 29 Mar 2017 13:26:15 +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 | 93 +++++++++++++++++++++++++++---------------= ---- src/storage/storage_util.h | 4 ++ 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7687eb89a..8459e9d5b 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2836,6 +2836,59 @@ virStorageBackendDeleteLocal(virConnectPtr conn ATTR= IBUTE_UNUSED, } +int +virStorageUtilGlusterExtractPoolSources(const char *host, + const char *xml, + int pooltype, + virStoragePoolSourceListPtr list) +{ + 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; + + src->format =3D pooltype; + } + + ret =3D nnodes; + + cleanup: + VIR_FREE(nodes); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); + + return ret; +} + + /** * virStorageBackendFindGlusterPoolSources: * @host: host to detect volumes on @@ -2856,12 +2909,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; @@ -2892,41 +2939,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; - - src->format =3D pooltype; - } - - ret =3D nnodes; + ret =3D virStorageUtilGlusterExtractPoolSources(host, outbuf, pooltype= , list); 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 fa3b6522c..bf8424808 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, + int pooltype, + virStoragePoolSourceListPtr li= st); int virStorageBackendFindGlusterPoolSources(const char *host, int pooltype, virStoragePoolSourceListPtr li= st, --=20 2.12.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list