]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Allow metadata crawler to report useful errors
authorPeter Krempa <pkrempa@redhat.com>
Thu, 11 Sep 2014 16:28:47 +0000 (18:28 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 24 Sep 2014 07:28:29 +0000 (09:28 +0200)
Add a new parameter to virStorageFileGetMetadata that will break the
backing chain detection process and report useful error message rather
than having to use virStorageFileChainGetBroken.

This patch just introduces the option, usage will be provided
separately.

src/qemu/qemu_domain.c
src/security/virt-aa-helper.c
src/storage/storage_driver.c
src/storage/storage_driver.h
tests/virstoragetest.c

index 5aad7361db466561abce2333d7f5d201977e42db..f4b5b8cdfcdce939f8d5cb94ddc8741bd9439860 100644 (file)
@@ -2730,7 +2730,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 
     if (virStorageFileGetMetadata(disk->src,
                                   uid, gid,
-                                  cfg->allowDiskFormatProbing) < 0)
+                                  cfg->allowDiskFormatProbing,
+                                  false) < 0)
         ret = -1;
 
  cleanup:
index a06ba4425bfaa2977ad4a5d28f4b76c4a3b8973a..9afc8db15c1aa429341c0ec8f0ab73f50e408a79 100644 (file)
@@ -932,7 +932,7 @@ get_files(vahControl * ctl)
          */
         if (!disk->src->backingStore) {
             bool probe = ctl->allowDiskFormatProbing;
-            virStorageFileGetMetadata(disk->src, -1, -1, probe);
+            virStorageFileGetMetadata(disk->src, -1, -1, probe, false);
         }
 
         /* XXX passing ignoreOpenFailure = true to get back to the behavior
index 433d7b723a64f7e3ccbb0093bacc578786d34c9c..c3b29c4916d06bfed13885fb2ac2dfdfae2bfb8b 100644 (file)
@@ -2783,6 +2783,7 @@ static int
 virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
                                  uid_t uid, gid_t gid,
                                  bool allow_probe,
+                                 bool report_broken,
                                  virHashTablePtr cycle)
 {
     int ret = -1;
@@ -2847,9 +2848,13 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
     else
         backingStore->format = backingFormat;
 
-    if (virStorageFileGetMetadataRecurse(backingStore,
-                                         uid, gid, allow_probe,
-                                         cycle) < 0) {
+    if ((ret = virStorageFileGetMetadataRecurse(backingStore,
+                                                uid, gid,
+                                                allow_probe, report_broken,
+                                                cycle)) < 0) {
+        if (report_broken)
+            goto cleanup;
+
         /* if we fail somewhere midway, just accept and return a
          * broken chain */
         ret = 0;
@@ -2883,15 +2888,20 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
  * format, since a malicious guest can turn a raw file into any
  * other non-raw format at will.
  *
+ * If @report_broken is true, the whole function fails with a possibly sane
+ * error instead of just returning a broken chain.
+ *
  * Caller MUST free result after use via virStorageSourceFree.
  */
 int
 virStorageFileGetMetadata(virStorageSourcePtr src,
                           uid_t uid, gid_t gid,
-                          bool allow_probe)
+                          bool allow_probe,
+                          bool report_broken)
 {
-    VIR_DEBUG("path=%s format=%d uid=%d gid=%d probe=%d",
-              src->path, src->format, (int)uid, (int)gid, allow_probe);
+    VIR_DEBUG("path=%s format=%d uid=%d gid=%d probe=%d, report_broken=%d",
+              src->path, src->format, (int)uid, (int)gid,
+              allow_probe, report_broken);
 
     virHashTablePtr cycle = NULL;
     int ret = -1;
@@ -2903,7 +2913,7 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
         src->format = allow_probe ? VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW;
 
     ret = virStorageFileGetMetadataRecurse(src, uid, gid,
-                                           allow_probe, cycle);
+                                           allow_probe, report_broken, cycle);
 
     virHashFree(cycle);
     return ret;
index e77392868ba81dfcea8176a76825f9a97d44d0cd..b805ddd3b5c458033429b98b2f4fd510a9b22e81 100644 (file)
@@ -50,7 +50,8 @@ bool virStorageFileSupportsSecurityDriver(virStorageSourcePtr src);
 
 int virStorageFileGetMetadata(virStorageSourcePtr src,
                               uid_t uid, gid_t gid,
-                              bool allow_probe)
+                              bool allow_probe,
+                              bool report_broken)
     ATTRIBUTE_NONNULL(1);
 
 int virStorageTranslateDiskSourcePool(virConnectPtr conn,
index e2ee3ff87e17e8f22168da5327480267f096515a..29f5c7a61f51349cbef0777ec76b3244dced36e8 100644 (file)
@@ -119,7 +119,7 @@ testStorageFileGetMetadata(const char *path,
     if (VIR_STRDUP(ret->path, path) < 0)
         goto error;
 
-    if (virStorageFileGetMetadata(ret, uid, gid, allow_probe) < 0)
+    if (virStorageFileGetMetadata(ret, uid, gid, allow_probe, false) < 0)
         goto error;
 
     return ret;