From: Alexander Polyakov <apolyakov@xxxxxxxxx> Add new virStorageBackendLogicalResizeVol function to implement resize of logical volumes Sparse volumes are not supported Signed-off-by: Alexander Polyakov <apolyakov@xxxxxxxxx> --- m4/virt-storage-lvm.m4 | 4 ++++ src/storage/storage_backend_logical.c | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/m4/virt-storage-lvm.m4 b/m4/virt-storage-lvm.m4 index a0ccca7a0..0932995b4 100644 --- a/m4/virt-storage-lvm.m4 +++ b/m4/virt-storage-lvm.m4 @@ -30,6 +30,7 @@ AC_DEFUN([LIBVIRT_STORAGE_CHECK_LVM], [ AC_PATH_PROG([VGREMOVE], [vgremove], [], [$LIBVIRT_SBIN_PATH]) AC_PATH_PROG([LVREMOVE], [lvremove], [], [$LIBVIRT_SBIN_PATH]) AC_PATH_PROG([LVCHANGE], [lvchange], [], [$LIBVIRT_SBIN_PATH]) + AC_PATH_PROG([LVRESIZE], [lvresize], [], [$LIBVIRT_SBIN_PATH]) AC_PATH_PROG([VGCHANGE], [vgchange], [], [$LIBVIRT_SBIN_PATH]) AC_PATH_PROG([VGSCAN], [vgscan], [], [$LIBVIRT_SBIN_PATH]) AC_PATH_PROG([PVS], [pvs], [], [$LIBVIRT_SBIN_PATH]) @@ -44,6 +45,7 @@ AC_DEFUN([LIBVIRT_STORAGE_CHECK_LVM], [ if test -z "$VGREMOVE" ; then AC_MSG_ERROR([We need vgremove for LVM storage driver]) ; fi if test -z "$LVREMOVE" ; then AC_MSG_ERROR([We need lvremove for LVM storage driver]) ; fi if test -z "$LVCHANGE" ; then AC_MSG_ERROR([We need lvchange for LVM storage driver]) ; fi + if test -z "$LVRESIZE" ; then AC_MSG_ERROR([We need lvresize for LVM storage driver]) ; fi if test -z "$VGCHANGE" ; then AC_MSG_ERROR([We need vgchange for LVM storage driver]) ; fi if test -z "$VGSCAN" ; then AC_MSG_ERROR([We need vgscan for LVM storage driver]) ; fi if test -z "$PVS" ; then AC_MSG_ERROR([We need pvs for LVM storage driver]) ; fi @@ -57,6 +59,7 @@ AC_DEFUN([LIBVIRT_STORAGE_CHECK_LVM], [ if test -z "$VGREMOVE" ; then with_storage_lvm=no ; fi if test -z "$LVREMOVE" ; then with_storage_lvm=no ; fi if test -z "$LVCHANGE" ; then with_storage_lvm=no ; fi + if test -z "$LVRESIZE" ; then with_storage_lvm=no ; fi if test -z "$VGCHANGE" ; then with_storage_lvm=no ; fi if test -z "$VGSCAN" ; then with_storage_lvm=no ; fi if test -z "$PVS" ; then with_storage_lvm=no ; fi @@ -75,6 +78,7 @@ AC_DEFUN([LIBVIRT_STORAGE_CHECK_LVM], [ AC_DEFINE_UNQUOTED([VGREMOVE],["$VGREMOVE"],[Location of vgremove program]) AC_DEFINE_UNQUOTED([LVREMOVE],["$LVREMOVE"],[Location of lvremove program]) AC_DEFINE_UNQUOTED([LVCHANGE],["$LVCHANGE"],[Location of lvchange program]) + AC_DEFINE_UNQUOTED([LVRESIZE],["$LVRESIZE"],[Location of lvresize program]) AC_DEFINE_UNQUOTED([VGCHANGE],["$VGCHANGE"],[Location of vgchange program]) AC_DEFINE_UNQUOTED([VGSCAN],["$VGSCAN"],[Location of vgscan program]) AC_DEFINE_UNQUOTED([PVS],["$PVS"],[Location of pvs program]) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 67f70e551..e5cb09922 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -1072,6 +1072,42 @@ virStorageBackendLogicalVolWipe(virConnectPtr conn, return -1; } +static int +virStorageBackendLogicalResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED, + virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStorageVolDefPtr vol, + unsigned long long capacity, + unsigned int flags) +{ + virCheckFlags(VIR_STORAGE_VOL_RESIZE_SHRINK | + VIR_STORAGE_VOL_RESIZE_DELTA, -1); + + bool delta = flags & VIR_STORAGE_VOL_RESIZE_DELTA; + bool shrink = flags & VIR_STORAGE_VOL_RESIZE_SHRINK; + + if (vol->target.sparse) { + virReportError(VIR_ERR_NO_SUPPORT, + _("logical volume '%s' is sparse, volume resize " + "not supported"), + vol->target.path); + return -1; + } + + virCommandPtr cmd = virCommandNewArgList(LVRESIZE, "-L", NULL); + + if (delta) { + virCommandAddArgFormat(cmd, "%c%lluB", shrink ? '-' : '+', + capacity); + } else { + virCommandAddArgFormat(cmd, "%lluB", capacity); + } + virCommandAddArgFormat(cmd, "%s", vol->target.path); + int ret = virCommandRun(cmd, NULL); + + virCommandFree(cmd); + return ret; +} + virStorageBackend virStorageBackendLogical = { .type = VIR_STORAGE_POOL_LOGICAL, @@ -1089,6 +1125,7 @@ virStorageBackend virStorageBackendLogical = { .uploadVol = virStorageBackendVolUploadLocal, .downloadVol = virStorageBackendVolDownloadLocal, .wipeVol = virStorageBackendLogicalVolWipe, + .resizeVol = virStorageBackendLogicalResizeVol, }; -- 2.13.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list