[Libvirt-cim] [PATCH] (#2) Fix MemoryPool.Reserved to show only actively allocated memory

Chip Vincent cvincent at linux.vnet.ibm.com
Wed Jun 22 15:33:03 UTC 2011


# HG changeset patch
# User Chip Vincent <cvincent at us.ibm.com>
# Date 1308756569 14400
# Node ID c5a9510b6bd1569c6ab0966624306e29ecd81727
# Parent  6c29c5b284443e226e7d97e7e5f11848b0c4e761
(#2) Fix MemoryPool.Reserved to show only actively allocated memory.

It appears Reserved is meant to show memory that is taken (actively in use by
VMs) as opposed to memory that is potentially taken (assigned to defined, but
not running VMs).
Also added CurrentlyConsumedResource (a much clearer name for the same thing)
and ConsumedResourceUnits, fixed units to conform with DSP1045, and cleaned
up some extraneous whitespace.

Changes from #1:
        - Fix return code checking

Signed-off-by: Chip Vincent <cvincent at us.ibm.com>

diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c
+++ b/src/Virt_DevicePool.c
@@ -676,17 +676,47 @@
         return memory != 0;
 }
 
-static bool mempool_set_reserved(CMPIInstance *inst, virConnectPtr conn)
+static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn)
 {
-        uint64_t memory;
+        uint64_t memory = 0;
+        int *domain_ids = NULL;
+        int count, i = 0;
 
-        /* NB: This doesn't account for memory to be claimed
-         * by ballooning dom0
-         */
-        memory = allocated_memory(conn);
+        count = virConnectNumOfDomains(conn);
+        if (count <= 0)
+                goto out;
+
+        domain_ids = calloc(count, sizeof(domain_ids[0]));
+        if (domain_ids == NULL)
+                goto out;
+
+        if (virConnectListDomains(conn, domain_ids, count) == -1)
+                goto out;
+
+        for (i = 0; i < count; i++) {
+                virDomainPtr dom = NULL;
+                virDomainInfo dom_info;
+
+                dom = virDomainLookupByID(conn, domain_ids[i]);
+                if (dom == NULL) {
+                        CU_DEBUG("Cannot connect to domain %n: excluding",
+                                domain_ids[i]);
+                        continue;
+                }
+
+                if (virDomainGetInfo(dom, &dom_info) == 0)
+                        memory += dom_info.memory;
+
+                virDomainFree(dom);
+        }
+
+ out:
+        free(domain_ids);
 
         CMSetProperty(inst, "Reserved",
                       (CMPIValue *)&memory, CMPI_uint64);
+        CMSetProperty(inst, "CurrentlyConsumedResource",
+                      (CMPIValue *)&memory, CMPI_uint64);
 
         return memory != 0;
 }
@@ -726,10 +756,14 @@
         CMSetProperty(inst, "ResourceType",
                       (CMPIValue *)&type, CMPI_uint16);
 
-        if (units != NULL)
+        if (units != NULL) {
                 CMSetProperty(inst, "AllocationUnits",
                               (CMPIValue *)units, CMPI_chars);
 
+                CMSetProperty(inst, "ConsumedResourceUnits",
+                              (CMPIValue *)units, CMPI_chars);
+        }
+
         if (caption != NULL)
                 CMSetProperty(inst, "Caption",
                               (CMPIValue *)caption, CMPI_chars);
@@ -761,9 +795,9 @@
                                   ns);
 
         mempool_set_total(inst, conn);
-        mempool_set_reserved(inst, conn);
+        mempool_set_consumed(inst, conn);
 
-        set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL, true);
+        set_params(inst, CIM_RES_TYPE_MEM, id, "byte*2^10", NULL, true);
 
         inst_list_add(list, inst);
 




More information about the Libvirt-cim mailing list