[PATCH 05/18] util: storage: Move checking of the actual backing image to the worker

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move the code checking the presence of the backing file to the recursive
worker function instead of the metadata parser. The recursive worker
will later be changed to parse more than just local files and this
change will help the separation.
---
 src/util/virstoragefile.c | 63 ++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 36 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 513f15d..a005e00 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -795,7 +795,7 @@ qcow2GetFeatures(virBitmapPtr *features,
  * information about the file and its backing store.  */
 static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
 ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(7)
-ATTRIBUTE_NONNULL(8) ATTRIBUTE_NONNULL(9)
+ATTRIBUTE_NONNULL(8)
 virStorageFileGetMetadataInternal(const char *path,
                                   const char *canonPath,
                                   const char *directory,
@@ -803,8 +803,7 @@ virStorageFileGetMetadataInternal(const char *path,
                                   size_t len,
                                   int format,
                                   virStorageFileMetadataPtr meta,
-                                  int *backingFormat,
-                                  char **backingDirectory)
+                                  int *backingFormat)
 {
     int ret = -1;

@@ -871,31 +870,6 @@ virStorageFileGetMetadataInternal(const char *path,

         if (store == BACKING_STORE_ERROR)
             goto cleanup;
-
-        if (meta->backingStoreRaw) {
-            if (virStorageIsFile(meta->backingStoreRaw)) {
-                if (virFindBackingFile(directory,
-                                       meta->backingStoreRaw,
-                                       backingDirectory,
-                                       &meta->backingStore) < 0) {
-                    /* the backing file is (currently) unavailable, treat this
-                     * file as standalone:
-                     * backingStoreRaw is kept to mark broken image chains */
-                    *backingFormat = VIR_STORAGE_FILE_NONE;
-                    VIR_WARN("Backing file '%s' of image '%s' is missing.",
-                             meta->backingStoreRaw, path);
-
-                }
-            } else {
-                if (VIR_STRDUP(meta->backingStore, meta->backingStoreRaw) < 0)
-                    goto cleanup;
-
-                *backingFormat = VIR_STORAGE_FILE_RAW;
-            }
-        } else {
-            meta->backingStore = NULL;
-            *backingFormat = VIR_STORAGE_FILE_NONE;
-        }
     }

     if (fileTypeInfo[format].getFeatures != NULL &&
@@ -1018,7 +992,7 @@ virStorageFileGetMetadataFromBuf(const char *path,

     if (virStorageFileGetMetadataInternal(path, canonPath, ".", buf, len,
                                           format, ret,
-                                          backingFormat, NULL) < 0) {
+                                          backingFormat) < 0) {
         virStorageFileFreeMetadata(ret);
         ret = NULL;
     }
@@ -1042,8 +1016,7 @@ virStorageFileGetMetadataFromFDInternal(const char *path,
                                         int fd,
                                         int format,
                                         virStorageFileMetadataPtr meta,
-                                        int *backingFormat,
-                                        char **backingDirectory)
+                                        int *backingFormat)
 {
     char *buf = NULL;
     ssize_t len = VIR_STORAGE_MAX_HEADER;
@@ -1085,7 +1058,7 @@ virStorageFileGetMetadataFromFDInternal(const char *path,

     ret = virStorageFileGetMetadataInternal(path, canonPath, directory,
                                             buf, len, format, meta,
-                                            backingFormat, backingDirectory);
+                                            backingFormat);

     if (ret == 0) {
         if (S_ISREG(sb.st_mode))
@@ -1128,7 +1101,7 @@ virStorageFileGetMetadataFromFD(const char *path,
         goto cleanup;
     if (virStorageFileGetMetadataFromFDInternal(path, canonPath, ".",
                                                 fd, format, ret,
-                                                NULL, NULL) < 0) {
+                                                NULL) < 0) {
         virStorageFileFreeMetadata(ret);
         ret = NULL;
     }
@@ -1174,8 +1147,7 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
         ret = virStorageFileGetMetadataFromFDInternal(path, canonPath,
                                                       directory,
                                                       fd, format, meta,
-                                                      &backingFormat,
-                                                      &backingDirectory);
+                                                      &backingFormat);

         if (VIR_CLOSE(fd) < 0)
             VIR_WARN("could not close file %s", path);
@@ -1192,7 +1164,26 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
         ret = 0;
     }

-    if (ret == 0 && meta->backingStore) {
+    if (ret == 0 && meta->backingStoreRaw) {
+        if (virStorageIsFile(meta->backingStoreRaw)) {
+            if (virFindBackingFile(directory,
+                                   meta->backingStoreRaw,
+                                   &backingDirectory,
+                                   &meta->backingStore) < 0) {
+                /* the backing file is (currently) unavailable, treat this
+                 * file as standalone:
+                 * backingStoreRaw is kept to mark broken image chains */
+                VIR_WARN("Backing file '%s' of image '%s' is missing.",
+                         meta->backingStoreRaw, path);
+
+                return 0;
+            }
+        } else {
+            if (VIR_STRDUP(meta->backingStore, meta->backingStoreRaw) < 0)
+                return -1;
+        }
+
+
         virStorageFileMetadataPtr backing;

         if (backingFormat == VIR_STORAGE_FILE_AUTO && !allow_probe)
-- 
1.9.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]