On 05/20/2012 09:56 AM, Peter Krempa wrote: > This patch adds a basic implementation of the listing code for > virConnectListAllDomains() to qemu driver. The listing code does > not support any filtering flags yet, but they may be easily added > later. We need to also cover all the other drivers; I'm wondering how many drivers will share common implementations, where we could factor things into src/conf/domain_conf.c. > > +struct virDomainListData { > + virConnectPtr conn; > + virDomainPtr *domains; > + int ndomains; > + int size; > + int limit; s/int/size_t/ for these three lines. > + bool error; > + bool populate; > +}; > + > +#define VIR_DOMAIN_LIST_POPULATION_INCREMENT 10 You don't need this. Instead, you can use VIR_RESIZE_N(domains, size, ndomains, 1) to guarantee at least ndomains+1 slots, but only allocating on geometric boundaries. > + > +static void > +qemuPopulateDomainList(void *payload, > + const void *name ATTRIBUTE_UNUSED, > + void *opaque) > +{ > + struct virDomainListData *data = opaque; > + virDomainObjPtr vm = payload; > + > + if (data->error || > + (data->limit >= 0 && > + data->ndomains >= data->limit)) > + return; I don't think you need data->limit at all. Here is where you would do any filtering based on flags. > + > + if (!data->populate) { > + data->ndomains++; > + return; > + } > + > + virDomainObjLock(vm); > + > + if (data->size == data->ndomains) { > + if (VIR_REALLOC_N(data->domains, > + data->size + VIR_DOMAIN_LIST_POPULATION_INCREMENT) < 0) See above about using VIR_EXPAND_N instead of VIR_REALLOC_N. > +static int > +qemuListAllDomains(virConnectPtr conn, > + virDomainPtr **domains, > + int ndomains, > + unsigned int flags) > +{ > + struct qemud_driver *driver = conn->privateData; > + int ret = -1; > + int i; > + > + struct virDomainListData data = { conn, NULL, 0, 0, ndomains, Why the double space? > + false, !!domains}; > + > + virCheckFlags(0, -1); > + > + qemuDriverLock(driver); > + > + virHashForEach(driver->domains.objs, qemuPopulateDomainList, > + (void *) &data); No need to cast to (void*) in C. -- Eric Blake eblake@xxxxxxxxxx +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list