This patch adds new virsh commands 'cpu-getmode' and
'cpu-setmode' using virDomainGetCPUMode and virDomainSetCPUMode.
'cpu-getmode' allows to get cpu mode of a running domain or persistent
configuration.
'cpu-setmode' allows to change cpu mode of a domain but affects only
persistent configuration.
Signed-off-by: Ken ICHIKAWA <ichikawa.ken(a)jp.fujitsu.com>
---
tools/virsh-domain.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 19 +++++++++
2 files changed, 128 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 96e62fc..b4ea137 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5371,6 +5371,113 @@ no_memory:
}
/*
+ * "cpu-getmode" command
+ */
+static const vshCmdInfo info_cpu_getmode[] = {
+ {"help", N_("show domain cpu mode")},
+ {"desc", N_("Show cpu mode of a domain")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_cpu_getmode[] = {
+ {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or
uuid")},
+ {"live", VSH_OT_BOOL, 0, N_("get running state")},
+ {"config", VSH_OT_BOOL, 0, N_("get persistent configuration")},
+ {"current", VSH_OT_BOOL, 0, N_("get current state
configuration")},
+ {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdCPUGetMode(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom;
+ bool config = vshCommandOptBool(cmd, "config");
+ bool live = vshCommandOptBool(cmd, "live");
+ bool current = vshCommandOptBool(cmd, "current");
+ char *mode = NULL;
+ unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+ bool ret = false;
+
+ if (current + config + live > 1) {
+ vshError(ctl, "%s",
+ _("--config, --live, and --current are mutually exclusive"));
+ return false;
+ }
+
+ if (config)
+ flags = VIR_DOMAIN_AFFECT_CONFIG;
+ if (live)
+ flags = VIR_DOMAIN_AFFECT_LIVE;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (!(mode = virDomainGetCPUMode(dom, flags))) {
+ vshError(ctl, _("Unable to get cpu mode"));
+ goto cleanup;
+ }
+
+ vshPrint(ctl, "%s\n", mode);
+
+ VIR_FREE(mode);
+ ret = true;
+
+ cleanup:
+ virDomainFree(dom);
+ return ret;
+}
+
+/*
+ * "cpu-setmode" command
+ */
+static const vshCmdInfo info_cpu_setmode[] = {
+ {"help", N_("set domain cpu mode")},
+ {"desc", N_("Modify cpu mode of a domain")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_cpu_setmode[] = {
+ {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or
uuid")},
+ {"mode", VSH_OT_DATA, VSH_OFLAG_REQ,
+ N_("cpu mode, one of custom, host-model and host-passthrough")},
+ {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdCPUSetMode(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom;
+ const char *mode = NULL;
+ bool ret = false;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (vshCommandOptString(cmd, "mode", &mode) < 0) {
+ vshError(ctl, _("Unable to parse mode."));
+ goto cleanup;
+ }
+
+ if (!mode) {
+ vshError(ctl, _("CPU mode is not specified."));
+ goto cleanup;
+ }
+
+ if (virDomainSetCPUMode(dom, mode, 0) < 0) {
+ vshError(ctl, _("Unable to change cpu mode"));
+ goto cleanup;
+ }
+
+ vshPrint(ctl, _("CPU mode updated successfully\n"));
+
+ ret = true;
+
+ cleanup:
+ virDomainFree(dom);
+ return ret;
+}
+
+/*
* "cpu-stats" command
*/
static const vshCmdInfo info_cpu_stats[] = {
@@ -8507,6 +8614,8 @@ const vshCmdDef domManagementCmds[] = {
#endif
{"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline, info_cpu_baseline, 0},
{"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare, 0},
+ {"cpu-getmode", cmdCPUGetMode, opts_cpu_getmode, info_cpu_getmode, 0},
+ {"cpu-setmode", cmdCPUSetMode, opts_cpu_setmode, info_cpu_setmode, 0},
{"cpu-stats", cmdCPUStats, opts_cpu_stats, info_cpu_stats, 0},
{"create", cmdCreate, opts_create, info_create, 0},
{"define", cmdDefine, opts_define, info_define, 0},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index b0e7064..109e256 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -999,6 +999,25 @@ except that it does some error checking.
The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment
variables, and defaults to C<vi>.
+=item B<cpu-getmode> I<domain> [[I<--config>] | [I<--live>] |
[I<--current>]]
+
+Get a domain's cpu mode, corresponding to the B<mode> attribute of
B<cpu>
+element of the domain XML. If cpu mode is not specified in the domain XML,
+'custom' is displayed as a default.
+
+If I<--live> is specified, affect a running guest.
+If I<--config> is specified, affect the next boot of a persistent guest.
+If I<--current> is specified, affect the current guest state.
+All flags are exclusive. If no flag is specified, behavior is the same as
+I<--current>.
+
+=item B<cpu-setmode> I<domain> I<mode>
+
+Set a domain's cpu mode, corresponding to the B<mode> attribute of
B<cpu>
+element of the domain XML. I<mode> can be one of 'custom',
'host-model'
+and 'host-passthrough'. Modification affects the next boot of a persistent
+guest.
+
=item B<managedsave> I<domain> [I<--bypass-cache>]
[{I<--running> | I<--paused>}] [I<--verbose>]
--
1.7.11.7