[libvirt] [PATCHv4 0/6] API for atomic listing of guests (rest of the series)

This is a respin of patches that have not yet been commited. Peter Krempa (6): virsh: Rename namesorter to vshNameSorter and clean up indentation virsh: add support for virConnectListAllDomains and clean up cmdList vbox: Add support for virConnectListAllDomains() hyperv: Add implementation for virConnectListAllDomains() esx: Add implementation for virConnectListAllDomains() maint: include ignore-value in internal.h src/conf/domain_audit.c | 1 - src/conf/domain_conf.c | 1 - src/conf/virdomainlist.c | 1 - src/esx/esx_driver.c | 194 +++++++++++++ src/hyperv/hyperv_driver.c | 136 +++++++++ src/internal.h | 1 + src/network/bridge_driver.c | 1 - src/node_device/node_device_hal.c | 1 - src/openvz/openvz_conf.c | 1 - src/qemu/qemu_domain.c | 1 - src/qemu/qemu_monitor_json.c | 1 - src/util/command.c | 1 - src/util/event_poll.c | 1 - src/util/logging.c | 1 - src/util/memory.c | 1 - src/util/threadpool.c | 1 - src/util/virfile.h | 1 - src/util/virnetdevbandwidth.c | 1 - src/vbox/vbox_tmpl.c | 170 +++++++++++ src/xenapi/xenapi_driver.c | 1 - tests/shunloadtest.c | 1 - tools/virsh.c | 575 +++++++++++++++++++++++++------------ tools/virsh.pod | 92 +++++-- 23 files changed, 962 insertions(+), 223 deletions(-) -- 1.7.8.6

