From: John Ferlan <jferlan(a)redhat.com>
This is an optimization over using the multistep approach to get a count,
get some memory, and get the list of domains (active and defined). Followed
other examples to ensure only building the code if the libvirt version is
correct. The API was added in 0.9.13.
Macro USE_VIR_CONNECT_LIST_ALL_DOMAINS is used to activate it, which
should be added in configure in the future.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
Reviewed-by: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
Signed-off-by: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
---
libxkutil/cs_util_instance.c | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/libxkutil/cs_util_instance.c b/libxkutil/cs_util_instance.c
index a383147..490017c 100644
--- a/libxkutil/cs_util_instance.c
+++ b/libxkutil/cs_util_instance.c
@@ -33,6 +33,31 @@
#include "cs_util.h"
#include <libcmpiutil/libcmpiutil.h>
+#define USE_VIR_CONNECT_LIST_ALL_DOMAINS 0
+
+#if LIBVIR_VERSION_NUMBER >= 9013 && USE_VIR_CONNECT_LIST_ALL_DOMAINS
+int get_domain_list(virConnectPtr conn, virDomainPtr **_list)
+{
+ virDomainPtr *nameList = NULL;
+ int n_names;
+ int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE;
+
+ n_names = virConnectListAllDomains(conn,
+ &nameList,
+ flags);
+ if (n_names > 0) {
+ *_list = nameList;
+ } else if (n_names == 0) {
+ /* Since there are no elements, no domain ptrs to free
+ * but still must free the nameList returned
+ */
+ free(nameList);
+ }
+
+ return n_names;
+}
+#else
int get_domain_list(virConnectPtr conn, virDomainPtr **_list)
{
char **names = NULL;
@@ -113,6 +138,7 @@ int get_domain_list(virConnectPtr conn, virDomainPtr **_list)
return idx;
}
+#endif /* LIBVIR_VERSION_NUMBER >= 0913 */
void set_instance_class_name(CMPIInstance *instance, char *name)
{
--
1.7.1