[PATCH 0 of 6] Add a new resource indication provider.

This provider will raise resource indication whenever resource(s) are created, deleted or modified. Signed-off-by: Sharad Mishra <snmishra@us.ibm.com>

# HG changeset patch # User snmishra@us.ibm.com # Date 1252684847 25200 # Node ID 92570a0539103628c8ccf0166983e9d85bb7431d # Parent f4e1a60c1d64888c6f8e53c9ed4ea15651825a69 Add resource indication feature Makefile changes. MOF and Registration files for the resource indication provider were added. Changes were made to src/Makefile.am to build resource indication provider. Signed-off-by: Sharad Mishra <snmishra@us.ibm.com> diff -r f4e1a60c1d64 -r 92570a053910 Makefile.am --- a/Makefile.am Fri Sep 04 14:12:46 2009 -0700 +++ b/Makefile.am Fri Sep 11 09:00:47 2009 -0700 @@ -27,6 +27,7 @@ schema/RegisteredProfile.mof \ schema/ElementConformsToProfile.mof \ schema/ComputerSystemIndication.mof \ + schema/ResourceAllocationSettingDataIndication.mof \ schema/ComputerSystemMigrationIndication.mof \ schema/Virt_ResourceAllocationSettingData.mof \ schema/ResourceAllocationSettingData.mof \ @@ -101,6 +102,7 @@ schema/DiskPool.registration \ schema/HostedResourcePool.registration \ schema/ComputerSystemIndication.registration \ + schema/ResourceAllocationSettingDataIndication.registration \ schema/ComputerSystemMigrationIndication.registration \ schema/ResourceAllocationSettingData.registration \ schema/ResourcePoolConfigurationService.registration \ diff -r f4e1a60c1d64 -r 92570a053910 src/Makefile.am --- a/src/Makefile.am Fri Sep 04 14:12:46 2009 -0700 +++ b/src/Makefile.am Fri Sep 11 09:00:47 2009 -0700 @@ -48,6 +48,7 @@ libVirt_VirtualSystemSnapshotServiceCapabilities.la \ libVirt_SystemDevice.la \ libVirt_ComputerSystemIndication.la \ + libVirt_ResourceAllocationSettingDataIndication.la \ libVirt_ComputerSystemMigrationIndication.la \ libVirt_VirtualSystemManagementCapabilities.la \ libVirt_AllocationCapabilities.la \ @@ -86,6 +87,10 @@ libVirt_ComputerSystemIndication_la_SOURCES = Virt_ComputerSystemIndication.c libVirt_ComputerSystemIndication_la_LIBADD = -lVirt_ComputerSystem -lVirt_HostSystem -lpthread -lrt +libVirt_ResourceAllocationSettingDataIndication_la_DEPENDENCIES = libVirt_ComputerSystem.la +libVirt_ResourceAllocationSettingDataIndication_la_SOURCES = Virt_ResourceAllocationSettingDataIndication.c +libVirt_ResourceAllocationSettingDataIndication_la_LIBADD = -lVirt_ComputerSystem + libVirt_ComputerSystemMigrationIndication_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ComputerSystemMigrationIndication_la_SOURCES = Virt_ComputerSystemMigrationIndication.c libVirt_ComputerSystemMigrationIndication_la_LIBADD = -lVirt_ComputerSystem

