[libvirt] [PATCH 6/6] virsh: Add support for virDomainGetControlInfo
Daniel Veillard
veillard at redhat.com
Mon Jun 13 08:32:45 UTC 2011
On Tue, Jun 07, 2011 at 03:02:00PM +0200, Jiri Denemark wrote:
> ---
> tools/virsh.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> tools/virsh.pod | 7 +++++
> 2 files changed, 73 insertions(+), 0 deletions(-)
>
> diff --git a/tools/virsh.c b/tools/virsh.c
> index d98be1c..2c81cf4 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -350,6 +350,7 @@ static void vshDebug(vshControl *ctl, int level, const char *format, ...)
> static int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
> static const char *vshDomainStateToString(int state);
> static const char *vshDomainStateReasonToString(int state, int reason);
> +static const char *vshDomainControlStateToString(int state);
> static const char *vshDomainVcpuStateToString(int state);
> static bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn);
>
> @@ -976,6 +977,53 @@ cleanup:
> return ret;
> }
>
> +/*
> + * "domcontrol" command
> + */
> +static const vshCmdInfo info_domcontrol[] = {
> + {"help", N_("domain control interface state")},
> + {"desc", N_("Returns state of a control interface to the domain.")},
> + {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_domcontrol[] = {
> + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
> + {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdDomControl(vshControl *ctl, const vshCmd *cmd)
> +{
> + virDomainPtr dom;
> + bool ret = true;
> + virDomainControlInfo info;
> +
> + if (!vshConnectionUsability(ctl, ctl->conn))
> + return false;
> +
> + if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
> + return false;
> +
> + if (virDomainGetControlInfo(dom, &info, 0) < 0) {
> + ret = false;
> + goto cleanup;
> + }
> +
> + if (info.state != VIR_DOMAIN_CONTROL_OK &&
> + info.state != VIR_DOMAIN_CONTROL_ERROR) {
> + vshPrint(ctl, "%s (%0.3fs)\n",
> + _(vshDomainControlStateToString(info.state)),
> + info.stateTime / 1000.0);
> + } else {
> + vshPrint(ctl, "%s\n",
> + _(vshDomainControlStateToString(info.state)));
> + }
> +
> +cleanup:
> + virDomainFree(dom);
> + return ret;
> +}
> +
> /* "domblkstat" command
> */
> static const vshCmdInfo info_domblkstat[] = {
> @@ -11107,6 +11155,7 @@ static const vshCmdDef domManagementCmds[] = {
> static const vshCmdDef domMonitoringCmds[] = {
> {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0},
> {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0},
> + {"domcontrol", cmdDomControl, opts_domcontrol, info_domcontrol, 0},
> {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0},
> {"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0},
> {"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat, 0},
> @@ -12621,6 +12670,23 @@ vshDomainStateReasonToString(int state, int reason)
> }
>
> static const char *
> +vshDomainControlStateToString(int state)
> +{
> + switch ((virDomainControlState) state) {
> + case VIR_DOMAIN_CONTROL_OK:
> + return N_("ok");
> + case VIR_DOMAIN_CONTROL_JOB:
> + return N_("background job");
> + case VIR_DOMAIN_CONTROL_OCCUPIED:
> + return N_("occupied");
> + case VIR_DOMAIN_CONTROL_ERROR:
> + return N_("error");
> + }
> +
> + return N_("unknown");
> +}
> +
> +static const char *
> vshDomainVcpuStateToString(int state)
> {
> switch (state) {
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index 7ed3003..3f55422 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -437,6 +437,13 @@ Convert a domain Id (or UUID) to domain name
> Returns state about a domain. I<--reason> tells virsh to also print
> reason for the state.
>
> +=item B<domcontrol> I<domain-id>
> +
> +Returns state of an interface to VMM used to control a domain. This
> +translates into monitor connection in QEMu world. For states other
that's "QEmu" I think, and that could be QMP or the monitor, so I'm
not sure we should try to give details about one specific
implementation :-)
> +than "ok" or "error" the command also prints number of seconds elapsed
> +since the control interface entered its current state.
> +
> =item B<domxml-from-native> I<format> I<config>
>
> Convert the file I<config> in the native guest configuration format
ACK otherwise,
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list