[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] some unsorted questions



On Thu, Jul 17, 2008 at 01:29:45AM +0200, Stefan de Konink wrote:
> If this gets implemented I would suggest a call that fetches all domains 
> from a running system and not only the defined or only the active ones.

This is a good idea regardless. The current APIs require an application
todo

   num = list number of domains
   for 1 to num
       lookup domain by id

In the case of the Xen drivers, this requires  O(n) calls to XenD which
are rather expensive. XenD does actually have ability to return data about
all domains in a single request. So if we had an API for fetching all
domains at once it'd only require  O(1)  expensive XenD calls. I'd imagine
something like this


    int virConnectListAllDomains(virConnectPtr conn,
                                 virDomainPtr **domains,
                                 int stateflags);

The 'stateflags' parameter would be a bit-field where each bit corresponded
to one of the virDomainState enumeration values. The 'domains' list would
be allocated by libvirt, and filled in with all the domain objects, and
the total number of domains as the return value.

So as an example, listing all paused domains

     virDomainPtr *domains;
     int ndomains;

     ndomains = virConnectListAllDomains(conn,
                                         &domains,
                                         (1 << VIR_DOMAIN_PAUSED));

We probably want to define constants for the latter set of flags

    #define VIR_DOMAIN_LIST_NOSTATE (1 << VIR_DOMAIN_NOSTATE)
    #define VIR_DOMAIN_LIST_RUNNING (1 << VIR_DOMAIN_RUNNING)
    #define VIR_DOMAIN_LIST_BLOCKED (1 << VIR_DOMAIN_BLOCKED)
    #define VIR_DOMAIN_LIST_PAUSED (1 << VIR_DOMAIN_PAUSED)
    #define VIR_DOMAIN_LIST_SHUTDOWN (1 << VIR_DOMAIN_SHUTDOWN)
    #define VIR_DOMAIN_LIST_SHUTOFF (1 << VIR_DOMAIN_SHUTOFF)
    #define VIR_DOMAIN_LIST_CRASHED (1 << VIR_DOMAIN_CRASHED)

And some convenience combos:

    #define VIR_DOMAIN_LIST_ACTIVE (VIR_DOMAIN_LIST_NOSTATE |
                                    VIR_DOMAIN_LIST_RUNNING |
                                    VIR_DOMAIN_LIST_BLOCKED |
                                    VIR_DOMAIN_LIST_PAUSED |
                                    VIR_DOMAIN_LIST_SHUTDOWN |
                                    VIR_DOMAIN_LIST_CRASHED)
    #define VIR_DOMAIN_LIST_INACTIVE (VIR_DOMAIN_LIST_SHUTOFF)
    #define VIR_DOMAIN_LIST_ALL (~0)

The same style API can be added for listing of virNetwork and virStoragePool
objects.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]