diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c index b620153f1e..bf47622372 100644 --- a/src/storage/storage_source.c +++ b/src/storage/storage_source.c @@ -527,14 +527,20 @@ virStorageFileGetMetadata(virStorageSourcePtr src, allow_probe, report_broken); virHashTablePtr cycle = NULL; + virStorageType actualType = virStorageSourceGetActualType(src); int ret = -1; if (!(cycle = virHashCreate(5, NULL))) return -1; - if (src->format <= VIR_STORAGE_FILE_NONE) - src->format = allow_probe ? - VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW; + if (src->format <= VIR_STORAGE_FILE_NONE) { + if (actualType == VIR_STORAGE_TYPE_DIR) + 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, allow_probe, report_broken, cycle); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index d83db78f56..60e3164b0a 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -111,7 +111,6 @@ testStorageFileGetMetadata(const char *path, if (stat(path, &st) == 0) { if (S_ISDIR(st.st_mode)) { ret->type = VIR_STORAGE_TYPE_DIR; - ret->format = VIR_STORAGE_FILE_DIR; } else if (S_ISBLK(st.st_mode)) { ret->type = VIR_STORAGE_TYPE_BLOCK; } @@ -963,7 +962,15 @@ mymain(void) .type = VIR_STORAGE_TYPE_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), ALLOW_PROBE | EXP_PASS); TEST_CHAIN(absdir, VIR_STORAGE_FILE_DIR,