[Libvirt-cim] [PATCH] Fix VSMS.RemoveResources() to take references instead of EOs

Zhengang Li zli at linux.vnet.ibm.com
Thu Dec 13 01:16:04 UTC 2007


Cool! Thanks for such a quick fix!

Dan Smith wrote:

> # HG changeset patch
> # User Dan Smith <danms at us.ibm.com>
> # Date 1197487329 28800
> # Node ID 59eb8770d96a71707804f26aec48ae76531b005e
> # Parent  b6c16e5a2a347b1e6a6fe314864865a9c6152532
> Fix VSMS.RemoveResources() to take references instead of EOs
> 
> This just adds a filter function that converts the references into
> instances.  It could be more efficient, but I think that allowing all
> of the resource operations to remain largely identical (as they did before)
> is worth the small amount of overhead here.
> 
> Also added REF2STR() macro to misc_util.h.  I do this a lot, mostly
> while testing, but it seems valid to have such a macro so we can start
> printing out more useful error messages with ease.
> 
> Signed-off-by: Dan Smith <danms at us.ibm.com>
> 
> diff -r b6c16e5a2a34 -r 59eb8770d96a libxkutil/misc_util.h
> --- a/libxkutil/misc_util.h	Wed Dec 12 09:42:09 2007 -0800
> +++ b/libxkutil/misc_util.h	Wed Dec 12 11:22:09 2007 -0800
> @@ -129,6 +129,8 @@ CMPIInstance *make_reference(const CMPIB
>                                        assoc);                           \
>          }
> 
> +#define REF2STR(r) CMGetCharPtr(CMObjectPathToString(r, NULL))
> +
>  /*
>   * Local Variables:
>   * mode: C
> diff -r b6c16e5a2a34 -r 59eb8770d96a src/Virt_VirtualSystemManagementService.c
> --- a/src/Virt_VirtualSystemManagementService.c	Wed Dec 12 09:42:09 2007 -0800
> +++ b/src/Virt_VirtualSystemManagementService.c	Wed Dec 12 11:22:09 2007 -0800
> @@ -947,6 +947,59 @@ static CMPIStatus update_resource_settin
>          return s;
>  }
> 
> +static CMPIStatus rasd_refs_to_insts(const CMPIContext *ctx,
> +                                     const CMPIObjectPath *reference,
> +                                     CMPIArray *arr,
> +                                     struct inst_list *list)
> +{
> +        CMPIStatus s;
> +        int i;
> +        int c;
> +
> +        c = CMGetArrayCount(arr, &s);
> +        if (s.rc != CMPI_RC_OK)
> +                return s;
> +
> +        for (i = 0; i < c; i++) {
> +                CMPIData d;
> +                CMPIObjectPath *ref;
> +                CMPIInstance *inst;
> +                const char *id;
> +                uint16_t type;
> +
> +                d = CMGetArrayElementAt(arr, i, &s);
> +                ref = d.value.ref;
> +                if (s.rc != CMPI_RC_OK) {
> +                        CU_DEBUG("Unable to get ResourceSettings[%i]", i);
> +                        continue;
> +                }
> +
> +                if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) {
> +                        CU_DEBUG("Unable to get InstanceID of `%s'",
> +                                 REF2STR(ref));
> +                        continue;
> +                }
> +
> +                if (rasd_type_from_classname(CLASSNAME(ref), &type) !=
> +                    CMPI_RC_OK) {
> +                        CU_DEBUG("Unable to get type of `%s'",
> +                                 REF2STR(ref));
> +                        continue;
> +                }
> +
> +                inst = get_rasd_instance(ctx, reference, _BROKER, id, type);
> +                if (inst != NULL)
> +                        inst_list_add(list, inst);
> +                else
> +                        CU_DEBUG("Failed to get instance for `%s'",
> +                                 REF2STR(ref));
> +        }
> +
> +        CMSetStatus(&s, CMPI_RC_OK);
> +
> +        return s;
> +}
> +
>  static CMPIStatus add_resource_settings(CMPIMethodMI *self,
>                                          const CMPIContext *context,
>                                          const CMPIResult *results,
> @@ -974,7 +1027,32 @@ static CMPIStatus rm_resource_settings(C
>                                         const CMPIArgs *argsin,
>                                         CMPIArgs *argsout)
>  {
> -        return update_resource_settings(reference, argsin, resource_del);
> +        /* The RemoveResources case is different from either Add or
> +         * Modify, because it takes references instead of instances
> +         */
> +
> +        CMPIArray *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,
> +                           CMPI_RC_ERR_FAILED,
> +                           "Missing ResourceSettings");
> +                goto out;
> +        }
> +
> +        s = rasd_refs_to_insts(context, reference, arr, &list);
> +        if (s.rc != CMPI_RC_OK)
> +                goto out;
> +
> +        s = _update_resource_settings(reference, &list, resource_del);
> + out:
> +        inst_list_free(&list);
> +
> +        return s;
>  }
> 
>  static struct method_handler DefineSystem = {
> @@ -1023,7 +1101,7 @@ static struct method_handler RemoveResou
>  static struct method_handler RemoveResourceSettings = {
>          .name = "RemoveResourceSettings",
>          .handler = rm_resource_settings,
> -        .args = {{"ResourceSettings", CMPI_stringA},
> +        .args = {{"ResourceSettings", CMPI_refA},
>                   ARG_END
>          }
>  };
> 
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim


-- 
- Zhengang




More information about the Libvirt-cim mailing list