From 83726a14d294c8cacf1e0decf5e55f84fba1c1c8 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 29 Apr 2015 16:15:53 +0200 Subject: [PATCH] conf: Add helper to convert list of virDomains to a list of virDomainObjs Add virDomainObjListConvert that will take a list of virDomains, apply filters and return a list of virDomainObjs. --- src/conf/domain_conf.c | 58 ++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 9 +++++++ src/libvirt_private.syms | 1 + 3 files changed, 68 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0fea61a642..93d24ee068 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23109,6 +23109,64 @@ virDomainObjListCollect(virDomainObjListPtr domlist, } +int +virDomainObjListConvert(virDomainObjListPtr domlist, + virConnectPtr conn, + virDomainPtr *doms, + size_t ndoms, + virDomainObjPtr **vms, + size_t *nvms, + virDomainObjListACLFilter filter, + unsigned int flags, + bool skip_missing) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDomainObjPtr vm; + size_t i; + + *nvms = 0; + *vms = NULL; + + virObjectLock(domlist); + for (i = 0; i < ndoms; i++) { + virDomainPtr dom = doms[i]; + + virUUIDFormat(dom->uuid, uuidstr); + + if (!(vm = virHashLookup(domlist->objs, uuidstr))) { + if (skip_missing) + continue; + + virObjectUnlock(domlist); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s' (%s)"), + uuidstr, dom->name); + goto error; + } + + virObjectRef(vm); + + if (VIR_APPEND_ELEMENT(*vms, *nvms, vm) < 0) { + virObjectUnlock(domlist); + virObjectUnref(vm); + goto error; + } + } + virObjectUnlock(domlist); + + virDomainObjListFilter(vms, nvms, conn, filter, flags); + + return 0; + + error: + virObjectListFreeCount(*vms, *nvms); + *vms = NULL; + *nvms = 0; + + return -1; +} + + int virDomainObjListExport(virDomainObjListPtr domlist, virConnectPtr conn, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8bc9536c58..2cd105a7aa 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3062,6 +3062,15 @@ int virDomainObjListExport(virDomainObjListPtr doms, virDomainPtr **domains, virDomainObjListACLFilter filter, unsigned int flags); +int virDomainObjListConvert(virDomainObjListPtr domlist, + virConnectPtr conn, + virDomainPtr *doms, + size_t ndoms, + virDomainObjPtr **vms, + size_t *nvms, + virDomainObjListACLFilter filter, + unsigned int flags, + bool skip_missing); int virDomainDefMaybeAddController(virDomainDefPtr def, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9a7a9448f0..67a7e21a20 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -386,6 +386,7 @@ virDomainObjGetPersistentDef; virDomainObjGetState; virDomainObjListAdd; virDomainObjListCollect; +virDomainObjListConvert; virDomainObjListExport; virDomainObjListFindByID; virDomainObjListFindByName; -- GitLab