Re: [PATCH v2 5/5] virsh: Expose new virDomainSuspendForDuration API

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

 



On Thu, Jan 26, 2012 at 08:59:47PM +0100, Michal Privoznik wrote:
> under new command "suspend-duration"
> ---
>  tools/virsh.c   |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh.pod |    8 ++++++
>  2 files changed, 75 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 74655c2..c00fe5d 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -2170,6 +2170,71 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd)
>  }
>  
>  /*
> + * "suspend-duration" command
> + */
> +static const vshCmdInfo info_suspend_duration[] = {
> +    {"help", N_("suspend a domain for a given time duration")},
> +    {"desc", N_("Suspend a running domain for a given time duration.")},
> +    {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_suspend_duration[] = {
> +    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
> +    /* {"duration", VSH_OT_INT, VSH_OFLAG_REQ, N_("duration in seconds")}, */
> +    {"target", VSH_OT_STRING, VSH_OFLAG_REQ, N_("mem(Suspend-to-RAM), "
> +                                                "disk(Suspend-to-Disk), "
> +                                                "hybrid(Hybrid-Suspend)")},
> +    {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdSuspendDuration(vshControl *ctl, const vshCmd *cmd)
> +{
> +    virDomainPtr dom;
> +    const char *name;
> +    bool ret = false;
> +    const char *target = NULL;
> +    unsigned int suspendTarget;
> +
> +    if (!vshConnectionUsability(ctl, ctl->conn))
> +        return false;
> +
> +    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
> +        return false;
> +
> +    if (vshCommandOptString(cmd, "target", &target) < 0) {
> +        vshError(ctl, _("Invalig target argument"));
> +        goto cleanup;
> +    }
> +
> +    if (STREQ(target, "mem"))
> +        suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM;
> +    else if (STREQ(target, "disk"))
> +        suspendTarget = VIR_NODE_SUSPEND_TARGET_DISK;
> +    else if (STREQ(target, "hybrid"))
> +        suspendTarget = VIR_NODE_SUSPEND_TARGET_HYBRID;
> +    else {
> +        vshError(ctl, "%s", _("Invalid target"));
> +        goto cleanup;
> +    }
> +
> +    if (virDomainSuspendForDuration(dom, suspendTarget, 0, 0) < 0) {
> +        vshError(ctl, _("Domain %s could not be suspended"),
> +                 virDomainGetName(dom));
> +        goto cleanup;
> +    }
> +
> +    vshPrint(ctl, _("Domain %s successfully suspended"),
> +             virDomainGetName(dom));
> +
> +    ret = true;
> +
> +cleanup:
> +    virDomainFree(dom);
> +    return ret;
> +}
> +
> +/*
>   * "create" command
>   */
>  static const vshCmdInfo info_create[] = {
> @@ -16070,6 +16135,8 @@ static const vshCmdDef domManagementCmds[] = {
>      {"shutdown", cmdShutdown, opts_shutdown, info_shutdown, 0},
>      {"start", cmdStart, opts_start, info_start, 0},
>      {"suspend", cmdSuspend, opts_suspend, info_suspend, 0},
> +    {"suspend-duration", cmdSuspendDuration,
> +     opts_suspend_duration, info_suspend_duration, 0},
>      {"ttyconsole", cmdTTYConsole, opts_ttyconsole, info_ttyconsole, 0},
>      {"undefine", cmdUndefine, opts_undefine, info_undefine, 0},
>      {"update-device", cmdUpdateDevice, opts_update_device,
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index 8599f66..dc6fd01 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -1239,6 +1239,14 @@ Moves a domain out of the suspended state.  This will allow a previously
>  suspended domain to now be eligible for scheduling by the underlying
>  hypervisor.
>  
> +=item B<suspend-duration> I<domain-id> I<target>
> +
> +Suspend a running domain into one of these states (possible I<target>
> +values):
> +    mem equivallent of S3 ACPI state
> +    disk equivallent of S4 ACPI state
> +    hybrid RAM is saved to disk but not powered off

As with the API, I think we need a different name prefix, like

   domnodesuspend

or

   dompmsuspend


ACK if we rename it in one of these ways or another suggestion

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
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]