A post commit id 'e3d66229' review (and followup):
http://www.redhat.com/archives/libvir-list/2014-May/msg00268.html
noted some issues with the code, so I have adjusted the code
accordingly. The difference between this and the commit prior
to the change (commit id 'f3be5f0c') will just be the check for
qcow2/qed using a non 512 block aligned size will result in a
round up of size. If the size is within the last 512 bytes to
ULLONG_MAX, then just set it there rather than erroring out.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_driver.c | 28 +++++++++-------------------
1 file changed, 9 insertions(+), 19 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4ff8a2d..8771cae 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9413,7 +9413,6 @@ qemuDomainBlockResize(virDomainPtr dom,
virDomainObjPtr vm;
qemuDomainObjPrivatePtr priv;
int ret = -1, idx;
- unsigned long long size_up;
char *device = NULL;
virDomainDiskDefPtr disk = NULL;
@@ -9434,12 +9433,6 @@ qemuDomainBlockResize(virDomainPtr dom,
return -1;
}
size *= 1024;
- size_up = size;
- } else {
- /* For 'qcow2' and 'qed', qemu resize blocks expects values
- * on sector boundary, so round our value up to prepare
- */
- size_up = VIR_ROUND_UP(size, 512);
}
if (!(vm = qemuDomObjFromDomain(dom)))
@@ -9466,19 +9459,16 @@ qemuDomainBlockResize(virDomainPtr dom,
}
disk = vm->def->disks[idx];
- /* qcow2 and qed must be sized appropriately, so be sure our value
- * is sized appropriately and will fit
+ /* qcow2 and qed must be sized on 512 byte blocks/sectors,
+ * so adjust size if necessary to round up (if possible).
*/
- if (size != size_up &&
- (disk->src.format == VIR_STORAGE_FILE_QCOW2 ||
- disk->src.format == VIR_STORAGE_FILE_QED)) {
- if (size_up > ULLONG_MAX) {
- virReportError(VIR_ERR_OVERFLOW,
- _("size must be less than %llu KiB"),
- ULLONG_MAX / 1024);
- goto endjob;
- }
- size = size_up;
+ if ((disk->src.format == VIR_STORAGE_FILE_QCOW2 ||
+ disk->src.format == VIR_STORAGE_FILE_QED) &&
+ (size % 512)) {
+ if ((ULLONG_MAX - size) < 512)
+ size = ULLONG_MAX;
+ else
+ size = VIR_ROUND_UP(size, 512);
}
if (virAsprintf(&device, "%s%s", QEMU_DRIVE_HOST_PREFIX,
--
1.9.0