
On 09/11/2009 01:50 PM, Sharad Mishra wrote:
# HG changeset patch # User snmishra@us.ibm.com # Date 1252684847 25200 # Node ID dd96ae8f1ec71af57012fcb37932d6a7b1f270fa # Parent 74607c71855e6baeeb49bbc134b773acc39675fb Support for resource indication was added to Virt_VirtualSystemManagementService
Code added to call resource indication when resources are added or deleted or modified.
Signed-off-by: Sharad Mishra<snmishra@us.ibm.com>
diff -r 74607c71855e -r dd96ae8f1ec7 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Sep 11 09:00:47 2009 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Fri Sep 11 09:00:47 2009 -0700 @@ -63,6 +63,9 @@ #define BRIDGE_TYPE "bridge" #define NETWORK_TYPE "network" #define USER_TYPE "user" +#define CREATED "ResourceAllocationSettingDataCreatedIndication" +#define DELETED "ResourceAllocationSettingDataDeletedIndication" +#define MODIFIED "ResourceAllocationSettingDataModifiedIndication"
const static CMPIBroker *_BROKER;
@@ -442,7 +445,7 @@ ret = cu_get_str_prop(inst, "VirtualSystemIdentifier",&val); if (ret != CMPI_RC_OK) goto out; - +
Don't add or remove spaces from the code if you don't need to change it.
free(domain->name); domain->name = strdup(val);
@@ -1416,7 +1419,69 @@ return s; }
-static CMPIInstance *create_system(CMPIInstance *vssd, +static CMPIStatus raise_rasd_indication(const CMPIContext *context, + const char *base_type, + CMPIInstance *prev_inst, + const CMPIObjectPath *ref, + struct inst_list *list) +{ + char *type; + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instc = NULL; + CMPIInstance *ind = NULL; + CMPIObjectPath *op = NULL; + int i; + + CU_DEBUG("raise_rasd_indication"); + + type = get_typed_class(CLASSNAME(ref), base_type); + ind = get_typed_instance(_BROKER, + CLASSNAME(ref), + base_type, + NAMESPACE(ref)); + if (ind == NULL) { + CU_DEBUG("Failed to get indication instance"); + s.rc = CMPI_RC_ERR_FAILED; + goto out; + } + + /* PreviousInstance is set only for modify case. */ + if (prev_inst != NULL) + CMSetProperty(ind, + "PreviousInstance", + (CMPIValue *)&prev_inst, + CMPI_instance); + + for (i=0; i< list->cur; i++) { + instc = list->list[i]; + op = CMGetObjectPath(instc, NULL); + CMPIString *str = CMGetClassName(op, NULL); + + CU_DEBUG("class name is %s\n", CMGetCharsPtr(str, NULL)); + + CMSetProperty(ind, + "SourceInstance", + (CMPIValue *)&instc, + CMPI_instance); + set_source_inst_props(_BROKER, context, ref, ind); + + s = stdi_raise_indication(_BROKER, + context, + type, + NAMESPACE(ref), + ind); + } + +out:
Our code style uses a single horizontal space before a label.
+ free(type); + return s; + +} + + +
Our code style uses a single vertical space to separate a functions
+static CMPIInstance *create_system(const CMPIContext *context, + CMPIInstance *vssd, CMPIArray *resources, const CMPIObjectPath *ref, const CMPIObjectPath *refconf, @@ -1427,9 +1492,13 @@ const char *msg = NULL; virConnectPtr conn = NULL; virDomainPtr dom = NULL; + struct inst_list list; + const char *props[] = {NULL};
struct domain *domain = NULL;
+ inst_list_init(&list); + if (refconf != NULL) { *s = get_reference_domain(&domain, ref, refconf); if (s->rc != CMPI_RC_OK) @@ -1477,18 +1546,40 @@ CU_DEBUG("System XML:\n%s", xml);
inst = connect_and_create(xml, ref, s); - if (inst != NULL) + if (inst != NULL) { update_dominfo(domain, CLASSNAME(ref));
+ *s = enum_rasds(_BROKER, + ref, + domain->name, + CIM_RES_TYPE_ALL, + props, +&list); + + if (s->rc != CMPI_RC_OK) { + CU_DEBUG("Failed to enumerate rasd\n"); + goto out; + } + + raise_rasd_indication(context, + CREATED, + NULL, + ref, +&list); + } + + out: cleanup_dominfo(&domain); free(xml); virDomainFree(dom); virConnectClose(conn); + inst_list_free(&list);
return inst; }
+
Remove this space
static bool trigger_indication(const CMPIContext *context, const char *base_type, const CMPIObjectPath *ref) @@ -1530,7 +1621,7 @@ if (s.rc != CMPI_RC_OK) goto out;
- sys = create_system(vssd, res, reference, refconf,&s); + sys = create_system(context, vssd, res, reference, refconf,&s); if (sys == NULL) goto out;
@@ -1564,12 +1655,15 @@ CMPIObjectPath *sys; virConnectPtr conn = NULL; virDomainPtr dom = NULL; + struct inst_list list; + const char *props[] = {NULL};
+ inst_list_init(&list); conn = connect_by_classname(_BROKER, CLASSNAME(reference), &status); if (conn == NULL) { - rc = -1; + rc = IM_RC_NOT_SUPPORTED; goto error; }
@@ -1580,6 +1674,18 @@ if (dom_name == NULL) goto error;
+ status = enum_rasds(_BROKER, + reference, + dom_name, + CIM_RES_TYPE_ALL, + props, +&list); + + if (status.rc != CMPI_RC_OK) { + CU_DEBUG("Failed to enumerate rasd"); + goto error; + } + dom = virDomainLookupByName(conn, dom_name); if (dom == NULL) { CU_DEBUG("No such domain `%s'", dom_name); @@ -1605,11 +1711,17 @@
error: if (rc == IM_RC_SYS_NOT_FOUND) - virt_set_status(_BROKER,&status, + virt_set_status(_BROKER, +&status, CMPI_RC_ERR_NOT_FOUND, conn, "Referenced domain `%s' does not exist", dom_name); + else if (rc == IM_RC_NOT_SUPPORTED) + virt_set_status(_BROKER,&status, + CMPI_RC_ERR_NOT_FOUND, + conn, + "Unable to raise resource indication"); else if (rc == IM_RC_FAILED) virt_set_status(_BROKER,&status, CMPI_RC_ERR_NOT_FOUND, @@ -1617,6 +1729,7 @@ "Unable to retrieve domain name"); else if (rc == IM_RC_OK) { status = (CMPIStatus){CMPI_RC_OK, NULL}; + raise_rasd_indication(context, DELETED, NULL, reference,&list); trigger_indication(context, "ComputerSystemDeletedIndication", reference); @@ -1625,7 +1738,7 @@ virDomainFree(dom); virConnectClose(conn); CMReturnData(results,&rc, CMPI_uint32); - + inst_list_free(&list); return status; }
@@ -2071,7 +2184,8 @@ return s; }
-static CMPIStatus _update_resources_for(const CMPIObjectPath *ref, +static CMPIStatus _update_resources_for(const CMPIContext *context, + const CMPIObjectPath *ref, virDomainPtr dom, const char *devid, CMPIInstance *rasd, @@ -2081,8 +2195,15 @@ struct domain *dominfo = NULL; uint16_t type; char *xml = NULL; + char *indication = NULL; CMPIObjectPath *op; + struct inst_list list; + CMPIInstance *prev_inst = NULL; + const char *props[] = {NULL}; + const char *inst_id; + int i, ret;
+ inst_list_init(&list); if (!get_dominfo(dom,&dominfo)) { virt_set_status(_BROKER,&s, CMPI_RC_ERR_FAILED, @@ -2106,6 +2227,7 @@ goto out; }
+
Remove this vertical space
s = func(dominfo, rasd, type, devid, NAMESPACE(ref)); if (s.rc != CMPI_RC_OK) { CU_DEBUG("Resource transform function failed"); @@ -2116,6 +2238,54 @@ if (xml != NULL) { CU_DEBUG("New XML:\n%s", xml); connect_and_create(xml, ref,&s); + + if (func ==&resource_add) { + indication = strdup(CREATED); + } + else if (func ==&resource_del) { + indication = strdup(DELETED); + } + else { + indication = strdup(MODIFIED); + + s = enum_rasds(_BROKER, + ref, + dominfo->name, + type, + props, +&list); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Failed to enumerate rasd"); + goto out; + } + + for(i=0; i< list.cur; i++) { + prev_inst = list.list[i]; + ret = cu_get_str_prop(prev_inst, + "InstanceID", +&inst_id); + + if (ret != CMPI_RC_OK)
If it fails and you can't leave, at least print a debug message before ignoring the error.
+ continue; + + if (STREQ(inst_id, + get_fq_devid(dominfo->name, + (char *)devid))) + break; + } + + } + + inst_list_init(&list); + if (inst_list_add(&list, rasd) == 0) { + CU_DEBUG("Unable to add RASD instance to the list\n"); + goto out; + } + raise_rasd_indication(context, + indication, + prev_inst, + ref, +&list); } else { cu_statusf(_BROKER,&s, CMPI_RC_ERR_FAILED, @@ -2125,6 +2295,8 @@ out: cleanup_dominfo(&dominfo); free(xml); + free(indication); + inst_list_free(&list);
return s; } @@ -2153,7 +2325,8 @@ return s; }
-static CMPIStatus _update_resource_settings(const CMPIObjectPath *ref, +static CMPIStatus _update_resource_settings(const CMPIContext *context, + const CMPIObjectPath *ref, const char *domain, CMPIArray *resources, const CMPIResult *results, @@ -2208,9 +2381,14 @@ goto end; }
- s = _update_resources_for(ref, dom, devid, inst, func); + s = _update_resources_for(context, + ref, + dom, + devid, + inst, + func);
- end: + end: free(name); free(devid); virDomainFree(dom); @@ -2310,7 +2488,9 @@ return s; }
- if (cu_get_ref_arg(argsin, "AffectedConfiguration",&sys) != CMPI_RC_OK) { + if (cu_get_ref_arg(argsin, + "AffectedConfiguration", +&sys) != CMPI_RC_OK) { cu_statusf(_BROKER,&s, CMPI_RC_ERR_INVALID_PARAMETER, "Missing AffectedConfiguration parameter"); @@ -2324,11 +2504,13 @@ return s; }
- s = _update_resource_settings(reference, + s = _update_resource_settings(context, + reference, domain, arr, results, resource_add); + free(domain);
return s; @@ -2351,7 +2533,8 @@ return s; }
- return _update_resource_settings(reference, + return _update_resource_settings(context, + reference, NULL, arr, results, @@ -2384,7 +2567,8 @@ if (s.rc != CMPI_RC_OK) goto out;
- s = _update_resource_settings(reference, + s = _update_resource_settings(context, + reference, NULL, resource_arr, results,
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com