From nobody Thu May 2 14:19:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517066900344758.7059405652936; Sat, 27 Jan 2018 07:28:20 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24F8D5D675; Sat, 27 Jan 2018 15:28:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1994D608EF; Sat, 27 Jan 2018 15:28:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D752418033D9; Sat, 27 Jan 2018 15:28:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0RFSDql013359 for ; Sat, 27 Jan 2018 10:28:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2DD4B5C20A; Sat, 27 Jan 2018 15:28:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27AB35C1AB for ; Sat, 27 Jan 2018 15:28:10 +0000 (UTC) Received: from cc.z1.sdstack.com (92-255-100-1.customer.comfortel.pro [92.255.100.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4F82C04AC43 for ; Sat, 27 Jan 2018 15:27:48 +0000 (UTC) Received: from vtolstov by cc.z1.sdstack.com with local (Exim 4.89) (envelope-from ) id 1ef8wv-00033n-41 for libvir-list@redhat.com; Fri, 26 Jan 2018 21:42:05 +0300 From: Vasiliy Tolstov To: libvir-list@redhat.com Date: Fri, 26 Jan 2018 21:42:01 +0300 Message-Id: <20180126184201.11058-2-v.tolstov@selfip.ru> In-Reply-To: <20180126184201.11058-1-v.tolstov@selfip.ru> References: <20180126184201.11058-1-v.tolstov@selfip.ru> X-Greylist: Delayed for 20:45:43 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 27 Jan 2018 15:28:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 27 Jan 2018 15:28:07 +0000 (UTC) for IP:'92.255.100.1' DOMAIN:'92-255-100-1.customer.comfortel.pro' HELO:'cc.z1.sdstack.com' FROM:'vtolstov@cc.z1.sdstack.com' RCPT:'' X-RedHat-Spam-Score: 0.364 (HEADER_FROM_DIFFERENT_DOMAINS, RDNS_DYNAMIC) 92.255.100.1 92-255-100-1.customer.comfortel.pro 92.255.100.1 92-255-100-1.customer.comfortel.pro X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/1] [WIP] implement vol rename X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 27 Jan 2018 15:28:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vasiliy Tolstov --- include/libvirt/libvirt-storage.h | 3 ++ m4/virt-storage-lvm.m4 | 3 ++ src/libvirt-storage.c | 39 +++++++++++++++++++++ src/libvirt_private.syms | 1 + src/libvirt_public.syms | 8 ++++- src/remote/remote_driver.c | 1 + src/storage/storage_backend_fs.c | 3 ++ src/storage/storage_backend_logical.c | 27 +++++++++++++++ src/storage/storage_backend_rbd.c | 28 +++++++++++++++ src/storage/storage_backend_vstorage.c | 1 + src/storage/storage_driver.c | 63 ++++--------------------------= ---- src/storage/storage_util.c | 13 +++++++ src/storage/storage_util.h | 5 +++ src/util/virstoragefile.c | 39 +++++++++++++++++++++ tools/virsh-volume.c | 53 ++++++++++++++++++++++++++++ 15 files changed, 229 insertions(+), 58 deletions(-) diff --git a/include/libvirt/libvirt-storage.h b/include/libvirt/libvirt-st= orage.h index 736e2e3b80bd..9c75957879e4 100644 --- a/include/libvirt/libvirt-storage.h +++ b/include/libvirt/libvirt-storage.h @@ -395,6 +395,9 @@ int virStorageVolResize = (virStorageVolPtr vol, unsigned long lon= g capacity, unsigned int flag= s); =20 +int virStorageVolRename (virStorageVolPtr = vol, + const char *name); + int virStoragePoolIsActive(virStoragePoolPtr pool); int virStoragePoolIsPersistent(virStoragePoolPtr pool); =20 diff --git a/m4/virt-storage-lvm.m4 b/m4/virt-storage-lvm.m4 index a0ccca7a00ab..74330c8ecb15 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([LVRENAME], [lvrename], [], [$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 "$LVRENAME" ; then AC_MSG_ERROR([We need lvrename 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 sto= rage driver]) ; fi if test -z "$PVS" ; then AC_MSG_ERROR([We need pvs for LVM storage d= river]) ; fi @@ -75,6 +77,7 @@ AC_DEFUN([LIBVIRT_STORAGE_CHECK_LVM], [ AC_DEFINE_UNQUOTED([VGREMOVE],["$VGREMOVE"],[Location of vgremove pr= ogram]) AC_DEFINE_UNQUOTED([LVREMOVE],["$LVREMOVE"],[Location of lvremove pr= ogram]) AC_DEFINE_UNQUOTED([LVCHANGE],["$LVCHANGE"],[Location of lvchange pr= ogram]) + AC_DEFINE_UNQUOTED([LVRENAME],["$LVRENAME"],[Location of lvrename pr= ogram]) AC_DEFINE_UNQUOTED([VGCHANGE],["$VGCHANGE"],[Location of vgchange pr= ogram]) AC_DEFINE_UNQUOTED([VGSCAN],["$VGSCAN"],[Location of vgscan program]) AC_DEFINE_UNQUOTED([PVS],["$PVS"],[Location of pvs program]) diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c index e4646cb80ff9..754adedcb21e 100644 --- a/src/libvirt-storage.c +++ b/src/libvirt-storage.c @@ -2122,6 +2122,45 @@ virStorageVolResize(virStorageVolPtr vol, } =20 =20 +/** + * virStorageVolRename: + * @vol: pointer to storage volume + * @name: new volume name + * + * Changes the nmae of the storage volume @vol to @name. + * + * Returns 0 on success, or -1 on error. + */ +int +virStorageVolRename(virStorageVolPtr vol, + const char *name) +{ + virConnectPtr conn; + VIR_DEBUG("vol=3D%p name=3D%s", vol, name); + + virResetLastError(); + + virCheckStorageVolReturn(vol, -1); + conn =3D vol->conn; + + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->storageDriver && conn->storageDriver->storageVolRename) { + int ret; + ret =3D conn->storageDriver->storageVolRename(vol, name); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(vol->conn); + return -1; +} + + /** * virStoragePoolIsActive: * @pool: pointer to the storage pool object diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f2a2c8650d97..3052b04d5282 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2720,6 +2720,7 @@ virStorageFileParseBackingStoreStr; virStorageFileParseChainIndex; virStorageFileProbeFormat; virStorageFileResize; +virStorageFileRename; virStorageIsFile; virStorageIsRelative; virStorageNetHostDefClear; diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 0efde25a7f76..a828d0a7ce5c 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -777,6 +777,12 @@ LIBVIRT_3.7.0 { =20 LIBVIRT_3.9.0 { global: - virDomainSetLifecycleAction; + virDomainSetLifecycleAction; } LIBVIRT_3.7.0; + +LIBVIRT_4.0.1 { + global: + virStorageVolRename; +} LIBVIRT_3.9.0; +=20 # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index f8fa64af998e..cf6bdf233ed8 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8587,6 +8587,7 @@ static virStorageDriver storage_driver =3D { .storageVolGetXMLDesc =3D remoteStorageVolGetXMLDesc, /* 0.4.1 */ .storageVolGetPath =3D remoteStorageVolGetPath, /* 0.4.1 */ .storageVolResize =3D remoteStorageVolResize, /* 0.9.10 */ + .storageVolRename =3D remoteStorageVolRename, /* 3.9.0 */ .storagePoolIsActive =3D remoteStoragePoolIsActive, /* 0.7.3 */ .storagePoolIsPersistent =3D remoteStoragePoolIsPersistent, /* 0.7.3 */ }; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index f54759983ceb..d19e83726bf7 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -664,6 +664,7 @@ virStorageBackend virStorageBackendDirectory =3D { .refreshVol =3D virStorageBackendVolRefreshLocal, .deleteVol =3D virStorageBackendVolDeleteLocal, .resizeVol =3D virStorageBackendVolResizeLocal, + .renameVol =3D virStorageBackendVolRenameLocal, .uploadVol =3D virStorageBackendVolUploadLocal, .downloadVol =3D virStorageBackendVolDownloadLocal, .wipeVol =3D virStorageBackendVolWipeLocal, @@ -685,6 +686,7 @@ virStorageBackend virStorageBackendFileSystem =3D { .refreshVol =3D virStorageBackendVolRefreshLocal, .deleteVol =3D virStorageBackendVolDeleteLocal, .resizeVol =3D virStorageBackendVolResizeLocal, + .renameVol =3D virStorageBackendVolRenameLocal, .uploadVol =3D virStorageBackendVolUploadLocal, .downloadVol =3D virStorageBackendVolDownloadLocal, .wipeVol =3D virStorageBackendVolWipeLocal, @@ -705,6 +707,7 @@ virStorageBackend virStorageBackendNetFileSystem =3D { .refreshVol =3D virStorageBackendVolRefreshLocal, .deleteVol =3D virStorageBackendVolDeleteLocal, .resizeVol =3D virStorageBackendVolResizeLocal, + .renameVol =3D virStorageBackendVolRenameLocal, .uploadVol =3D virStorageBackendVolUploadLocal, .downloadVol =3D virStorageBackendVolDownloadLocal, .wipeVol =3D virStorageBackendVolWipeLocal, diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 5df30de29d17..015188508123 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -902,6 +902,32 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn = ATTRIBUTE_UNUSED, } =20 =20 +static int +virStorageBackendLogicalRenameVol(virConnectPtr conn ATTRIBUTE_UNUSED, + virStoragePoolObjPtr pool, + virStorageVolDefPtr vol, + const char *name) +{ + int ret =3D -1; + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + virCommandPtr lvrename_cmd =3D NULL; + + virCheckFlags(0, -1); + + virWaitForDevices(); + + lvrename_cmd =3D virCommandNewArgList(LVRENAME, "%s", def->target.path= , vol->name, name, NULL); + + if (virCommandRun(lvrename_cmd, NULL) < 0) { + goto cleanup; + } + + ret =3D 0; + cleanup: + virCommandFree(lvrename_cmd); + return ret; +} + static int virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUS= ED, @@ -1107,6 +1133,7 @@ virStorageBackend virStorageBackendLogical =3D { .buildVolFrom =3D virStorageBackendLogicalBuildVolFrom, .createVol =3D virStorageBackendLogicalCreateVol, .deleteVol =3D virStorageBackendLogicalDeleteVol, + .renameVol =3D virStorageBackendLogicalRenameVol, .uploadVol =3D virStorageBackendVolUploadLocal, .downloadVol =3D virStorageBackendVolDownloadLocal, .wipeVol =3D virStorageBackendLogicalVolWipe, diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index 7f9597cabea3..ddc28904c76c 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -1091,6 +1091,34 @@ virStorageBackendRBDRefreshVol(virConnectPtr conn, return ret; } =20 +static int +virStorageBackendRBDRenameVol(virConnectPtr conn ATTRIBUTE_UNUSED, + virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStorageVolDefPtr vol, + const char *name) +{ + virStorageBackendRBDStatePtr ptr =3D NULL; + int ret =3D -1; + int r =3D 0; + + virCheckFlags(0, -1); + + if (!(ptr =3D virStorageBackendRBDNewState(conn, pool))) + goto cleanup; + + if ((r =3D rbd_rename(ptr->ioctx, vol->name, name)) < 0) { + virReportSystemError(-r, _("failed to rename the RBD image '%s' to = '%s'"), + vol->name, name); + goto cleanup; + } + + ret =3D 0; + + cleanup: + virStorageBackendRBDFreeState(&ptr); + return ret; +} + static int virStorageBackendRBDResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, diff --git a/src/storage/storage_backend_vstorage.c b/src/storage/storage_b= ackend_vstorage.c index 2dc26af38706..3607312ae486 100644 --- a/src/storage/storage_backend_vstorage.c +++ b/src/storage/storage_backend_vstorage.c @@ -182,6 +182,7 @@ virStorageBackend virStorageBackendVstorage =3D { .refreshVol =3D virStorageBackendVolRefreshLocal, .deleteVol =3D virStorageBackendVolDeleteLocal, .resizeVol =3D virStorageBackendVolResizeLocal, + .renameVol =3D virStorageBackendVolRenameLocal, .uploadVol =3D virStorageBackendVolUploadLocal, .downloadVol =3D virStorageBackendVolDownloadLocal, .wipeVol =3D virStorageBackendVolWipeLocal, diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 3b66d517191b..e68f158288ca 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2358,21 +2358,15 @@ storageVolUpload(virStorageVolPtr vol, } =20 static int -storageVolResize(virStorageVolPtr vol, - unsigned long long capacity, - unsigned int flags) +storageVolRename(virStorageVolPtr vol, + const char *name) { virStorageBackendPtr backend; virStoragePoolObjPtr obj =3D NULL; virStoragePoolDefPtr def; virStorageVolDefPtr voldef =3D NULL; - unsigned long long abs_capacity, delta =3D 0; int ret =3D -1; =20 - virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE | - VIR_STORAGE_VOL_RESIZE_DELTA | - VIR_STORAGE_VOL_RESIZE_SHRINK, -1); - if (!(voldef =3D virStorageVolDefFromVol(vol, &obj, &backend))) return -1; def =3D virStoragePoolObjGetDef(obj); @@ -2394,61 +2388,16 @@ storageVolResize(virStorageVolPtr vol, goto cleanup; } =20 - if (flags & VIR_STORAGE_VOL_RESIZE_DELTA) { - if (flags & VIR_STORAGE_VOL_RESIZE_SHRINK) - abs_capacity =3D voldef->target.capacity - MIN(capacity, volde= f->target.capacity); - else - abs_capacity =3D voldef->target.capacity + capacity; - flags &=3D ~VIR_STORAGE_VOL_RESIZE_DELTA; - } else { - abs_capacity =3D capacity; - } - - if (abs_capacity < voldef->target.allocation) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("can't shrink capacity below " - "existing allocation")); - goto cleanup; - } - - if (abs_capacity < voldef->target.capacity && - !(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("Can't shrink capacity below current " - "capacity unless shrink flag explicitly specified= ")); - goto cleanup; - } - - if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) - delta =3D abs_capacity - voldef->target.allocation; - - if (delta > def->available) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("Not enough space left in storage pool")); - goto cleanup; - } - - if (!backend->resizeVol) { + if (!backend->renameVol) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support changing of " - "volume capacity")); + "volume name")); goto cleanup; } =20 - if (backend->resizeVol(vol->conn, obj, voldef, abs_capacity, flags) < = 0) + if (backend->renameVol(vol->conn, obj, voldef, name) < 0) goto cleanup; =20 - voldef->target.capacity =3D abs_capacity; - /* Only update the allocation and pool values if we actually did the - * allocation; otherwise, this is akin to a create operation with a - * capacity value different and potentially much larger than available - */ - if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) { - voldef->target.allocation =3D abs_capacity; - def->allocation +=3D delta; - def->available -=3D delta; - } - ret =3D 0; =20 cleanup: @@ -2732,7 +2681,7 @@ static virStorageDriver storageDriver =3D { .storageVolGetXMLDesc =3D storageVolGetXMLDesc, /* 0.4.0 */ .storageVolGetPath =3D storageVolGetPath, /* 0.4.0 */ .storageVolResize =3D storageVolResize, /* 0.9.10 */ - + .storageVolRename =3D storageVolRename, /* 3.9.0 */ .storagePoolIsActive =3D storagePoolIsActive, /* 0.7.3 */ .storagePoolIsPersistent =3D storagePoolIsPersistent, /* 0.7.3 */ }; diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 9e1b63a43609..528286b145d5 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2475,6 +2475,19 @@ virStorageBackendVolResizeLocal(virConnectPtr conn, } =20 =20 +/** + * Rename a volume + */ +int +virStorageBackendVolRenameLocal(virConnectPtr conn ATTRIBUTE_UNUSED, + virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStorageVolDefPtr vol, + const char *name) +{ + return virStorageFileRename(vol->target.path, name); +} + + /* * Check whether the ploop image has snapshots. * return: -1 - failed to check diff --git a/src/storage/storage_util.h b/src/storage/storage_util.h index dc7e62517b4f..0e90a762df8a 100644 --- a/src/storage/storage_util.h +++ b/src/storage/storage_util.h @@ -69,6 +69,11 @@ int virStorageBackendVolResizeLocal(virConnectPtr conn, unsigned long long capacity, unsigned int flags); =20 +int virStorageBackendVolRenameLocal(virConnectPtr conn, + virStoragePoolObjPtr pool, + virStorageVolDefPtr vol, + const char *name); + int virStorageBackendVolUploadLocal(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5780180a94ef..c5da169194fd 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1359,6 +1359,45 @@ virStorageFileResize(const char *path, } =20 =20 +/** + * virStorageFileRename: + * + * Change the name file at 'path'. + */ +int +virStorageFileRename(const char *path, + const char *name) +{ + int ret =3D -1; + int rc; + char *opath =3D NULL; + char *npath =3D NULL; + char *base =3D NULL; + + VIR_STRDUP(*opath, path) < 0) + goto cleanup; + + base =3D dirname(npath); + if (virAsprintf(npath, "%s/%s", base, name) < 0) + goto cleanup; + + + if (rename(path, name) < 0) { + virReportSystemError(errno, + _("Failed to rename file '%s' to '%s'"), opat= h, npath); + goto cleanup; + } + + ret =3D 0; + + cleanup: + VIR_FREE(opath); + VIR_FREE(npath); + return ret; +} + + + int virStorageFileIsClusterFS(const char *path) { /* These are coherent cluster filesystems known to be safe for diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index bacbec0d27b7..00a1468feb52 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -1189,6 +1189,59 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) return ret; } =20 +/* + * "vol-rename" command + */ +static const vshCmdInfo info_vol_rename[] =3D { + {.name =3D "help", + .data =3D N_("rename a vol") + }, + {.name =3D "desc", + .data =3D N_("Renames a storage volume") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_vol_rename[] =3D { + VIRSH_COMMON_OPT_VOLUME_VOL, + {.name =3D "name", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("new name for the vol") + }, + {.name =3D NULL} +}; + + +static bool +cmdVolRename(vshControl *ctl, const vshCmd *cmd) +{ + virStorageVolPtr vol; + const char *name =3D NULL; + bool ret =3D false; + + if (!(vol =3D virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0) + goto cleanup; + virSkipSpaces(&name); + + if (virStorageVolRename(vol, name) =3D=3D 0) { + vshPrintExtra(ctl, _("Name of volume '%s' successfully changed to = %s\n"), + virStorageVolGetName(vol), name); + ret =3D true; + } else { + vshError(ctl, _("Failed to change name of volume '%s' to %s"), + virStorageVolGetName(vol), name); + ret =3D false; + } + + cleanup: + virStorageVolFree(vol); + return ret; +} + /* * "vol-dumpxml" command */ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list