[libvirt] [PATCH v4 5/7] virsh: Implement managedsave-define command

Kothapally Madhu Pavan kmp at linux.vnet.ibm.com
Tue Aug 8 08:02:53 UTC 2017


Add a simple virsh command handler which makes use of the new API.

Signed-off-by: Kothapally Madhu Pavan <kmp at linux.vnet.ibm.com>
---
 tools/virsh-domain.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod      | 14 ++++++++++
 2 files changed, 93 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 512804c..8baea2a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4705,6 +4705,79 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "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;
+
+    dom = virshCommandOptDomain(ctl, cmd, NULL);
+    if (dom == 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
  */
 static const vshCmdInfo info_schedinfo[] = {
@@ -13845,6 +13918,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 43d6f0c..11e2321 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1630,6 +1630,20 @@ 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 account for file naming
+differences resulting from creating disk snapshots of underlying storage
+after the guest was saved.
+
+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
-- 
1.8.3.1




More information about the libvir-list mailing list