# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1225145197 25200
# Node ID 10bd66c67a6ad4eebe6a0f8dc81db2b4912d5650
# Parent e043f46f299ec3dd3d1e48e51e57437fa90db136
Add a domain_vcpu_count() function to return the number of active VCPUs for
a given domain.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r e043f46f299e -r 10bd66c67a6a libxkutil/misc_util.c
--- a/libxkutil/misc_util.c Wed Oct 22 08:28:37 2008 -0700
+++ b/libxkutil/misc_util.c Mon Oct 27 15:06:37 2008 -0700
@@ -541,6 +541,45 @@
return result;
}
+int domain_vcpu_count(virDomainPtr dom)
+{
+ virVcpuInfoPtr info = NULL;
+ int max;
+ int count;
+ int actual = 0;
+ int i;
+ virConnectPtr conn = NULL;
+
+ conn = virDomainGetConnect(dom);
+ if (conn == NULL) {
+ CU_DEBUG("Failed to get connection from domain");
+ return -1;
+ }
+
+ max = virConnectGetMaxVcpus(conn, virConnectGetType(conn));
+ if (max <= 0) {
+ CU_DEBUG("Failed to get max vcpu count");
+ return -1;
+ }
+
+ info = calloc(max, sizeof(*info));
+ if (info == NULL) {
+ CU_DEBUG("Failed to allocate %i vcpuinfo structures", max);
+ return -1;
+ }
+
+ count = virDomainGetVcpus(dom, info, max, NULL, 0);
+
+ free(info);
+
+ for (i = 0; i < count; i++) {
+ if (info[i].cpu != -1)
+ actual++;
+ }
+
+ return actual;
+}
+
/*
* Local Variables:
* mode: C
diff -r e043f46f299e -r 10bd66c67a6a libxkutil/misc_util.h
--- a/libxkutil/misc_util.h Wed Oct 22 08:28:37 2008 -0700
+++ b/libxkutil/misc_util.h Mon Oct 27 15:06:37 2008 -0700
@@ -124,6 +124,8 @@
bool check_refs_pfx_match(const CMPIObjectPath *refa,
const CMPIObjectPath *refb);
+int domain_vcpu_count(virDomainPtr dom);
+
#define LIBVIRT_CIM_DEFAULT_MAKEREF() \
static CMPIInstance* make_ref(const CMPIObjectPath *source_ref, \
const CMPIInstance *target_inst, \