# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1204545502 -3600
# Node ID 4748d0422f3891598680b74b3aa1bcb4acdcb9a1
# Parent eefe9c56b43c7ca0cad6f579fd88c5b89134bba0
DevicePool: adopt get_ interface common look and feel
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r eefe9c56b43c -r 4748d0422f38 src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c Mon Mar 03 11:51:00 2008 +0100
+++ b/src/Virt_DevicePool.c Mon Mar 03 12:58:22 2008 +0100
@@ -701,13 +701,13 @@ CMPIStatus get_pool_by_type(const CMPIBr
return _get_pool(broker, conn, type, NULL, ns, list);
}
-CMPIInstance *get_pool_by_id(const CMPIBroker *broker,
- virConnectPtr conn,
- const char *id,
- const char *ns)
-{
- CMPIInstance *inst = NULL;
- CMPIStatus s;
+CMPIStatus get_pool_by_name(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char *id,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ virConnectPtr conn = NULL;
char *type = NULL;
char *poolid = NULL;
int ret;
@@ -715,18 +715,34 @@ CMPIInstance *get_pool_by_id(const CMPIB
inst_list_init(&list);
+ conn = connect_by_classname(broker, CLASSNAME(reference), &s);
+ if (conn == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance.");
+ goto out;
+ }
+
ret = sscanf(id, "%a[^/]/%as", &type, &poolid);
- if (ret != 2)
- goto out;
-
- s = _get_pool(broker, conn, type, poolid, ns, &list);
+ if (ret != 2) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s).",
+ id);
+ goto out;
+ }
+
+ s = _get_pool(broker, conn, type, poolid, NAMESPACE(reference), &list);
if ((s.rc == CMPI_RC_OK) && (list.cur > 0))
- inst = list.list[0];
+ *_inst = list.list[0];
+
+ free(type);
+ free(poolid);
out:
inst_list_free(&list);
- return inst;
+ return s;
}
CMPIStatus get_all_pools(const CMPIBroker *broker,
@@ -763,8 +779,7 @@ static void __return_pool(const CMPIResu
static CMPIStatus return_pool(const CMPIObjectPath *ref,
const CMPIResult *results,
- bool name_only,
- bool single_only)
+ bool name_only)
{
CMPIStatus s;
char *type;
@@ -811,13 +826,12 @@ static CMPIStatus return_pool(const CMPI
return s;
}
-CMPIStatus get_pool_inst(const CMPIBroker *broker,
- const CMPIObjectPath *reference,
- CMPIInstance **instance)
-{
- CMPIStatus s;
+CMPIStatus get_pool_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ CMPIInstance **instance)
+{
+ CMPIStatus s = {CMPI_RC_OK};
CMPIInstance *inst = NULL;
- virConnectPtr conn = NULL;
const char *id = NULL;
if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) {
@@ -827,24 +841,17 @@ CMPIStatus get_pool_inst(const CMPIBroke
goto out;
}
- conn = connect_by_classname(broker, CLASSNAME(reference), &s);
- if (conn == NULL) {
- cu_statusf(broker, &s,
- CMPI_RC_ERR_NOT_FOUND,
- "No such instance");
- goto out;
- }
-
- inst = get_pool_by_id(broker, conn, id, NAMESPACE(reference));
- if (inst == NULL)
- cu_statusf(broker, &s,
- CMPI_RC_ERR_NOT_FOUND,
- "No such instance (%s)", id);
+ s = get_pool_by_name(broker, reference, id, &inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ s = cu_validate_ref(broker, reference, inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ *instance = inst;
out:
- virConnectClose(conn);
- *instance = inst;
-
return s;
}
@@ -853,7 +860,7 @@ static CMPIStatus EnumInstanceNames(CMPI
const CMPIResult *results,
const CMPIObjectPath *reference)
{
- return return_pool(reference, results, true, false);
+ return return_pool(reference, results, true);
}
static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -862,7 +869,7 @@ static CMPIStatus EnumInstances(CMPIInst
const CMPIObjectPath *reference,
const char **properties)
{
- return return_pool(reference, results, false, false);
+ return return_pool(reference, results, false);
}
static CMPIStatus GetInstance(CMPIInstanceMI *self,
@@ -871,13 +878,16 @@ static CMPIStatus GetInstance(CMPIInstan
const CMPIObjectPath *reference,
const char **properties)
{
- CMPIStatus s;
+ CMPIStatus s = {CMPI_RC_OK};
CMPIInstance *inst = NULL;
- s = get_pool_inst(_BROKER, reference, &inst);
- if ((s.rc == CMPI_RC_OK) && (inst != NULL))
- CMReturnInstance(results, inst);
-
+ s = get_pool_by_ref(_BROKER, reference, &inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ CMReturnInstance(results, inst);
+
+ out:
return s;
}
diff -r eefe9c56b43c -r 4748d0422f38 src/Virt_DevicePool.h
--- a/src/Virt_DevicePool.h Mon Mar 03 11:51:00 2008 +0100
+++ b/src/Virt_DevicePool.h Mon Mar 03 12:58:22 2008 +0100
@@ -33,12 +33,6 @@ CMPIStatus get_pool_by_type(const CMPIBr
const char *type,
const char *ns,
struct inst_list *list);
-
-CMPIInstance *get_pool_by_id(const CMPIBroker *broker,
- virConnectPtr conn,
- const char *id,
- const char *ns);
-
/**
* Get the InstanceID of a pool that a given RASD id (for type) is in
@@ -82,9 +76,23 @@ CMPIStatus get_all_pools(const CMPIBroke
* @param reference The reference passed to the CIMOM
* @param instance Return corresponding instance
*/
-CMPIStatus get_pool_inst(const CMPIBroker *broker,
- const CMPIObjectPath *reference,
- CMPIInstance **instance);
+CMPIStatus get_pool_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ CMPIInstance **instance);
+
+/**
+ * Get device pool instance specified by the id
+ *
+ * @param broker A pointer to the current broker
+ * @param ref The object path containing namespace and prefix info
+ * @param name The device pool id
+ * @param _inst In case of success the pointer to the instance
+ * @returns CMPIStatus
+ */
+CMPIStatus get_pool_by_name(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char *id,
+ CMPIInstance **_inst);
#endif