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

Re: [libvirt] [PATCH v4 4/4] Add virsh command to initiate suspend on the host



On Mon, Nov 28, 2011 at 05:33:29PM +0530, Srivatsa S. Bhat wrote:
> Add a new command 'nodesuspend' to perform a timed suspend on the host.
> 
> Signed-off-by: Srivatsa S. Bhat <srivatsa bhat linux vnet ibm com>
> ---
> 
>  tools/virsh.c   |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh.pod |    7 ++++++
>  2 files changed, 71 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 89fb4e7..17bc44c 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -5198,6 +5198,69 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
>  }
>  
>  /*
> + * "nodesuspend" command
> + */
> +static const vshCmdInfo info_nodesuspend[] = {
> +    {"help", N_("suspend the host node for a given time duration")},
> +    {"desc", N_("Suspend the host node for a given time duration "
> +                               "and attempt to resume thereafter.")},
> +    {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_node_suspend[] = {
> +    {"state", VSH_OT_DATA, VSH_OFLAG_REQ, N_("mem(Suspend-to-RAM), "
> +                                               "disk(Suspend-to-Disk), hybrid(Hybrid-Suspend)")},
> +    {"duration", VSH_OT_INT, VSH_OFLAG_REQ, N_("Suspend duration in seconds")},
> +    {"flags", VSH_OT_INT, VSH_OFLAG_NONE, N_("Suspend flags, 0 for default")},
> +    {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
> +{
> +    const char *state = NULL;
> +    int suspendState;
> +    long long duration;
> +    unsigned int flags = 0;
> +
> +    if (!vshConnectionUsability(ctl, ctl->conn))
> +        return false;
> +
> +    if (vshCommandOptString(cmd, "state", &state) < 0)
> +        return false;
> +
> +    if (vshCommandOptLongLong(cmd, "duration", &duration) < 0)
> +        return false;
> +
> +    if (vshCommandOptUInt(cmd, "flags", &flags) < 0)
> +        return false;
> +
> +    if (!strcmp(state, "mem"))
> +        suspendState = VIR_NODE_S3;

If we call it 'RAM' in the API, we should be consistent here and use
'ram' too. Otherwise we should make the API VIR_SUSPEND_TARGET_MEM
instead.

> +    else if (!strcmp(state, "disk"))
> +        suspendState = VIR_NODE_S4;
> +    else if (!strcmp(state, "hybrid"))
> +        suspendState = VIR_NODE_HYBRID_SUSPEND;
> +    else {
> +        vshError(ctl, "%s", _("Invalid state"));
> +        return false;
> +    }
> +
> +    if (duration <= 0) {
> +        vshError(ctl, "%s", _("Invalid duration"));
> +        return false;
> +    }
> +
> +    if (virNodeSuspendForDuration(ctl->conn, suspendState, duration,
> +                                  flags) < 0) {
> +        vshError(ctl, "%s", _("The host was not suspended"));
> +        return false;
> +    }
> +    return true;

> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index db872dd..25cdfa9 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -253,6 +253,13 @@ statistics during 1 second.
>  Returns memory stats of the node.
>  If I<cell> is specified, this will prints specified cell statistics only.
>  
> +=item B<nodesuspend> [I<state>] [I<duration>] [I<flags>]
> +
> +Puts the node (host machine) into a system-wide sleep state such as
> +Suspend-to-RAM (S3), Suspend-to-Disk (S4) or Hybrid-Suspend and sets up
> +a Real-Time-Clock interrupt to fire (to wake up the node) after a time delay
> +specified by the 'duration' parameter.

Again, S3/S4 are x86 specific terminology we can do without here IMHO


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


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