mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virDomainBlockResize: Introduce VIR_DOMAIN_BLOCK_RESIZE_CAPACITY
Allow users to easily resize 'raw' images on block devices to the full capacity of the block device. Obviously this won't work on file-backed storage (filling the remaining capacity is most likely wrong) or for formats with metadata due to the overhead. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
a7b357fd5c
commit
04adeac76e
@ -1421,7 +1421,7 @@ blockresize
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
blockresize domain path size
|
blockresize domain path ([size] | [--capacity])
|
||||||
|
|
||||||
Resize a block device of domain while the domain is running, *path*
|
Resize a block device of domain while the domain is running, *path*
|
||||||
specifies the absolute path of the block device; it corresponds
|
specifies the absolute path of the block device; it corresponds
|
||||||
@ -1429,6 +1429,10 @@ to a unique target name (<target dev='name'/>) or source file (<source
|
|||||||
file='name'/>) for one of the disk devices attached to *domain* (see
|
file='name'/>) for one of the disk devices attached to *domain* (see
|
||||||
also ``domblklist`` for listing these names).
|
also ``domblklist`` for listing these names).
|
||||||
|
|
||||||
|
For image formats without metadata (raw) stored inside fixed-size storage (e.g.
|
||||||
|
block devices) the --capacity flag can be used to resize the device to the
|
||||||
|
full size of the backing device.
|
||||||
|
|
||||||
*size* is a scaled integer (see ``NOTES`` above) which defaults to KiB
|
*size* is a scaled integer (see ``NOTES`` above) which defaults to KiB
|
||||||
(blocks of 1024 bytes) if there is no suffix. You must use a suffix of
|
(blocks of 1024 bytes) if there is no suffix. You must use a suffix of
|
||||||
"B" to get bytes (note that for historical reasons, this differs from
|
"B" to get bytes (note that for historical reasons, this differs from
|
||||||
|
@ -2172,6 +2172,7 @@ int virDomainBlockPeek (virDomainPtr dom,
|
|||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
VIR_DOMAIN_BLOCK_RESIZE_BYTES = 1 << 0, /* size in bytes instead of KiB (Since: 0.9.11) */
|
VIR_DOMAIN_BLOCK_RESIZE_BYTES = 1 << 0, /* size in bytes instead of KiB (Since: 0.9.11) */
|
||||||
|
VIR_DOMAIN_BLOCK_RESIZE_CAPACITY = 1 << 1, /* resize to full the capacity of the source (Since: 10.0.0) */
|
||||||
} virDomainBlockResizeFlags;
|
} virDomainBlockResizeFlags;
|
||||||
|
|
||||||
int virDomainBlockResize (virDomainPtr dom,
|
int virDomainBlockResize (virDomainPtr dom,
|
||||||
|
@ -6388,6 +6388,11 @@ virDomainBlockPeek(virDomainPtr dom,
|
|||||||
* size. Depending on the file format, the hypervisor may round up
|
* size. Depending on the file format, the hypervisor may round up
|
||||||
* to the next alignment boundary.
|
* to the next alignment boundary.
|
||||||
*
|
*
|
||||||
|
* If @flag contains VIR_DOMAIN_BLOCK_RESIZE_CAPACITY (since 10.0.0) the
|
||||||
|
* hypervisor will resize the guest block device to fully fill the source,
|
||||||
|
* ignoring @size. This is possible only for image formats with no metadata
|
||||||
|
* ('raw') and for source devices with limited capacity such as block devices.
|
||||||
|
*
|
||||||
* The @disk parameter is either an unambiguous source name of the
|
* The @disk parameter is either an unambiguous source name of the
|
||||||
* block device (the <source file='...'/> sub-element, such as
|
* block device (the <source file='...'/> sub-element, such as
|
||||||
* "/path/to/image"), or (since 0.9.5) the device target shorthand
|
* "/path/to/image"), or (since 0.9.5) the device target shorthand
|
||||||
|
@ -2949,9 +2949,12 @@ static const vshCmdOptDef opts_blockresize[] = {
|
|||||||
},
|
},
|
||||||
{.name = "size",
|
{.name = "size",
|
||||||
.type = VSH_OT_INT,
|
.type = VSH_OT_INT,
|
||||||
.flags = VSH_OFLAG_REQ,
|
|
||||||
.help = N_("New size of the block device, as scaled integer (default KiB)")
|
.help = N_("New size of the block device, as scaled integer (default KiB)")
|
||||||
},
|
},
|
||||||
|
{.name = "capacity",
|
||||||
|
.type = VSH_OT_BOOL,
|
||||||
|
.help = N_("resize to capacity of source (block device)")
|
||||||
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2963,17 +2966,23 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd)
|
|||||||
unsigned long long size = 0;
|
unsigned long long size = 0;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
|
||||||
|
VSH_ALTERNATIVE_OPTIONS("size", "capacity");
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0)
|
if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Prefer the older interface of KiB. */
|
if (vshCommandOptBool(cmd, "capacity")) {
|
||||||
if (size % 1024 == 0)
|
flags |= VIR_DOMAIN_BLOCK_RESIZE_CAPACITY;
|
||||||
size /= 1024;
|
} else {
|
||||||
else
|
/* Prefer the older interface of KiB. */
|
||||||
flags |= VIR_DOMAIN_BLOCK_RESIZE_BYTES;
|
if (size % 1024 == 0)
|
||||||
|
size /= 1024;
|
||||||
|
else
|
||||||
|
flags |= VIR_DOMAIN_BLOCK_RESIZE_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user