Wednesday, 30 January
2008
Wed, 30 Jan
'08
3:17 p.m.
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1201727729 28800
# Node ID f5608aab522382af73d5d57578c445590c1fdb10
# Parent b8d69e734306e618b4efb53e23c17ffdd8bab128
Remove the embedded object parsing pieces from VirtualSystemManagmentService.
Remove embedded object parsing since libcmpiutil now handles this. Also update the method
handlers to expect instances instead of strings as arguments.
The following methods have been updated:
DefineSystem
AddResourceSettings
ModifyResourceSettings
ModifySystemSettings
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r b8d69e734306 -r f5608aab5223 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c Wed Jan 30 09:27:27 2008 -0800
+++ b/src/Virt_VirtualSystemManagementService.c Wed Jan 30 13:15:29 2008 -0800
@@ -57,69 +57,23 @@ enum ResourceAction {
RESOURCE_MOD,
};
-static int parse_str_inst_array(CMPIArray *array,
- const char *ns,
- struct inst_list *list)
-{
- int count;
- int i;
-
- count = CMGetArrayCount(array, NULL);
-
- for (i = 0; i < count; i++) {
- CMPIInstance *inst;
- CMPIData item;
- int ret;
-
- item = CMGetArrayElementAt(array, i, NULL);
- /* FIXME: Check for string here */
-
- ret = cu_parse_embedded_instance(CMGetCharPtr(item.value.string),
- _BROKER,
- ns,
- &inst);
-
- if (ret == 0)
- inst_list_add(list, inst);
- }
-
- return 1;
-}
-
static CMPIStatus define_system_parse_args(const CMPIArgs *argsin,
CMPIInstance **sys,
const char *ns,
- struct inst_list *res)
+ CMPIArray **res)
{
CMPIStatus s = {CMPI_RC_ERR_FAILED, NULL};
- const char *sys_str = NULL;
- CMPIArray *res_arr;
- int ret;
-
- if (cu_get_str_arg(argsin, "SystemSettings", &sys_str) !=
CMPI_RC_OK) {
+
+ if (cu_get_inst_arg(argsin, "SystemSettings", sys) != CMPI_RC_OK) {
CU_DEBUG("No SystemSettings string argument");
goto out;
}
- ret = cu_parse_embedded_instance(sys_str,
- _BROKER,
- ns,
- sys);
- if (ret) {
- CU_DEBUG("Unable to parse SystemSettings instance");
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "SystemSettings parse error");
- goto out;
- }
-
- if (cu_get_array_arg(argsin, "ResourceSettings", &res_arr) !=
+ if (cu_get_array_arg(argsin, "ResourceSettings", res) !=
CMPI_RC_OK) {
CU_DEBUG("Failed to get array arg");
goto out;
}
-
- ret = parse_str_inst_array(res_arr, ns, res);
CMSetStatus(&s, CMPI_RC_OK);
@@ -317,24 +271,34 @@ static int rasd_to_vdev(CMPIInstance *in
return 0;
}
-static int classify_resources(struct inst_list *all,
+static int classify_resources(CMPIArray *resources,
struct domain *domain)
{
int i;
uint16_t type;
+ int count;
domain->dev_disk_ct = domain->dev_net_ct = 0;
domain->dev_vcpu_ct = domain->dev_mem_ct = 0;
-
- domain->dev_disk = calloc(all->cur, sizeof(struct virt_device));
- domain->dev_vcpu = calloc(all->cur, sizeof(struct virt_device));
- domain->dev_mem = calloc(all->cur, sizeof(struct virt_device));
- domain->dev_net = calloc(all->cur, sizeof(struct virt_device));
-
- for (i = 0; i < all->cur; i++) {
+
+ count = CMGetArrayCount(resources, NULL);
+ if (count < 1)
+ return 0;
+
+ domain->dev_disk = calloc(count, sizeof(struct virt_device));
+ domain->dev_vcpu = calloc(count, sizeof(struct virt_device));
+ domain->dev_mem = calloc(count, sizeof(struct virt_device));
+ domain->dev_net = calloc(count, sizeof(struct virt_device));
+
+ for (i = 0; i < count; i++) {
CMPIObjectPath *op;
-
- op = CMGetObjectPath(all->list[i], NULL);
+ CMPIData item;
+
+ item = CMGetArrayElementAt(resources, i, NULL);
+ if (CMIsNullObject(item.value.inst))
+ return 0;
+
+ op = CMGetObjectPath(item.value.inst, NULL);
if (op == NULL)
return 0;
@@ -343,16 +307,16 @@ static int classify_resources(struct ins
return 0;
if (type == CIM_RASD_TYPE_PROC)
- rasd_to_vdev(all->list[i],
+ rasd_to_vdev(item.value.inst,
&domain->dev_vcpu[domain->dev_vcpu_ct++]);
else if (type == CIM_RASD_TYPE_MEM)
- rasd_to_vdev(all->list[i],
+ rasd_to_vdev(item.value.inst,
&domain->dev_mem[domain->dev_mem_ct++]);
else if (type == CIM_RASD_TYPE_DISK)
- rasd_to_vdev(all->list[i],
+ rasd_to_vdev(item.value.inst,
&domain->dev_disk[domain->dev_disk_ct++]);
else if (type == CIM_RASD_TYPE_NET)
- rasd_to_vdev(all->list[i],
+ rasd_to_vdev(item.value.inst,
&domain->dev_net[domain->dev_net_ct++]);
}
@@ -398,7 +362,7 @@ static CMPIInstance *connect_and_create(
}
static CMPIInstance *create_system(CMPIInstance *vssd,
- struct inst_list *resources,
+ CMPIArray *resources,
const CMPIObjectPath *ref,
CMPIStatus *s)
{
@@ -467,10 +431,8 @@ static CMPIStatus define_system(CMPIMeth
CMPIInstance *vssd;
CMPIInstance *sys;
CMPIObjectPath *sys_op;
- struct inst_list res;
+ CMPIArray *res;
CMPIStatus s;
-
- inst_list_init(&res);
CU_DEBUG("DefineSystem");
@@ -478,11 +440,9 @@ static CMPIStatus define_system(CMPIMeth
if (s.rc != CMPI_RC_OK)
goto out;
- sys = create_system(vssd, &res, reference, &s);
+ sys = create_system(vssd, res, reference, &s);
if (sys == NULL)
goto out;
-
- inst_list_free(&res);
CMAddArg(argsout, "ResultingSystem", &sys, CMPI_instance);
@@ -623,27 +583,14 @@ static CMPIStatus mod_system_settings(CM
const CMPIArgs *argsin,
CMPIArgs *argsout)
{
- const char *inst_str;
CMPIInstance *inst;
- if (cu_get_str_arg(argsin, "SystemSettings", &inst_str) !=
CMPI_RC_OK) {
+ if (cu_get_inst_arg(argsin, "SystemSettings", &inst) != CMPI_RC_OK)
{
CMPIStatus s;
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
"Missing SystemSettings");
- return s;
- }
-
- if (cu_parse_embedded_instance(inst_str,
- _BROKER,
- NAMESPACE(reference),
- &inst)) {
- CMPIStatus s;
-
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Internal Parse Error on SystemSettings");
return s;
}
@@ -953,23 +900,30 @@ static CMPIStatus _update_resources_for(
}
static CMPIStatus _update_resource_settings(const CMPIObjectPath *ref,
- struct inst_list *list,
+ CMPIArray *resources,
resmod_fn func)
{
int i;
virConnectPtr conn = NULL;
CMPIStatus s;
+ int count;
conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
if (conn == NULL)
goto out;
- for (i = 0; i < list->cur; i++) {
- CMPIInstance *inst = list->list[i];
+ count = CMGetArrayCount(resources, NULL);
+
+ for (i = 0; i < count; i++) {
+ CMPIData item;
+ CMPIInstance *inst;
const char *id = NULL;
char *name = NULL;
char *devid = NULL;
virDomainPtr dom = NULL;
+
+ item = CMGetArrayElementAt(resources, i, NULL);
+ inst = item.value.inst;
if (cu_get_str_prop(inst, "InstanceID", &id) != CMPI_RC_OK)
{
cu_statusf(_BROKER, &s,
@@ -1027,9 +981,7 @@ static CMPIStatus update_resource_settin
goto out;
}
- parse_str_inst_array(arr, NAMESPACE(ref), &list);
-
- s = _update_resource_settings(ref, &list, func);
+ s = _update_resource_settings(ref, arr, func);
out:
inst_list_free(&list);
@@ -1040,7 +992,7 @@ static CMPIStatus rasd_refs_to_insts(con
static CMPIStatus rasd_refs_to_insts(const CMPIContext *ctx,
const CMPIObjectPath *reference,
CMPIArray *arr,
- struct inst_list *list)
+ CMPIArray **out_arr)
{
CMPIStatus s;
int i;
@@ -1049,6 +1001,11 @@ static CMPIStatus rasd_refs_to_insts(con
c = CMGetArrayCount(arr, &s);
if (s.rc != CMPI_RC_OK)
return s;
+
+ *out_arr = CMNewArray(_BROKER,
+ c,
+ CMPI_instance,
+ &s);
for (i = 0; i < c; i++) {
CMPIData d;
@@ -1079,7 +1036,9 @@ static CMPIStatus rasd_refs_to_insts(con
inst = get_rasd_instance(ctx, reference, _BROKER, id, type);
if (inst != NULL)
- inst_list_add(list, inst);
+ CMSetArrayElementAt(*out_arr, i,
+ &inst,
+ CMPI_instance);
else
CU_DEBUG("Failed to get instance for `%s'",
REF2STR(ref));
@@ -1122,10 +1081,8 @@ static CMPIStatus rm_resource_settings(C
*/
CMPIArray *arr;
+ CMPIArray *resource_arr;
CMPIStatus s;
- struct inst_list list;
-
- inst_list_init(&list);
if (cu_get_array_arg(argsin, "ResourceSettings", &arr) !=
CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
@@ -1134,22 +1091,20 @@ static CMPIStatus rm_resource_settings(C
goto out;
}
- s = rasd_refs_to_insts(context, reference, arr, &list);
+ s = rasd_refs_to_insts(context, reference, arr, &resource_arr);
if (s.rc != CMPI_RC_OK)
goto out;
- s = _update_resource_settings(reference, &list, resource_del);
- out:
- inst_list_free(&list);
-
+ s = _update_resource_settings(reference, resource_arr, resource_del);
+ out:
return s;
}
static struct method_handler DefineSystem = {
.name = "DefineSystem",
.handler = define_system,
- .args = {{"SystemSettings", CMPI_string},
- {"ResourceSettings", CMPI_stringA},
+ .args = {{"SystemSettings", CMPI_instance},
+ {"ResourceSettings", CMPI_instanceA},
{"ReferencedConfiguration", CMPI_string},
ARG_END
}
@@ -1167,7 +1122,7 @@ static struct method_handler AddResource
.name = "AddResourceSettings",
.handler = add_resource_settings,
.args = {{"AffectedConfiguration", CMPI_ref},
- {"ResourceSettings", CMPI_stringA},
+ {"ResourceSettings", CMPI_instanceA},
ARG_END
}
};
@@ -1175,7 +1130,7 @@ static struct method_handler ModifyResou
static struct method_handler ModifyResourceSettings = {
.name = "ModifyResourceSettings",
.handler = mod_resource_settings,
- .args = {{"ResourceSettings", CMPI_stringA},
+ .args = {{"ResourceSettings", CMPI_instanceA},
ARG_END
}
};
@@ -1183,7 +1138,7 @@ static struct method_handler ModifySyste
static struct method_handler ModifySystemSettings = {
.name = "ModifySystemSettings",
.handler = mod_system_settings,
- .args = {{"SystemSettings", CMPI_string},
+ .args = {{"SystemSettings", CMPI_instance},
ARG_END
}
};