--- New in series. --- tools/virsh.c | 32 +++++++++++++++++--------------- 1 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index a117424..0912781 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -500,12 +500,14 @@ static int idsorter(const void *a, const void *b) { return -1; return 0; } -static int namesorter(const void *a, const void *b) { - const char **sa = (const char**)a; - const char **sb = (const char**)b; +static int +vshNameSorter(const void *a, const void *b) +{ + const char **sa = (const char**)a; + const char **sb = (const char**)b; - /* User visible sort, so we want locale-specific case comparison. */ - return strcasecmp(*sa, *sb); + /* User visible sort, so we want locale-specific case comparison. */ + return strcasecmp(*sa, *sb); } static double @@ -1083,7 +1085,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) goto cleanup; } - qsort(&names[0], maxname, sizeof(char*), namesorter); + qsort(&names[0], maxname, sizeof(char*), vshNameSorter); } } @@ -8672,7 +8674,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return false; } - qsort(&activeNames[0], maxactive, sizeof(char *), namesorter); + qsort(&activeNames[0], maxactive, sizeof(char *), vshNameSorter); } } if (inactive) { @@ -8694,7 +8696,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return false; } - qsort(&inactiveNames[0], maxinactive, sizeof(char*), namesorter); + qsort(&inactiveNames[0], maxinactive, sizeof(char*), vshNameSorter); } } vshPrintExtra(ctl, "%-20s %-10s %s\n", _("Name"), _("State"), @@ -8944,7 +8946,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return false; } - qsort(&activeNames[0], maxactive, sizeof(char *), namesorter); + qsort(&activeNames[0], maxactive, sizeof(char *), vshNameSorter); } } if (inactive) { @@ -8966,7 +8968,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return false; } - qsort(&inactiveNames[0], maxinactive, sizeof(char*), namesorter); + qsort(&inactiveNames[0], maxinactive, sizeof(char*), vshNameSorter); } } vshPrintExtra(ctl, "%-20s %-10s %s\n", _("Name"), _("State"), @@ -9938,7 +9940,7 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return false; } - qsort(&names[0], numfilters, sizeof(char *), namesorter); + qsort(&names[0], numfilters, sizeof(char *), vshNameSorter); vshPrintExtra(ctl, "%-36s %-20s \n", _("UUID"), _("Name")); vshPrintExtra(ctl, @@ -10728,7 +10730,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } /* Sort the storage pool names */ - qsort(poolNames, numAllPools, sizeof(*poolNames), namesorter); + qsort(poolNames, numAllPools, sizeof(*poolNames), vshNameSorter); /* Collect the storage pool information for display */ for (i = 0; i < numAllPools; i++) { @@ -12385,7 +12387,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } /* Sort the volume names */ - qsort(&activeNames[0], numVolumes, sizeof(*activeNames), namesorter); + qsort(&activeNames[0], numVolumes, sizeof(*activeNames), vshNameSorter); /* Set aside memory for volume information pointers */ volInfoTexts = vshCalloc(ctl, numVolumes, sizeof(*volInfoTexts)); @@ -13048,7 +13050,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return false; } - qsort(uuids, maxuuids, sizeof(char *), namesorter); + qsort(uuids, maxuuids, sizeof(char *), vshNameSorter); vshPrintExtra(ctl, "%-36s %s\n", _("UUID"), _("Usage")); vshPrintExtra(ctl, "-----------------------------------------------------------\n"); @@ -13331,7 +13333,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) VIR_FREE(devices); return false; } - qsort(&devices[0], num_devices, sizeof(char*), namesorter); + qsort(&devices[0], num_devices, sizeof(char*), vshNameSorter); if (tree) { char **parents = vshMalloc(ctl, sizeof(char *) * num_devices); struct vshNodeList arrays = { devices, parents }; -- 1.7.8.6

On 06/20/2012 07:33 AM, Peter Krempa wrote:
--- New in series. --- tools/virsh.c | 32 +++++++++++++++++--------------- 1 files changed, 17 insertions(+), 15 deletions(-)
ACK -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 06/21/12 04:05, Eric Blake wrote:
On 06/20/2012 07:33 AM, Peter Krempa wrote:
--- New in series. --- tools/virsh.c | 32 +++++++++++++++++--------------- 1 files changed, 17 insertions(+), 15 deletions(-)
ACK
Pushed; Thanks. Peter

This patch makes use of the newly added api virConnectListAllDomains() to list domains in virsh. Virsh now represents lists of domains using an internal structure vshDomainList. This structure contains the virDomainPtr list as provided by virConnectListAllDomains() and the count of domains in the list. For backwards compatiblity, the function vshDomainListCollect was added that tries to enumerate the domains using the new API and if the API is not supported falls back to the older approach with the two list functions. The helper function also simulates filtering by all currently supported flags added with virConnectListAllDomains(). This patch also cleans up the "list" command handler to use the new helpers and adds new command line flags to make use of filtering. --- Diff to v3: -Fixed compacting of domain list in fallback filter -removed redundant filter for active state -split out re-indentation and rename of namesorter to a separate patch -renamed functions -renamed flags -tweaked docs (typos/grammar) --- tools/virsh.c | 545 ++++++++++++++++++++++++++++++++++++++----------------- tools/virsh.pod | 92 +++++++--- 2 files changed, 445 insertions(+), 192 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 0912781..7ed38dd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -64,6 +64,7 @@ #include "util/bitmap.h" #include "conf/domain_conf.h" #include "virtypedparam.h" +#include "intprops.h" static char *progname; @@ -490,16 +491,6 @@ _vshStrdup(vshControl *ctl, const char *s, const char *filename, int line) #define realloc use_vshRealloc_instead_of_realloc #define strdup use_vshStrdup_instead_of_strdup -static int idsorter(const void *a, const void *b) { - const int *ia = (const int *)a; - const int *ib = (const int *)b; - - if (*ia > *ib) - return 1; - else if (*ia < *ib) - return -1; - return 0; -} static int vshNameSorter(const void *a, const void *b) { @@ -990,11 +981,317 @@ static const vshCmdInfo info_list[] = { {NULL, NULL} }; +/* compare domains, pack NULLed ones at the end*/ +static int +vshDomainSorter(const void *a, const void *b) +{ + virDomainPtr *da = (virDomainPtr *) a; + virDomainPtr *db = (virDomainPtr *) b; + unsigned int ida; + unsigned int idb; + unsigned int inactive = (unsigned int) -1; + + if (*da && !*db) + return -1; + + if (!*da) + return *db != NULL; + + ida = virDomainGetID(*da); + idb = virDomainGetID(*db); + + if (ida == inactive && idb == inactive) + return strcasecmp(virDomainGetName(*da), virDomainGetName(*db)); + + if (ida != inactive && idb != inactive) { + if (ida > idb) + return 1; + else if (ida < idb) + return -1; + } + + if (ida != inactive) + return -1; + else + return 1; +} + +struct vshDomainList { + virDomainPtr *domains; + size_t ndomains; +}; +typedef struct vshDomainList *vshDomainListPtr; + +static void +vshDomainListFree(vshDomainListPtr domlist) +{ + int i; + + if (!domlist || !domlist->domains) + return; + + for (i = 0; i < domlist->ndomains; i++) { + if (domlist->domains[i]) + virDomainFree(domlist->domains[i]); + } + + VIR_FREE(domlist->domains); + VIR_FREE(domlist); +} + +#define MATCH(FLAG) (flags & (FLAG)) +static vshDomainListPtr +vshDomainListCollect(vshControl *ctl, unsigned int flags) +{ + vshDomainListPtr list = vshMalloc(ctl, sizeof(*list)); + int i; + int ret; + int *ids = NULL; + int nids = 0; + char **names = NULL; + int nnames = 0; + virDomainPtr dom; + bool success = false; + size_t deleted = 0; + int persistent; + int autostart; + int state; + int nsnap; + int mansave; + + /* try the list with flags support (0.9.13 and later) */ + if ((ret = virConnectListAllDomains(ctl->conn, &list->domains, + flags)) >= 0) { + list->ndomains = ret; + goto finished; + } + + /* check if the command is actually supported */ + if (last_error && last_error->code == VIR_ERR_NO_SUPPORT) { + virFreeError(last_error); + last_error = NULL; + goto fallback; + } + + if (last_error && last_error->code == VIR_ERR_INVALID_ARG) { + /* try the new API again but mask non-guaranteed flags */ + unsigned int newflags = flags & (VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE); + + virFreeError(last_error); + last_error = NULL; + if ((ret = virConnectListAllDomains(ctl->conn, &list->domains, + newflags)) >= 0) { + list->ndomains = ret; + goto filter; + } + } + + /* there was an error during the first or second call */ + vshError(ctl, "%s", _("Failed to list domains")); + goto cleanup; + + +fallback: + /* fall back to old method (0.9.12 and older) */ + virResetLastError(); + + /* list active domains, if necessary */ + if (!MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE) || + MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE)) { + if ((nids = virConnectNumOfDomains(ctl->conn)) < 0) { + vshError(ctl, "%s", _("Failed to list active domains")); + goto cleanup; + } + + if (nids) { + ids = vshMalloc(ctl, sizeof(int) * nids); + + if ((nids = virConnectListDomains(ctl->conn, ids, nids)) < 0) { + vshError(ctl, "%s", _("Failed to list active domains")); + goto cleanup; + } + } + } + + if (!MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE) || + MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE)) { + if ((nnames = virConnectNumOfDefinedDomains(ctl->conn)) < 0) { + vshError(ctl, "%s", _("Failed to list inactive domains")); + goto cleanup; + } + + if (nnames) { + names = vshMalloc(ctl, sizeof(char *) * nnames); + + if ((nnames = virConnectListDefinedDomains(ctl->conn, names, + nnames)) < 0) { + vshError(ctl, "%s", _("Failed to list inactive domains")); + goto cleanup; + } + } + } + + list->domains = vshMalloc(ctl, sizeof(virDomainPtr) * (nids + nnames)); + list->ndomains = 0; + + /* get active domains */ + for (i = 0; i < nids; i++) { + if (!(dom = virDomainLookupByID(ctl->conn, ids[i]))) + continue; + list->domains[list->ndomains++] = dom; + } + + /* get inactive domains */ + for (i = 0; i < nnames; i++) { + if (!(dom = virDomainLookupByName(ctl->conn, names[i]))) + continue; + list->domains[list->ndomains++] = dom; + } + + /* truncate domanis that weren't found */ + deleted = (nids + nnames) - list->ndomains; + +filter: + /* filter list the list if the list was acquired by fallback means */ + for (i = 0; i < list->ndomains; i++) { + dom = list->domains[i]; + + /* persistence filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT | + VIR_CONNECT_LIST_DOMAINS_TRANSIENT)) { + if ((persistent = virDomainIsPersistent(dom)) < 0) { + vshError(ctl, "%s", _("Failed to get domain persistence info")); + goto cleanup; + } + + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT) && persistent) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) && !persistent))) + goto remove_entry; + } + + /* domain state filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING | + VIR_CONNECT_LIST_DOMAINS_PAUSED | + VIR_CONNECT_LIST_DOMAINS_SHUTOFF | + VIR_CONNECT_LIST_DOMAINS_OTHER)) { + if (virDomainGetState(dom, &state, NULL, 0) < 0) { + vshError(ctl, "%s", _("Failed to get domain state")); + goto cleanup; + } + + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) && + state == VIR_DOMAIN_RUNNING) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) && + state == VIR_DOMAIN_PAUSED) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) && + state == VIR_DOMAIN_SHUTOFF) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) && + (state != VIR_DOMAIN_RUNNING && + state != VIR_DOMAIN_PAUSED && + state != VIR_DOMAIN_SHUTOFF)))) + goto remove_entry; + } + + /* autostart filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART | + VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) { + if (virDomainGetAutostart(dom, &autostart) < 0) { + vshError(ctl, "%s", _("Failed to get domain autostart state")); + goto cleanup; + } + + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && autostart) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART) && !autostart))) + goto remove_entry; + } + + /* managed save filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE | + VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)) { + if ((mansave = virDomainHasManagedSaveImage(dom, 0)) < 0) { + vshError(ctl, "%s", + _("Failed to check for managed save image")); + goto cleanup; + } + + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) && mansave) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE) && !mansave))) + goto remove_entry; + } + + /* snapshot filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT | + VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT)) { + if ((nsnap = virDomainSnapshotNum(dom, 0)) < 0) { + vshError(ctl, "%s", _("Failed to get snapshot count")); + goto cleanup; + } + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && nsnap > 0) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && nsnap == 0))) + goto remove_entry; + } + + /* the domain matched all filters, it may stay */ + continue; + +remove_entry: + /* the domain has to be removed as it failed one of the filters */ + virDomainFree(list->domains[i]); + list->domains[i] = NULL; + deleted++; + } + +finished: + /* sort the list */ + if (list->domains && list->ndomains) + qsort(list->domains, list->ndomains, sizeof(*list->domains), + vshDomainSorter); + + /* truncate the list if filter simulation deleted entries */ + if (deleted) + VIR_SHRINK_N(list->domains, list->ndomains, deleted); + + success = true; + +cleanup: + for (i = 0; i < nnames; i++) + VIR_FREE(names[i]); + + if (!success) { + vshDomainListFree(list); + list = NULL; + } + + VIR_FREE(names); + VIR_FREE(ids); + return list; +} +#undef MATCH + + static const vshCmdOptDef opts_list[] = { {"inactive", VSH_OT_BOOL, 0, N_("list inactive domains")}, {"all", VSH_OT_BOOL, 0, N_("list inactive & active domains")}, {"transient", VSH_OT_BOOL, 0, N_("list transient domains")}, {"persistent", VSH_OT_BOOL, 0, N_("list persistent domains")}, + {"with-snapshot", VSH_OT_BOOL, 0, + N_("list domains with existing snapshot")}, + {"without-snapshot", VSH_OT_BOOL, 0, + N_("list domains without a snapshot")}, + {"state-running", VSH_OT_BOOL, 0, N_("list domains in running state")}, + {"state-paused", VSH_OT_BOOL, 0, N_("list domains in paused state")}, + {"state-shutoff", VSH_OT_BOOL, 0, N_("list domains in shutoff state")}, + {"state-other", VSH_OT_BOOL, 0, N_("list domains in other states")}, + {"autostart", VSH_OT_BOOL, 0, N_("list domains with autostart enabled")}, + {"no-autostart", VSH_OT_BOOL, 0, + N_("list domains with autostart disabled")}, + {"with-managed-save", VSH_OT_BOOL, 0, + N_("list domains with managed save state")}, + {"without-managed-save", VSH_OT_BOOL, 0, + N_("list domains without managed save")}, {"uuid", VSH_OT_BOOL, 0, N_("list uuid's only")}, {"name", VSH_OT_BOOL, 0, N_("list domain names only")}, {"table", VSH_OT_BOOL, 0, N_("list table (default)")}, @@ -1005,38 +1302,52 @@ static const vshCmdOptDef opts_list[] = { }; +#define FILTER(NAME, FLAG) \ + if (vshCommandOptBool(cmd, NAME)) \ + flags |= (FLAG) static bool cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { - bool inactive = vshCommandOptBool(cmd, "inactive"); - bool all = vshCommandOptBool(cmd, "all"); - bool active = !inactive || all; - int *ids = NULL, maxid = 0, i; - char **names = NULL; - int maxname = 0; bool managed = vshCommandOptBool(cmd, "managed-save"); bool optTitle = vshCommandOptBool(cmd, "title"); bool optTable = vshCommandOptBool(cmd, "table"); bool optUUID = vshCommandOptBool(cmd, "uuid"); bool optName = vshCommandOptBool(cmd, "name"); - bool optPersistent = vshCommandOptBool(cmd, "persistent"); - bool optTransient = vshCommandOptBool(cmd, "transient"); - bool persistUsed = true; - virDomainPtr dom = NULL; + int i; char *title; char uuid[VIR_UUID_STRING_BUFLEN]; int state; - int persistent; bool ret = false; + vshDomainListPtr list = NULL; + virDomainPtr dom; + char id_buf[INT_BUFSIZE_BOUND(unsigned int)]; + unsigned int id; + unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; - inactive |= all; + /* construct filter flags */ + if (vshCommandOptBool(cmd, "inactive")) + flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE; - /* process arguments */ - if (!optPersistent && !optTransient) { - optPersistent = true; - optTransient = true; - persistUsed = false; - } + if (vshCommandOptBool(cmd, "all")) + flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE | + VIR_CONNECT_LIST_DOMAINS_ACTIVE; + + FILTER("persistent", VIR_CONNECT_LIST_DOMAINS_PERSISTENT); + FILTER("transient", VIR_CONNECT_LIST_DOMAINS_TRANSIENT); + + FILTER("with-managed-save", VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE); + FILTER("without-managed-save", VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE); + + FILTER("autostart", VIR_CONNECT_LIST_DOMAINS_AUTOSTART); + FILTER("no-autostart", VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART); + + FILTER("with-snapshot", VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT); + FILTER("without-snapshot", VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT); + + FILTER("state-running", VIR_CONNECT_LIST_DOMAINS_RUNNING); + FILTER("state-paused", VIR_CONNECT_LIST_DOMAINS_PAUSED); + FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF); + FILTER("state-other", VIR_CONNECT_LIST_DOMAINS_OTHER); if (optTable + optName + optUUID > 1) { vshError(ctl, "%s", @@ -1051,169 +1362,69 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) if (!vshConnectionUsability(ctl, ctl->conn)) return false; - if (active) { - maxid = virConnectNumOfDomains(ctl->conn); - if (maxid < 0) { - vshError(ctl, "%s", _("Failed to list active domains")); - return false; - } - if (maxid) { - ids = vshMalloc(ctl, sizeof(int) * maxid); - - if ((maxid = virConnectListDomains(ctl->conn, ids, maxid)) < 0) { - vshError(ctl, "%s", _("Failed to list active domains")); - goto cleanup; - } - - qsort(ids, maxid, sizeof(int), idsorter); - } - } - - if (inactive) { - maxname = virConnectNumOfDefinedDomains(ctl->conn); - if (maxname < 0) { - vshError(ctl, "%s", _("Failed to list inactive domains")); - goto cleanup; - } - if (maxname) { - names = vshMalloc(ctl, sizeof(char *) * maxname); - - if ((maxname = virConnectListDefinedDomains(ctl->conn, - names, - maxname)) < 0) { - vshError(ctl, "%s", _("Failed to list inactive domains")); - goto cleanup; - } - - qsort(&names[0], maxname, sizeof(char*), vshNameSorter); - } - } + if (!(list = vshDomainListCollect(ctl, flags))) + goto cleanup; /* print table header in legacy mode */ if (optTable) { - if (optTitle) { + if (optTitle) vshPrintExtra(ctl, " %-5s %-30s %-10s %-20s\n%s\n", _("Id"), _("Name"), _("State"), _("Title"), "-----------------------------------------" "-----------------------------------------"); - } else { + else vshPrintExtra(ctl, " %-5s %-30s %s\n%s\n", _("Id"), _("Name"), _("State"), "-----------------------------------------" "-----------"); - } } - for (i = 0; i < maxid; i++) { - dom = virDomainLookupByID(ctl->conn, ids[i]); - - /* this kind of work with domains is not atomic operation */ - if (!dom) - continue; + for (i = 0; i < list->ndomains; i++) { + dom = list->domains[i]; + id = virDomainGetID(dom); + if (id != (unsigned int) -1) + snprintf(id_buf, sizeof(id_buf), "%d", id); + else + ignore_value(virStrcpyStatic(id_buf, "-")); - if (persistUsed) { - persistent = virDomainIsPersistent(dom); - if (persistent < 0) { - vshError(ctl, "%s", - _("Failed to determine domain's persistent state")); - goto cleanup; - } + state = vshDomainState(ctl, dom, NULL); + if (optTable && managed && state == VIR_DOMAIN_SHUTOFF && + virDomainHasManagedSaveImage(dom, 0) > 0) + state = -2; - if (!(persistent ? optPersistent : optTransient)) { - virDomainFree(dom); - dom = NULL; - continue; - } - } - - if (optTable) { - if (optTitle) { - if (!(title = vshGetDomainDescription(ctl, dom, true, 0))) - goto cleanup; - - vshPrint(ctl, " %-5d %-30s %-10s %-20s\n", - virDomainGetID(dom), - virDomainGetName(dom), - _(vshDomainStateToString(vshDomainState(ctl, dom, NULL))), - title); - VIR_FREE(title); - } else { - vshPrint(ctl, " %-5d %-30s %s\n", - virDomainGetID(dom), - virDomainGetName(dom), - _(vshDomainStateToString(vshDomainState(ctl, dom, NULL)))); - } - } else if (optUUID) { - if (virDomainGetUUIDString(dom, uuid) < 0) { - vshError(ctl, "%s", - _("Failed to get domain's UUID")); - goto cleanup; - } - vshPrint(ctl, "%s\n", uuid); - } else if (optName) { - vshPrint(ctl, "%s\n", virDomainGetName(dom)); - } - - virDomainFree(dom); - dom = NULL; - } - - if (optPersistent) { - for (i = 0; i < maxname; i++) { - dom = virDomainLookupByName(ctl->conn, names[i]); - - /* this kind of work with domains is not atomic operation */ - if (!dom) - continue; + if (optTable) { + if (optTitle) { + if (!(title = vshGetDomainDescription(ctl, dom, true, 0))) + goto cleanup; - if (optTable) { - state = vshDomainState(ctl, dom, NULL); - if (managed && state == VIR_DOMAIN_SHUTOFF && - virDomainHasManagedSaveImage(dom, 0) > 0) - state = -2; - - if (optTitle) { - if (!(title = vshGetDomainDescription(ctl, dom, true, 0))) - goto cleanup; - - vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", - "-", - names[i], - state == -2 ? _("saved") : _(vshDomainStateToString(state)), - title); - VIR_FREE(title); - } else { - vshPrint(ctl, " %-5s %-30s %s\n", - "-", - names[i], - state == -2 ? _("saved") : _(vshDomainStateToString(state))); - } - } else if (optUUID) { - if (virDomainGetUUIDString(dom, uuid) < 0) { - vshError(ctl, "%s", - _("Failed to get domain's UUID")); - goto cleanup; - } - vshPrint(ctl, "%s\n", uuid); - } else if (optName) { - vshPrint(ctl, "%s\n", names[i]); - } + vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf, + virDomainGetName(dom), + state == -2 ? _("saved") : _(vshDomainStateToString(state)), + title); - virDomainFree(dom); - dom = NULL; + VIR_FREE(title); + } else { + vshPrint(ctl, " %-5s %-30s %s\n", id_buf, + virDomainGetName(dom), + state == -2 ? _("saved") : _(vshDomainStateToString(state))); + } + } else if (optUUID) { + if (virDomainGetUUIDString(dom, uuid) < 0) { + vshError(ctl, "%s", _("Failed to get domain's UUID")); + goto cleanup; + } + vshPrint(ctl, "%s\n", uuid); + } else if (optName) { + vshPrint(ctl, "%s\n", virDomainGetName(dom)); } } ret = true; cleanup: - if (dom) - virDomainFree(dom); - VIR_FREE(ids); - for (i = 0; i < maxname; i++) - VIR_FREE(names[i]); - VIR_FREE(names); + vshDomainListFree(list); return ret; } +#undef FILTER /* * "desc" command for managing domain description and title diff --git a/tools/virsh.pod b/tools/virsh.pod index 839c156..f83a29d 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -306,9 +306,15 @@ The XML also show the NUMA topology information if available. Inject NMI to the guest. -=item B<list> [I<--inactive> | I<--all>] [I<--managed-save>] [I<--title>] - { [I<--table>] | I<--name> | I<--uuid> } [I<--persistent>] - [I<--transient>] +=item B<list> [I<--inactive> | I<--all>] + [I<--managed-save>] [I<--title>] + { [I<--table>] | I<--name> | I<--uuid> } + [I<--persistent>] [I<--transient>] + [I<--with-managed-save>] [I<--without-managed-save>] + [I<--autostart>] [I<--no-autostart>] + [I<--with-snapshot>] [I<--without-snapshot>] + [I<--state-running>] [I<--state-paused>] + [I<--state-shutoff>] [I<--state-other>] Prints information about existing domains. If no options are specified it prints out information about running domains. @@ -316,13 +322,10 @@ specified it prints out information about running domains. An example format for the list is as follows: B<virsh> list - Id Name State - ----------------------------------- - - 0 Domain-0 running - 2 fedora paused - + Id Name State + ---------------------------------------------------- + 0 Domain-0 running + 2 fedora paused Name is the name of the domain. ID the domain numeric id. State is the run state (see below). @@ -380,11 +383,56 @@ into s3 state. =back -If I<--managed-save> is specified, then domains that have managed save -state (only possible if they are in the B<shut off> state, so you need to -specify I<--inactive> or I<--all> to actually list them) will instead -show as B<saved> in the listing. This flag is usable only with the -default I<--table> output. +Normally only active domains are listed. To list inactive domains specify +I<--inactive> or I<--all> to list both active and inactive domains. + +To filter the list of domains present on the hypervisor you may specify one or +more of filtering flags supported by the B<list> command. These flags are +grouped by function. Specifying one or more flags from a group enables the +filter group. Supported filtering flags and groups: + +=over 4 + +=item B<Persistence> + +Flag I<--persistent> is used to include persistent domains in the returned +list. To include transient domains specify I<--transient>. + +=item B<Existence of managed save image> + +To list domains having a managed save image specify flag +I<--with-managed-save>. For domains that don't have a managed save image +specify I<--without-managed-save>. + +=item B<Domain state> + +The following filter flags select a domain by its state: +I<--state-running> for running domains, I<--state-paused> for paused domains, +I<--state-shutoff> for turned off domains and I<--state-other> for all +other states as a fallback. + +=item B<Autostarting domains> + +To list autostarting domains use the flag I<--autostart>. To list domains with +this feature disabled use I<--no-autostart>. + +=item B<Snapshot existence> + +Domains that have snapshot images can be listed using flag I<--with-snapshot>, +domains without a snapshot I<--without-snapshot>. + +=back + +When talking to older servers, this command is forced to use a series of API +calls with an inherent race, where a domain might not be listed or might appear +more than once if it changed state between calls while the list was being +collected. Newer servers do not have this problem. + +If I<--managed-save> is specified, then domains that have managed save state +(only possible if they are in the B<shut off> state, so you need to specify +I<--inactive> or I<--all> to actually list them) will instead show as B<saved> +in the listing. This flag is usable only with the default I<--table> output. +Note that this flag does not filter the list of domains. If I<--name> is specified, domain names are printed instead of the table formatted one per line. If I<--uuid> is specified domain's UUID's are printed @@ -392,12 +440,6 @@ instead of names. Flag I<--table> specifies that the legacy table-formatted output should be used. This is the default. All of these are mutually exclusive. -Flag I<--persistent> specifies that persistent domains should be printed. -Similarly I<--transient> enables output of transient domains. These flags -may be combined. Default behavior is as though both were specified. (Note that -if any of these flags is specified, the check for the persistence state is done -and may fail. If none of these flags is specified, the check is skipped.) - If I<--title> is specified, then the short domain description (title) is printed in an extra column. This flag is usable only with the default I<--table> output. @@ -405,10 +447,10 @@ I<--table> output. Example: B<virsh> list --title - Id Name State Title - ----------------------------------------------- - 0 Domain-0 running Mailserver 1 - 2 fedora paused + Id Name State Title + -------------------------------------------------------------------------- + 0 Domain-0 running Mailserver 1 + 2 fedora paused =item B<freecell> [{ [I<--cellno>] B<cellno> | I<--all> }] -- 1.7.8.6

On 06/20/2012 07:33 AM, Peter Krempa wrote:
This patch makes use of the newly added api virConnectListAllDomains() to list domains in virsh.
Virsh now represents lists of domains using an internal structure vshDomainList. This structure contains the virDomainPtr list as provided by virConnectListAllDomains() and the count of domains in the list.
For backwards compatiblity, the function vshDomainListCollect was added
s/compatiblity/compatibility/
that tries to enumerate the domains using the new API and if the API is not supported falls back to the older approach with the two list functions. The helper function also simulates filtering by all currently supported flags added with virConnectListAllDomains().
This patch also cleans up the "list" command handler to use the new helpers and adds new command line flags to make use of filtering. --- Diff to v3: -Fixed compacting of domain list in fallback filter -removed redundant filter for active state -split out re-indentation and rename of namesorter to a separate patch -renamed functions -renamed flags -tweaked docs (typos/grammar)
+static void +vshDomainListFree(vshDomainListPtr domlist) +{ + int i; + + if (!domlist || !domlist->domains) + return;
Memory leak if domlist && !domlist->domains.
+ + if (last_error && last_error->code == VIR_ERR_INVALID_ARG) { + /* try the new API again but mask non-guaranteed flags */ + unsigned int newflags = flags & (VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE);
Might be easier to use VIR_CONNECT_LIST_FILTERS_ACTIVE from virdomainlist.h.
+ /* fall back to old method (0.9.12 and older) */ + virResetLastError(); + + /* list active domains, if necessary */ + if (!MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE) ||
Again, using ...LIST_FILTERS_ACTIVE might be easier.
+ + /* truncate domanis that weren't found */
s/domanis/domains/
+ deleted = (nids + nnames) - list->ndomains; + +filter: + /* filter list the list if the list was acquired by fallback means */ + for (i = 0; i < list->ndomains; i++) { + dom = list->domains[i]; + + /* persistence filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT | + VIR_CONNECT_LIST_DOMAINS_TRANSIENT)) {
VIR_CONNECT_LIST_FILTERS_PERSISTENT (and so forth, I'll quit pointing it out)
+ /* autostart filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART | + VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) { + if (virDomainGetAutostart(dom, &autostart) < 0) { + vshError(ctl, "%s", _("Failed to get domain autostart state")); + goto cleanup; + }
Here, I think it is safe to assume that failure of virDomainGetAutostart() implies that we can treat the domain like it does not support autostart (that is, match DOMAINS_NO_AUTOSTART), instead of erroring out. But up to you; I'm also okay with the error, because in that case, you can avoid the error by not passing in the flag to virsh in the first place.
+ + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && autostart) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART) && !autostart))) + goto remove_entry; + } + + /* managed save filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE | + VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)) { + if ((mansave = virDomainHasManagedSaveImage(dom, 0)) < 0) { + vshError(ctl, "%s", + _("Failed to check for managed save image")); + goto cleanup; + }
Same story - if the API fails, you can probably safely assume there is no managed save image.
+ + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) && mansave) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE) && !mansave))) + goto remove_entry; + } + + /* snapshot filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT | + VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT)) { + if ((nsnap = virDomainSnapshotNum(dom, 0)) < 0) { + vshError(ctl, "%s", _("Failed to get snapshot count")); + goto cleanup; + }
Likewise, if the API fails, you can assume no snapshots.
+ +To filter the list of domains present on the hypervisor you may specify one or +more of filtering flags supported by the B<list> command. These flags are
s/more of/more/ ACK with typo fixes and memory leak plugged. I'm okay if you push without posting a v5, now that the fixes are down to a manageable amount. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 06/21/12 04:34, Eric Blake wrote:
On 06/20/2012 07:33 AM, Peter Krempa wrote:
This patch makes use of the newly added api virConnectListAllDomains() to list domains in virsh.
Virsh now represents lists of domains using an internal structure vshDomainList. This structure contains the virDomainPtr list as provided by virConnectListAllDomains() and the count of domains in the list.
For backwards compatiblity, the function vshDomainListCollect was added
s/compatiblity/compatibility/
that tries to enumerate the domains using the new API and if the API is not supported falls back to the older approach with the two list functions. The helper function also simulates filtering by all currently supported flags added with virConnectListAllDomains().
This patch also cleans up the "list" command handler to use the new helpers and adds new command line flags to make use of filtering. --- Diff to v3: -Fixed compacting of domain list in fallback filter -removed redundant filter for active state -split out re-indentation and rename of namesorter to a separate patch -renamed functions -renamed flags -tweaked docs (typos/grammar)
+ /* autostart filter */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART | + VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) { + if (virDomainGetAutostart(dom, &autostart) < 0) { + vshError(ctl, "%s", _("Failed to get domain autostart state")); + goto cleanup; + }
Here, I think it is safe to assume that failure of virDomainGetAutostart() implies that we can treat the domain like it does not support autostart (that is, match DOMAINS_NO_AUTOSTART), instead of erroring out. But up to you; I'm also okay with the error, because in that case, you can avoid the error by not passing in the flag to virsh in the first place.
I've decided to go with this as it's here with the option to fix this in a later patch: My idea is to print warnings/errors when the api call fails and continue with the default values. This will notify the user that something has failed, but will produce the list. Will this solution be OK?
+ + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && autostart) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART) && !autostart))) + goto remove_entry; + } +
ACK with typo fixes and memory leak plugged. I'm okay if you push without posting a v5, now that the fixes are down to a manageable amount.
I've fixed the leak, typos and changed the filter group matching to macros provided in virdomainlist.h and pushed. Thanks Peter

