If a block device is an LVM logical volume we can resize it using standard LVM tools.
In raw_co_truncate() check if the block device is a LV using lvdisplay and resize it executing lvresize. Signed-off-by: Alexander Ivanov <alexander.iva...@virtuozzo.com> --- block/file-posix.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 35684f7e21..cf8a04e6f7 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2670,6 +2670,33 @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { int64_t cur_length = raw_getlength(bs); + /* + * Check if the device is an LVM logical volume and try to resize + * it using LVM tools. + */ + if (S_ISBLK(st.st_mode) && offset > 0) { + char cmd[PATH_MAX + 32]; + + snprintf(cmd, sizeof(cmd), "lvdisplay %s > /dev/null", + bs->filename); + ret = system(cmd); + if (ret != 0) { + error_setg(errp, "lvdisplay returned %d error for '%s'", + ret, bs->filename); + return ret; + } + + snprintf(cmd, sizeof(cmd), "lvresize -f -L %ldB %s > /dev/null", + offset, bs->filename); + ret = system(cmd); + if (ret != 0) { + error_setg(errp, "lvresize returned %d error for '%s'", + ret, bs->filename); + } + + return ret; + } + if (offset != cur_length && exact) { error_setg(errp, "Cannot resize device files"); return -ENOTSUP; -- 2.40.1