]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Determine the local storage type right away
authorPeter Krempa <pkrempa@redhat.com>
Fri, 25 Apr 2014 13:16:25 +0000 (15:16 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jun 2014 07:27:23 +0000 (09:27 +0200)
When walking the backing chain we previously set the storage type to
_FILE and let the virStorageFileGetMetadataFromFDInternal update it to
the correct type later on.

This patch moves the actual storage type determination to the place
where we parse the backing store name so that the code can later be
switched to use virStorageFileReadHeader() directly.

src/storage/storage_driver.c

index 59f6fa809f8a646788d7cc5e99b117c4539778ee..f92a5538df267921934a8551463eec8a2916b85f 100644 (file)
@@ -3111,6 +3111,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
 {
     int fd;
     int ret = -1;
+    struct stat st;
     virStorageSourcePtr backingStore = NULL;
     int backingFormat;
 
@@ -3173,6 +3174,16 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
             ret = 0;
             goto cleanup;
         }
+
+        /* update the type for local storage */
+        if (stat(backingStore->path, &st) == 0) {
+            if (S_ISDIR(st.st_mode)) {
+                backingStore->type = VIR_STORAGE_TYPE_DIR;
+                backingStore->format = VIR_STORAGE_FILE_DIR;
+            } else if (S_ISBLK(st.st_mode)) {
+                backingStore->type = VIR_STORAGE_TYPE_BLOCK;
+            }
+        }
     } else {
         /* TODO: To satisfy the test case, copy the network URI as path. This
          * will be removed later. */