]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: storagefile: Always store raw backing name in the metadata
authorPeter Krempa <pkrempa@redhat.com>
Mon, 14 Apr 2014 13:49:28 +0000 (15:49 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 23 Apr 2014 21:05:01 +0000 (23:05 +0200)
Don't use the backingStoreRaw as a indication of broken chains. Fill it
always and tweak the broken image chain detector to avoid changing the
semantics.

The new semantics to detect a broken chain is the presence of string in
backingStoreRaw but the lack of the backing chain metadata structure in
the chain.

Now that the raw backing store name is always filled there's no need to
pass the raw name variable separately to fill in case the backing is not
a file. Tweak the function so that it can handle a NULL in that case.

src/util/virstoragefile.c

index 73cfef02bed657569b05aff3418b8cd25baf94a0..5fbb6e77da141c65e4dda7e2dd1f142b5c1b686f 100644 (file)
@@ -864,8 +864,7 @@ virStorageFileGetMetadataInternal(const char *path,
     }
 
     if (fileTypeInfo[format].getBackingStore != NULL) {
-        char *backing = NULL;
-        int store = fileTypeInfo[format].getBackingStore(&backing,
+        int store = fileTypeInfo[format].getBackingStore(&meta->backingStoreRaw,
                                                          backingFormat,
                                                          buf, len);
         if (store == BACKING_STORE_INVALID)
@@ -874,15 +873,10 @@ virStorageFileGetMetadataInternal(const char *path,
         if (store == BACKING_STORE_ERROR)
             goto cleanup;
 
-        if (backing != NULL) {
-            if (VIR_STRDUP(meta->backingStore, backing) < 0) {
-                VIR_FREE(backing);
-                goto cleanup;
-            }
-            if (virStorageIsFile(backing)) {
-                meta->backingStoreRaw = meta->backingStore;
-                meta->backingStore = NULL;
-                if (virFindBackingFile(directory, backing,
+        if (meta->backingStoreRaw) {
+            if (virStorageIsFile(meta->backingStoreRaw)) {
+                if (virFindBackingFile(directory,
+                                       meta->backingStoreRaw,
                                        backingDirectory,
                                        &meta->backingStore) < 0) {
                     /* the backing file is (currently) unavailable, treat this
@@ -894,11 +888,15 @@ virStorageFileGetMetadataInternal(const char *path,
 
                 }
             } else {
-                *backingStore = backing;
-                backing = NULL;
+                if (VIR_STRDUP(meta->backingStore, meta->backingStoreRaw) < 0)
+                    goto cleanup;
+
+                if (backingStore &&
+                    VIR_STRDUP(*backingStore, meta->backingStoreRaw) < 0)
+                    goto cleanup;
+
                 *backingFormat = VIR_STORAGE_FILE_RAW;
             }
-            VIR_FREE(backing);
         } else {
             meta->backingStore = NULL;
             *backingFormat = VIR_STORAGE_FILE_NONE;
@@ -1085,7 +1083,7 @@ virStorageFileGetMetadataFromFDInternal(const char *path,
 
     ret = virStorageFileGetMetadataInternal(path, canonPath, directory,
                                             buf, len, format, meta,
-                                            &meta->backingStoreRaw,
+                                            NULL,
                                             backingFormat, backingDirectory);
 
     if (ret == 0) {
@@ -1296,31 +1294,24 @@ virStorageFileChainGetBroken(virStorageFileMetadataPtr chain,
                              char **brokenFile)
 {
     virStorageFileMetadataPtr tmp;
-    int ret = -1;
 
     *brokenFile = NULL;
 
     if (!chain)
         return 0;
 
-    tmp = chain;
-    while (tmp) {
+    for (tmp = chain; tmp; tmp = tmp->backingMeta) {
         /* Break when we hit end of chain; report error if we detected
          * a missing backing file, infinite loop, or other error */
-       if (!tmp->backingStoreRaw)
-           break;
-       if (!tmp->backingStore) {
-           if (VIR_STRDUP(*brokenFile, tmp->backingStoreRaw) < 0)
-               goto error;
-           break;
-       }
-       tmp = tmp->backingMeta;
-    }
+        if (!tmp->backingMeta && tmp->backingStoreRaw) {
+            if (VIR_STRDUP(*brokenFile, tmp->backingStoreRaw) < 0)
+                return -1;
 
-    ret = 0;
+           return 0;
+        }
+    }
 
- error:
-    return ret;
+    return 0;
 }