render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Daniel P. Berrange e3a592
From d33f44c2e74de28c89b64cdc2c0a6564662e075c Mon Sep 17 00:00:00 2001
Daniel P. Berrange e3a592
From: Daniel P. Berrange <berrange@redhat.com>
Daniel P. Berrange e3a592
Date: Fri, 9 Jul 2010 11:28:40 +0100
Daniel P. Berrange e3a592
Subject: [PATCH 11/11] Use the extract backing store format in storage volume lookup
Daniel P. Berrange e3a592
Daniel P. Berrange e3a592
The storage volume lookup code was probing for the backing store
Daniel P. Berrange e3a592
format, instead of using the format extracted from the file
Daniel P. Berrange e3a592
itself. This meant it could report in accurate information. If
Daniel P. Berrange e3a592
a format is included in the file, then use that in preference,
Daniel P. Berrange e3a592
with probing as a fallback.
Daniel P. Berrange e3a592
Daniel P. Berrange e3a592
* src/storage/storage_backend_fs.c: Use extracted backing store
Daniel P. Berrange e3a592
  format
Daniel P. Berrange e3a592
---
Daniel P. Berrange e3a592
 src/storage/storage_backend_fs.c |   80 +++++++++++++++++---------------------
Daniel P. Berrange e3a592
 1 files changed, 36 insertions(+), 44 deletions(-)
Daniel P. Berrange e3a592
Daniel P. Berrange e3a592
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
Daniel P. Berrange e3a592
index d3ac0fe..ffb0071 100644
Daniel P. Berrange e3a592
--- a/src/storage/storage_backend_fs.c
Daniel P. Berrange e3a592
+++ b/src/storage/storage_backend_fs.c
Daniel P. Berrange e3a592
@@ -51,6 +51,7 @@
Daniel P. Berrange e3a592
 static int
Daniel P. Berrange e3a592
 virStorageBackendProbeTarget(virStorageVolTargetPtr target,
Daniel P. Berrange e3a592
                              char **backingStore,
Daniel P. Berrange e3a592
+                             int *backingStoreFormat,
Daniel P. Berrange e3a592
                              unsigned long long *allocation,
Daniel P. Berrange e3a592
                              unsigned long long *capacity,
Daniel P. Berrange e3a592
                              virStorageEncryptionPtr *encryption)
Daniel P. Berrange e3a592
@@ -58,6 +59,10 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
Daniel P. Berrange e3a592
     int fd, ret;
Daniel P. Berrange e3a592
     virStorageFileMetadata meta;
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
+    if (backingStore)
Daniel P. Berrange e3a592
+        *backingStore = NULL;
Daniel P. Berrange e3a592
+    if (backingStoreFormat)
Daniel P. Berrange e3a592
+        *backingStoreFormat = VIR_STORAGE_FILE_AUTO;
Daniel P. Berrange e3a592
     if (encryption)
