[libvirt] [PATCH 0/2] qemu: Allow block-copy for persistent VMs under same conditions as for transient

Peter Krempa (2): qemu: Conditionally allow block-copy for persistent domains virsh: Add support for VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB include/libvirt/libvirt-domain.h | 3 +++ src/libvirt-domain.c | 3 +++ src/qemu/qemu_driver.c | 9 ++++++--- tools/virsh-domain.c | 10 +++++++++- tools/virsh.pod | 4 ++++ 5 files changed, 25 insertions(+), 4 deletions(-) -- 2.12.2

Allow starting the block-copy job for a persistent domain if a user declares by using a flag that the job will not be recovered if the VM is switched off while the job is active. This allows to use the block-copy job with persistent VMs under the same conditions as would apply to transient domains. --- include/libvirt/libvirt-domain.h | 3 +++ src/libvirt-domain.c | 3 +++ src/qemu/qemu_driver.c | 9 ++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 720db32f7..45f939a8c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2428,6 +2428,9 @@ typedef enum { backing chain */ VIR_DOMAIN_BLOCK_COPY_REUSE_EXT = 1 << 1, /* Reuse existing external file for a copy */ + VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB = 1 << 2, /* Don't force usage of + recoverable job for the + copy operation */ } virDomainBlockCopyFlags; /** diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 310b91b37..6726a5120 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -10027,6 +10027,9 @@ virDomainBlockRebase(virDomainPtr dom, const char *disk, * or virDomainDetachDevice(), while a copy job is active; they may * also restrict a copy job to transient domains. * + * If @flags contains VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB the job will not be + * recoverable if the VM is turned of while job is active. + * * The @disk parameter is either an unambiguous source name of the * block device (the <source file='...'/> sub-element, such as * "/path/to/image"), or the device target shorthand (the diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f0cdea659..29efda198 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16507,7 +16507,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, /* Preliminaries: find the disk we are editing, sanity checks */ virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW | - VIR_DOMAIN_BLOCK_COPY_REUSE_EXT, -1); + VIR_DOMAIN_BLOCK_COPY_REUSE_EXT | + VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB, -1); priv = vm->privateData; cfg = virQEMUDriverGetConfig(driver); @@ -16546,7 +16547,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, _("block copy is not supported with this QEMU binary")); goto endjob; } - if (vm->persistent) { + if (!(flags & VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB) && + vm->persistent) { /* XXX if qemu ever lets us start a new domain with mirroring * already active, we can relax this; but for now, the risk of * 'managedsave' due to libvirt-guests means we can't risk @@ -16773,7 +16775,8 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml, size_t i; virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW | - VIR_DOMAIN_BLOCK_COPY_REUSE_EXT, -1); + VIR_DOMAIN_BLOCK_COPY_REUSE_EXT | + VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB, -1); if (virTypedParamsValidate(params, nparams, VIR_DOMAIN_BLOCK_COPY_BANDWIDTH, VIR_TYPED_PARAM_ULLONG, -- 2.12.2

On Tue, Jun 06, 2017 at 16:46:14 +0200, Peter Krempa wrote:
Allow starting the block-copy job for a persistent domain if a user declares by using a flag that the job will not be recovered if the VM is switched off while the job is active.
This allows to use the block-copy job with persistent VMs under the same conditions as would apply to transient domains. --- include/libvirt/libvirt-domain.h | 3 +++ src/libvirt-domain.c | 3 +++ src/qemu/qemu_driver.c | 9 ++++++--- 3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 720db32f7..45f939a8c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2428,6 +2428,9 @@ typedef enum { backing chain */ VIR_DOMAIN_BLOCK_COPY_REUSE_EXT = 1 << 1, /* Reuse existing external file for a copy */ + VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB = 1 << 2, /* Don't force usage of + recoverable job for the + copy operation */ } virDomainBlockCopyFlags;
/** diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 310b91b37..6726a5120 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -10027,6 +10027,9 @@ virDomainBlockRebase(virDomainPtr dom, const char *disk, * or virDomainDetachDevice(), while a copy job is active; they may * also restrict a copy job to transient domains.
I think a short note saying the restriction can be lifted by using the new flag if the user is willing to accept the limitation you described below.
* + * If @flags contains VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB the job will not be + * recoverable if the VM is turned of while job is active.
s/of/off/ ACK Jirka

Allow using the new flag with virsh. --- tools/virsh-domain.c | 10 +++++++++- tools/virsh.pod | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ccb514ef9..f39589c20 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2184,6 +2184,10 @@ static const vshCmdOptDef opts_block_copy[] = { .type = VSH_OT_BOOL, .help = N_("the bandwidth limit is in bytes/s rather than MiB/s") }, + {.name = "transient-job", + .type = VSH_OT_BOOL, + .help = N_("the copy job is not persisted if VM is turned off") + }, {.name = NULL} }; @@ -2205,6 +2209,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) bool blocking = vshCommandOptBool(cmd, "wait") || finish || pivot; bool async = vshCommandOptBool(cmd, "async"); bool bytes = vshCommandOptBool(cmd, "bytes"); + bool transientjob = vshCommandOptBool(cmd, "transient-job"); int timeout = 0; const char *path = NULL; int abort_flags = 0; @@ -2234,6 +2239,8 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_BLOCK_REBASE_SHALLOW; if (vshCommandOptBool(cmd, "reuse-external")) flags |= VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT; + if (transientjob) + flags |= VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; @@ -2282,7 +2289,8 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) } } - if (granularity || buf_size || (format && STRNEQ(format, "raw")) || xml) { + if (granularity || buf_size || (format && STRNEQ(format, "raw")) || xml || + transientjob) { /* New API */ if (bandwidth || granularity || buf_size) { params = vshCalloc(ctl, 3, sizeof(*params)); diff --git a/tools/virsh.pod b/tools/virsh.pod index aee964689..b15595c3c 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1078,6 +1078,7 @@ command. | I<--xml> B<file> } [I<--shallow>] [I<--reuse-external>] [I<bandwidth>] [I<--wait> [I<--async>] [I<--verbose>]] [{I<--pivot> | I<--finish>}] [I<--timeout> B<seconds>] [I<granularity>] [I<buf-size>] [I<--bytes>] +[I<--transient-job>] Copy a disk backing image chain to a destination. Either I<dest> as the destination file name, or I<--xml> with the name of an XML file containing @@ -1132,6 +1133,9 @@ within a certain range. Specifying I<buf-size> will control how much data can be simultaneously in-flight during the copy; larger values use more memory but may allow faster completion (the default value is usually correct). +I<--transient-job> allows to specify that the user does not require the job to +be recovered if the VM crashes or is turned off before the job completes. + =item B<blockpull> I<domain> I<path> [I<bandwidth>] [I<--bytes>] [I<base>] [I<--wait> [I<--verbose>] [I<--timeout> B<seconds>] [I<--async>]] [I<--keep-relative>] -- 2.12.2

On Tue, Jun 06, 2017 at 16:46:15 +0200, Peter Krempa wrote:
Allow using the new flag with virsh. --- tools/virsh-domain.c | 10 +++++++++- tools/virsh.pod | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) ... diff --git a/tools/virsh.pod b/tools/virsh.pod index aee964689..b15595c3c 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1078,6 +1078,7 @@ command. | I<--xml> B<file> } [I<--shallow>] [I<--reuse-external>] [I<bandwidth>] [I<--wait> [I<--async>] [I<--verbose>]] [{I<--pivot> | I<--finish>}] [I<--timeout> B<seconds>] [I<granularity>] [I<buf-size>] [I<--bytes>] +[I<--transient-job>]
Copy a disk backing image chain to a destination. Either I<dest> as the destination file name, or I<--xml> with the name of an XML file containing @@ -1132,6 +1133,9 @@ within a certain range. Specifying I<buf-size> will control how much data can be simultaneously in-flight during the copy; larger values use more memory but may allow faster completion (the default value is usually correct).
+I<--transient-job> allows to specify that the user does not require the job to +be recovered if the VM crashes or is turned off before the job completes. +
Something similar could be added here too. ACK Jirka
participants (2)
-
Jiri Denemark
-
Peter Krempa