[Libvirt-cim] [PATCH 2/2] ComputerSystem: Reboot/Shutdown state changes as jobs

Eduardo Lima (Etrunko) eblima at linux.vnet.ibm.com
Fri Mar 2 17:45:20 UTC 2012


On 02/20/2012 05:43 PM, Eduardo Lima (Etrunko) wrote:
> From: "Eduardo Lima (Etrunko)" <eblima at br.ibm.com>
> 
> For Reboot and Shutdown, th RequestStateChange method returns immediately with
> return code 0 (successful) even though the state change is still not completed.
> 
> According to the DMTF specification DSP1052 (Computer System Profile) the
> RequestStateChange() method should return 0x1000 and a corresponding job
> reference in the return parameters which can be polled for completion.
> 
> Signed-off-by: Eduardo Lima (Etrunko) <eblima at br.ibm.com>
> ---
>  schema/ComputerSystem.mof |    9 ++
>  src/Virt_ComputerSystem.c |  300 +++++++++++++++++++++++++++++++++++++++++++--
>  2 files changed, 299 insertions(+), 10 deletions(-)
> 
> diff --git a/schema/ComputerSystem.mof b/schema/ComputerSystem.mof
> index 10cb8c4..886c085 100644
> --- a/schema/ComputerSystem.mof
> +++ b/schema/ComputerSystem.mof
> @@ -1,5 +1,14 @@
>  // Copyright IBM Corp. 2007
> 
> +class Xen_ComputerSystemStateChangeJob : CIM_ConcreteJob {
> +};
> +
> +class KVM_ComputerSystemStateChangeJob : CIM_ConcreteJob {
> +};
> +
> +class LXC_ComputerSystemStateChangeJob : CIM_ConcreteJob {
> +};
> +
>  [Description (
>  	"A class derived from CIM_ComputerSystem to represent "
>  	"the Xen virtual machines/domains running on the system."),
> diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c
> index e6c7e55..dee4ef7 100644
> --- a/src/Virt_ComputerSystem.c
> +++ b/src/Virt_ComputerSystem.c
[snip]

> +
> +static CMPI_THREAD_RETURN state_change_thread(void *data)
> +{
> +        CMPIStatus s;
> +        CMPIInstance *inst = NULL;
> +        state_change_job_t *job = (state_change_job_t *) data;
> +        virConnectPtr conn = NULL;
> +        virDomainPtr dom = NULL;
> +        virDomainInfo info;
> +        int job_cb = -1;
> +
> +        /* Set job state */
> +        CBAttachThread(_BROKER, job->context);
> +        CU_DEBUG("State change job %s started", job->uuid);
> +        job->status = CIM_JOB_STATE_RUNNING;
> +
> +        inst = CBGetInstance(_BROKER, job->context, job->obj_path, NULL, &s);
> +        if ((inst == NULL) || (s.rc != CMPI_RC_OK)) {
> +                CU_DEBUG("Failed to get job instance (%i)", s.rc);
> +                return NULL;
> +        }
> +
> +        CMSetProperty(inst, "JobState",
> +                      (CMPIValue *)&(job->status), CMPI_uint16);
> +        CMSetProperty(inst, "Status",
> +                      (CMPIValue *) "Running", CMPI_chars);
> +
> +        /* Connect to domain event callback */
> +        conn = connect_by_classname(_BROKER, CLASSNAME(job->obj_path), &s);
> +        if (conn == NULL) {
> +                CU_DEBUG("Unable to connect to '%s' hypervisor",
> +                         CLASSNAME(job->obj_path));
> +                goto out;
> +        }
> +
> +        dom = virDomainLookupByName(conn, job->dom_name);
> +        if (dom == NULL) {
> +                CU_DEBUG("Unable to get domain '%s'", job->dom_name);
> +                goto out;
> +        }
> +
> +        if (virDomainGetInfo(dom, &info) != 0) {
> +                CU_DEBUG("Unable to get domain info for '%s'", job->dom_name);
> +                goto out;
> +        }
> +
> +        if (events_registered == false) {
> +                events_registered = true;
> +                virEventRegisterDefaultImpl();
> +        }
> +
> +        if (job->dom_state == CIM_STATE_REBOOT) {
> +                job_cb = virConnectDomainEventRegisterAny(conn, NULL,
> +                                VIR_DOMAIN_EVENT_ID_REBOOT,
> +                                VIR_DOMAIN_EVENT_CALLBACK(state_change_reboot_cb),
> +                                job, NULL);
> +
> +                if (job_cb == -1) {
> +                        CU_DEBUG("Unable to connect domain reboot callback");
> +                        goto out;
> +                }
> +
> +                s = state_change_reboot(dom, &info);
> +
> +                if (s.rc != CMPI_RC_OK) {
> +                        CU_DEBUG("Unable to trigger domain reboot: '%s'",
> +                                 CMGetCharPtr(s.msg));
> +                        goto out;
> +                }
> +        } else if (job->dom_state == CIM_STATE_SHUTDOWN) {
> +                job_cb = virConnectDomainEventRegisterAny(conn, NULL,
> +                                VIR_DOMAIN_EVENT_ID_REBOOT,
> +                                VIR_DOMAIN_EVENT_CALLBACK(state_change_shutdown_cb),
> +                                job, NULL);
> +

Sharad has just found another issue here, for shutdown the event is
VIR_DOMAIN_EVENT_ID_LIFECYCLE, and not VIR_DOMAIN_EVENT_ID_REBOOT.


-- 
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima at br.ibm.com




More information about the Libvirt-cim mailing list