]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: storage: Inline use of virStorageFileGetMetadataFromFDInternal
authorPeter Krempa <pkrempa@redhat.com>
Mon, 7 Jul 2014 09:24:14 +0000 (11:24 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 8 Jul 2014 09:27:08 +0000 (11:27 +0200)
There was just one callsite left. Integrate the body to the only calling
function.

src/util/virstoragefile.c

index 9208b77477114a3c93bb5601bd1643c3586b633d..01d4a7eac998b418c57bfa169671549c5e5c0fcf 100644 (file)
@@ -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;
 }