[PATCH 0 of 2] (#3) [CU] Migration Indication libcmpiutil changes

One last fix to cu_dup_instances, and this should be good to go.

# HG changeset patch # User Jay Gagnon <grendel@linux.vnet.ibm.com> # Date 1202245292 18000 # Node ID 493b8a943286a780e2fb7c2829cd49e60ccaa264 # Parent ab0e3b05a10e7b5db7eb493920f01bb402d2feae [CU] Add dup_instance function to libcmpiutil It appears there are some situations where we have to duplicate an instance; this seemed like the kind of thing that would belong in libcmpiutil. Changes from #1 to #2: cu dup_instance returns instance, sets status using pointer cu_dup_instance copies all properties Changes from #2 to #3: use CMGetCharPtr instead of doing char * cast manually Signed-off-by: Jay Gagnon <grendel@linux.vnet.ibm.com> diff -r ab0e3b05a10e -r 493b8a943286 instance_util.c --- a/instance_util.c Wed Jan 30 11:15:32 2008 -0800 +++ b/instance_util.c Tue Feb 05 16:01:32 2008 -0500 @@ -202,6 +202,55 @@ CMPIStatus cu_copy_prop(const CMPIBroker out: return s; +} + +CMPIInstance *cu_dup_instance(const CMPIBroker *broker, + CMPIInstance *src, + CMPIStatus *s) +{ + int i; + int prop_count; + CMPIData data; + CMPIObjectPath *ref; + CMPIInstance *dest = NULL; + + ref = CMGetObjectPath(src, NULL); + if ((s->rc != CMPI_RC_OK) || CMIsNullObject(ref)) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Could not get objectpath from instance"); + goto out; + } + + dest = CMNewInstance(broker, ref, s); + + prop_count = CMGetPropertyCount(src, s); + if (s->rc != CMPI_RC_OK) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Could not get property count for copy"); + goto out; + } + + for (i = 0; i < prop_count; i++) { + CMPIString *prop; + char *prop_name; + + data = CMGetPropertyAt(src, i, &prop, s); + prop_name = CMGetCharPtr(prop); + if (s->rc != CMPI_RC_OK) { + goto out; + } + + *s = CMSetProperty(dest, prop_name, + &(data.value), data.type); + if (s->rc != CMPI_RC_OK) { + goto out; + } + } + + out: + return dest; } /* diff -r ab0e3b05a10e -r 493b8a943286 libcmpiutil.h --- a/libcmpiutil.h Wed Jan 30 11:15:32 2008 -0800 +++ b/libcmpiutil.h Tue Feb 05 16:01:32 2008 -0500 @@ -164,6 +164,18 @@ CMPIrc cu_get_u16_path(const CMPIObjectP CMPIrc cu_get_u16_path(const CMPIObjectPath *reference, const char *key, uint16_t *target); + +/** + * Create a copy of an instance + * + * @param src Source instance + * @param dest Destination instance + * @returns {CMPI_RC_OK, NULL} if success, CMPI_RC ERR_FAILED and + * error message otherwise + */ +CMPIInstance *cu_dup_instance(const CMPIBroker *broker, + CMPIInstance *src, + CMPIStatus *s); /* Forward declaration */ struct inst_list;

Jay Gagnon wrote:
+ for (i = 0; i < prop_count; i++) { + CMPIString *prop; + char *prop_name; + + data = CMGetPropertyAt(src, i, &prop, s); + prop_name = CMGetCharPtr(prop); + if (s->rc != CMPI_RC_OK) { + goto out; + } + + *s = CMSetProperty(dest, prop_name, + &(data.value), data.type); + if (s->rc != CMPI_RC_OK) { + goto out; + } + } + + out: + return dest; }
It's probably worth pointing out that CMGetCharPtr simply does the casting for me; there is no strdup, so I believe it is not necessary to free prop_name here. I only say this because up until today when I looked it up, if I saw someone using CMGetCharPtr, I would have asked where the free is. -- -Jay

