[libvirt RFC v3 18/19] tools: add parallel parameter to virsh restore command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Claudio Fontana <cfontana@xxxxxxx>
---
 docs/manpages/virsh.rst | 11 +++++++++-
 tools/virsh-domain.c    | 47 ++++++++++++++++++++++++++++++++++-------
 2 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 2bce701057..21bfc8b16b 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -3752,12 +3752,14 @@ restore
 ::
 
    restore state-file [--bypass-cache] [--xml file]
+      [--parallel] [--parallel-connections connections]
       [{--running | --paused}] [--reset-nvram]
 
 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
@@ -3773,6 +3775,13 @@ 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 from multiple
+state files over parallel connections. The main save file is specified
+with ``state-file``, and the number of additional channels can be set
+using *--parallel-connections*
+
+Parallel connections may help in speeding up the save operation.
+
 ``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 1e3adaa1be..3a5df609a7 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5302,6 +5302,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/files for parallel restore")
+    },
     {.name = "xml",
      .type = VSH_OT_STRING,
      .completer = virshCompletePathLocalExisting,
@@ -5326,17 +5334,36 @@ static bool
 cmdRestore(vshControl *ctl, const vshCmd *cmd)
 {
     const char *from = NULL;
+    virTypedParameterPtr params = NULL;
+    int nparams = 0;
+    int maxparams = 0;
+    int intOpt = 0;
     unsigned int flags = 0;
     const char *xmlfile = NULL;
     g_autofree char *xml = NULL;
     virshControl *priv = ctl->privData;
-    int rc;
+    int rc = -1;
 
-    if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
-        return false;
+    if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) {
+        goto out;
+    } else {
+        if (virTypedParamsAddString(&params, &nparams, &maxparams,
+                                    VIR_SAVE_PARAM_FILE, from) < 0)
+            goto out;
+    }
 
     if (vshCommandOptBool(cmd, "bypass-cache"))
         flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE;
+    if (vshCommandOptBool(cmd, "parallel"))
+        flags |= VIR_DOMAIN_SAVE_PARALLEL;
+    if ((rc = vshCommandOptInt(ctl, cmd, "parallel-connections", &intOpt)) < 0) {
+        goto out;
+    } else if (rc > 0) {
+        rc = -1;
+        if (virTypedParamsAddInt(&params, &nparams, &maxparams,
+                                 VIR_SAVE_PARAM_PARALLEL_CONNECTIONS, intOpt) < 0)
+            goto out;
+    }
     if (vshCommandOptBool(cmd, "running"))
         flags |= VIR_DOMAIN_SAVE_RUNNING;
     if (vshCommandOptBool(cmd, "paused"))
@@ -5345,13 +5372,15 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_SAVE_RESET_NVRAM;
 
     if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
-        return false;
+        goto out;
 
     if (xmlfile &&
         virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
-        return false;
+        goto out;
 
-    if (flags || xml) {
+    if (flags & VIR_DOMAIN_SAVE_PARALLEL) {
+        rc = virDomainRestoreParametersFlags(priv->conn, params, nparams, flags);
+    } else if (flags || xml) {
         rc = virDomainRestoreFlags(priv->conn, from, xml, flags);
     } else {
         rc = virDomainRestore(priv->conn, from);
@@ -5359,11 +5388,13 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
 
     if (rc < 0) {
         vshError(ctl, _("Failed to restore domain from %s"), from);
-        return false;
+        goto out;
     }
 
     vshPrintExtra(ctl, _("Domain restored from %s\n"), from);
-    return true;
+ out:
+    virTypedParamsFree(params, nparams);
+    return rc >= 0;
 }
 
 /*
-- 
2.34.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux