[libvirt] [PATCH 4/5] qemu: implement virConnectListAllDomains() for qemu driver

Eric Blake eblake at redhat.com
Thu May 24 11:46:51 UTC 2012


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.
> ---
>  src/qemu/qemu_driver.c |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 97 insertions(+), 0 deletions(-)

> +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;
> +
> +    if (!data->populate) {
> +        data->ndomains++;
> +        return;
> +    }
> +
> +    virDomainObjLock(vm);

I just realized: Since we are executing this under the driver lock, and
no VM can change state until we let go of the driver lock, it is not
necessary to lock vms in this loop.  That will help things go faster in
computing the list.

> +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,
> +                                     false, !!domains};
> +
> +    virCheckFlags(0, -1);
> +
> +    qemuDriverLock(driver);
> +
> +    virHashForEach(driver->domains.objs, qemuPopulateDomainList,
> +                   (void *) &data);

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120524/95b17145/attachment-0001.sig>


More information about the libvir-list mailing list