VirtualBox doesn't use the common virDomainObj implementation so this patch adds a separate implementation using the VirtualBox API. This driver implementation supports all currently defined flags. As VirtualBox does not support transient guests, managed save images and autostarting we assume all guests are persistent, don't have a managed save image and are not autostarted. Filtering for existence of those properities results in empty list. --- Diff to v3: -tweaked style -done some testing on useful flag combinations -Did not change two problematic places pointed out by Eric in his review: Explanation in older thread. --- src/vbox/vbox_tmpl.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 170 insertions(+), 0 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 4b0ee2e..b83d577 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -57,6 +57,7 @@ #include "virfile.h" #include "fdstream.h" #include "viruri.h" +#include "virdomainlist.h" /* This one changes from version to version. */ #if VBOX_API_VERSION == 2002 @@ -9097,6 +9098,174 @@ endjob: } #endif /* VBOX_API_VERSION >= 4000 */ + +#define MATCH(FLAG) (flags & (FLAG)) +static int +vboxListAllDomains(virConnectPtr conn, + virDomainPtr **domains, + unsigned int flags) +{ + VBOX_OBJECT_CHECK(conn, int, -1); + vboxArray machines = VBOX_ARRAY_INITIALIZER; + char *machineNameUtf8 = NULL; + PRUnichar *machineNameUtf16 = NULL; + unsigned char uuid[VIR_UUID_BUFLEN]; + vboxIID iid = VBOX_IID_INITIALIZER; + PRUint32 state; + nsresult rc; + int i; + virDomainPtr dom; + virDomainPtr *doms = NULL; + int count = 0; + bool active; + PRUint32 snapshotCount; + + virCheckFlags(VIR_CONNECT_LIST_FILTERS_ALL, -1); + + /* filter out flag options that will produce 0 results in vbox driver: + * - managed save: vbox guests don't have managed save images + * - autostart: vbox doesn't support autostarting guests + * - persistance: vbox doesn't support transient guests + */ + if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) { + if (domains && + VIR_ALLOC_N(*domains, 1) < 0) + goto no_memory; + + ret = 0; + goto cleanup; + } + + rc = vboxArrayGet(&machines, data->vboxObj, data->vboxObj->vtbl->GetMachines); + if (NS_FAILED(rc)) { + vboxError(VIR_ERR_INTERNAL_ERROR, + _("Could not get list of domains, rc=%08x"), (unsigned)rc); + goto cleanup; + } + + if (domains && + VIR_ALLOC_N(doms, machines.count + 1) < 0) + goto no_memory; + + for (i = 0; i < machines.count; i++) { + IMachine *machine = machines.items[i]; + + if (machine) { + PRBool isAccessible = PR_FALSE; + machine->vtbl->GetAccessible(machine, &isAccessible); + if (isAccessible) { + machine->vtbl->GetState(machine, &state); + + if (state >= MachineState_FirstOnline && + state <= MachineState_LastOnline) + active = true; + else + active = false; + + /* filter by active state */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_ACTIVE) && + !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) && active) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) && !active))) + continue; + + /* filter by snapshot existence */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_SNAPSHOT)) { + rc = machine->vtbl->GetSnapshotCount(machine, &snapshotCount); + if (NS_FAILED(rc)) { + vboxError(VIR_ERR_INTERNAL_ERROR, + _("could not get snapshot count for listed domains")); + goto cleanup; + } + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && + snapshotCount > 0) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && + snapshotCount == 0))) + continue; + } + + /* filter by machine state */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_STATE) && + !((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) && + state == MachineState_Running) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) && + state == MachineState_Paused) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) && + state == MachineState_PoweredOff) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) && + (state != MachineState_Running && + state != MachineState_Paused && + state != MachineState_PoweredOff)))) + continue; + + /* just count the machines */ + if (!doms) { + count++; + continue; + } + + machine->vtbl->GetName(machine, &machineNameUtf16); + VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineNameUtf8); + machine->vtbl->GetId(machine, &iid.value); + vboxIIDToUUID(&iid, uuid); + vboxIIDUnalloc(&iid); + + dom = virGetDomain(conn, machineNameUtf8, uuid); + + if (machineNameUtf8) { + VBOX_UTF8_FREE(machineNameUtf8); + machineNameUtf8 = NULL; + } + + if (machineNameUtf16) { + VBOX_COM_UNALLOC_MEM(machineNameUtf16); + machineNameUtf16 = NULL; + } + + if (!dom) + goto no_memory; + + if (active) + dom->id = i + 1; + + doms[count++] = dom; + } + } + } + + if (doms) { + /* safe to ignore, new size will be equal or less than + * previous allocation*/ + ignore_value(VIR_REALLOC_N(doms, count + 1)); + *domains = doms; + } + doms = NULL; + ret = count; + +cleanup: + if (doms) { + for (i = 0; i < count; i++) { + if (doms[i]) + virDomainFree(doms[i]); + } + } + VIR_FREE(doms); + + vboxArrayRelease(&machines); + return ret; + +no_memory: + virReportOOMError(); + goto cleanup; +} +#undef MATCH + + + /** * Function Tables */ @@ -9113,6 +9282,7 @@ virDriver NAME(Driver) = { .getCapabilities = vboxGetCapabilities, /* 0.6.3 */ .listDomains = vboxListDomains, /* 0.6.3 */ .numOfDomains = vboxNumOfDomains, /* 0.6.3 */ + .listAllDomains = vboxListAllDomains, /* 0.9.13 */ .domainCreateXML = vboxDomainCreateXML, /* 0.6.3 */ .domainLookupByID = vboxDomainLookupByID, /* 0.6.3 */ .domainLookupByUUID = vboxDomainLookupByUUID, /* 0.6.3 */ -- 1.7.8.6