JG> It's probably worth pointing out that CMGetCharPtr simply does the JG> casting for me; there is no strdup, so I believe it is not JG> necessary to free prop_name here. I only say this because up JG> until today when I looked it up, if I saw someone using JG> CMGetCharPtr, I would have asked where the free is. Correct, no free() needed. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Jay Gagnon <grendel@linux.vnet.ibm.com> # Date 1202245300 18000 # Node ID c544bc4a7470f80f53765f1eeac344ffba946969 # Parent 493b8a943286a780e2fb7c2829cd49e60ccaa264 [CU] Improve std_indication's raise functionality Turns out STDI_IndicationMIStub was not creating the CMPIFooMIFTs correctly; this patch fixes that. It also adds a default_raise function to std_indication. This is for indication providers that don't need to do anything other than call CBDeliverIndication, which will most likely be the majority. Signed-off-by: Jay Gagnon <grendel@linux.vnet.ibm.com> diff -r 493b8a943286 -r c544bc4a7470 std_indication.c --- a/std_indication.c Tue Feb 05 16:01:32 2008 -0500 +++ b/std_indication.c Tue Feb 05 16:01:40 2008 -0500 @@ -19,6 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <string.h> +#include <stdbool.h> #include <cmpidt.h> #include <cmpift.h> @@ -40,19 +41,40 @@ static CMPIStatus trigger(struct std_ind return ctx->handler->trigger_fn(context); } +static CMPIStatus default_raise(const CMPIBroker *broker, + const CMPIContext *context, + CMPIInstance *ind) +{ + CMPIObjectPath *ref; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + ref = CMGetObjectPath(ind, NULL); + + CBDeliverIndication(broker, + context, + NAMESPACE(ref), + ind); + return s; +} + static CMPIStatus raise(struct std_indication_ctx *ctx, const CMPIContext *context, const CMPIArgs *argsin) { CMPIInstance *inst; - if (ctx->handler->raise_fn == NULL) - return (CMPIStatus){CMPI_RC_OK, NULL}; + if (!ctx->enabled) { + CU_DEBUG("Indication disabled, not raising."); + return (CMPIStatus) {CMPI_RC_OK, NULL}; + } if (cu_get_inst_arg(argsin, "Indication", &inst) != CMPI_RC_OK) return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL}; - return ctx->handler->raise_fn(context, inst); + if (ctx->handler->raise_fn == NULL) + return default_raise(ctx->brkr, context, inst); + + return ctx->handler->raise_fn(ctx->brkr, context, inst); } CMPIStatus stdi_handler(CMPIMethodMI *self, diff -r 493b8a943286 -r c544bc4a7470 std_indication.h --- a/std_indication.h Tue Feb 05 16:01:32 2008 -0500 +++ b/std_indication.h Tue Feb 05 16:01:40 2008 -0500 @@ -24,6 +24,7 @@ #include <cmpidt.h> #include <cmpift.h> #include <cmpimacs.h> +#include <stdio.h> #include "libcmpiutil.h" #include "std_invokemethod.h" @@ -51,7 +52,8 @@ CMPIStatus stdi_cleanup(CMPIMethodMI *se const CMPIContext *context, CMPIBoolean terminating); -typedef CMPIStatus (*raise_indication_t)(const CMPIContext *ctx, +typedef CMPIStatus (*raise_indication_t)(const CMPIBroker *broker, + const CMPIContext *ctx, const CMPIInstance *ind); typedef CMPIStatus (*trigger_indication_t)(const CMPIContext *ctx); @@ -64,14 +66,44 @@ struct std_indication_ctx { struct std_indication_ctx { const CMPIBroker *brkr; struct std_indication_handler *handler; + bool enabled; }; #define STDI_IndicationMIStub(pfx, pn, _broker, hook, _handler) \ + static struct std_indication_ctx _ctx = { \ + .brkr = NULL, \ + .handler = _handler, \ + .enabled = false, \ + }; \ + \ + static CMPIIndicationMIFT indMIFT__ = { \ + CMPICurrentVersion, \ + CMPICurrentVersion, \ + "Indication" #pn, \ + pfx##IndicationCleanup, \ + pfx##AuthorizeFilter, \ + pfx##MustPoll, \ + pfx##ActivateFilter, \ + pfx##DeActivateFilter, \ + CMIndicationMIStubExtensions(pfx) \ + }; \ CMPIIndicationMI * \ pn##_Create_IndicationMI(const CMPIBroker *, \ - const CMPIContext *, \ - CMPIStatus *); \ - CMIndicationMIStub(pfx, pn, _broker, hook); \ + const CMPIContext *, \ + CMPIStatus *); \ + CMPIIndicationMI * \ + pn##_Create_IndicationMI(const CMPIBroker *brkr, \ + const CMPIContext *ctx, \ + CMPIStatus *rc) { \ + static CMPIIndicationMI mi = { \ + &_ctx, \ + &indMIFT__, \ + }; \ + _ctx.brkr = brkr; \ + _broker = brkr; \ + hook; \ + return &mi; \ + } \ \ static CMPIMethodMIFT methMIFT__ = { \ CMPICurrentVersion, \ @@ -88,13 +120,11 @@ struct std_indication_ctx { CMPIMethodMI *pn##_Create_MethodMI(const CMPIBroker *brkr, \ const CMPIContext *ctx, \ CMPIStatus *rc) { \ - static struct std_indication_ctx _ctx; \ static CMPIMethodMI mi = { \ &_ctx, \ &methMIFT__, \ }; \ _ctx.brkr = brkr; \ - _ctx.handler = _handler; \ _broker = brkr; \ hook; \ return &mi; \

