[PATCH 0 of 2] (#2) Updates to DevicePool

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1208195852 25200 # Node ID b342662208d69fb8f3c7189b1f227e3dff04fd59 # Parent 9518a04a73bef32166da24e795f0d5c8c6665981 Add function to parse out pool name from InstanceID Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 9518a04a73be -r b342662208d6 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Mon Apr 14 10:57:32 2008 -0700 +++ b/src/Virt_DevicePool.c Mon Apr 14 10:57:32 2008 -0700 @@ -500,6 +500,17 @@ uint16_t res_type_from_pool_id(const cha return CIM_RES_TYPE_UNKNOWN; } +char *name_from_pool_id(const char *id) +{ + char *s; + + s = strchr(id, '/'); + if (s == NULL) + return NULL; + + return strdup((char *)s+1); +} + static bool mempool_set_total(CMPIInstance *inst, virConnectPtr conn) { virNodeInfo info; diff -r 9518a04a73be -r b342662208d6 src/Virt_DevicePool.h --- a/src/Virt_DevicePool.h Mon Apr 14 10:57:32 2008 -0700 +++ b/src/Virt_DevicePool.h Mon Apr 14 10:57:32 2008 -0700 @@ -58,6 +58,14 @@ uint16_t res_type_from_pool_id(const cha uint16_t res_type_from_pool_id(const char *id); /** + * Get the pool name from a given pool's InstanceID + * + * @param id The InstanceID of the pool + * @returns the name (must be free'd by the caller) + */ +char *name_from_pool_id(const char *id); + +/** * Get all device pools on the system for the given type * *

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1208196681 25200 # Node ID 4d7ede1d251ba8c8982a2bc65f53b8de3982a04e # Parent b342662208d69fb8f3c7189b1f227e3dff04fd59 Add ability to get a default pool of a given type to the pool provider Changes: - Make ProcPool ProcessorPool Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r b342662208d6 -r 4d7ede1d251b src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Mon Apr 14 10:57:32 2008 -0700 +++ b/src/Virt_DevicePool.c Mon Apr 14 11:11:21 2008 -0700 @@ -991,6 +991,39 @@ CMPIStatus enum_pools(const CMPIBroker * return _get_pools(broker, reference, type, NULL, list); } +CMPIInstance *default_device_pool(const CMPIBroker *broker, + const CMPIObjectPath *reference, + uint16_t type, + CMPIStatus *s) +{ + CMPIInstance *inst = NULL; + struct inst_list list; + + inst_list_init(&list); + + 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) { + *s = enum_pools(broker, reference, type, &list); + if (s->rc == CMPI_RC_OK) + inst = list.list[0]; + } else if (type == CIM_RES_TYPE_NET) { + *s = enum_pools(broker, reference, type, &list); + if (s->rc == CMPI_RC_OK) + inst = list.list[0]; + } else { + cu_statusf(broker, s, + CMPI_RC_ERR_INVALID_PARAMETER, + "No such device type `%s'", type); + } + + inst_list_free(&list); + + return inst; +} + static CMPIStatus return_pool(const CMPIObjectPath *ref, const CMPIResult *results, bool names_only) diff -r b342662208d6 -r 4d7ede1d251b src/Virt_DevicePool.h --- a/src/Virt_DevicePool.h Mon Apr 14 10:57:32 2008 -0700 +++ b/src/Virt_DevicePool.h Mon Apr 14 11:11:21 2008 -0700 @@ -105,6 +105,20 @@ CMPIStatus get_pool_by_name(const CMPIBr const char *id, CMPIInstance **_inst); +/** + * Get the default 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 Default instance of a pool + */ +CMPIInstance *default_device_pool(const CMPIBroker *broker, + const CMPIObjectPath *reference, + uint16_t type, + CMPIStatus *status); + #endif /*

+ } else if (type == CIM_RES_TYPE_DISK) { + *s = enum_pools(broker, reference, type, &list); + if (s->rc == CMPI_RC_OK) + inst = list.list[0]; + } else if (type == CIM_RES_TYPE_NET) { + *s = enum_pools(broker, reference, type, &list); + if (s->rc == CMPI_RC_OK) + inst = list.list[0];
I somehow missed this last time - you could collapse these statements into one else if. However, I think having the statements parallel the PROC and MEM statements is easier to read (and easier to change later on if need be). +1 -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert