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

Eduardo Lima (Etrunko) eblima at linux.vnet.ibm.com
Tue Jun 21 19:36:39 UTC 2011


On 06/21/2011 12:35 PM, Chip Vincent wrote:
> # HG changeset patch
> # User Chip Vincent<cvincent at us.ibm.com>
> # Date 1308669482 14400
> # Node ID 637801be4b6f6cc0c065f4fe406e85b78186654b
> # Parent  6c29c5b284443e226e7d97e7e5f11848b0c4e761
> 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.
>
> 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 == 0)
> +                goto out;
> +

Shouldn't you be checking for NULL instead of 0 here?

> +        if (virConnectListDomains(conn, domain_ids, count) == 0)
> +                goto out;
> +

And here for -1 instead of 0?

> +        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);

Best Regards,

-- 
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima at br.ibm.com




More information about the Libvirt-cim mailing list