Jay Gagnon wrote:
# HG changeset patch # User Jay Gagnon <grendel@linux.vnet.ibm.com> # Date 1202245300 18000 # Node ID c544bc4a7470f80f53765f1eeac344ffba946969 # Parent 493b8a943286a780e2fb7c2829cd49e60ccaa264 [CU] Improve std_indication's raise functionality
Turns out STDI_IndicationMIStub was not creating the CMPIFooMIFTs correctly; this patch fixes that. It also adds a default_raise function to std_indication. This is for indication providers that don't need to do anything other than call CBDeliverIndication, which will most likely be the majority.
Signed-off-by: Jay Gagnon <grendel@linux.vnet.ibm.com>
Sorry, but I can not apply this patch to the latest libcmpiutil. Am I missing something ? -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

Heidi Eckhart wrote:
Jay Gagnon wrote:
# HG changeset patch # User Jay Gagnon <grendel@linux.vnet.ibm.com> # Date 1202245300 18000 # Node ID c544bc4a7470f80f53765f1eeac344ffba946969 # Parent 493b8a943286a780e2fb7c2829cd49e60ccaa264 [CU] Improve std_indication's raise functionality
Turns out STDI_IndicationMIStub was not creating the CMPIFooMIFTs correctly; this patch fixes that. It also adds a default_raise function to std_indication. This is for indication providers that don't need to do anything other than call CBDeliverIndication, which will most likely be the majority.
Signed-off-by: Jay Gagnon <grendel@linux.vnet.ibm.com>
Sorry, but I can not apply this patch to the latest libcmpiutil. Am I missing something ?
I just made sure my local tree was up to date and it looks like Dan applied the raise functionality patch last time, since that one was not dependent on the others and there were no issues with it. Did you get something like this when you tried to apply? 2 out of 2 hunks ignored -- saving rejects to file std_indication.c.rej 4 out of 4 hunks ignored -- saving rejects to file std_indication.h.rej That's what I got, and when I checked the changesets that had been added in my last update I noticed the raise functionality patch was already in. -- -Jay

Jay Gagnon wrote:
2 out of 2 hunks ignored -- saving rejects to file std_indication.c.rej 4 out of 4 hunks ignored -- saving rejects to file std_indication.h.rej
That's what I got, and when I checked the changesets that had been added in my last update I noticed the raise functionality patch was already in.
Yes, that's exactly what I got. So fine. Then everything is ok :). Thanks. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor
participants (4)
-
Dan Smith
-
Heidi Eckhart
-
Jay Gagnon
-
Kaitlin Rupert