[Libvirt-cim] [PATCH 3 of 3] Migration Job Indication

Jay Gagnon grendel at linux.vnet.ibm.com
Fri Mar 7 15:00:55 UTC 2008


# HG changeset patch
# User Jay Gagnon <grendel at linux.vnet.ibm.com>
# Date 1204901289 18000
# Node ID 1ccab6e9470c08a4dd6f411078325d3574cd9abf
# Parent  38cd28b072e3416714053bd049c91a55fca9c0c3
Migration Job Indication

We need to add some more indication to VS_MigrationService.  ComputerSystemMigrationIndication is getting broken up into ComputerSystemMigrationJob[Created|Modified|Deleted]Indication, so that we can give clients that did not initiate the migration a better idea of what's going on.  Each migration will fire a couple additional indications now.

Changes required to make this happen:
Enumeration of supported indication types.
A new function ind_type_to_name.  Converts int from the enumeration to an indication name.
A new function ref_from_job (migration_job struct -> objectpath).  This is mainly existing functionality but is now needed in two places.
A new function raise_deleted_ind.  The work required to raise the Deleted indication was cluttering up migrate_vs so I broke it out.
Changes to prepare_indication and raise_indication to accomodate the new indication types.
Then of course a few lines to actually use the new stuff.


Signed-off-by: Jay Gagnon <grendel at linux.vnet.ibm.com>

diff -r 38cd28b072e3 -r 1ccab6e9470c src/Virt_VSMigrationService.c
--- a/src/Virt_VSMigrationService.c	Fri Mar 07 09:34:32 2008 -0500
+++ b/src/Virt_VSMigrationService.c	Fri Mar 07 09:48:09 2008 -0500
@@ -51,6 +51,12 @@
 
 const static CMPIBroker *_BROKER;
 