# HG changeset patch # User snmishra@us.ibm.com # Date 1252684847 25200 # Node ID 44e2c3144f199c7e552e3f5066186289b424b5db # Parent 92570a0539103628c8ccf0166983e9d85bb7431d Modify Virt_CS so set_source-inst_props() can be used by other providers. Signed-off-by: Sharad Mishra <snmishra@us.ibm.com> diff -r 92570a053910 -r 44e2c3144f19 src/Virt_ComputerSystemIndication.c --- a/src/Virt_ComputerSystemIndication.c Fri Sep 11 09:00:47 2009 -0700 +++ b/src/Virt_ComputerSystemIndication.c Fri Sep 11 09:00:47 2009 -0700 @@ -192,9 +192,9 @@ return ret; } -static void set_source_inst_props(const CMPIBroker *broker, +void set_source_inst_props(const CMPIBroker *broker, const CMPIContext *context, - CMPIObjectPath *ref, + const CMPIObjectPath *ref, CMPIInstance *ind) { const char *host; diff -r 92570a053910 -r 44e2c3144f19 src/Virt_ComputerSystemIndication.h --- a/src/Virt_ComputerSystemIndication.h Fri Sep 11 09:00:47 2009 -0700 +++ b/src/Virt_ComputerSystemIndication.h Fri Sep 11 09:00:47 2009 -0700 @@ -29,6 +29,10 @@ const CMPIObjectPath *newsystem, char *type); +void set_source_inst_props(const CMPIBroker *broker, + const CMPIContext *context, + const CMPIObjectPath *ref, + CMPIInstance *ind); #endif /*

# HG changeset patch # User snmishra@us.ibm.com # Date 1252684847 25200 # Node ID 74607c71855e6baeeb49bbc134b773acc39675fb # Parent 44e2c3144f199c7e552e3f5066186289b424b5db Modify Virt_RASD so that rasd_from_vdev() can be used by other providers. Signed-off-by: Sharad Mishra <snmishra@us.ibm.com> diff -r 44e2c3144f19 -r 74607c71855e src/Virt_RASD.c --- a/src/Virt_RASD.c Fri Sep 11 09:00:47 2009 -0700 +++ b/src/Virt_RASD.c Fri Sep 11 09:00:47 2009 -0700 @@ -368,7 +368,7 @@ return s; } -static CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, +CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, struct virt_device *dev, const char *host, const CMPIObjectPath *ref, diff -r 44e2c3144f19 -r 74607c71855e src/Virt_RASD.h --- a/src/Virt_RASD.h Fri Sep 11 09:00:47 2009 -0700 +++ b/src/Virt_RASD.h Fri Sep 11 09:00:47 2009 -0700 @@ -66,6 +66,13 @@ const uint16_t type, const char *host, struct virt_device **list); + +CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, + struct virt_device *dev, + const char *host, + const CMPIObjectPath *ref, + const char **properties); + #endif /*

# 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; - + 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: + free(type); + return s; + +} + + + +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; } + 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; } + 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) + 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,

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

