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

[libvirt] [PATCH v3 2/4] storage: report error rather than warning if backing files doesn't exist



If one of backing files for disk source doesn't exist, the guest will not
be able to find and use the disk even though the disk still exists in
guest xml definition. So reporting an error make more sense.

Adding virFileAccessibleAs() to check if the backing file described in
disk meta exist in real path. If not, report error. the uid and gid
arguments don't have so much meannings for F_OK, so give 0 for them.
---
 src/util/virstoragefile.c | 23 +++++++++++++++--------
 tests/virstoragetest.c    | 16 ++++++++--------
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index b985df4..4781221 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -534,6 +534,13 @@ virFindBackingFile(const char *start, bool start_is_dir, const char *path,
         goto cleanup;
     }
 
+    if (virFileAccessibleAs(combined, F_OK, 0, 0) < 0) {
+        virReportSystemError(errno,
+                             _("Backing file '%s' does not exist"),
+                             combined);
+        goto cleanup;
+    }
+
     if (!(*canonical = canonicalize_file_name(combined))) {
         virReportSystemError(errno,
                              _("Can't canonicalize path '%s'"), path);
@@ -784,14 +791,10 @@ virStorageFileGetMetadataInternal(const char *path,
                                        !!directory, backing,
                                        &meta->directory,
                                        &meta->backingStore) < 0) {
-                    /* the backing file is (currently) unavailable, treat this
-                     * file as standalone:
-                     * backingStoreRaw is kept to mark broken image chains */
-                    meta->backingStoreIsFile = false;
-                    backingFormat = VIR_STORAGE_FILE_NONE;
-                    VIR_WARN("Backing file '%s' of image '%s' is missing.",
-                             meta->backingStoreRaw, path);
-
+                    VIR_ERROR(_("Backing file '%s' of image '%s' is missing."),
+                              meta->backingStoreRaw, path);
+                    VIR_FREE(backing);
+                    goto cleanup;
                 }
             }
             VIR_FREE(backing);
@@ -968,6 +971,10 @@ virStorageFileGetMetadataRecurse(const char *path, const char *directory,
                                                             uid, gid,
                                                             allow_probe,
                                                             cycle);
+        if (!ret->backingMeta) {
+            virStorageFileFreeMetadata(ret);
+            ret = NULL;
+        }
     }
 
     return ret;
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index fef4b37..fb5da5c 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -483,10 +483,10 @@ mymain(void)
     /* Qcow2 file with missing backing file but specified type */
     const testFileData chain9[] = { qcow2_bogus };
     TEST_CHAIN(9, "qcow2", absqcow2, VIR_STORAGE_FILE_QCOW2,
-               chain9, EXP_WARN,
-               chain9, ALLOW_PROBE | EXP_WARN,
-               chain9, EXP_WARN,
-               chain9, ALLOW_PROBE | EXP_WARN);
+               chain9, EXP_FAIL,
+               chain9, ALLOW_PROBE | EXP_FAIL,
+               chain9, EXP_FAIL,
+               chain9, ALLOW_PROBE | EXP_FAIL);
 
     /* Rewrite qcow2 to a missing backing file, without backing type */
     virCommandFree(cmd);
@@ -498,10 +498,10 @@ mymain(void)
     /* Qcow2 file with missing backing file and no specified type */
     const testFileData chain10[] = { qcow2_bogus };
     TEST_CHAIN(10, "qcow2", absqcow2, VIR_STORAGE_FILE_QCOW2,
-               chain10, EXP_WARN,
-               chain10, ALLOW_PROBE | EXP_WARN,
-               chain10, EXP_WARN,
-               chain10, ALLOW_PROBE | EXP_WARN);
+               chain10, EXP_FAIL,
+               chain10, ALLOW_PROBE | EXP_FAIL,
+               chain10, EXP_FAIL,
+               chain10, ALLOW_PROBE | EXP_FAIL);
 
     /* Rewrite qcow2 to use an nbd: protocol as backend */
     virCommandFree(cmd);
-- 
1.8.1.4


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