# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1225207324 25200
# Node ID 819ae6c97a071eb28c56719a8bb29bf584664556
# Parent e043f46f299ec3dd3d1e48e51e57437fa90db136
Add a domain_vcpu_count() function to return the number of active VCPUs for
a given domain.
Changes:
- Fix misplaced free()
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r e043f46f299e -r 819ae6c97a07 libxkutil/misc_util.c
--- a/libxkutil/misc_util.c Wed Oct 22 08:28:37 2008 -0700
+++ b/libxkutil/misc_util.c Tue Oct 28 08:22:04 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);
+
+ for (i = 0; i < count; i++) {
+ if (info[i].cpu != -1)
+ actual++;
+ }
+
+ free(info);
+
+ return actual;
+}
+
/*
* Local Variables:
* mode: C
diff -r e043f46f299e -r 819ae6c97a07 libxkutil/misc_util.h
--- a/libxkutil/misc_util.h Wed Oct 22 08:28:37 2008 -0700
+++ b/libxkutil/misc_util.h Tue Oct 28 08:22:04 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, \