|
|
9119d9 |
From a50730a3f46ffae2e9178a69dda6ac995bbdc154 Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <a50730a3f46ffae2e9178a69dda6ac995bbdc154@dist-git>
|
|
|
9119d9 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
Date: Wed, 24 Sep 2014 11:01:27 +0200
|
|
|
9119d9 |
Subject: [PATCH] util: storage: Allow metadata crawler to report useful errors
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1138231
|
|
|
9119d9 |
|
|
|
9119d9 |
Add a new parameter to virStorageFileGetMetadata that will break the
|
|
|
9119d9 |
backing chain detection process and report useful error message rather
|
|
|
9119d9 |
than having to use virStorageFileChainGetBroken.
|
|
|
9119d9 |
|
|
|
9119d9 |
This patch just introduces the option, usage will be provided
|
|
|
9119d9 |
separately.
|
|
|
9119d9 |
|
|
|
9119d9 |
(cherry picked from commit b8549877a1e3ca1854fab2527508637b38e63f0d)
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/qemu/qemu_domain.c | 3 ++-
|
|
|
9119d9 |
src/security/virt-aa-helper.c | 2 +-
|
|
|
9119d9 |
src/storage/storage_driver.c | 24 +++++++++++++++++-------
|
|
|
9119d9 |
src/storage/storage_driver.h | 3 ++-
|
|
|
9119d9 |
tests/virstoragetest.c | 2 +-
|
|
|
9119d9 |
5 files changed, 23 insertions(+), 11 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
|
|
|
9119d9 |
index 746625a..e471af5 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_domain.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_domain.c
|
|
|
9119d9 |
@@ -2734,7 +2734,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virStorageFileGetMetadata(disk->src,
|
|
|
9119d9 |
uid, gid,
|
|
|
9119d9 |
- cfg->allowDiskFormatProbing) < 0)
|
|
|
9119d9 |
+ cfg->allowDiskFormatProbing,
|
|
|
9119d9 |
+ false) < 0)
|
|
|
9119d9 |
ret = -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
|
|
|
9119d9 |
index 311ce3b..ba542cc 100644
|
|
|
9119d9 |
--- a/src/security/virt-aa-helper.c
|
|
|
9119d9 |
+++ b/src/security/virt-aa-helper.c
|
|
|
9119d9 |
@@ -932,7 +932,7 @@ get_files(vahControl * ctl)
|
|
|
9119d9 |
*/
|
|
|
9119d9 |
if (!disk->src->backingStore) {
|
|
|
9119d9 |
bool probe = ctl->allowDiskFormatProbing;
|
|
|
9119d9 |
- virStorageFileGetMetadata(disk->src, -1, -1, probe);
|
|
|
9119d9 |
+ virStorageFileGetMetadata(disk->src, -1, -1, probe, false);
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
/* XXX passing ignoreOpenFailure = true to get back to the behavior
|
|
|
9119d9 |
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
|
|
|
9119d9 |
index 433d7b7..c3b29c4 100644
|
|
|
9119d9 |
--- a/src/storage/storage_driver.c
|
|
|
9119d9 |
+++ b/src/storage/storage_driver.c
|
|
|
9119d9 |
@@ -2783,6 +2783,7 @@ static int
|
|
|
9119d9 |
virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|
|
9119d9 |
uid_t uid, gid_t gid,
|
|
|
9119d9 |
bool allow_probe,
|
|
|
9119d9 |
+ bool report_broken,
|
|
|
9119d9 |
virHashTablePtr cycle)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
int ret = -1;
|
|
|
9119d9 |
@@ -2847,9 +2848,13 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|
|
9119d9 |
else
|
|
|
9119d9 |
backingStore->format = backingFormat;
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (virStorageFileGetMetadataRecurse(backingStore,
|
|
|
9119d9 |
- uid, gid, allow_probe,
|
|
|
9119d9 |
- cycle) < 0) {
|
|
|
9119d9 |
+ if ((ret = virStorageFileGetMetadataRecurse(backingStore,
|
|
|
9119d9 |
+ uid, gid,
|
|
|
9119d9 |
+ allow_probe, report_broken,
|
|
|
9119d9 |
+ cycle)) < 0) {
|
|
|
9119d9 |
+ if (report_broken)
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
/* if we fail somewhere midway, just accept and return a
|
|
|
9119d9 |
* broken chain */
|
|
|
9119d9 |
ret = 0;
|
|
|
9119d9 |
@@ -2883,15 +2888,20 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|
|
9119d9 |
* format, since a malicious guest can turn a raw file into any
|
|
|
9119d9 |
* other non-raw format at will.
|
|
|
9119d9 |
*
|
|
|
9119d9 |
+ * If @report_broken is true, the whole function fails with a possibly sane
|
|
|
9119d9 |
+ * error instead of just returning a broken chain.
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
* Caller MUST free result after use via virStorageSourceFree.
|
|
|
9119d9 |
*/
|
|
|
9119d9 |
int
|
|
|
9119d9 |
virStorageFileGetMetadata(virStorageSourcePtr src,
|
|
|
9119d9 |
uid_t uid, gid_t gid,
|
|
|
9119d9 |
- bool allow_probe)
|
|
|
9119d9 |
+ bool allow_probe,
|
|
|
9119d9 |
+ bool report_broken)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
- VIR_DEBUG("path=%s format=%d uid=%d gid=%d probe=%d",
|
|
|
9119d9 |
- src->path, src->format, (int)uid, (int)gid, allow_probe);
|
|
|
9119d9 |
+ VIR_DEBUG("path=%s format=%d uid=%d gid=%d probe=%d, report_broken=%d",
|
|
|
9119d9 |
+ src->path, src->format, (int)uid, (int)gid,
|
|
|
9119d9 |
+ allow_probe, report_broken);
|
|
|
9119d9 |
|
|
|
9119d9 |
virHashTablePtr cycle = NULL;
|
|
|
9119d9 |
int ret = -1;
|
|
|
9119d9 |
@@ -2903,7 +2913,7 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
|
|
|
9119d9 |
src->format = allow_probe ? VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW;
|
|
|
9119d9 |
|
|
|
9119d9 |
ret = virStorageFileGetMetadataRecurse(src, uid, gid,
|
|
|
9119d9 |
- allow_probe, cycle);
|
|
|
9119d9 |
+ allow_probe, report_broken, cycle);
|
|
|
9119d9 |
|
|
|
9119d9 |
virHashFree(cycle);
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h
|
|
|
9119d9 |
index e773928..b805ddd 100644
|
|
|
9119d9 |
--- a/src/storage/storage_driver.h
|
|
|
9119d9 |
+++ b/src/storage/storage_driver.h
|
|
|
9119d9 |
@@ -50,7 +50,8 @@ bool virStorageFileSupportsSecurityDriver(virStorageSourcePtr src);
|
|
|
9119d9 |
|
|
|
9119d9 |
int virStorageFileGetMetadata(virStorageSourcePtr src,
|
|
|
9119d9 |
uid_t uid, gid_t gid,
|
|
|
9119d9 |
- bool allow_probe)
|
|
|
9119d9 |
+ bool allow_probe,
|
|
|
9119d9 |
+ bool report_broken)
|
|
|
9119d9 |
ATTRIBUTE_NONNULL(1);
|
|
|
9119d9 |
|
|
|
9119d9 |
int virStorageTranslateDiskSourcePool(virConnectPtr conn,
|
|
|
9119d9 |
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
|
|
|
9119d9 |
index e2ee3ff..29f5c7a 100644
|
|
|
9119d9 |
--- a/tests/virstoragetest.c
|
|
|
9119d9 |
+++ b/tests/virstoragetest.c
|
|
|
9119d9 |
@@ -119,7 +119,7 @@ testStorageFileGetMetadata(const char *path,
|
|
|
9119d9 |
if (VIR_STRDUP(ret->path, path) < 0)
|
|
|
9119d9 |
goto error;
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (virStorageFileGetMetadata(ret, uid, gid, allow_probe) < 0)
|
|
|
9119d9 |
+ if (virStorageFileGetMetadata(ret, uid, gid, allow_probe, false) < 0)
|
|
|
9119d9 |
goto error;
|
|
|
9119d9 |
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.1
|
|
|
9119d9 |
|