提交 3401e208 编写于 作者: M Martin Kletzander

qemu: Don't mangle the storage format for type='dir'

Our backing probing code handles directory file types properly in
virStorageFileGetMetadataRecurse(), by that I mean it leaves them
alone.  However its caller, the virStorageFileGetMetadata() resets the
type to raw before probing, without even checking the type.  We need
to special-case TYPE_DIR in order to achieve desired results.

Also, in order to properly test this, we need to stop resetting format
of volumes in tests for TYPE_DIR (probably the reason why we didn't
catch that and why the test data didn't need to be modified).

Partially-resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1443434Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 912bc720
...@@ -527,14 +527,20 @@ virStorageFileGetMetadata(virStorageSourcePtr src, ...@@ -527,14 +527,20 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
allow_probe, report_broken); allow_probe, report_broken);
virHashTablePtr cycle = NULL; virHashTablePtr cycle = NULL;
virStorageType actualType = virStorageSourceGetActualType(src);
int ret = -1; int ret = -1;
if (!(cycle = virHashCreate(5, NULL))) if (!(cycle = virHashCreate(5, NULL)))
return -1; return -1;
if (src->format <= VIR_STORAGE_FILE_NONE) if (src->format <= VIR_STORAGE_FILE_NONE) {
src->format = allow_probe ? if (actualType == VIR_STORAGE_TYPE_DIR)
VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW; src->format = VIR_STORAGE_FILE_DIR;
else if (allow_probe)
src->format = VIR_STORAGE_FILE_AUTO;
else
src->format = VIR_STORAGE_FILE_RAW;
}
ret = virStorageFileGetMetadataRecurse(src, src, uid, gid, ret = virStorageFileGetMetadataRecurse(src, src, uid, gid,
allow_probe, report_broken, cycle); allow_probe, report_broken, cycle);
......
...@@ -111,7 +111,6 @@ testStorageFileGetMetadata(const char *path, ...@@ -111,7 +111,6 @@ testStorageFileGetMetadata(const char *path,
if (stat(path, &st) == 0) { if (stat(path, &st) == 0) {
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
ret->type = VIR_STORAGE_TYPE_DIR; ret->type = VIR_STORAGE_TYPE_DIR;
ret->format = VIR_STORAGE_FILE_DIR;
} else if (S_ISBLK(st.st_mode)) { } else if (S_ISBLK(st.st_mode)) {
ret->type = VIR_STORAGE_TYPE_BLOCK; ret->type = VIR_STORAGE_TYPE_BLOCK;
} }
...@@ -963,7 +962,15 @@ mymain(void) ...@@ -963,7 +962,15 @@ mymain(void)
.type = VIR_STORAGE_TYPE_DIR, .type = VIR_STORAGE_TYPE_DIR,
.format = VIR_STORAGE_FILE_DIR, .format = VIR_STORAGE_FILE_DIR,
}; };
TEST_CHAIN(absdir, VIR_STORAGE_FILE_AUTO, testFileData dir_as_raw = {
.path = canondir,
.type = VIR_STORAGE_TYPE_DIR,
.format = VIR_STORAGE_FILE_RAW,
};
TEST_CHAIN(absdir, VIR_STORAGE_FILE_RAW,
(&dir_as_raw), EXP_PASS,
(&dir_as_raw), ALLOW_PROBE | EXP_PASS);
TEST_CHAIN(absdir, VIR_STORAGE_FILE_NONE,
(&dir), EXP_PASS, (&dir), EXP_PASS,
(&dir), ALLOW_PROBE | EXP_PASS); (&dir), ALLOW_PROBE | EXP_PASS);
TEST_CHAIN(absdir, VIR_STORAGE_FILE_DIR, TEST_CHAIN(absdir, VIR_STORAGE_FILE_DIR,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册