]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: add parallel parameter to virsh restore command
authorClaudio Fontana <cfontana@suse.de>
Mon, 25 Apr 2022 16:32:31 +0000 (10:32 -0600)
committerJim Fehlig <jfehlig@suse.com>
Thu, 20 Mar 2025 17:17:48 +0000 (11:17 -0600)
Signed-off-by: Claudio Fontana <cfontana@suse.de>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
docs/manpages/virsh.rst
tools/virsh-domain.c

index 38f3967ed81feb5894bfcec287c6e0643125d325..8143366826ded616e578ed3fababe3cfc11f6a6a 100644 (file)
@@ -4125,12 +4125,13 @@ restore
 ::
 
    restore state-file [--bypass-cache] [--xml file]
-      [{--running | --paused}] [--reset-nvram]
+      [{--running | --paused}] [--reset-nvram] [--parallel] [--parallel-channels]
 
 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
@@ -4146,6 +4147,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 IO channels specified with *--parallel-channels*. Parallel
+channels 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
index fd56400f6a0ab73415aaf69858c0672d60f73e53..1bee9698244b3343e9769024e442ba37eaab086d 100644 (file)
@@ -5666,6 +5666,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-channels",
+     .type = VSH_OT_INT,
+     .help = N_("number of IO channels to use for parallel restore")
+    },
     {.name = "xml",
      .type = VSH_OT_STRING,
      .unwanted_positional = true,
@@ -5695,13 +5703,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 = 1;
     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"))
@@ -5709,15 +5720,35 @@ 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 (flags & VIR_DOMAIN_SAVE_PARALLEL) {
+        if ((rc = vshCommandOptInt(ctl, cmd, "parallel-channels", &nchannels)) < 0)
+            return false;
+
+        if (virTypedParamsAddInt(&params, &nparams, &maxparams,
+                                 VIR_DOMAIN_SAVE_PARAM_PARALLEL_CHANNELS, 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);
     }