[libvirt] [PATCH] virsh: fix forget jump to clean up when set a big bandwidth

We already have a check for this, just add a jump to cleanup and change to use vshError instead of virReportError. Signed-off-by: Luyao Huang <lhuang@redhat.com> --- tools/virsh-domain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 1d8225c..33fbf9c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2253,9 +2253,8 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) * ullong bytes/s; make sure we don't overflow */ unsigned long long limit = MIN(ULONG_MAX, ULLONG_MAX >> 20); if (bandwidth > limit) { - virReportError(VIR_ERR_OVERFLOW, - _("bandwidth must be less than %llu"), - ULLONG_MAX >> 20); + vshError(ctl, _("bandwidth must be less than %llu"), limit); + goto cleanup; } if (virTypedParameterAssign(¶ms[nparams++], VIR_DOMAIN_BLOCK_COPY_BANDWIDTH, -- 1.8.3.1

https://bugzilla.redhat.com/show_bug.cgi?id=1206479
From our manual of virsh and qemu side code, we know this value must be power of 2, so instead of let qemu output error, we can add a check when we file this value in qemuDomainBlockCopy.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_driver.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2c55fb0..6d63317 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16871,6 +16871,11 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml, } bandwidth = param->value.ul; } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_GRANULARITY)) { + if (param->value.ui != VIR_ROUND_UP_POWER_OF_TWO(param->value.ui)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("granularity must be power of 2")); + goto cleanup; + } granularity = param->value.ui; } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_BUF_SIZE)) { buf_size = param->value.ul; -- 1.8.3.1

On 27.03.2015 10:56, Luyao Huang wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1206479
From our manual of virsh and qemu side code, we know this value must be power of 2, so instead of let qemu output error, we can add a check when we file this value in qemuDomainBlockCopy.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_driver.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2c55fb0..6d63317 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16871,6 +16871,11 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml, } bandwidth = param->value.ul; } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_GRANULARITY)) { + if (param->value.ui != VIR_ROUND_UP_POWER_OF_TWO(param->value.ui)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("granularity must be power of 2")); + goto cleanup; + } granularity = param->value.ui; } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_BUF_SIZE)) { buf_size = param->value.ul;
In fact, the virsh man page is not as precise as it could be either: diff --git a/tools/virsh.pod b/tools/virsh.pod index 63325ff..5d52761 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1039,10 +1039,10 @@ unlimited, but more likely would overflow; it is safer to use 0 for that purpose. Specifying I<granularity> allows fine-tuning of the granularity that will be copied when a dirty region is detected; larger values trigger less I/O overhead but may end up copying more data overall (the default value is usually correct); {+hypervisors may restrict+} this [-value must-]{+to+} be a power of [-two.-]{+two or fall+} {+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). =item B<blockpull> I<domain> I<path> [I<bandwidth>] [I<base>] [I<--wait> [I<--verbose>] [I<--timeout> B<seconds>] [I<--async>]] I'm fixing the man page too, rewording the commit message a bit and ACKing. Will push after the release. Michal

On 04/01/2015 04:12 PM, Michal Privoznik wrote:
On 27.03.2015 10:56, Luyao Huang wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1206479
From our manual of virsh and qemu side code, we know this value must be power of 2, so instead of let qemu output error, we can add a check when we file this value in qemuDomainBlockCopy.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_driver.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2c55fb0..6d63317 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16871,6 +16871,11 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml, } bandwidth = param->value.ul; } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_GRANULARITY)) { + if (param->value.ui != VIR_ROUND_UP_POWER_OF_TWO(param->value.ui)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("granularity must be power of 2")); + goto cleanup; + } granularity = param->value.ui; } else if (STREQ(param->field, VIR_DOMAIN_BLOCK_COPY_BUF_SIZE)) { buf_size = param->value.ul;
In fact, the virsh man page is not as precise as it could be either:
diff --git a/tools/virsh.pod b/tools/virsh.pod index 63325ff..5d52761 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1039,10 +1039,10 @@ unlimited, but more likely would overflow; it is safer to use 0 for that purpose. Specifying I<granularity> allows fine-tuning of the granularity that will be copied when a dirty region is detected; larger values trigger less I/O overhead but may end up copying more data overall (the default value is usually correct); {+hypervisors may restrict+} this [-value must-]{+to+} be a power of [-two.-]{+two or fall+} {+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).
=item B<blockpull> I<domain> I<path> [I<bandwidth>] [I<base>] [I<--wait> [I<--verbose>] [I<--timeout> B<seconds>] [I<--async>]]
I'm fixing the man page too, rewording the commit message a bit and ACKing. Will push after the release.
Oh, thanks a lot for your remind and your fix for man page looks good for me. Thanks for your review.
Michal
Luyao

On Fri, Mar 27, 2015 at 17:56:29 +0800, Luyao Huang wrote:
We already have a check for this, just add a jump to cleanup and change to use vshError instead of virReportError.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- tools/virsh-domain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
I've reworded the commit message and pushed the patch. Peter
participants (4)
-
lhuang
-
Luyao Huang
-
Michal Privoznik
-
Peter Krempa