Signed-off-by: Claudio Fontana <cfontana(a)suse.de>
---
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 e9012b85d1..3bf9b54806 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -3754,12 +3754,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
@@ -3775,6 +3777,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 4e39834118..9fdb4e43d0 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5312,6 +5312,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,
@@ -5336,17 +5344,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(¶ms, &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(¶ms, &nparams, &maxparams,
+ VIR_SAVE_PARAM_PARALLEL_CONNECTIONS, intOpt) < 0)
+ goto out;
+ }
if (vshCommandOptBool(cmd, "running"))
flags |= VIR_DOMAIN_SAVE_RUNNING;
if (vshCommandOptBool(cmd, "paused"))
@@ -5355,13 +5382,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 = virDomainRestoreParams(priv->conn, params, nparams, flags);
+ } else if (flags || xml) {
rc = virDomainRestoreFlags(priv->conn, from, xml, flags);
} else {
rc = virDomainRestore(priv->conn, from);
@@ -5369,11 +5398,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