From fc2c73b56598403fb6a8c3c22e4bcf2c880ecdb7 Mon Sep 17 00:00:00 2001 From: Kothapally Madhu Pavan Date: Tue, 8 Aug 2017 13:32:53 +0530 Subject: [PATCH] virsh: Implement managedsave-define command Add a simple virsh command handler which makes use of the new API. Signed-off-by: Kothapally Madhu Pavan --- 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 a3410e791c..8f048f678a 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 15a414399d..5c87af3026 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1630,6 +1630,18 @@ has any managed save image. Remove the B 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 I I [{I<--running> | I<--paused>}] + +Update the domain XML that will be used when I is later +started. The I 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 should use. + =item B [I] Provide the maximum number of virtual CPUs supported for a guest VM on