This patch adds support for listing all domains into drivers that use
the common virDomainObj implementation: libxl, lxc, openvz, qemu, test,
uml, vmware.
The qemu driver has extra support for filtering by managed save image
existence.
---
New in series. I couldn't test libxl, openvz, uml and vmware, but they share the
implementation, so they should work.
---
src/libxl/libxl_driver.c | 33 +++++++++++++++++
src/lxc/lxc_driver.c | 32 ++++++++++++++++
src/openvz/openvz_driver.c | 30 +++++++++++++++
src/qemu/qemu_driver.c | 87 ++++++++++++++++++++++++++++++++++++++++----
src/test/test_driver.c | 31 ++++++++++++++++
src/uml/uml_driver.c | 31 ++++++++++++++++
src/vmware/vmware_driver.c | 31 ++++++++++++++++
7 files changed, 268 insertions(+), 7 deletions(-)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 500d51b..00410f9 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -45,6 +45,7 @@
#include "xen_xm.h"
#include "virtypedparam.h"
#include "viruri.h"
+#include "virdomainlist.h"
#define VIR_FROM_THIS VIR_FROM_LIBXL
@@ -3831,6 +3832,37 @@ libxlIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
return 1;
}
+static int
+libxlListAllDomains(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags)
+{
+ libxlDriverPrivatePtr driver = conn->privateData;
+ int ret = -1;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, -1);
+
+ libxlDriverLock(driver);
+
+ ret = virDomainList(conn, driver->domains.objs, domains, flags);
+
+ libxlDriverUnlock(driver);
+
+ return ret;
+}
+
+
static virDriver libxlDriver = {
.no = VIR_DRV_LIBXL,
@@ -3907,6 +3939,7 @@ static virDriver libxlDriver = {
.domainEventRegisterAny = libxlDomainEventRegisterAny, /* 0.9.0 */
.domainEventDeregisterAny = libxlDomainEventDeregisterAny, /* 0.9.0 */
.isAlive = libxlIsAlive, /* 0.9.8 */
+ .listAllDomains = libxlListAllDomains, /* 0.9.13 */
};
static virStateDriver libxlStateDriver = {
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 919f4ab..099e9bc 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -61,6 +61,7 @@
#include "virtime.h"
#include "virtypedparam.h"
#include "viruri.h"
+#include "virdomainlist.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -3821,6 +3822,36 @@ cleanup:
}
static int
+lxcListAllDomains(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags)
+{
+ lxc_driver_t *driver = conn->privateData;
+ int ret = -1;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, -1);
+
+ lxcDriverLock(driver);
+
+ ret = virDomainList(conn, driver->domains.objs, domains, flags);
+
+ lxcDriverUnlock(driver);
+
+ return ret;
+}
+
+static int
lxcVMFilterRebuild(virConnectPtr conn ATTRIBUTE_UNUSED,
virHashIterator iter, void *data)
{
@@ -3912,6 +3943,7 @@ static virDriver lxcDriver = {
.domainOpenConsole = lxcDomainOpenConsole, /* 0.8.6 */
.isAlive = lxcIsAlive, /* 0.9.8 */
.nodeSuspendForDuration = nodeSuspendForDuration, /* 0.9.8 */
+ .listAllDomains = lxcListAllDomains, /* 0.9.13 */
};
static virStateDriver lxcStateDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index fb72cde..12baf90 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -60,6 +60,7 @@
#include "command.h"
#include "viruri.h"
#include "stats_linux.h"
+#include "virdomainlist.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
@@ -1945,6 +1946,34 @@ cleanup:
return ret;
}
+static int
+openvzListAllDomains(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags)
+{
+ struct openvz_driver *driver = conn->privateData;
+ int ret = -1;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, -1);
+
+ openvzDriverLock(driver);
+ ret = virDomainList(conn, driver->domains.objs, domains, flags);
+ openvzDriverUnlock(driver);
+
+ return ret;
+}
+
static virDriver openvzDriver = {
.no = VIR_DRV_OPENVZ,
@@ -2000,6 +2029,7 @@ static virDriver openvzDriver = {
.domainIsPersistent = openvzDomainIsPersistent, /* 0.7.3 */
.domainIsUpdated = openvzDomainIsUpdated, /* 0.8.6 */
.isAlive = openvzIsAlive, /* 0.9.8 */
+ .listAllDomains = openvzListAllDomains, /* 0.9.13 */
};
int openvzRegister(void) {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d3f74d2..dae76ee 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -92,6 +92,7 @@
#include "virnodesuspend.h"
#include "virtime.h"
#include "virtypedparam.h"
+#include "virdomainlist.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -2919,12 +2920,29 @@ cleanup:
}
static int
+qemuDomainObjHasManagedSaveImage(struct qemud_driver *driver,
+ virDomainObjPtr vm)
+{
+ char *name;
+ int ret;
+
+ name = qemuDomainManagedSavePath(driver, vm);
+ if (name == NULL)
+ return -1;
+
+ ret = virFileExists(name);
+
+ VIR_FREE(name);
+
+ return ret;
+}
+
+static int
qemuDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm = NULL;
int ret = -1;
- char *name = NULL;
virCheckFlags(0, -1);
@@ -2938,14 +2956,9 @@ qemuDomainHasManagedSaveImage(virDomainPtr dom, unsigned int
flags)
goto cleanup;
}
- name = qemuDomainManagedSavePath(driver, vm);
- if (name == NULL)
- goto cleanup;
-
- ret = virFileExists(name);
+ ret = qemuDomainObjHasManagedSaveImage(driver, vm);
cleanup:
- VIR_FREE(name);
if (vm)
virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
@@ -12946,6 +12959,65 @@ cleanup:
return ret;
}
+static int
+qemuListAllDomainsManagedSaveFilter(virDomainPtr domain)
+{
+ struct qemud_driver *driver = domain->conn->privateData;
+ int ret;
+
+ /* driver is already locked */
+ virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, domain->uuid);
+
+ ret = qemuDomainObjHasManagedSaveImage(driver, vm);
+ virDomainObjUnlock(vm);
+ return ret;
+}
+
+static int
+qemuListAllDomains(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags)
+{
+ struct qemud_driver *driver = conn->privateData;
+ int ret = -1;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE |
+ VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE |
+ VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, -1);
+
+ qemuDriverLock(driver);
+
+ if ((ret = virDomainList(conn, driver->domains.objs, domains, flags)) < 0)
+ goto cleanup;
+
+ /* driver specific filters */
+ /* filter by managed save image */
+ if (!(flags & VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE &&
+ flags & VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)) {
+ if (flags & VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE)
+ virDomainListFilter(domains, &ret,
+ qemuListAllDomainsManagedSaveFilter, 0);
+ if (flags & VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)
+ virDomainListFilter(domains, &ret,
+ qemuListAllDomainsManagedSaveFilter, 1);
+ }
+
+cleanup:
+ qemuDriverUnlock(driver);
+ return ret;
+}
+
static virDriver qemuDriver = {
.no = VIR_DRV_QEMU,
.name = QEMU_DRIVER_NAME,
@@ -13106,6 +13178,7 @@ static virDriver qemuDriver = {
.domainPMSuspendForDuration = qemuDomainPMSuspendForDuration, /* 0.9.11 */
.domainPMWakeup = qemuDomainPMWakeup, /* 0.9.11 */
.domainGetCPUStats = qemuDomainGetCPUStats, /* 0.9.11 */
+ .listAllDomains = qemuListAllDomains, /* 0.9.13 */
};
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 7038741..6ab1067 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -52,6 +52,7 @@
#include "virfile.h"
#include "virtypedparam.h"
#include "virrandom.h"
+#include "virdomainlist.h"
#define VIR_FROM_THIS VIR_FROM_TEST
@@ -5517,6 +5518,35 @@ static int testNWFilterClose(virConnectPtr conn) {
return 0;
}
+static int testListAllDomains(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags)
+{
+ testConnPtr privconn = conn->privateData;
+ int ret;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, -1);
+
+
+ testDriverLock(privconn);
+ ret = virDomainList(conn, privconn->domains.objs, domains, flags);
+ testDriverUnlock(privconn);
+
+ return ret;
+}
+
+
static virDriver testDriver = {
.no = VIR_DRV_TEST,
.name = "Test",
@@ -5584,6 +5614,7 @@ static virDriver testDriver = {
.domainEventRegisterAny = testDomainEventRegisterAny, /* 0.8.0 */
.domainEventDeregisterAny = testDomainEventDeregisterAny, /* 0.8.0 */
.isAlive = testIsAlive, /* 0.9.8 */
+ .listAllDomains = testListAllDomains, /* 0.9.13 */
};
static virNetworkDriver testNetworkDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 219246d..79306f3 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -64,6 +64,7 @@
#include "virnetdevtap.h"
#include "virnodesuspend.h"
#include "viruri.h"
+#include "virdomainlist.h"
#define VIR_FROM_THIS VIR_FROM_UML
@@ -2519,6 +2520,35 @@ static void umlDomainEventQueue(struct uml_driver *driver,
virDomainEventStateQueue(driver->domainEventState, event);
}
+static int umlListAllDomains(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags)
+{
+ struct uml_driver *driver = conn->privateData;
+ int ret = -1;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, -1);
+
+ umlDriverLock(driver);
+
+ ret = virDomainList(conn, driver->domains.objs, domains, flags);
+
+ umlDriverUnlock(driver);
+
+ return ret;
+}
+
static virDriver umlDriver = {
@@ -2578,6 +2608,7 @@ static virDriver umlDriver = {
.domainOpenConsole = umlDomainOpenConsole, /* 0.8.6 */
.isAlive = umlIsAlive, /* 0.9.8 */
.nodeSuspendForDuration = nodeSuspendForDuration, /* 0.9.8 */
+ .listAllDomains = umlListAllDomains, /* 0.9.13 */
};
static int
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 8f9d922..acf45b4 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -33,6 +33,7 @@
#include "vmx.h"
#include "vmware_conf.h"
#include "vmware_driver.h"
+#include "virdomainlist.h"
static const char *vmw_types[] = { "player", "ws" };
@@ -994,6 +995,35 @@ vmwareIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
return 1;
}
+static int
+vmwareListAllDomains(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags)
+{
+ struct vmware_driver *driver = conn->privateData;
+ int ret = -1;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, -1);
+
+ vmwareDriverLock(driver);
+ ret = virDomainList(conn, driver->domains.objs, domains, flags);
+ vmwareDriverUnlock(driver);
+ return ret;
+}
+
+
+
static virDriver vmwareDriver = {
.no = VIR_DRV_VMWARE,
.name = "VMWARE",
@@ -1029,6 +1059,7 @@ static virDriver vmwareDriver = {
.domainIsActive = vmwareDomainIsActive, /* 0.8.7 */
.domainIsPersistent = vmwareDomainIsPersistent, /* 0.8.7 */
.isAlive = vmwareIsAlive, /* 0.9.8 */
+ .listAllDomains = vmwareListAllDomains, /* 0.9.13 */
};
int
--
1.7.3.4