From: Kothapally Madhu Pavan <kmp(a)linux.vnet.ibm.com>
Add a simple virsh command handler which makes use of the new API.
Signed-off-by: Kothapally Madhu Pavan <kmp(a)linux.vnet.ibm.com>
---
tools/virsh-domain.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 12 ++++++++
2 files changed, 90 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index a3410e791..8f048f678 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4704,6 +4704,78 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
return ret;
}
+/*
+ * "managedsave-define" command
+ */
+static const vshCmdInfo info_managed_save_define[] = {
+ {.name = "help",
+ .data = N_("redefine the XML for a domain's managed save state file")
+ },
+ {.name = "desc",
+ .data = N_("Replace the domain XML associated with a managed save state
file")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_managed_save_define[] = {
+ VIRSH_COMMON_OPT_DOMAIN_FULL,
+ {.name = "xml",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("filename containing updated XML for the target")
+ },
+ {.name = "running",
+ .type = VSH_OT_BOOL,
+ .help = N_("set domain to be running on start")
+ },
+ {.name = "paused",
+ .type = VSH_OT_BOOL,
+ .help = N_("set domain to be paused on start")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd)
+{
+ bool ret = false;
+ virDomainPtr dom = NULL;
+ const char *xmlfile = NULL;
+ char *xml = NULL;
+ unsigned int flags = 0;
+
+ if (vshCommandOptBool(cmd, "running"))
+ flags |= VIR_DOMAIN_SAVE_RUNNING;
+ if (vshCommandOptBool(cmd, "paused"))
+ flags |= VIR_DOMAIN_SAVE_PAUSED;
+
+ VSH_EXCLUSIVE_OPTIONS("running", "paused");
+
+ if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
+ return false;
+
+ if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
+ return false;
+
+ if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+ goto cleanup;
+
+ if (virDomainManagedSaveDefineXML(dom, xml, flags) < 0) {
+ vshError(ctl, _("Failed to update %s XML configuration"),
+ virDomainGetName(dom));
+ goto cleanup;
+ }
+
+ vshPrintExtra(ctl, _("Managed save state file of domain %s updated.\n"),
+ virDomainGetName(dom));
+ ret = true;
+
+ cleanup:
+ virshDomainFree(dom);
+ VIR_FREE(xml);
+ return ret;
+}
+
/*
* "schedinfo" command
*/
@@ -13886,6 +13958,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_managedsaveremove,
.flags = 0
},
+ {.name = "managedsave-define",
+ .handler = cmdManagedSaveDefine,
+ .opts = opts_managed_save_define,
+ .info = info_managed_save_define,
+ .flags = 0
+ },
{.name = "memtune",
.handler = cmdMemtune,
.opts = opts_memtune,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 15a414399..5c87af302 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1630,6 +1630,18 @@ has any managed save image.
Remove the B<managedsave> state file for a domain, if it exists. This
ensures the domain will do a full boot the next time it is started.
+=item B<managedsave-define> I<domain> I<xml> [{I<--running> |
I<--paused>}]
+
+Update the domain XML that will be used when I<domain> is later
+started. The I<xml> argument must be a file name containing
+the alternative XML, with changes only in the host-specific portions of
+the domain XML. For example, it can be used to change disk file paths.
+
+The managed save image records whether the domain should be started to a
+running or paused state. Normally, this command does not alter the
+recorded state; passing either the I<--running> or I<--paused> flag
+will allow overriding which state the B<start> should use.
+
=item B<maxvcpus> [I<type>]
Provide the maximum number of virtual CPUs supported for a guest VM on
--
2.14.1