util: storage: Allow metadata crawler to report useful errors
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.
This commit is contained in:
parent
a9bad1a337
commit
b8549877a1
@ -2730,7 +2730,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
if (virStorageFileGetMetadata(disk->src,
|
if (virStorageFileGetMetadata(disk->src,
|
||||||
uid, gid,
|
uid, gid,
|
||||||
cfg->allowDiskFormatProbing) < 0)
|
cfg->allowDiskFormatProbing,
|
||||||
|
false) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -932,7 +932,7 @@ get_files(vahControl * ctl)
|
|||||||
*/
|
*/
|
||||||
if (!disk->src->backingStore) {
|
if (!disk->src->backingStore) {
|
||||||
bool probe = ctl->allowDiskFormatProbing;
|
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
|
/* XXX passing ignoreOpenFailure = true to get back to the behavior
|
||||||
|
@ -2783,6 +2783,7 @@ static int
|
|||||||
virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
||||||
uid_t uid, gid_t gid,
|
uid_t uid, gid_t gid,
|
||||||
bool allow_probe,
|
bool allow_probe,
|
||||||
|
bool report_broken,
|
||||||
virHashTablePtr cycle)
|
virHashTablePtr cycle)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -2847,9 +2848,13 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|||||||
else
|
else
|
||||||
backingStore->format = backingFormat;
|
backingStore->format = backingFormat;
|
||||||
|
|
||||||
if (virStorageFileGetMetadataRecurse(backingStore,
|
if ((ret = virStorageFileGetMetadataRecurse(backingStore,
|
||||||
uid, gid, allow_probe,
|
uid, gid,
|
||||||
cycle) < 0) {
|
allow_probe, report_broken,
|
||||||
|
cycle)) < 0) {
|
||||||
|
if (report_broken)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
/* if we fail somewhere midway, just accept and return a
|
/* if we fail somewhere midway, just accept and return a
|
||||||
* broken chain */
|
* broken chain */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -2883,15 +2888,20 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|||||||
* format, since a malicious guest can turn a raw file into any
|
* format, since a malicious guest can turn a raw file into any
|
||||||
* other non-raw format at will.
|
* 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.
|
* Caller MUST free result after use via virStorageSourceFree.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virStorageFileGetMetadata(virStorageSourcePtr src,
|
virStorageFileGetMetadata(virStorageSourcePtr src,
|
||||||
uid_t uid, gid_t gid,
|
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",
|
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);
|
src->path, src->format, (int)uid, (int)gid,
|
||||||
|
allow_probe, report_broken);
|
||||||
|
|
||||||
virHashTablePtr cycle = NULL;
|
virHashTablePtr cycle = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -2903,7 +2913,7 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
|
|||||||
src->format = allow_probe ? VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW;
|
src->format = allow_probe ? VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW;
|
||||||
|
|
||||||
ret = virStorageFileGetMetadataRecurse(src, uid, gid,
|
ret = virStorageFileGetMetadataRecurse(src, uid, gid,
|
||||||
allow_probe, cycle);
|
allow_probe, report_broken, cycle);
|
||||||
|
|
||||||
virHashFree(cycle);
|
virHashFree(cycle);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -50,7 +50,8 @@ bool virStorageFileSupportsSecurityDriver(virStorageSourcePtr src);
|
|||||||
|
|
||||||
int virStorageFileGetMetadata(virStorageSourcePtr src,
|
int virStorageFileGetMetadata(virStorageSourcePtr src,
|
||||||
uid_t uid, gid_t gid,
|
uid_t uid, gid_t gid,
|
||||||
bool allow_probe)
|
bool allow_probe,
|
||||||
|
bool report_broken)
|
||||||
ATTRIBUTE_NONNULL(1);
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
int virStorageTranslateDiskSourcePool(virConnectPtr conn,
|
int virStorageTranslateDiskSourcePool(virConnectPtr conn,
|
||||||
|
@ -119,7 +119,7 @@ testStorageFileGetMetadata(const char *path,
|
|||||||
if (VIR_STRDUP(ret->path, path) < 0)
|
if (VIR_STRDUP(ret->path, path) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virStorageFileGetMetadata(ret, uid, gid, allow_probe) < 0)
|
if (virStorageFileGetMetadata(ret, uid, gid, allow_probe, false) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user