On 20.06.2012 15:33, Peter Krempa wrote:
VirtualBox doesn't use the common virDomainObj implementation so this patch adds a separate implementation using the VirtualBox API.
This driver implementation supports all currently defined flags. As VirtualBox does not support transient guests, managed save images and autostarting we assume all guests are persistent, don't have a managed save image and are not autostarted. Filtering for existence of those properities results in empty list. --- Diff to v3: -tweaked style -done some testing on useful flag combinations -Did not change two problematic places pointed out by Eric in his review: Explanation in older thread. --- src/vbox/vbox_tmpl.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 170 insertions(+), 0 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 4b0ee2e..b83d577 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -57,6 +57,7 @@ #include "virfile.h" #include "fdstream.h" #include "viruri.h" +#include "virdomainlist.h"
/* This one changes from version to version. */ #if VBOX_API_VERSION == 2002 @@ -9097,6 +9098,174 @@ endjob: } #endif /* VBOX_API_VERSION >= 4000 */
+ +#define MATCH(FLAG) (flags & (FLAG)) +static int +vboxListAllDomains(virConnectPtr conn, + virDomainPtr **domains, + unsigned int flags) +{ + VBOX_OBJECT_CHECK(conn, int, -1); + vboxArray machines = VBOX_ARRAY_INITIALIZER; + char *machineNameUtf8 = NULL; + PRUnichar *machineNameUtf16 = NULL; + unsigned char uuid[VIR_UUID_BUFLEN]; + vboxIID iid = VBOX_IID_INITIALIZER; + PRUint32 state; + nsresult rc; + int i; + virDomainPtr dom; + virDomainPtr *doms = NULL; + int count = 0; + bool active; + PRUint32 snapshotCount; + + virCheckFlags(VIR_CONNECT_LIST_FILTERS_ALL, -1); + + /* filter out flag options that will produce 0 results in vbox driver: + * - managed save: vbox guests don't have managed save images + * - autostart: vbox doesn't support autostarting guests + * - persistance: vbox doesn't support transient guests + */ + if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) { + if (domains && + VIR_ALLOC_N(*domains, 1) < 0) + goto no_memory; + + ret = 0; + goto cleanup; + } + + rc = vboxArrayGet(&machines, data->vboxObj, data->vboxObj->vtbl->GetMachines); + if (NS_FAILED(rc)) { + vboxError(VIR_ERR_INTERNAL_ERROR, + _("Could not get list of domains, rc=%08x"), (unsigned)rc); + goto cleanup; + } + + if (domains && + VIR_ALLOC_N(doms, machines.count + 1) < 0) + goto no_memory; + + for (i = 0; i < machines.count; i++) { + IMachine *machine = machines.items[i]; + + if (machine) { + PRBool isAccessible = PR_FALSE; + machine->vtbl->GetAccessible(machine, &isAccessible); + if (isAccessible) { + machine->vtbl->GetState(machine, &state); + + if (state >= MachineState_FirstOnline && + state <= MachineState_LastOnline) + active = true; + else + active = false; + + /* filter by active state */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_ACTIVE) && + !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) && active) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) && !active))) + continue; + + /* filter by snapshot existence */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_SNAPSHOT)) { + rc = machine->vtbl->GetSnapshotCount(machine, &snapshotCount); + if (NS_FAILED(rc)) { + vboxError(VIR_ERR_INTERNAL_ERROR, + _("could not get snapshot count for listed domains")); + goto cleanup; + } + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && + snapshotCount > 0) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && + snapshotCount == 0))) + continue; + } + + /* filter by machine state */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_STATE) && + !((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) && + state == MachineState_Running) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) && + state == MachineState_Paused) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) && + state == MachineState_PoweredOff) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) && + (state != MachineState_Running && + state != MachineState_Paused && + state != MachineState_PoweredOff)))) + continue; + + /* just count the machines */ + if (!doms) { + count++; + continue; + } + + machine->vtbl->GetName(machine, &machineNameUtf16); + VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineNameUtf8); + machine->vtbl->GetId(machine, &iid.value); + vboxIIDToUUID(&iid, uuid); + vboxIIDUnalloc(&iid); + + dom = virGetDomain(conn, machineNameUtf8, uuid); + + if (machineNameUtf8) { + VBOX_UTF8_FREE(machineNameUtf8); + machineNameUtf8 = NULL; + } + + if (machineNameUtf16) { + VBOX_COM_UNALLOC_MEM(machineNameUtf16); + machineNameUtf16 = NULL; + }
These two checks for !NULL are useless.
+ + if (!dom) + goto no_memory; + + if (active) + dom->id = i + 1; + + doms[count++] = dom; + } + } + } + + if (doms) { + /* safe to ignore, new size will be equal or less than + * previous allocation*/ + ignore_value(VIR_REALLOC_N(doms, count + 1)); + *domains = doms; + } + doms = NULL;
This assignment can be moved into the body of if statement. But that's just small optimization.
+ ret = count; + +cleanup: + if (doms) { + for (i = 0; i < count; i++) { + if (doms[i]) + virDomainFree(doms[i]); + } + } + VIR_FREE(doms); + + vboxArrayRelease(&machines); + return ret; + +no_memory: + virReportOOMError(); + goto cleanup; +} +#undef MATCH + + + /** * Function Tables */ @@ -9113,6 +9282,7 @@ virDriver NAME(Driver) = { .getCapabilities = vboxGetCapabilities, /* 0.6.3 */ .listDomains = vboxListDomains, /* 0.6.3 */ .numOfDomains = vboxNumOfDomains, /* 0.6.3 */ + .listAllDomains = vboxListAllDomains, /* 0.9.13 */ .domainCreateXML = vboxDomainCreateXML, /* 0.6.3 */ .domainLookupByID = vboxDomainLookupByID, /* 0.6.3 */ .domainLookupByUUID = vboxDomainLookupByUUID, /* 0.6.3 */
ACK with those nits fixed. Michal