Daniel P. Berrange e3a592
         *encryption = NULL;
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
@@ -89,22 +94,30 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
     close(fd);
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
-    if (backingStore) {
Daniel P. Berrange e3a592
-        *backingStore = meta.backingStore;
Daniel P. Berrange e3a592
-        meta.backingStore = NULL;
Daniel P. Berrange e3a592
+    if (meta.backingStore) {
Daniel P. Berrange e3a592
+        if (backingStore) {
Daniel P. Berrange e3a592
+            *backingStore = meta.backingStore;
Daniel P. Berrange e3a592
+            meta.backingStore = NULL;
Daniel P. Berrange e3a592
+            if (meta.backingStoreFormat == VIR_STORAGE_FILE_AUTO) {
Daniel P. Berrange e3a592
+                if ((*backingStoreFormat = virStorageFileProbeFormat(*backingStore)) < 0) {
Daniel P. Berrange e3a592
+                    close(fd);
Daniel P. Berrange e3a592
+                    goto cleanup;
Daniel P. Berrange e3a592
+                }
Daniel P. Berrange e3a592
+            } else {
Daniel P. Berrange e3a592
+                *backingStoreFormat = meta.backingStoreFormat;
Daniel P. Berrange e3a592
+            }
Daniel P. Berrange e3a592
+        } else {
Daniel P. Berrange e3a592
+            VIR_FREE(meta.backingStore);
Daniel P. Berrange e3a592
+        }
Daniel P. Berrange e3a592
     }
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
-    VIR_FREE(meta.backingStore);
Daniel P. Berrange e3a592
-
Daniel P. Berrange e3a592
     if (capacity && meta.capacity)
Daniel P. Berrange e3a592
         *capacity = meta.capacity;
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
     if (encryption != NULL && meta.encrypted) {
Daniel P. Berrange e3a592
         if (VIR_ALLOC(*encryption) < 0) {
Daniel P. Berrange e3a592
             virReportOOMError();
Daniel P. Berrange e3a592
-            if (backingStore)
Daniel P. Berrange e3a592
-                VIR_FREE(*backingStore);
Daniel P. Berrange e3a592
-            return -1;
Daniel P. Berrange e3a592
+            goto cleanup;
Daniel P. Berrange e3a592
         }
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
         switch (target->format) {
Daniel P. Berrange e3a592
@@ -124,6 +137,11 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
Daniel P. Berrange e3a592
     }
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
     return 0;
Daniel P. Berrange e3a592
+
Daniel P. Berrange e3a592
+cleanup:
Daniel P. Berrange e3a592
+    if (backingStore)
Daniel P. Berrange e3a592
+        VIR_FREE(*backingStore);
Daniel P. Berrange e3a592
+    return -1;
Daniel P. Berrange e3a592
 }
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
 #if WITH_STORAGE_FS
Daniel P. Berrange e3a592
@@ -585,6 +603,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
Daniel P. Berrange e3a592
     while ((ent = readdir(dir)) != NULL) {
Daniel P. Berrange e3a592
         int ret;
Daniel P. Berrange e3a592
         char *backingStore;
Daniel P. Berrange e3a592
+        int backingStoreFormat;
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
         if (VIR_ALLOC(vol) < 0)
Daniel P. Berrange e3a592
             goto no_memory;
Daniel P. Berrange e3a592
@@ -604,6 +623,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
         if ((ret = virStorageBackendProbeTarget(&vol->target,
Daniel P. Berrange e3a592
                                                 &backingStore,
Daniel P. Berrange e3a592
+                                                &backingStoreFormat,
Daniel P. Berrange e3a592
                                                 &vol->allocation,
Daniel P. Berrange e3a592
                                                 &vol->capacity,
Daniel P. Berrange e3a592
                                                 &vol->target.encryption)) < 0) {
Daniel P. Berrange e3a592
@@ -619,46 +639,18 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
Daniel P. Berrange e3a592
         }
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
         if (backingStore != NULL) {
Daniel P. Berrange e3a592
-            if (vol->target.format == VIR_STORAGE_FILE_QCOW2 &&
Daniel P. Berrange e3a592
-                STRPREFIX("fmt:", backingStore)) {
Daniel P. Berrange e3a592
-                char *fmtstr = backingStore + 4;
Daniel P. Berrange e3a592
-                char *path = strchr(fmtstr, ':');
Daniel P. Berrange e3a592
-                if (!path) {
Daniel P. Berrange e3a592
-                    VIR_FREE(backingStore);
Daniel P. Berrange e3a592
-                } else {
Daniel P. Berrange e3a592
-                    *path = '\0';
Daniel P. Berrange e3a592
-                    if ((vol->backingStore.format =
Daniel P. Berrange e3a592
-                         virStorageFileFormatTypeFromString(fmtstr)) < 0) {
Daniel P. Berrange e3a592
-                        VIR_FREE(backingStore);
Daniel P. Berrange e3a592
-                    } else {
Daniel P. Berrange e3a592
-                        memmove(backingStore, path, strlen(path) + 1);
Daniel P. Berrange e3a592
-                        vol->backingStore.path = backingStore;
Daniel P. Berrange e3a592
-
Daniel P. Berrange e3a592
-                        if (virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
Daniel P. Berrange e3a592
-                                                                 NULL,
Daniel P. Berrange e3a592
-                                                                 NULL) < 0)
Daniel P. Berrange e3a592
-                            VIR_FREE(vol->backingStore);
Daniel P. Berrange e3a592
-                    }
Daniel P. Berrange e3a592
-                }
Daniel P. Berrange e3a592
-            } else {
Daniel P. Berrange e3a592
-                vol->backingStore.path = backingStore;
Daniel P. Berrange e3a592
-
Daniel P. Berrange e3a592
-                if ((ret = virStorageBackendProbeTarget(&vol->backingStore,
Daniel P. Berrange e3a592
-                                                        NULL, NULL, NULL,
Daniel P. Berrange e3a592
-                                                        NULL)) < 0) {
Daniel P. Berrange e3a592
-                    if (ret == -1)
Daniel P. Berrange e3a592
-                        goto cleanup;
Daniel P. Berrange e3a592
-                    else {
Daniel P. Berrange e3a592
-                        /* Silently ignore non-regular files,
Daniel P. Berrange e3a592
-                         * eg '.' '..', 'lost+found' */
Daniel P. Berrange e3a592
-                        VIR_FREE(vol->backingStore);
Daniel P. Berrange e3a592
-                    }
Daniel P. Berrange e3a592
-                }
Daniel P. Berrange e3a592
+            vol->backingStore.path = backingStore;
Daniel P. Berrange e3a592
+            vol->backingStore.format = backingStoreFormat;
Daniel P. Berrange e3a592
+
Daniel P. Berrange e3a592
+            if (virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
Daniel P. Berrange e3a592
+                                                     NULL,
Daniel P. Berrange e3a592
+                                                     NULL) < 0) {
Daniel P. Berrange e3a592
+                VIR_FREE(vol->backingStore.path);
Daniel P. Berrange e3a592
+                goto cleanup;
Daniel P. Berrange e3a592
             }
Daniel P. Berrange e3a592
         }
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
 
Daniel P. Berrange e3a592
-
Daniel P. Berrange e3a592
         if (VIR_REALLOC_N(pool->volumes.objs,
Daniel P. Berrange e3a592
                           pool->volumes.count+1) < 0)
Daniel P. Berrange e3a592
             goto no_memory;
Daniel P. Berrange e3a592
-- 
Daniel P. Berrange e3a592
1.7.1.1
Daniel P. Berrange e3a592