+#define CREATED "ResourceAllocationSettingDataCreatedIndication" +#define DELETED "ResourceAllocationSettingDataDeletedIndication" +#define MODIFIED "ResourceAllocationSettingDataModifiedIndication"
These are generic names - can you make them more specific to RASD indications?
+ else if (rc == IM_RC_NOT_SUPPORTED) + virt_set_status(_BROKER, &status, + CMPI_RC_ERR_NOT_FOUND, + conn, + "Unable to raise resource indication");
IM_RC_NOT_SUPPORTED is set because a connection to libvirt cannot be made. Can you change the error message here to reflect this?
else if (rc == IM_RC_FAILED) virt_set_status(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND,
@@ -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++) {
Space needed between i and =, also between = and 0.
+ prev_inst = list.list[i]; + ret = cu_get_str_prop(prev_inst, + "InstanceID", + &inst_id); + + if (ret != CMPI_RC_OK) + continue; + + if (STREQ(inst_id, + get_fq_devid(dominfo->name, + (char *)devid))) + break; + }
Can you break this out into a separate function? There's lots of indention here, an this else statement makes the function quite long.
+ + } + + 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);
Why not make indication a const char *? Then you wouldn't need to free it. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User snmishra@us.ibm.com # Date 1252687743 25200 # Node ID 18b62ae07a118517ae81529fa8a9c10757a02a9b # Parent dd96ae8f1ec71af57012fcb37932d6a7b1f270fa Add the mof and reg files needed to register the resource indication provider Signed-off-by: Sharad Mishra <snmishra@us.ibm.com> diff -r dd96ae8f1ec7 -r 18b62ae07a11 schema/ResourceAllocationSettingDataIndication.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ResourceAllocationSettingDataIndication.mof Fri Sep 11 09:49:03 2009 -0700 @@ -0,0 +1,66 @@ +// Copyright IBM Corp. 2007 + +[Description ("Xen_ResourceAllocationSettingData created"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class Xen_ResourceAllocationSettingDataCreatedIndication : CIM_InstCreation +{ +}; + +[Description ("Xen_ResourceAllocationSettingData deleted"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class Xen_ResourceAllocationSettingDataDeletedIndication : CIM_InstDeletion +{ +}; + +[Description ("Xen_ResourceAllocationSettingData modified"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class Xen_ResourceAllocationSettingDataModifiedIndication : CIM_InstModification +{ +}; + + +[Description ("KVM_ResourceAllocationSettingData created"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class KVM_ResourceAllocationSettingDataCreatedIndication : CIM_InstCreation +{ +}; + +[Description ("KVM_ResourceAllocationSettingData deleted"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class KVM_ResourceAllocationSettingDataDeletedIndication : CIM_InstDeletion +{ +}; + +[Description ("KVM_ResourceAllocationSettingData modified"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class KVM_ResourceAllocationSettingDataModifiedIndication : CIM_InstModification +{ +}; + + +[Description ("LXC_ResourceAllocationSettingData created"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class LXC_ResourceAllocationSettingDataCreatedIndication : CIM_InstCreation +{ +}; + +[Description ("LXC_ResourceAllocationSettingData deleted"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class LXC_ResourceAllocationSettingDataDeletedIndication : CIM_InstDeletion +{ +}; + +[Description ("LXC_ResourceAllocationSettingData modified"), + Provider("cmpi::Virt_ResourceAllocationSettingDataIndication") +] +class LXC_ResourceAllocationSettingDataModifiedIndication : CIM_InstModification +{ +}; diff -r dd96ae8f1ec7 -r 18b62ae07a11 schema/ResourceAllocationSettingDataIndication.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ResourceAllocationSettingDataIndication.registration Fri Sep 11 09:49:03 2009 -0700 @@ -0,0 +1,11 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_ResourceAllocationSettingDataCreatedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +Xen_ResourceAllocationSettingDataDeletedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +Xen_ResourceAllocationSettingDataModifiedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +KVM_ResourceAllocationSettingDataCreatedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +KVM_ResourceAllocationSettingDataDeletedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +KVM_ResourceAllocationSettingDataModifiedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +LXC_ResourceAllocationSettingDataCreatedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +LXC_ResourceAllocationSettingDataDeletedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method +LXC_ResourceAllocationSettingDataModifiedIndication root/virt Virt_ResourceAllocationSettingDataIndicationProvider Virt_ResourceAllocationSettingDataIndication indication method