On 06/28/12 14:58, Michal Privoznik wrote:
On 20.06.2012 15:33, Peter Krempa wrote:
VirtualBox doesn't use the common virDomainObj implementation so this patch adds a separate implementation using the VirtualBox API.
This driver implementation supports all currently defined flags. As VirtualBox does not support transient guests, managed save images and autostarting we assume all guests are persistent, don't have a managed save image and are not autostarted. Filtering for existence of those properities results in empty list. ---
...
+ + machine->vtbl->GetName(machine, &machineNameUtf16); + VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineNameUtf8); + machine->vtbl->GetId(machine, &iid.value); + vboxIIDToUUID(&iid, uuid); + vboxIIDUnalloc(&iid); + + dom = virGetDomain(conn, machineNameUtf8, uuid); + + if (machineNameUtf8) { + VBOX_UTF8_FREE(machineNameUtf8); + machineNameUtf8 = NULL; + } + + if (machineNameUtf16) { + VBOX_COM_UNALLOC_MEM(machineNameUtf16); + machineNameUtf16 = NULL; + }
These two checks for !NULL are useless.
Indeed. I verified that in the Vbox XPCOM code.
+ + if (!dom) + goto no_memory; + + if (active)
...
+ ignore_value(VIR_REALLOC_N(doms, count + 1)); + *domains = doms; + } + doms = NULL;
This assignment can be moved into the body of if statement. But that's just small optimization.
+ ret = count; + +cleanup: + if (doms) { + for (i = 0; i < count; i++) { + if (doms[i])
ACK with those nits fixed.
Michal
I've fix them and pushed. Thanks for the reveiw. Peter

Hyperv doesn't use the common virDomainObj implementation so this patch adds a separate implementation. This driver supports all currently added flags for filtering although some of those don't make sense with this driver (no support yet) and thus produce no output when used. --- No change. Still not even compile tested. So if anybody has a working setup, please review. --- src/hyperv/hyperv_driver.c | 136 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 136 insertions(+), 0 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 3b15292..7a4937d 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -42,6 +42,7 @@ #include "hyperv_util.h" #include "hyperv_wmi.h" #include "openwsman.h" +#include "virdomainlist.h" #define VIR_FROM_THIS VIR_FROM_HYPERV @@ -1259,6 +1260,140 @@ hypervDomainManagedSaveRemove(virDomainPtr domain, unsigned int flags) } +#define MATCH(FLAG) (flags & (FLAG)) +static int +hypervListAllDomains(virConnectPtr conn, + virDomainPtr **domains, + unsigned int flags) +{ + hypervPrivate *priv = conn->privateData; + virBuffer query = VIR_BUFFER_INITIALIZER; + Msvm_ComputerSystem *computerSystemList = NULL; + Msvm_ComputerSystem *computerSystem = NULL; + size_t ndoms; + virDomainPtr domain; + virDomainPtr *doms = NULL; + int count = 0; + int ret = -1; + int i; + + virCheckFlags(VIR_CONNECT_LIST_FILTERS_ALL, -1); + + /* check for filter combinations that return no results: + * persistent: all hyperv guests are persistent + * snapshot: the driver does not support snapshot management + * autostart: the driver does not support autostarting guests + */ + if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT))) { + if (domains && + VIR_ALLOC_N(*domains, 1) < 0) + goto no_memory; + + ret = 0; + goto cleanup; + } + + virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT); + virBufferAddLit(&query, "where "); + virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL); + + /* construct query with filter depending on flags */ + if (!(flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE && + flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE)) { + if (flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE) { + virBufferAddLit(&query, "and "); + virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_ACTIVE); + } + if (flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE) { + virBufferAddLit(&query, "and "); + virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_INACTIVE); + } + } + + if (hypervGetMsvmComputerSystemList(priv, &query, + &computerSystemList) < 0) + goto cleanup; + + if (domains) { + if (VIR_ALLOC_N(doms, 1) < 0) + goto no_memory; + ndoms = 1; + } + + for (computerSystem = computerSystemList; computerSystem != NULL; + computerSystem = computerSystem->next) { + + /* filter by domain state */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_STATE)) { + int st = hypervMsvmComputerSystemEnabledStateToDomainState(computerSystem); + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) && + st == VIR_DOMAIN_RUNNING) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) && + st == VIR_DOMAIN_PAUSED) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) && + st == VIR_DOMAIN_SHUTOFF) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) && + (st != VIR_DOMAIN_RUNNING && + st != VIR_DOMAIN_PAUSED && + st != VIR_DOMAIN_SHUTOFF)))) + continue; + } + + /* managed save filter */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_MANAGEDSAVE)) { + bool mansave = computerSystem->data->EnabledState == + MSVM_COMPUTERSYSTEM_ENABLEDSTATE_SUSPENDED; + + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) && mansave) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE) && !mansave))) + continue; + } + + if (!doms) { + count++; + continue; + } + + if (VIR_RESIZE_N(doms, ndoms, count, 2) < 0) + goto no_memory; + + if (hypervMsvmComputerSystemToDomain(conn, computerSystem, + &domain) < 0) + goto cleanup; + + doms[count++] = domain; + } + + if (doms) + *domains = doms; + doms = NULL; + ret = count; + +cleanup: + if (doms) { + for (i = 0; i < count; ++i) { + if (doms[i]) + virDomainFree(doms[i]); + } + } + + VIR_FREE(doms); + hypervFreeObject(priv, (hypervObject *)computerSystemList); + return ret; + +no_memory: + virReportOOMError(); + goto cleanup; +} +#undef MATCH + + + static virDriver hypervDriver = { .no = VIR_DRV_HYPERV, @@ -1270,6 +1405,7 @@ static virDriver hypervDriver = { .nodeGetInfo = hypervNodeGetInfo, /* 0.9.5 */ .listDomains = hypervListDomains, /* 0.9.5 */ .numOfDomains = hypervNumberOfDomains, /* 0.9.5 */ + .listAllDomains = hypervListAllDomains, /* 0.9.13 */ .domainLookupByID = hypervDomainLookupByID, /* 0.9.5 */ .domainLookupByUUID = hypervDomainLookupByUUID, /* 0.9.5 */ .domainLookupByName = hypervDomainLookupByName, /* 0.9.5 */ -- 1.7.8.6

Esx doesn't use the common virDomainObj implementation so this patch adds a separate implementation. This driver supports all currently defined filtering flags, but as with other drivers some combinations yield a empty result list. --- No change. Anyone with working setup, please review. --- src/esx/esx_driver.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 194 insertions(+), 0 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index b3f1948..09f09cc 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -45,6 +45,7 @@ #include "esx_vi_methods.h" #include "esx_util.h" #include "viruri.h" +#include "virdomainlist.h" #define VIR_FROM_THIS VIR_FROM_ESX @@ -4947,6 +4948,198 @@ esxDomainGetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params, return result; } +#define MATCH(FLAG) (flags & (FLAG)) +static int +esxListAllDomains(virConnectPtr conn, + virDomainPtr **domains, + unsigned int flags) +{ + int ret = -1; + esxPrivate *priv = conn->privateData; + virDomainPtr dom; + virDomainPtr *doms = NULL; + size_t ndoms = 0; + esxVI_ObjectContent *virtualMachineList = NULL; + esxVI_ObjectContent *virtualMachine = NULL; + esxVI_String *propertyNameList = NULL; + esxVI_AutoStartDefaults *autostart_defaults = NULL; + esxVI_VirtualMachinePowerState powerState; + esxVI_AutoStartPowerInfo *powerInfoList = NULL; + esxVI_AutoStartPowerInfo *powerInfo = NULL; + esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; + char *name = NULL; + int id; + unsigned char uuid[VIR_UUID_BUFLEN]; + int count = 0; + int snapshotCount; + bool autostart; + int state; + + virCheckFlags(VIR_CONNECT_LIST_FILTERS_ALL, -1); + + /* check for flags that would produce empty output lists: + * - persistence: all esx machines are persistent + * - managed save: esx doesn't support managed save + */ + if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) && + !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) { + if (domains && + VIR_ALLOC_N(*domains, 1) < 0) + goto no_memory; + + ret = 0; + goto cleanup; + } + + if (esxVI_EnsureSession(priv->primary) < 0) + return -1; + + /* check system default autostart value */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_AUTOSTART)) { + if (esxVI_LookupAutoStartDefaults(priv->primary, + &autostart_defaults) < 0) + goto cleanup; + + if (esxVI_LookupAutoStartPowerInfoList(priv->primary, + &powerInfoList) < 0) + goto cleanup; + } + + if (esxVI_String_AppendValueToList(&propertyNameList, + "runtime.powerState") < 0 || + esxVI_LookupVirtualMachineList(priv->primary, propertyNameList, + &virtualMachineList) < 0) + goto cleanup; + + if (domains) { + if (VIR_ALLOC_N(doms, 1) < 0) + goto no_memory; + ndoms = 1; + } + + for (virtualMachine = virtualMachineList; virtualMachine != NULL; + virtualMachine = virtualMachine->_next) { + + VIR_FREE(name); + + if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, uuid) < 0 || + esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) + goto cleanup; + + /* filter by active state */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_ACTIVE) && + !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) && + powerState != esxVI_VirtualMachinePowerState_PoweredOff) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) && + powerState == esxVI_VirtualMachinePowerState_PoweredOff))) + continue; + + /* filter by snapshot existence */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_SNAPSHOT)) { + if (esxVI_LookupRootSnapshotTreeList(priv->primary, uuid, + &rootSnapshotTreeList) < 0) { + ESX_ERROR(VIR_ERR_INTERNAL_ERROR, + _("Could not retrieve snapshot list for domain")); + goto cleanup; + } + + snapshotCount = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList, + true, false); + + esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); + + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && + snapshotCount > 0) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && + snapshotCount == 0))) + continue; + } + + /* filter by autostart */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_AUTOSTART)) { + autostart = false; + + for (powerInfo = powerInfoList; powerInfo != NULL; + powerInfo = powerInfo->_next) { + if (STREQ(powerInfo->key->value, virtualMachine->obj->value)) { + if (STRCASEEQ(powerInfo->startAction, "powerOn")) + autostart = true; + + break; + } + } + + autostart = autostart && + autostart_defaults->enabled == esxVI_Boolean_True; + + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && + autostart) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART) && + !autostart))) + goto cleanup; + } + + /* filter by domain state */ + if (MATCH(VIR_CONNECT_LIST_FILTERS_STATE)) { + state = esxVI_VirtualMachinePowerState_ConvertToLibvirt(powerState); + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) && + state == VIR_DOMAIN_RUNNING) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) && + state == VIR_DOMAIN_PAUSED) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) && + state == VIR_DOMAIN_SHUTOFF) || + (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) && + (state != VIR_DOMAIN_RUNNING && + state != VIR_DOMAIN_PAUSED && + state != VIR_DOMAIN_SHUTOFF)))) + goto cleanup; + } + + /* just count the machines */ + if (!doms) { + count++; + continue; + } + + if (!(dom = virGetDomain(conn, name, uuid))) + goto no_memory; + + /* Only running/suspended virtual machines have an ID != -1 */ + if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) + dom->id = id; + else + dom->id = -1; + + if (VIR_EXPAND_N(doms, ndoms, 1) < 0) + goto no_memory; + doms[count++] = dom; + } + + if (doms) + *domains = doms; + doms = NULL; + ret = count; + +cleanup: + if (doms) { + for (id = 0; id < count; id++) { + if (doms[id]) + virDomainFree(doms[id]); + } + } + VIR_FREE(doms); + VIR_FREE(name); + esxVI_String_Free(&propertyNameList); + esxVI_ObjectContent_Free(&virtualMachineList); + return ret; + +no_memory: + virReportOOMError(); + goto cleanup; +} +#undef MATCH static virDriver esxDriver = { @@ -4962,6 +5155,7 @@ static virDriver esxDriver = { .getCapabilities = esxGetCapabilities, /* 0.7.1 */ .listDomains = esxListDomains, /* 0.7.0 */ .numOfDomains = esxNumberOfDomains, /* 0.7.0 */ + .listAllDomains = esxListAllDomains, /* 0.9.13 */ .domainLookupByID = esxDomainLookupByID, /* 0.7.0 */ .domainLookupByUUID = esxDomainLookupByUUID, /* 0.7.0 */ .domainLookupByName = esxDomainLookupByName, /* 0.7.0 */ -- 1.7.8.6

