]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: fs: Drop-in replace use of virStorageFileGetMetadataFromBuf
authorPeter Krempa <pkrempa@redhat.com>
Wed, 28 May 2014 12:48:36 +0000 (14:48 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 28 May 2014 17:23:35 +0000 (19:23 +0200)
Use virStorageFileGetMetadataFromFD instead in
virStorageBackendProbeTarget as it now returns all required data and the
storage file is already open in a filedescriptor.

Also fix improper error code being returned when virFileReadHeaderFD
would fail as virStorageBackendUpdateVolTargetInfoFD would set the
return code to 0.

src/storage/storage_backend_fs.c

index 33551e73791df0fc687a1714825ca4089018730c..003c6df4b38e78221e45ba9a1dccb476391dc4fd 100644 (file)
@@ -71,8 +71,6 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
     int ret = -1;
     virStorageSourcePtr meta = NULL;
     struct stat sb;
-    char *header = NULL;
-    ssize_t len = VIR_STORAGE_MAX_HEADER;
 
     *backingStore = NULL;
     *backingStoreFormat = VIR_STORAGE_FILE_AUTO;
@@ -89,22 +87,19 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
         goto error;
     }
 
+    ret = -1;
+
     if (S_ISDIR(sb.st_mode)) {
         target->format = VIR_STORAGE_FILE_DIR;
     } else {
-        if ((len = virFileReadHeaderFD(fd, len, &header)) < 0) {
-            virReportSystemError(errno, _("cannot read header '%s'"),
-                                 target->path);
+        if (!(meta = virStorageFileGetMetadataFromFD(target->path,
+                                                     fd,
+                                                     VIR_STORAGE_FILE_AUTO,
+                                                     backingStoreFormat)))
             goto error;
-        }
 
-        if (!(meta = virStorageFileGetMetadataFromBuf(target->path,
-                                                      header, len,
-                                                      backingStore,
-                                                      backingStoreFormat))) {
-            ret = -1;
+        if (VIR_STRDUP(*backingStore, meta->backingStoreRaw) < 0)
             goto error;
-        }
     }
 
     VIR_FORCE_CLOSE(fd);
@@ -170,7 +165,6 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 
  cleanup:
     virStorageSourceFree(meta);
-    VIR_FREE(header);
     return ret;
 
 }