+enum {
+        MIG_CREATED,
+        MIG_MODIFIED,
+        MIG_DELETED,
+};
+
 struct migration_job {
         CMPIContext *context;
         char *domain;
@@ -271,23 +277,49 @@ static CMPIStatus vs_migratable_system(C
         return vs_migratable(ref, name, dname, results, argsout);
 }
 
+static char *ind_type_to_name(int ind_type)
+{
+        char *ind_name = NULL;
+
+        switch (ind_type) {
+        case MIG_CREATED:
+                ind_name = "ComputerSystemMigrationJobCreatedIndication";
+                break;
+        case MIG_DELETED:
+                ind_name = "ComputerSystemMigrationJobDeletedIndication";
+                break;
+        case MIG_MODIFIED:
+                ind_name = "ComputerSystemMigrationJobModifiedIndication";
+                break;
+        }
+        
+        return ind_name;
+}
+
 static bool raise_indication(const CMPIContext *context,
-                             const char *base_type,
+                             int ind_type,
                              const char *ns,
                              CMPIInstance *inst,
                              CMPIInstance *ind)
 {
         char *type;
         CMPIStatus s;
+        char *ind_name = NULL;
+
+        ind_name = ind_type_to_name(ind_type);
 
         CU_DEBUG("Setting SourceInstance");
         CMSetProperty(ind, "SourceInstance",
                       (CMPIValue *)&inst, CMPI_instance);
 
         /* Seems like this shouldn't be hardcoded. */
-        type = get_typed_class("Xen", base_type);
-
+        type = get_typed_class("Xen", ind_name);
+
+        CU_DEBUG("stdi_raise");
+        CU_DEBUG("broker %p, context %p, type %s, ns %s, ind %p",
+                 _BROKER, context, type, ns, ind);
         s = stdi_raise_indication(_BROKER, context, type, ns, ind);
+        CU_DEBUG("raise done");
 
         free(type);
 
@@ -297,41 +329,95 @@ static CMPIInstance *prepare_indication(
 static CMPIInstance *prepare_indication(const CMPIBroker *broker,
                                         CMPIInstance *inst,
                                         char *ns,
+                                        int ind_type,
                                         CMPIStatus *s)
 {
+        char *ind_name = NULL;
         CMPIInstance *ind = NULL;
         CMPIInstance *prev_inst = NULL;
 
-        CU_DEBUG("Creating indication.");
+        ind_name = ind_type_to_name(ind_type);
+
+        CU_DEBUG("Creating indication: '%s:%s_%s'",
+                 ns, "Xen", ind_name);
         /* Prefix needs to be dynamic */
-        ind = get_typed_instance(broker,
-                                 "Xen",
-                                 "ComputerSystemMigrationIndication",
-                                 ns);
+        ind = get_typed_instance(broker, "Xen", ind_name, ns);
         /* Prefix needs to be dynamic */
         if (ind == NULL) {
                 CU_DEBUG("Failed to create ind, type '%s:%s_%s'", 
-                         ns,
-                         "Xen",
-                         "ComputerSystemMigrationIndication");
-        }
-
-        /* Need to copy job inst before attaching as PreviousInstance because 
-           otherwise the changes we are about to make to job inst are made 
-           to PreviousInstance as well. */
-        prev_inst = cu_dup_instance(_BROKER, inst, s);
-        if (s->rc != CMPI_RC_OK || prev_inst == NULL) {
-                CU_DEBUG("dup_instance failed (%i:%s)", s->rc, s->msg);
-                ind = NULL;
-                goto out;
-        }
-
-        CU_DEBUG("Setting PreviousInstance");
-        CMSetProperty(ind, "PreviousInstance", 
-                      (CMPIValue *)&prev_inst, CMPI_instance);
+                         ns, "Xen", ind_name);
+        }
+
+        if (ind_type == MIG_MODIFIED) {
+                /* Need to copy job inst before attaching as PreviousInstance because 
+                   otherwise the changes we are about to make to job inst are made 
+                   to PreviousInstance as well. */
+                prev_inst = cu_dup_instance(_BROKER, inst, s);
+                if (s->rc != CMPI_RC_OK || prev_inst == NULL) {
+                        CU_DEBUG("dup_instance failed (%i:%s)", s->rc, s->msg);
+                        ind = NULL;
+                        goto out;
+                }
+                CU_DEBUG("Setting PreviousInstance");
+                CMSetProperty(ind, "PreviousInstance", 
+                              (CMPIValue *)&prev_inst, CMPI_instance);
+        }
 
  out:
         return ind;
+}
+
+static CMPIObjectPath *ref_from_job(struct migration_job *job,
+                                    CMPIStatus *s)
+{
+        CMPIObjectPath *ref = NULL;
+        
+        ref = CMNewObjectPath(_BROKER,
+                              job->ref_ns,
+                              "Virt_MigrationJob",
+                              s);
+        if (s->rc != CMPI_RC_OK) {
+                CU_DEBUG("Failed to create job ref for update");
+                goto out;
+        }
+
+        CMSetNameSpace(ref, job->ref_ns);
+        CMAddKey(ref, "InstanceID", (CMPIValue *)job->uuid, CMPI_chars);
+
+        CU_DEBUG("Getting job instance %s", job->uuid);
+        CU_DEBUG("  REF: %s", CMGetCharPtr(CMObjectPathToString(ref, NULL)));
+        
+ out:
+        return ref;
+}
+
+static void raise_deleted_ind(struct migration_job *job)
+{
+        CMPIInstance *ind = NULL;
+        CMPIInstance *inst = NULL;
+        CMPIObjectPath *ref = NULL;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        bool rc;
+
+        ref = ref_from_job(job, &s);
+        if ((ref == NULL) || (s.rc != CMPI_RC_OK)) {
+                CU_DEBUG("Failed to get job ref for delete");
+                return;
+        }
+        inst = CBGetInstance(_BROKER, job->context, ref, NULL, &s);
+        if ((inst == NULL) || (s.rc != CMPI_RC_OK)) {
+                CU_DEBUG("Failed to get job instance for delete (%i)", s.rc);
+                return;
+        }
+
+        ind = prepare_indication(_BROKER, inst, job->ref_ns, MIG_DELETED, &s);
+        
+        rc = raise_indication(job->context, MIG_MODIFIED, job->ref_ns, 
+                              inst, ind);
+        if (!rc)
+                CU_DEBUG("Failed to raise indication");
+
+        return;
 }
 
 static void migrate_job_set_state(struct migration_job *job,
@@ -344,27 +430,18 @@ static void migrate_job_set_state(struct
         CMPIStatus s;
         CMPIObjectPath *op;
 
-        op = CMNewObjectPath(_BROKER,
-                             job->ref_ns,
-                             "Virt_MigrationJob",
-                             &s);
-        if (s.rc != CMPI_RC_OK) {
-                CU_DEBUG("Failed to create job path for update");
+        op = ref_from_job(job, &s);
+        if ((op == NULL) || (s.rc != CMPI_RC_OK)) {
+                CU_DEBUG("Failed to get job ref for update");
                 return;
         }
-
-        CMSetNameSpace(op, job->ref_ns);
-        CMAddKey(op, "InstanceID", (CMPIValue *)job->uuid, CMPI_chars);
-
-        CU_DEBUG("Getting job instance %s", job->uuid);
-        CU_DEBUG("  OP: %s", CMGetCharPtr(CMObjectPathToString(op, NULL)));
         inst = CBGetInstance(_BROKER, job->context, op, NULL, &s);
         if ((inst == NULL) || (s.rc != CMPI_RC_OK)) {
                 CU_DEBUG("Failed to get job instance for update (%i)", s.rc);
                 return;
         }
 
-        ind = prepare_indication(_BROKER, inst, job->ref_ns, &s);
+        ind = prepare_indication(_BROKER, inst, job->ref_ns, MIG_MODIFIED, &s);
 
         CMSetProperty(inst, "JobState",
                       (CMPIValue *)&state, CMPI_uint16);
@@ -378,11 +455,8 @@ static void migrate_job_set_state(struct
                 CU_DEBUG("Failed to update job instance: %s",
                          CMGetCharPtr(s.msg));
 
-        rc = raise_indication(job->context,
-                              "ComputerSystemMigrationIndication",
-                              job->ref_ns,
-                              inst,
-                              ind);
+        rc = raise_indication(job->context, MIG_MODIFIED, job->ref_ns, 
+                              inst, ind);
         if (!rc)
                 CU_DEBUG("Failed to raise indication");
 }
@@ -549,6 +623,8 @@ static CMPIStatus migrate_vs(struct migr
                    "");
 
  out:
+        raise_deleted_ind(job);
+        
         free(uri);
         free(xml);
         virDomainFree(dom);
@@ -714,6 +790,9 @@ static CMPIStatus migrate_do(const CMPIO
         struct migration_job *job;
         CMPI_THREAD_TYPE thread;
         uint32_t retcode = 1;
+        CMPIInstance *ind = NULL;
+        CMPIInstance *inst = NULL;
+        bool rc;
 
         job = migrate_job_prepare(context, ref, domain, host, type);
         if (job == NULL) {
@@ -728,8 +807,20 @@ static CMPIStatus migrate_do(const CMPIO
         s = migrate_create_job_instance(context, job, &job_op);
         if (s.rc != CMPI_RC_OK)
                 goto out;
-
+        
         CMAddArg(argsout, "Job", (CMPIValue *)&job_op, CMPI_ref);
+
+        inst = CBGetInstance(_BROKER, job->context, job_op, NULL, &s);
+        if ((inst == NULL) || (s.rc != CMPI_RC_OK)) {
+                CU_DEBUG("Failed to get job instance for create ind", s.rc);
+                goto out;
+        }
+
+        ind = prepare_indication(_BROKER, inst, job->ref_ns, MIG_CREATED, &s);
+        rc = raise_indication(job->context, MIG_CREATED, job->ref_ns, 
+                              inst, ind);
+        if (!rc)
+                CU_DEBUG("Failed to raise indication");
 
         thread = _BROKER->xft->newThread((void*)migration_thread, job, 0);
 




More information about the Libvirt-cim mailing list