From nobody Thu Nov 28 16:37:27 2024 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 1521099195988738.1189691957596; Thu, 15 Mar 2018 00:33:15 -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 A7DAD46668; Thu, 15 Mar 2018 07:33:14 +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 7FC62620A0; Thu, 15 Mar 2018 07:33: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 44865181BA11; Thu, 15 Mar 2018 07:33: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 w2EHLo93025144 for ; Wed, 14 Mar 2018 13:22:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB69A5E1B9; Wed, 14 Mar 2018 17:21:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2F835C552 for ; Wed, 14 Mar 2018 17:21:48 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4BFAC058EB0 for ; Wed, 14 Mar 2018 17:21:46 +0000 (UTC) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2EHKRj3023557 for ; Wed, 14 Mar 2018 13:21:46 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gq446444a-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 14 Mar 2018 13:21:45 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Mar 2018 17:21:44 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Mar 2018 17:21:41 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2EHLeBT65994788 for ; Wed, 14 Mar 2018 17:21:40 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 517384C044 for ; Wed, 14 Mar 2018 17:14:55 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA1C04C04A for ; Wed, 14 Mar 2018 17:14:54 +0000 (GMT) Received: from localhost.localdomain (unknown [9.79.182.166]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Wed, 14 Mar 2018 17:14:54 +0000 (GMT) From: Shivaprasad G Bhat To: libvir-list@redhat.com Date: Wed, 14 Mar 2018 22:51:38 +0530 In-Reply-To: <152104711186.10112.1077788328340024644.stgit@localhost.localdomain> References: <152104711186.10112.1077788328340024644.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18031417-0008-0000-0000-000004DD796B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031417-0009-0000-0000-00001E707F2A Message-Id: <152104808071.10112.13304848195442484697.stgit@localhost.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-14_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803140193 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 14 Mar 2018 17:21:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 14 Mar 2018 17:21:46 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'sbhat@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.7 (RCVD_IN_DNSWL_LOW) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 19/28] Introduce virDomainDeviceDefParseXMLMany 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: , 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.30]); Thu, 15 Mar 2018 07:33:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Shivaprasad G Bhat --- src/conf/domain_conf.c | 169 ++++++++++++++++++++++++++++++++++++++++--= ---- src/conf/domain_conf.h | 36 ++++++++++ src/libvirt_private.syms | 6 ++ 3 files changed, 190 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3deed8eb4d..5f4a5127d4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -963,6 +963,83 @@ virDomainXMLOptionClassDispose(void *obj) (xmlopt->config.privFree)(xmlopt->config.priv); } =20 +/* virDomainDeviceDefListAddCopy - add a *copy* of the device to this list= */ +int +virDomainDeviceDefListAddCopy(virDomainDeviceDefListPtr list, + virDomainDeviceDefPtr dev, + virDomainDeviceDefListDataPtr data) +{ + virDomainDeviceDefPtr copy =3D virDomainDeviceDefCopy(dev, data->def, = data->caps, data->xmlopt); + + if (!copy) + return -1; + if (VIR_APPEND_ELEMENT(list->devs, list->count, copy) < 0) { + virDomainDeviceDefFree(copy); + return -1; + } + return 0; +} + +void virDomainDeviceDefListFree(virDomainDeviceDefListPtr list) +{ + size_t i; + + if (!list) + return; + for (i =3D 0; i < list->count; i++) + virDomainDeviceDefFree(list->devs[i]); + VIR_FREE(list->devs); +} + +void virDomainDeviceDefListFreeShallow(virDomainDeviceDefListPtr list) +{ + size_t i; + + if (!list) + return; + for (i =3D 0; i < list->count; i++) + VIR_FREE(list->devs[i]); +} + + +/* virDomainDeviceDefListIter - Iterate through the list with the callback= */ +int +virDomainDeviceDefListIterate(virDomainDeviceDefListPtr list, + virDomainDeviceDefListIterCallback cb, + void *data) +{ + size_t i; + + for (i =3D 0; i < list->count; i++) + if (cb(list->devs[i], data)) + return -1; + + return 0; +} + +virDomainDeviceDefListPtr +virDomainDeviceDefListCopy(virDomainDeviceDefListPtr list, + virDomainDeviceDefListDataPtr data) +{ + size_t i; + virDomainDeviceDefListPtr devlist =3D NULL; + + if (list && (VIR_ALLOC(devlist) < 0)) + goto cleanup; + + for (i =3D 0; i < list->count; i++) { + if (virDomainDeviceDefListAddCopy(devlist, list->devs[i], data) < = 0) + goto cleanup; + } + + return devlist; + cleanup: + virDomainDeviceDefListFree(devlist); + return NULL; +} + + + /** * virDomainKeyWrapCipherDefParseXML: * @@ -15677,25 +15754,16 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, return ret; } =20 - -virDomainDeviceDefPtr -virDomainDeviceDefParse(const char *xmlStr, - const virDomainDef *def, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int flags) +static +virDomainDeviceDefPtr virDomainDeviceDefParseXML(xmlNodePtr node, + const virDomainDef *def, + virCapsPtr caps, + virDomainXMLOptionPtr xml= opt, + xmlXPathContextPtr ctxt, + unsigned int flags) { - xmlDocPtr xml; - xmlNodePtr node; - xmlXPathContextPtr ctxt =3D NULL; virDomainDeviceDefPtr dev =3D NULL; char *netprefix; - - if (!(xml =3D virXMLParseStringCtxt(xmlStr, _("(device_definition)"), = &ctxt))) - goto error; - - node =3D ctxt->node; - if (VIR_ALLOC(dev) < 0) goto error; =20 @@ -15846,14 +15914,33 @@ virDomainDeviceDefParse(const char *xmlStr, if (virDomainDeviceDefValidate(dev, def, flags, xmlopt) < 0) goto error; =20 - cleanup: + return dev; + error: + return NULL; +} + +virDomainDeviceDefPtr +virDomainDeviceDefParse(const char *xmlStr, + const virDomainDef *def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlDocPtr xml; + xmlNodePtr node; + xmlXPathContextPtr ctxt =3D NULL; + virDomainDeviceDefPtr dev =3D NULL; + + if (!(xml =3D virXMLParseStringCtxt(xmlStr, _("(device_definition)"), = &ctxt))) + return NULL; + + node =3D ctxt->node; + + dev =3D virDomainDeviceDefParseXML(node, def, caps, xmlopt, ctxt, flag= s); + xmlFreeDoc(xml); xmlXPathFreeContext(ctxt); return dev; - - error: - VIR_FREE(dev); - goto cleanup; } =20 =20 @@ -29394,3 +29481,43 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefP= tr def) virStoragePoolDefFree(pooldef); return ret; } + +virDomainDeviceDefListPtr +virDomainDeviceDefParseXMLMany(const char *xml, + const virDomainDef *def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlXPathContextPtr ctxt =3D NULL; + xmlDocPtr xmlPtr; + xmlNodePtr node, root; + virDomainDeviceDefPtr dev =3D NULL; + virDomainDeviceDefListPtr devlist; + + if (!(xmlPtr =3D virXMLParseStringCtxt(xml, _("(device_definition)"), = &ctxt))) + return NULL; + + if (VIR_ALLOC(devlist) < 0) + goto exit; + + root =3D xmlDocGetRootElement(xmlPtr); + node =3D root->children; + while (node) { + if (node->type =3D=3D XML_ELEMENT_NODE) { + dev =3D virDomainDeviceDefParseXML(node, def, caps, xmlopt, ct= xt, flags); + if (VIR_APPEND_ELEMENT(devlist->devs, devlist->count, dev) < 0= ) { + virDomainDeviceDefFree(dev); + virDomainDeviceDefListFree(devlist); + goto exit; + } + dev =3D NULL; + } + node =3D node->next; + } + + exit: + xmlFreeDoc(xmlPtr); + xmlXPathFreeContext(ctxt); + return devlist; +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a3d686a5ca..828fe9f6d8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2561,6 +2561,37 @@ typedef int (*virDomainDefPostParseBasicCallback)(vi= rDomainDefPtr def, virCapsPtr caps, void *opaque); =20 +typedef struct _virDomainDeviceDefListData virDomainDeviceDefListData; +typedef virDomainDeviceDefListData *virDomainDeviceDefListDataPtr; +struct _virDomainDeviceDefListData { + const virDomainDef *def; + virCapsPtr caps; + virDomainXMLOptionPtr xmlopt; +}; + +struct virDomainDeviceDefList { + virDomainDeviceDefPtr *devs; + size_t count; +}; +typedef struct virDomainDeviceDefList *virDomainDeviceDefListPtr; + +typedef int (*virDomainDeviceDefListIterCallback)(virDomainDeviceDefPtr de= v, + void *opaque); +int virDomainDeviceDefListIterate(virDomainDeviceDefListPtr devlist, + virDomainDeviceDefListIterCallback cb, + void *data); +int +virDomainDeviceDefListAddCopy(virDomainDeviceDefListPtr list, + virDomainDeviceDefPtr dev, + virDomainDeviceDefListDataPtr data); +virDomainDeviceDefListPtr +virDomainDeviceDefListCopy(virDomainDeviceDefListPtr list, + virDomainDeviceDefListDataPtr data); + +void virDomainDeviceDefListFree(virDomainDeviceDefListPtr list); +void virDomainDeviceDefListFreeShallow(virDomainDeviceDefListPtr list); + + /* Called once after everything else has been parsed, for adjusting * overall domain defaults. * @parseOpaque is opaque data passed by virDomainDefParse* caller, @@ -2935,6 +2966,11 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(const = char *xmlStr, virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags); +virDomainDeviceDefListPtr virDomainDeviceDefParseXMLMany(const char *xmlSt= r, + const virDomainDe= f *def, + virCapsPtr caps, + virDomainXMLOptio= nPtr xmlopt, + unsigned int flag= s); virStorageSourcePtr virDomainDiskDefSourceParse(const char *xmlStr, const virDomainDef *def, virDomainXMLOptionPtr xmlo= pt, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b0e8f2ca61..d1ff2f5f99 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -300,7 +300,13 @@ virDomainDeviceAddressTypeToString; virDomainDeviceAliasIsUserAlias; virDomainDeviceDefCopy; virDomainDeviceDefFree; +virDomainDeviceDefListAddCopy; +virDomainDeviceDefListCopy; +virDomainDeviceDefListFree; +virDomainDeviceDefListFreeShallow; +virDomainDeviceDefListIterate; virDomainDeviceDefParse; +virDomainDeviceDefParseXMLMany; virDomainDeviceFindSCSIController; virDomainDeviceGetInfo; virDomainDeviceInfoIterate; -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list