# HG changeset patch # User snmishra@us.ibm.com # Date 1252687805 25200 # Node ID 43076113ae79f638317b0b7a0669c59a864e7904 # Parent 18b62ae07a118517ae81529fa8a9c10757a02a9b Add resource indication provider. Signed-off-by: Sharad Mishra <snmishra@us.ibm.com> diff -r 18b62ae07a11 -r 43076113ae79 src/Virt_ResourceAllocationSettingDataIndication.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_ResourceAllocationSettingDataIndication.c Fri Sep 11 09:50:05 2009 -0700 @@ -0,0 +1,155 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Sharad Mishra <snmishra@us.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <stdio.h> +#include <string.h> + +#include <cmpidt.h> +#include <cmpift.h> +#include <cmpimacs.h> + +#include <libvirt/libvirt.h> +#include <libcmpiutil/libcmpiutil.h> +#include <libcmpiutil/std_indication.h> +#include <misc_util.h> +#include <cs_util.h> + +static const CMPIBroker *_BROKER; + +DECLARE_FILTER(xen_created, + "Xen_ResourceAllocationSettingDataCreatedIndication"); +DECLARE_FILTER(xen_deleted, + "Xen_ResourceAllocationSettingDataDeletedIndication"); +DECLARE_FILTER(xen_modified, + "Xen_ResourceAllocationSettingDataModifiedIndication"); +DECLARE_FILTER(kvm_created, + "KVM_ResourceAllocationSettingDataCreatedIndication"); +DECLARE_FILTER(kvm_deleted, + "KVM_ResourceAllocationSettingDataDeletedIndication"); +DECLARE_FILTER(kvm_modified, + "KVM_ResourceAllocationSettingDataModifiedIndication"); +DECLARE_FILTER(lxc_created, + "LXC_ResourceAllocationSettingDataCreatedIndication"); +DECLARE_FILTER(lxc_deleted, + "LXC_ResourceAllocationSettingDataDeletedIndication"); +DECLARE_FILTER(lxc_modified, + "LXC_ResourceAllocationSettingDataModifiedIndication"); + +static struct std_ind_filter *filters[] = { + &xen_created, + &xen_deleted, + &xen_modified, + &kvm_created, + &kvm_deleted, + &kvm_modified, + &lxc_created, + &lxc_deleted, + &lxc_modified, + NULL, +}; + + +static CMPIStatus raise_indication(const CMPIBroker *broker, + const CMPIContext *ctx, + const CMPIInstance *ind) +{ + struct std_indication_ctx *_ctx = NULL; + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct ind_args *args = NULL; + CMPIObjectPath *ref = NULL; + + _ctx = malloc(sizeof(struct std_indication_ctx)); + if (_ctx == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to allocate indication context"); + goto out; + } + + _ctx->brkr = broker; + _ctx->handler = NULL; + _ctx->filters = filters; + _ctx->enabled = 1; + + args = malloc(sizeof(struct ind_args)); + if (args == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to allocate ind_args"); + goto out; + } + + ref = CMGetObjectPath(ind, &s); + if (ref == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Got a null object path"); + goto out; + } + + /* FIXME: This is a Pegasus work around. Pegsus loses the namespace + when an ObjectPath is pulled from an instance */ + + + CMSetNameSpace(ref, "root/virt"); + args->ns = strdup(NAMESPACE(ref)); + args->classname = strdup(CLASSNAME(ref)); + args->_ctx = _ctx; + + s = stdi_deliver(broker, ctx, args, (CMPIInstance *)ind); + if (s.rc == CMPI_RC_OK) { + CU_DEBUG("Indication delivered"); + } else { + CU_DEBUG("Not delivered: %s", CMGetCharPtr(s.msg)); + } + + out: + return s; +} + +static struct std_indication_handler rasdi = { + .raise_fn = raise_indication, + .trigger_fn = NULL, + .activate_fn = NULL, + .deactivate_fn = NULL, + .enable_fn = NULL, + .disable_fn = NULL, +}; + +DEFAULT_IND_CLEANUP(); +DEFAULT_AF(); +DEFAULT_MP(); + +STDI_IndicationMIStub(, + Virt_ResourceAllocationSettingDataIndicationProvider, + _BROKER, + libvirt_cim_init(), + &rasdi, + filters); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */

Sharad Mishra wrote:
# HG changeset patch # User snmishra@us.ibm.com
Can you fix your user id? You can do this by modifying your ~/.hgrc: Add / modify the following: [ui] username = Kaitlin Rupert <karupert@us.ibm.com> Thanks!
# Date 1252687805 25200 # Node ID 43076113ae79f638317b0b7a0669c59a864e7904 # Parent 18b62ae07a118517ae81529fa8a9c10757a02a9b Add resource indication provider.
Signed-off-by: Sharad Mishra <snmishra@us.ibm.com>
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Kaitlin Rupert
-
Richard Maciel
-
Sharad Mishra