# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1203934392 -3600
# Node ID 6e25b6b5b541ee6a3547ab2125937a7207bd21fc
# Parent 875e54efe5feb2f65572c0b4d786081506e65cc8
RASD: add function get_rasd_by_ref() for usage in associations
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r 875e54efe5fe -r 6e25b6b5b541 src/Virt_RASD.c
--- a/src/Virt_RASD.c Mon Feb 25 11:09:49 2008 +0100
+++ b/src/Virt_RASD.c Mon Feb 25 11:13:12 2008 +0100
@@ -357,38 +357,97 @@ static CMPIInstance *rasd_from_vdev(cons
return inst;
}
-CMPIInstance *get_rasd_instance(const CMPIContext *context,
- const CMPIObjectPath *ref,
- const CMPIBroker *broker,
- const char *id,
- const uint16_t type)
+CMPIStatus get_rasd_by_name(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char *name,
+ const uint16_t type,
+ CMPIInstance **_inst)
{
CMPIInstance *inst = NULL;
- CMPIStatus s;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
int ret;
char *host = NULL;
char *devid = NULL;
virConnectPtr conn = NULL;
struct virt_device *dev;
- ret = parse_fq_devid((char *)id, &host, &devid);
- if (!ret)
- return NULL;
-
- conn = connect_by_classname(broker, CLASSNAME(ref), &s);
- if (conn == NULL)
- 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;
+ }
+
+ ret = parse_fq_devid((char *)name, &host, &devid);
+ if (ret != 1) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)",
+ name);
+ goto out;
+ }
dev = find_dev(conn, type, host, devid);
- if (dev)
- inst = rasd_from_vdev(broker, dev, host, ref);
-
+ if (!dev) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)",
+ name);
+ goto out;
+ }
+
+ inst = rasd_from_vdev(broker, dev, host, reference);
+ if (inst == NULL)
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to set instance properties");
+ else
+ *_inst = inst;
+
out:
virConnectClose(conn);
free(host);
free(devid);
- return inst;
+ return s;
+}
+
+CMPIStatus get_rasd_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ CMPIInstance **_inst)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
+ const char *name = NULL;
+ uint16_t type;
+
+ if (cu_get_str_path(reference, "InstanceID", &name) != CMPI_RC_OK)
{
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Missing InstanceID");
+ goto out;
+ }
+
+ if (rasd_type_from_classname(CLASSNAME(reference), &type) != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to determine RASD type");
+ goto out;
+ }
+
+ s = get_rasd_by_name(broker, reference, name, type, &inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ s = cu_validate_ref(broker, reference, inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ *_inst = inst;
+
+ out:
+ return s;
}
CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type)
@@ -544,32 +603,14 @@ static CMPIStatus GetInstance(CMPIInstan
const char **properties)
{
CMPIStatus s = {CMPI_RC_OK, NULL};
- CMPIInstance *inst;
- const char *id = NULL;
- uint16_t type;
-
- if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Missing InstanceID");
- goto out;
- }
-
- if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Unable to determine RASD type");
- goto out;
- }
-
- inst = get_rasd_instance(context, ref, _BROKER, id, type);
-
- if (inst != NULL)
- CMReturnInstance(results, inst);
- else
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_NOT_FOUND,
- "No such instance (%s)", id);
+ CMPIInstance *inst = NULL;
+
+ s = get_rasd_by_ref(_BROKER, ref, &inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ CMReturnInstance(results, inst);
+
out:
return s;
}
diff -r 875e54efe5fe -r 6e25b6b5b541 src/Virt_RASD.h
--- a/src/Virt_RASD.h Mon Feb 25 11:09:49 2008 +0100
+++ b/src/Virt_RASD.h Mon Feb 25 11:13:12 2008 +0100
@@ -42,11 +42,15 @@ CMPIrc rasd_type_from_classname(const ch
CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type);
CMPIrc rasd_classname_from_type(uint16_t type, const char **cn);
-CMPIInstance *get_rasd_instance(const CMPIContext *context,
- const CMPIObjectPath *ref,
- const CMPIBroker *broker,
- const char *id,
- const uint16_t type);
+CMPIStatus get_rasd_by_name(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char *name,
+ const uint16_t type,
+ CMPIInstance **_inst);
+
+CMPIStatus get_rasd_by_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ CMPIInstance **_inst);
#endif