[PATCH 20/20] tools: add parallel parameter to virsh restore command

Jim Fehlig via Devel posted 20 patches 3 months, 2 weeks ago
[PATCH 20/20] tools: add parallel parameter to virsh restore command
Posted by Jim Fehlig via Devel 3 months, 2 weeks ago
From: Claudio Fontana <cfontana@suse.de>

Signed-off-by: Claudio Fontana <cfontana@suse.de>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 docs/manpages/virsh.rst |  9 +++++++--
 tools/virsh-domain.c    | 38 ++++++++++++++++++++++++++++++++++----
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index fa038e4547..2217728efd 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -3915,12 +3915,13 @@ restore
 ::
 
    restore state-file [--bypass-cache] [--xml file]
-      [{--running | --paused}] [--reset-nvram]
+      [{--running | --paused}] [--reset-nvram] [--parallel] [--parallel-connections]
 
 Restores a domain from a ``virsh save`` state file. See *save* for more info.
 
 If *--bypass-cache* is specified, the restore will avoid the file system
-cache, although this may slow down the operation.
+cache; depending on the specific scenario this may slow down or speed up
+the operation.
 
 *--xml* ``file`` is usually omitted, but can be used to supply an
 alternative XML file for use on the restored guest with changes only
@@ -3936,6 +3937,10 @@ domain should be started in.
 If *--reset-nvram* is specified, any existing NVRAM file will be deleted
 and re-initialized from its pristine template.
 
+*--parallel* option will cause the save data to be loaded using the number
+of parallel connections specified with *--parallel-connections*. Parallel
+connections will help speed up large restore operations.
+
 ``Note``: To avoid corrupting file system contents within the domain, you
 should not reuse the saved state file for a second ``restore`` unless you
 have also reverted all storage volumes back to the same contents as when
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ec0e43ae7b..73c04390cc 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5265,6 +5265,14 @@ static const vshCmdOptDef opts_restore[] = {
      .type = VSH_OT_BOOL,
      .help = N_("avoid file system cache when restoring")
     },
+    {.name = "parallel",
+     .type = VSH_OT_BOOL,
+     .help = N_("enable parallel restore")
+    },
+    {.name = "parallel-connections",
+     .type = VSH_OT_INT,
+     .help = N_("number of connections to use for parallel restore")
+    },
     {.name = "xml",
      .type = VSH_OT_STRING,
      .unwanted_positional = true,
@@ -5294,13 +5302,16 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
     const char *xmlfile = NULL;
     g_autofree char *xml = NULL;
     virshControl *priv = ctl->privData;
+    virTypedParameterPtr params = NULL;
+    int nparams = 0;
+    int maxparams = 0;
+    int nchannels = 0;
     int rc;
 
-    if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
-        return false;
-
     if (vshCommandOptBool(cmd, "bypass-cache"))
         flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE;
+    if (vshCommandOptBool(cmd, "parallel"))
+        flags |= VIR_DOMAIN_SAVE_PARALLEL;
     if (vshCommandOptBool(cmd, "running"))
         flags |= VIR_DOMAIN_SAVE_RUNNING;
     if (vshCommandOptBool(cmd, "paused"))
@@ -5308,15 +5319,34 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptBool(cmd, "reset-nvram"))
         flags |= VIR_DOMAIN_SAVE_RESET_NVRAM;
 
+    if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
+        return false;
+    if (from &&
+        virTypedParamsAddString(&params, &nparams, &maxparams,
+                                VIR_DOMAIN_SAVE_PARAM_FILE, from) < 0)
+        return false;
+
     if (vshCommandOptString(ctl, cmd, "xml", &xmlfile) < 0)
         return false;
 
     if (xmlfile &&
         virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
         return false;
+    if (xml &&
+        virTypedParamsAddString(&params, &nparams, &maxparams,
+                                VIR_DOMAIN_SAVE_PARAM_DXML, xml) < 0)
+        return false;
+
+    if ((rc = vshCommandOptInt(ctl, cmd, "parallel-connections", &nchannels)) < 0) {
+        return false;
+    } else if (rc > 0) {
+        if (virTypedParamsAddInt(&params, &nparams, &maxparams,
+                                 VIR_DOMAIN_SAVE_PARAM_PARALLEL_CONNECTIONS, nchannels) < 0)
+            return false;
+    }
 
     if (flags || xml) {
-        rc = virDomainRestoreFlags(priv->conn, from, xml, flags);
+        rc = virDomainRestoreParams(priv->conn, params, nparams, flags);
     } else {
         rc = virDomainRestore(priv->conn, from);
     }
-- 
2.35.3