Introduce flag for the block rebase API to allow the rebase operation to
leave the chain relatively addressed. Also adds a virsh switch to enable
this behavior.
---
include/libvirt/libvirt.h.in | 2 ++
src/libvirt.c | 5 +++++
tools/virsh-domain.c | 22 +++++++++++++++++++---
tools/virsh.pod | 4 ++++
4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index bacdf57..44efd60 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2573,6 +2573,8 @@ typedef enum {
file for a copy */
VIR_DOMAIN_BLOCK_REBASE_COPY_RAW = 1 << 2, /* Make destination file raw */
VIR_DOMAIN_BLOCK_REBASE_COPY = 1 << 3, /* Start a copy job */
+ VIR_DOMAIN_BLOCK_REBASE_RELATIVE = 1 << 4, /* Keep backing chain relative
+ if possible */
} virDomainBlockRebaseFlags;
int virDomainBlockRebase(virDomainPtr dom, const char *disk,
diff --git a/src/libvirt.c b/src/libvirt.c
index 21ef41f..a5f9547 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -19716,6 +19716,11 @@ virDomainBlockPull(virDomainPtr dom, const char *disk,
* exists. If the job is aborted, a new one can be started later to
* resume from the same point.
*
+ * If @flags contains VIR_DOMAIN_BLOCK_REBASE_RELATIVE, the name recorded
+ * into the overlay of the @base image as path to the new backing file
+ * will be kept relative to other images in case the backing chain was
+ * using relative names.
+ *
* When @flags includes VIR_DOMAIN_BLOCK_REBASE_COPY, this starts a copy,
* where @base must be the name of a new file to copy the chain to. By
* default, the copy will pull the entire source chain into the destination
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f26a133..e9162db 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1479,10 +1479,14 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
case VSH_CMD_BLOCK_JOB_PULL:
if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0)
goto cleanup;
- if (base)
- ret = virDomainBlockRebase(dom, path, base, bandwidth, 0);
- else
+ if (base) {
+ if (vshCommandOptBool(cmd, "keep-relative"))
+ flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE;
+
+ ret = virDomainBlockRebase(dom, path, base, bandwidth, flags);
+ } else {
ret = virDomainBlockPull(dom, path, bandwidth, 0);
+ }
break;
case VSH_CMD_BLOCK_JOB_COMMIT:
if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0 ||
@@ -2072,6 +2076,11 @@ static const vshCmdOptDef opts_block_pull[] = {
.type = VSH_OT_BOOL,
.help = N_("with --wait, don't wait for cancel to finish")
},
+ {.name = "keep-relative",
+ .type = VSH_OT_BOOL,
+ .help = N_("keep the backing chain relative if it was relatively "
+ "referenced if it was before")
+ },
{.name = NULL}
};
@@ -2092,6 +2101,13 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
bool quit = false;
int abort_flags = 0;
+ if (vshCommandOptBool(cmd, "keep-relative") &&
+ !vshCommandOptBool(cmd, "base")) {
+ vshError(ctl, "%s", _("--keep-relative is supported only with
partial "
+ "pull operations with --base specified"));
+ return false;
+ }
+
if (blocking) {
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
return false;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 5816c0b..84a60a7 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -846,6 +846,7 @@ I<bandwidth> specifies copying bandwidth limit in MiB/s.
=item B<blockpull> I<domain> I<path> [I<bandwidth>]
[I<base>]
[I<--wait> [I<--verbose>] [I<--timeout> B<seconds>]
[I<--async>]]
+[I<--keep-relative>]
Populate a disk from its backing image chain. By default, this command
flattens the entire chain; but if I<base> is specified, containing the
@@ -865,6 +866,9 @@ is triggered, I<--async> will return control to the user as fast
as
possible, otherwise the command may continue to block a little while
longer until the job is done cleaning up.
+Using the I<--keep-relative> flag will try to keep the backing chain names
+relative (if they were relative before).
+
I<path> specifies fully-qualified path of the disk; it corresponds
to a unique target name (<target dev='name'/>) or source file (<source
file='name'/>) for one of the disk devices attached to I<domain> (see
--
1.9.3