# HG changeset patch
# User Jay Gagnon <grendel(a)linux.vnet.ibm.com>
# Date 1200514883 18000
# Node ID dd91142f9b502f4c3f134fe3c51c105c4a290cb1
# Parent e4000f4735b6e90b0b0acc4fd40d8d9c06800032
Clean up CSI/CSMI integration
The functions responsible for actually firing the indication weren't really integrated
in the first patch, so much as co-existing. This one attempts to reconcile the two
approaches, although there is still probably more that can be done.
Signed-off-by: Jay Gagnon <grendel(a)linux.vnet.ibm.com>
diff -r e4000f4735b6 -r dd91142f9b50 src/Virt_ComputerSystemIndication.c
--- a/src/Virt_ComputerSystemIndication.c Wed Jan 16 15:16:16 2008 -0500
+++ b/src/Virt_ComputerSystemIndication.c Wed Jan 16 15:21:23 2008 -0500
@@ -48,6 +48,7 @@ static CMPI_THREAD_TYPE lifecycle_thread
enum CS_EVENTS {CS_CREATED,
CS_DELETED,
+ CS_MODIFIED,
};
static pthread_cond_t lifecycle_cond = PTHREAD_COND_INITIALIZER;
@@ -163,82 +164,57 @@ static bool dom_changed(struct dom_xml p
return ret;
}
-static bool _lifecycle_indication(const CMPIBroker *broker,
- const CMPIContext *ctx,
- const CMPIObjectPath *newsystem,
- const char *type)
+static bool _do_indication(const CMPIBroker *broker,
+ const CMPIContext *ctx,
+ CMPIInstance *affected_inst,
+ int ind_type,
+ const char *ind_type_name,
+ char *prefix,
+ char *ns)
{
+ CMPIObjectPath *affected_op;
CMPIObjectPath *ind_op;
CMPIInstance *ind;
CMPIStatus s;
+ bool ret = true;
ind = get_typed_instance(broker,
- "Xen", /* Temporary hack */
- type,
- NAMESPACE(newsystem));
+ prefix,
+ ind_type_name,
+ ns);
if (ind == NULL) {
CU_DEBUG("Failed to create ind");
- return false;
+ ret = false;
}
ind_op = CMGetObjectPath(ind, &s);
if (s.rc != CMPI_RC_OK) {
CU_DEBUG("Failed to get ind_op");
- return false;
+ ret = false;
}
- CMSetProperty(ind, "AffectedSystem",
- (CMPIValue *)&newsystem, CMPI_ref);
+ switch(ind_type) {
+ case CS_CREATED:
+ case CS_DELETED:
+ affected_op = CMGetObjectPath(affected_inst, NULL);
+ CMSetProperty(ind, "AffectedSystem",
+ (CMPIValue *)&affected_op, CMPI_ref);
+ break;
+ case CS_MODIFIED:
+ CMSetProperty(ind, "PreviousInstance",
+ (CMPIValue *)&affected_inst, CMPI_instance);
+ break;
+ }
CU_DEBUG("Delivering Indication: %s",
- CMGetCharPtr(CMObjectPathToString(ind_op, NULL)));
+ CMGetCharPtr(CMObjectPathToString(ind_op, NULL)));
- CBDeliverIndication(_BROKER,
+ CBDeliverIndication(broker,
ctx,
- NAMESPACE(newsystem),
+ ns,
ind);
-
- return true;
-}
-
-static bool _do_modified_indication(const CMPIBroker *broker,
- const CMPIContext *ctx,
- CMPIInstance *mod_inst,
- char *prefix,
- char *ns)
-{
- CMPIObjectPath *ind_op;
- CMPIInstance *ind;
- CMPIStatus s;
-
- ind = get_typed_instance(broker,
- prefix,
- "ComputerSystemModifiedIndication",
- ns);
- if (ind == NULL) {
- CU_DEBUG("Failed to create ind");
- return false;
- }
-
- ind_op = CMGetObjectPath(ind, &s);
- if (s.rc != CMPI_RC_OK) {
- CU_DEBUG("Failed to get ind_op");
- return false;
- }
-
- CMSetProperty(ind, "PreviousInstance",
- (CMPIValue *)&mod_inst, CMPI_instance);
-
- CU_DEBUG("Delivering Indication: %s\n",
- CMGetCharPtr(CMObjectPathToString(ind_op, NULL)));
-
- CBDeliverIndication(_BROKER,
- ctx,
- CIM_VIRT_NS,
- ind);
-
- return true;
+ return ret;
}
static bool wait_for_event(void)
@@ -278,16 +254,15 @@ static bool async_ind(CMPIContext *conte
static bool async_ind(CMPIContext *context,
virConnectPtr conn,
const char *name,
- int type)
+ int type,
+ char *prefix,
+ char *ns)
{
CMPIInstance *newinst;
CMPIObjectPath *op;
CMPIStatus s;
const char *type_name;
char *type_cn = NULL;
- const char *ns = CIM_VIRT_NS;
-
- /* FIXME: Hmm, need to get the namespace a better way */
if (type == CS_CREATED) {
type_name = "ComputerSystemCreatedIndication";
@@ -310,11 +285,10 @@ static bool async_ind(CMPIContext *conte
/* A deleted domain will have no instance to lookup */
newinst = CMNewInstance(_BROKER, op, &s);
- op = CMGetObjectPath(newinst, NULL);
-
free(type_cn);
- return _lifecycle_indication(_BROKER, context, op, type_name);
+ return _do_indication(_BROKER, context, newinst, type, type_name,
+ prefix, ns);
}
static bool mod_ind(CMPIContext *context,
@@ -344,7 +318,9 @@ static bool mod_ind(CMPIContext *context
CMSetProperty(mod_inst, "UUID",
(CMPIValue *)prev_dom.uuid, CMPI_chars);
- rc = _do_modified_indication(_BROKER, context, mod_inst, prefix, ns);
+ rc = _do_indication(_BROKER, context, mod_inst,
+ CS_MODIFIED, "ComputerSystemModifiedIndication",
+ prefix, ns);
out:
free(name);
@@ -399,7 +375,9 @@ static CMPI_THREAD_RETURN lifecycle_thre
async_ind(context,
conn,
virDomainGetName(cur_list[i]),
- CS_CREATED);
+ CS_CREATED,
+ prefix,
+ ns);
}
for (i = 0; i < prev_count; i++) {
@@ -408,7 +386,9 @@ static CMPI_THREAD_RETURN lifecycle_thre
async_ind(context,
conn,
virDomainGetName(prev_list[i]),
- CS_DELETED);
+ CS_DELETED,
+ prefix,
+ ns);
}
for (i = 0; i < prev_count; i++) {