1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

qemuDomainBlockResize: Implement VIR_DOMAIN_BLOCK_RESIZE_CAPACITY

Resizing of block-backed storage requires the user to pass the exact
capacity of the device. Implement code which will query it instead so
the user doesn't need to do that.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/449
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-12-13 15:44:36 +01:00
parent 04adeac76e
commit d09f46a9fb

View File

@ -9246,7 +9246,8 @@ qemuDomainBlockResize(virDomainPtr dom,
const char *nodename = NULL;
virDomainDiskDef *disk = NULL;
virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES |
VIR_DOMAIN_BLOCK_RESIZE_CAPACITY, -1);
/* We prefer operating on bytes. */
if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) == 0) {
@ -9292,6 +9293,25 @@ qemuDomainBlockResize(virDomainPtr dom,
goto endjob;
}
if (flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) {
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);
if (!qemuBlockStorageSourceIsRaw(disk->src) ||
!virStorageSourceIsBlockLocal(disk->src)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("block resize to full capacity supported only with 'raw' local block-based disks"));
goto endjob;
}
if (qemuDomainStorageUpdatePhysical(cfg, vm, disk->src) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("failed to update capacity of '%1$s'"), disk->src->path);
goto endjob;
}
size = disk->src->physical;
}
/* qcow2 and qed must be sized on 512 byte blocks/sectors,
* so adjust size if necessary to round up.
*/