Re: for testing the new qemu specific regiater API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/16/2011 09:59 AM, shaohef@xxxxxxxxxxxxxxxxxx wrote:
> From: ShaoHe Feng <shaohef@xxxxxxxxxxxxxxxxxx>
> 
> this patch is just used to the new register API
> 
> add two command, register-event and deregister-event in virsh in order to test the new API.
> 
> there will come an  "RESUME" events when qemu domains are started.
> 
> virish starts a qemu domain and to catch "RESUME" event.
> virsh# register-event RESUME
> virsh# start domain

I'd name this qemu-register-event, to make it obvious that it depends on
libvirt-qemu.

> +void printRegistEvent(virConnectPtr conn,
> +                      virDomainPtr dom,
> +                      const char *eventName, /* The JSON event name */
> +                      const char *eventArgs, /* The JSON string of args */
> +                      void *opaque){
> +    char *uriName = virConnectGetURI (conn);
> +    fputc('\n', stdout);
> +    if (uriName != NULL)
> +       fprintf(stdout, "connect URI: %s, ",uriName);
> +
> +    if (dom != NULL)
> +       fprintf(stdout, "dom: %s(%d) receive an event:\n", dom->name, dom->id);
> +
> +    if (eventName != NULL)
> +        fprintf(stdout, "{ event: %s", eventName);
> +    if (eventArgs != NULL)
> +        fprintf(stdout, ", data: %s }\n", eventArgs);
> +    else
> +        fprintf(stdout, " }\n");
> +    fprintf(stdout, "----------------------------------------------");
> +    fputc('\n', stdout);
> +}

Hmm, looks like it does as much as can be expected when receiving an event.

> +
> +static bool
> +cmdRegisterEvent(vshControl *ctl, const vshCmd *cmd)
> +{
> +    const char *name = NULL;
> +    virDomainPtr dom;
> +    bool ret = false;
> +    int eventID = -1;
> +
> +    if (!vshConnectionUsability(ctl, ctl->conn))
> +        return false;
> +
> +    if (vshCommandOptString(cmd, "event", &name) < 0) {
> +        vshError(ctl, "%s", _("Please specify valid event name"));
> +        return false;
> +    }
> +
> +    dom = NULL;
> +    eventID = virConnectDomainQemuEventRegister(ctl->conn, dom, name, printRegistEvent, NULL, NULL);
> +    if (eventID < 0) {
> +       fprintf(stdout, "%s event register error.\n", name);
> +       return false;
> +    }
> +    fprintf(stdout, "%s event call back ID is %d, you can use it to deregister the event.\n", name, eventID);
> +    ret = true;
> + cleanup:
> +    return ret;
> +}

What happens if virsh dies without deregistering the event?  I'm
guessing this is the sort of task where you'd either have to run virsh
in command mode (not batch mode).

Perhaps it might also be worth setting up a mode where you can do:

virsh qemu-register-event --wait domain RESUME &

which then blocks that virsh instance until a RESUME event arrives, so
that you can use backgrounded virsh tasks as a one-shot view into an
event firing.

> @@ -15363,6 +15467,8 @@ static const vshCmdDef domManagementCmds[] = {
>      {"vcpupin", cmdVcpuPin, opts_vcpupin, info_vcpupin, 0},
>      {"version", cmdVersion, opts_version, info_version, 0},
>      {"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay, 0},
> +    {"register-event", cmdRegisterEvent, opts_regevent, info_regevent, 0},
> +    {"deregister-event", cmdDeregisterEvent, opts_deregevent, info_deregevent, 0},
>      {NULL, NULL, NULL, NULL, 0}

Sort these new commands with the other qemu-* commands.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]