The ignore_value macro is used across libvirt. This patch includes it in the internal header and cleans all other includes. --- No change, just bumping if anybody has objections. --- src/conf/domain_audit.c | 1 - src/conf/domain_conf.c | 1 - src/conf/virdomainlist.c | 1 - src/internal.h | 1 + src/network/bridge_driver.c | 1 - src/node_device/node_device_hal.c | 1 - src/openvz/openvz_conf.c | 1 - src/qemu/qemu_domain.c | 1 - src/qemu/qemu_monitor_json.c | 1 - src/util/command.c | 1 - src/util/event_poll.c | 1 - src/util/logging.c | 1 - src/util/memory.c | 1 - src/util/threadpool.c | 1 - src/util/virfile.h | 1 - src/util/virnetdevbandwidth.c | 1 - src/xenapi/xenapi_driver.c | 1 - tests/shunloadtest.c | 1 - 18 files changed, 1 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index 653657b..e3f3681 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -31,7 +31,6 @@ #include "uuid.h" #include "logging.h" #include "memory.h" -#include "ignore-value.h" /* Return nn:mm in hex for block and character devices, and NULL * for other file types, stat failure, or allocation failure. */ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 81c6308..e2d2b2d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -44,7 +44,6 @@ #include "c-ctype.h" #include "logging.h" #include "nwfilter_conf.h" -#include "ignore-value.h" #include "storage_file.h" #include "virfile.h" #include "bitmap.h" diff --git a/src/conf/virdomainlist.c b/src/conf/virdomainlist.c index 6ac2af1..f9fbde8 100644 --- a/src/conf/virdomainlist.c +++ b/src/conf/virdomainlist.c @@ -30,7 +30,6 @@ #include "memory.h" #include "datatypes.h" #include "virterror_internal.h" -#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN diff --git a/src/internal.h b/src/internal.h index 60be95d..fd8d190 100644 --- a/src/internal.h +++ b/src/internal.h @@ -45,6 +45,7 @@ # include "libvirt_internal.h" # include "c-strcase.h" +# include "ignore-value.h" /* On architectures which lack these limits, define them (ie. Cygwin). * Note that the libvirt code should be robust enough to handle the diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 79d3010..7e8de19 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -58,7 +58,6 @@ #include "logging.h" #include "dnsmasq.h" #include "configmake.h" -#include "ignore-value.h" #include "virnetdev.h" #include "virnetdevbridge.h" #include "virnetdevtap.h" diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index b2e502e..7f8b076 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -38,7 +38,6 @@ #include "pci.h" #include "logging.h" #include "node_device_driver.h" -#include "ignore-value.h" #include "virdbus.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 0c5ab74..bb61b13 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -53,7 +53,6 @@ #include "nodeinfo.h" #include "virfile.h" #include "command.h" -#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_OPENVZ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 91c0645..201ec03 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -32,7 +32,6 @@ #include "virterror_internal.h" #include "c-ctype.h" #include "cpu/cpu.h" -#include "ignore-value.h" #include "uuid.h" #include "virfile.h" #include "domain_event.h" diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 7d2da21..964ec38 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -41,7 +41,6 @@ #include "datatypes.h" #include "virterror_internal.h" #include "json.h" -#include "ignore-value.h" #ifdef WITH_DTRACE_PROBES # include "libvirt_qemu_probes.h" diff --git a/src/util/command.c b/src/util/command.c index 62848cd..5838d45 100644 --- a/src/util/command.c +++ b/src/util/command.c @@ -41,7 +41,6 @@ #include "virfile.h" #include "virpidfile.h" #include "buf.h" -#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/event_poll.c b/src/util/event_poll.c index 038e75f..3841673 100644 --- a/src/util/event_poll.c +++ b/src/util/event_poll.c @@ -37,7 +37,6 @@ #include "memory.h" #include "util.h" #include "virfile.h" -#include "ignore-value.h" #include "virterror_internal.h" #include "virtime.h" diff --git a/src/util/logging.c b/src/util/logging.c index cf62184..f8233cd 100644 --- a/src/util/logging.c +++ b/src/util/logging.c @@ -38,7 +38,6 @@ # include <execinfo.h> #endif -#include "ignore-value.h" #include "virterror_internal.h" #include "logging.h" #include "memory.h" diff --git a/src/util/memory.c b/src/util/memory.c index bfa32a8..90ca29a 100644 --- a/src/util/memory.c +++ b/src/util/memory.c @@ -24,7 +24,6 @@ #include <stdlib.h> #include "memory.h" -#include "ignore-value.h" #if TEST_OOM diff --git a/src/util/threadpool.c b/src/util/threadpool.c index e8689d9..305a22f 100644 --- a/src/util/threadpool.c +++ b/src/util/threadpool.c @@ -29,7 +29,6 @@ #include "memory.h" #include "threads.h" #include "virterror_internal.h" -#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virfile.h b/src/util/virfile.h index 6882a73..fb8109b 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -29,7 +29,6 @@ # include <stdio.h> # include "internal.h" -# include "ignore-value.h" typedef enum virFileCloseFlags { VIR_FILE_CLOSE_PRESERVE_ERRNO = 1 << 0, diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index b9bd2e3..596ffd6 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -26,7 +26,6 @@ #include "command.h" #include "memory.h" #include "virterror_internal.h" -#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 0ad6aff..298ab21 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -40,7 +40,6 @@ #include "xenapi_driver.h" #include "xenapi_driver_private.h" #include "xenapi_utils.h" -#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_XENAPI diff --git a/tests/shunloadtest.c b/tests/shunloadtest.c index 8113ef3..45ef0a1 100644 --- a/tests/shunloadtest.c +++ b/tests/shunloadtest.c @@ -50,7 +50,6 @@ # include <signal.h> # include "internal.h" -# include "ignore-value.h" # include "testutils.h" pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -- 1.7.8.6

On 06/20/12 15:33, Peter Krempa wrote:
The ignore_value macro is used across libvirt. This patch includes it in the internal header and cleans all other includes. --- No change, just bumping if anybody has objections. ---
Nobody objected by now, so following Eric's conditional ACK I went ahead and pushed this patch. Thanks. Peter
participants (3)
-
Eric Blake
-
Michal Privoznik
-
Peter Krempa