From: Peter Krempa <pkrempa@redhat.com> Use the new VIR_DOMAIN_BLOCK_RESIZE_EXTEND to prevent accidentally shrinking a disk and thus destroying data. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/manpages/virsh.rst | 7 ++++++- tools/virsh-domain.c | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 4b8bbec7d6..80b0ea14a8 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1642,7 +1642,7 @@ blockresize :: - blockresize domain path ([size] | [--capacity]) + blockresize domain path ([size] | [--capacity]) [--extend] Resize a block device of domain while the domain is running, *path* specifies the absolute path of the block device; it corresponds @@ -1650,6 +1650,11 @@ to a unique target name (<target dev='name'/>) or source file (<source file='name'/>) for one of the disk devices attached to *domain* (see also ``domblklist`` for listing these names). +The *--extend* flag instructs the hypervisor to ensure that the new size isn't +smaller than the old size, thus prevents (accidental) shrinking of the block +device which may lead to data loss. Users are encouraged to always use this +flag unless communicating with an older hypervisor. + 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. diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index a17c8b42e2..08a1ce3953 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3339,6 +3339,10 @@ static const vshCmdOptDef opts_blockresize[] = { .type = VSH_OT_BOOL, .help = N_("resize to capacity of source (block device)") }, + {.name = "extend", + .type = VSH_OT_BOOL, + .help = N_("ensure that the new size is larger than actual capacity (prevent shrink)") + }, {.name = NULL} }; @@ -3352,6 +3356,9 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) VSH_ALTERNATIVE_OPTIONS("size", "capacity"); + if (vshCommandOptBool(cmd, "extend")) + flags |= VIR_DOMAIN_BLOCK_RESIZE_EXTEND; + if (vshCommandOptString(ctl, cmd, "path", (const char **) &path) < 0) return false; -- 2.53.0