]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virstoragefile: move virStorageFileResize into virfile
authorPavel Hrdina <phrdina@redhat.com>
Mon, 7 Dec 2020 11:04:04 +0000 (12:04 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 6 Jan 2021 12:15:17 +0000 (13:15 +0100)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/libvirt_private.syms
src/storage/storage_util.c
src/util/virfile.c
src/util/virfile.h
src/util/virstoragefile.c
src/util/virstoragefile.h

index 78d4e5ab30c2c5d2f6c707cf7f6776352a6c8d8c..e79dc54d331d813886eba76c206039d77aaff97b 100644 (file)
@@ -2121,6 +2121,7 @@ virFileRelLinkPointsTo;
 virFileRemove;
 virFileRemoveLastComponent;
 virFileRemoveXAttr;
+virFileResize;
 virFileResolveAllLinks;
 virFileResolveLink;
 virFileRewrite;
@@ -3150,7 +3151,6 @@ virStorageFileParseChainIndex;
 virStorageFileProbeFormat;
 virStorageFileRead;
 virStorageFileReportBrokenChain;
-virStorageFileResize;
 virStorageFileStat;
 virStorageFileSupportsAccess;
 virStorageFileSupportsBackingChainTraversal;
index 83b120924b237d87dd0b67fc165b6d93afd99a2a..2478cb0a4a00d7df490eec78888756095d151d4b 100644 (file)
@@ -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",
index 3f4c6d1d0ae04780201e0f49c34fdf917e73fe10..6e16780e3098ed9912611d0ca833a04ea9ceb9d5 100644 (file)
@@ -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;
index 28dfe864456429d9b9e39c3713d4f280ce78ab66..45b75a059e54f7a73d2ac6a88edb3e6bc9b38ca6 100644 (file)
@@ -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,
index d6ff47e4a760a180b6f648639d3c517aec9d204a..66694bfcc0e368b2acbd9ddd41cef16d74260fd5 100644 (file)
@@ -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
index ec34f2d8993868fcb36510c14860bc69899d6611..94bb889d846b117827c2590c41473ff6e0fe2029 100644 (file)
@@ -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);