Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/libvirt_private.syms | 2 +- src/storage/storage_util.c | 2 +- src/util/virfile.c | 47 ++++++++++++++++++++++++++++++++++++++ src/util/virfile.h | 4 ++++ src/util/virstoragefile.c | 47 -------------------------------------- src/util/virstoragefile.h | 4 ---- 6 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 78d4e5ab30..e79dc54d33 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2121,6 +2121,7 @@ virFileRelLinkPointsTo; virFileRemove; virFileRemoveLastComponent; virFileRemoveXAttr; +virFileResize; virFileResolveAllLinks; virFileResolveLink; virFileRewrite; @@ -3150,7 +3151,6 @@ virStorageFileParseChainIndex; virStorageFileProbeFormat; virStorageFileRead; virStorageFileReportBrokenChain; -virStorageFileResize; virStorageFileStat; virStorageFileSupportsAccess; virStorageFileSupportsBackingChainTraversal; diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 83b120924b..2478cb0a4a 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2394,7 +2394,7 @@ virStorageBackendVolResizeLocal(virStoragePoolObjPtr pool, VIR_STORAGE_VOL_RESIZE_SHRINK, -1); if (vol->target.format == VIR_STORAGE_FILE_RAW && !vol->target.encryption) { - return virStorageFileResize(vol->target.path, capacity, pre_allocate); + return virFileResize(vol->target.path, capacity, pre_allocate); } else if (vol->target.format == VIR_STORAGE_FILE_RAW && vol->target.encryption) { if (pre_allocate) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", diff --git a/src/util/virfile.c b/src/util/virfile.c index 3f4c6d1d0a..6e16780e30 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -557,6 +557,53 @@ virFileRewriteStr(const char *path, } +/** + * virFileResize: + * + * Change the capacity of the raw storage file at 'path'. + */ +int +virFileResize(const char *path, + unsigned long long capacity, + bool pre_allocate) +{ + int rc; + VIR_AUTOCLOSE fd = -1; + + if ((fd = open(path, O_RDWR)) < 0) { + virReportSystemError(errno, _("Unable to open '%s'"), path); + return -1; + } + + if (pre_allocate) { + if ((rc = virFileAllocate(fd, 0, capacity)) != 0) { + if (rc == -2) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("preallocate is not supported on this platform")); + } else { + virReportSystemError(errno, + _("Failed to pre-allocate space for " + "file '%s'"), path); + } + return -1; + } + } + + if (ftruncate(fd, capacity) < 0) { + virReportSystemError(errno, + _("Failed to truncate file '%s'"), path); + return -1; + } + + if (VIR_CLOSE(fd) < 0) { + virReportSystemError(errno, _("Unable to save '%s'"), path); + return -1; + } + + return 0; +} + + int virFileTouch(const char *path, mode_t mode) { int fd = -1; diff --git a/src/util/virfile.h b/src/util/virfile.h index 28dfe86445..45b75a059e 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -133,6 +133,10 @@ int virFileRewriteStr(const char *path, mode_t mode, const char *str); +int virFileResize(const char *path, + unsigned long long capacity, + bool pre_allocate); + int virFileTouch(const char *path, mode_t mode); int virFileUpdatePerm(const char *path, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d6ff47e4a7..66694bfcc0 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1193,53 +1193,6 @@ virStorageFileGetMetadataFromFD(const char *path, } -/** - * virStorageFileResize: - * - * Change the capacity of the raw storage file at 'path'. - */ -int -virStorageFileResize(const char *path, - unsigned long long capacity, - bool pre_allocate) -{ - int rc; - VIR_AUTOCLOSE fd = -1; - - if ((fd = open(path, O_RDWR)) < 0) { - virReportSystemError(errno, _("Unable to open '%s'"), path); - return -1; - } - - if (pre_allocate) { - if ((rc = virFileAllocate(fd, 0, capacity)) != 0) { - if (rc == -2) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("preallocate is not supported on this platform")); - } else { - virReportSystemError(errno, - _("Failed to pre-allocate space for " - "file '%s'"), path); - } - return -1; - } - } - - if (ftruncate(fd, capacity) < 0) { - virReportSystemError(errno, - _("Failed to truncate file '%s'"), path); - return -1; - } - - if (VIR_CLOSE(fd) < 0) { - virReportSystemError(errno, _("Unable to save '%s'"), path); - return -1; - } - - return 0; -} - - int virStorageFileIsClusterFS(const char *path) { /* These are coherent cluster filesystems known to be safe for diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index ec34f2d899..94bb889d84 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -420,10 +420,6 @@ virStorageSourcePtr virStorageFileChainLookup(virStorageSourcePtr chain, virStorageSourcePtr *parent) ATTRIBUTE_NONNULL(1); -int virStorageFileResize(const char *path, - unsigned long long capacity, - bool pre_allocate); - int virStorageFileIsClusterFS(const char *path); bool virStorageIsFile(const char *path); bool virStorageIsRelative(const char *backing); -- 2.29.2