[Libvirt-cim] [PATCH 1 of 2] Add parent_device_pool() which returnsthe parent pool for a given device type
Richard Maciel
rmaciel at linux.vnet.ibm.com
Fri May 8 20:37:16 UTC 2009
Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert <karupert at us.ibm.com>
> # Date 1240877148 25200
> # Node ID e132a8e94381d218d39eb2fffc94b27a438abb32
> # Parent 570c3507c7b2c3e55680e9a70f4889accb9a1cf7
> Add parent_device_pool() which returns the parent pool for a given device type
>
> Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>
>
> diff -r 570c3507c7b2 -r e132a8e94381 src/Virt_DevicePool.c
> --- a/src/Virt_DevicePool.c Tue May 05 18:08:58 2009 -0700
> +++ b/src/Virt_DevicePool.c Mon Apr 27 17:05:48 2009 -0700
> @@ -77,7 +77,7 @@
> goto out;
> }
>
> - pools[count].tag = strdup("Parent");
> + pools[count].tag = strdup("0");
> pools[count].path = NULL;
> pools[count].primordial = true;
> count++;
> @@ -1234,6 +1234,45 @@
> return _get_pools(broker, reference, type, NULL, list);
> }
>
> +CMPIInstance *parent_device_pool(const CMPIBroker *broker,
> + const CMPIObjectPath *reference,
> + uint16_t type,
> + CMPIStatus *s)
> +{
> + CMPIInstance *inst = NULL;
> + const char *id = NULL;
> +
> + if (type == CIM_RES_TYPE_MEM) {
> + id = "MemoryPool/0";
> + } else if (type == CIM_RES_TYPE_PROC) {
> + id = "ProcessorPool/0";
> + } else if (type == CIM_RES_TYPE_DISK) {
> + id = "DiskPool/0";
> + } else if (type == CIM_RES_TYPE_NET) {
> + id = "NetworkPool/0";
> + } else if (type == CIM_RES_TYPE_GRAPHICS) {
> + id = "GraphicsPool/0";
> + } else if (type == CIM_RES_TYPE_INPUT) {
> + id = "InputPool/0";
> + } else {
> + cu_statusf(broker, s,
> + CMPI_RC_ERR_INVALID_PARAMETER,
> + "No such device type `%s'", type);
> + goto out;
> + }
> +
> + *s = get_pool_by_name(broker, reference, id, &inst);
> + if (inst == NULL) {
> + cu_statusf(broker, s,
> + CMPI_RC_ERR_FAILED,
> + "No default pool found for type %hi", type);
> + }
> +
> + out:
> +
> + return inst;
> +}
> +
> CMPIInstance *default_device_pool(const CMPIBroker *broker,
> const CMPIObjectPath *reference,
> uint16_t type,
> @@ -1241,43 +1280,38 @@
> {
> CMPIInstance *inst = NULL;
> struct inst_list list;
> + bool val;
>
> - inst_list_init(&list);
> + if ((type == CIM_RES_TYPE_DISK) || (type == CIM_RES_TYPE_NET)) {
> + int i = 0;
> + CMPIrc rc;
>
> - if (type == CIM_RES_TYPE_MEM) {
> - *s = get_pool_by_name(broker, reference, "MemoryPool/0", &inst);
> - } else if (type == CIM_RES_TYPE_PROC) {
> - *s = get_pool_by_name(broker, reference, "ProcessorPool/0", &inst);
> - } else if (type == CIM_RES_TYPE_DISK) {
> + inst_list_init(&list);
> +
> *s = enum_pools(broker, reference, type, &list);
> - if ((s->rc == CMPI_RC_OK) && (list.cur > 0))
You probably should insert a CU_DEBUG here just to help debug
> - inst = list.list[0];
> - } else if (type == CIM_RES_TYPE_NET) {
> - *s = enum_pools(broker, reference, type, &list);
> - if ((s->rc == CMPI_RC_OK) && (list.cur > 0))
> - inst = list.list[0];
Same here
> - } else if (type == CIM_RES_TYPE_GRAPHICS) {
> - *s = get_pool_by_name(broker,
> - reference,
> - "GraphicsPool/0",
> - &inst);
Same here
> - } else if (type == CIM_RES_TYPE_INPUT) {
> - *s = get_pool_by_name(broker,
> - reference,
> - "InputPool/0",
> - &inst);
> + if ((s->rc == CMPI_RC_OK) && (list.cur > 0)) {
> +
> + for (i = 0; i < list.cur; i++) {
> + rc = cu_get_bool_prop(list.list[i],
> + "Primordial",
> + &val);
> + if ((rc != CMPI_RC_OK) || (val))
> + continue;
> +
> + inst = list.list[i];
> + break;
> + }
Same here
> + }
> +
> + inst_list_free(&list);
> +
> + if (inst == NULL) {
> + cu_statusf(broker, s,
> + CMPI_RC_ERR_FAILED,
> + "No default pool found for type %hi", type);
> + }
> } else {
> - cu_statusf(broker, s,
> - CMPI_RC_ERR_INVALID_PARAMETER,
> - "No such device type `%s'", type);
> - }
> -
> - inst_list_free(&list);
> -
> - if (inst == NULL) {
> - cu_statusf(broker, s,
> - CMPI_RC_ERR_FAILED,
> - "No default pool found for type %hi", type);
> + inst = parent_device_pool(broker, reference, type, s);
> }
>
> return inst;
> diff -r 570c3507c7b2 -r e132a8e94381 src/Virt_DevicePool.h
> --- a/src/Virt_DevicePool.h Tue May 05 18:08:58 2009 -0700
> +++ b/src/Virt_DevicePool.h Mon Apr 27 17:05:48 2009 -0700
> @@ -106,6 +106,20 @@
> CMPIInstance **_inst);
>
> /**
> + * Get the parent pool for a given device type
> + *
> + * @param broker A pointer to the current broker
> + * @param ref The object path containing namespace and prefix info
> + * @param type The device type in question
> + * @param status The returned status
> + * @returns Parent pool instance
> + */
> +CMPIInstance *parent_device_pool(const CMPIBroker *broker,
> + const CMPIObjectPath *reference,
> + uint16_t type,
> + CMPIStatus *s);
> +
> +/**
> * Get the default pool for a given device type
> *
> * @param broker A pointer to the current broker
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
--
Richard Maciel, MSc
IBM Linux Technology Center
rmaciel at linux.vnet.ibm.com
More information about the Libvirt-cim
mailing list