[PATCH 1/4] util: storage: Inline use of virStorageFileGetMetadataFromFDInternal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There was just one callsite left. Integrate the body to the only calling
function.
---
 src/util/virstoragefile.c | 91 ++++++++++++++++++++---------------------------
 1 file changed, 39 insertions(+), 52 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 9208b77..01d4a7e 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -973,16 +973,31 @@ virStorageFileGetMetadataFromBuf(const char *path,
 }


-/* Internal version that also supports a containing directory name.  */
-static int
-virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta,
-                                        int fd,
-                                        int *backingFormat)
+/**
+ * virStorageFileGetMetadataFromFD:
+ *
+ * Extract metadata about the storage volume with the specified
+ * image format. If image format is VIR_STORAGE_FILE_AUTO, it
+ * will probe to automatically identify the format.  Does not recurse.
+ *
+ * Callers are advised never to use VIR_STORAGE_FILE_AUTO as a
+ * format, since a malicious guest can turn a raw file into any
+ * other non-raw format at will.
+ *
+ * Caller MUST free the result after use via virStorageSourceFree.
+ */
+virStorageSourcePtr
+virStorageFileGetMetadataFromFD(const char *path,
+                                int fd,
+                                int format,
+                                int *backingFormat)
+
 {
+    virStorageSourcePtr ret = NULL;
+    virStorageSourcePtr meta = NULL;
     char *buf = NULL;
     ssize_t len = VIR_STORAGE_MAX_HEADER;
     struct stat sb;
-    int ret = -1;
     int dummy;

     if (!backingFormat)
@@ -992,17 +1007,20 @@ virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta,

     if (fstat(fd, &sb) < 0) {
         virReportSystemError(errno,
-                             _("cannot stat file '%s'"),
-                             meta->relPath);
-        return -1;
+                             _("cannot stat file '%s'"), path);
+        return NULL;
     }

+    if (!(meta = virStorageFileMetadataNew(path, format)))
+        return NULL;
+
     if (S_ISDIR(sb.st_mode)) {
         /* No header to probe for directories, but also no backing file. Just
          * update the metadata.*/
         meta->type = VIR_STORAGE_TYPE_DIR;
         meta->format = VIR_STORAGE_FILE_DIR;
-        ret = 0;
+        ret = meta;
+        meta = NULL;
         goto cleanup;
     }

@@ -1016,51 +1034,20 @@ virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta,
         goto cleanup;
     }

-    ret = virStorageFileGetMetadataInternal(meta, buf, len, backingFormat);
-
-    if (ret == 0) {
-        if (S_ISREG(sb.st_mode))
-            meta->type = VIR_STORAGE_TYPE_FILE;
-        else if (S_ISBLK(sb.st_mode))
-            meta->type = VIR_STORAGE_TYPE_BLOCK;
-    }
- cleanup:
-    VIR_FREE(buf);
-    return ret;
-}
-
-
-/**
- * virStorageFileGetMetadataFromFD:
- *
- * Extract metadata about the storage volume with the specified
- * image format. If image format is VIR_STORAGE_FILE_AUTO, it
- * will probe to automatically identify the format.  Does not recurse.
- *
- * Callers are advised never to use VIR_STORAGE_FILE_AUTO as a
- * format, since a malicious guest can turn a raw file into any
- * other non-raw format at will.
- *
- * Caller MUST free the result after use via virStorageSourceFree.
- */
-virStorageSourcePtr
-virStorageFileGetMetadataFromFD(const char *path,
-                                int fd,
-                                int format,
-                                int *backingFormat)
-
-{
-    virStorageSourcePtr ret;
-
-    if (!(ret = virStorageFileMetadataNew(path, format)))
-        return NULL;
+    if (virStorageFileGetMetadataInternal(meta, buf, len, backingFormat) < 0)
+        goto cleanup;

+    if (S_ISREG(sb.st_mode))
+        meta->type = VIR_STORAGE_TYPE_FILE;
+    else if (S_ISBLK(sb.st_mode))
+        meta->type = VIR_STORAGE_TYPE_BLOCK;

-    if (virStorageFileGetMetadataFromFDInternal(ret, fd, backingFormat) < 0) {
-        virStorageSourceFree(ret);
-        return NULL;
-    }
+    ret = meta;
+    meta = NULL;

+ cleanup:
+    virStorageSourceFree(meta);
+    VIR_FREE(buf);
     return ret;
 }

-- 
2.0.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]