const char *directory,
int fd,
int format,
- virStorageFileMetadataPtr meta)
+ virStorageFileMetadataPtr meta,
+ int *backingFormat)
{
char *buf = NULL;
ssize_t len = VIR_STORAGE_MAX_HEADER;
struct stat sb;
int ret = -1;
+ int dummy;
+ if (!backingFormat)
+ backingFormat = &dummy;
+ *backingFormat = VIR_STORAGE_FILE_NONE;
if (fstat(fd, &sb) < 0) {
virReportSystemError(errno,
_("cannot stat file '%s'"),
ret = virStorageFileGetMetadataInternal(path, canonPath, directory,
buf, len, format, meta,
&meta->backingStoreRaw,
- &meta->backingStoreFormat);
+ backingFormat);
if (ret == 0) {
if (S_ISREG(sb.st_mode))
* format, since a malicious guest can turn a raw file into any
* other non-raw format at will.
*
- * If the returned meta.backingStoreFormat is VIR_STORAGE_FILE_AUTO
- * it indicates the image didn't specify an explicit format for its
- * backing store. Callers are advised against probing for the
- * backing store format in this case.
- *
* Caller MUST free the result after use via virStorageFileFreeMetadata.
*/
virStorageFileMetadataPtr
if (VIR_ALLOC(ret) < 0)
goto cleanup;
if (virStorageFileGetMetadataFromFDInternal(path, canonPath, ".",
- fd, format, ret) < 0) {
+ fd, format, ret, NULL) < 0) {
virStorageFileFreeMetadata(ret);
ret = NULL;
}
{
int fd;
int ret = -1;
+ int backingFormat;
+
VIR_DEBUG("path=%s canonPath=%s dir=%s format=%d uid=%d gid=%d probe=%d",
path, canonPath, NULLSTR(directory), format,
(int)uid, (int)gid, allow_probe);
ret = virStorageFileGetMetadataFromFDInternal(path, canonPath,
directory,
- fd, format, meta);
+ fd, format, meta,
+ &backingFormat);
if (VIR_CLOSE(fd) < 0)
VIR_WARN("could not close file %s", path);
if (ret == 0 && meta->backingStore) {
virStorageFileMetadataPtr backing;
- if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO && !allow_probe)
- meta->backingStoreFormat = VIR_STORAGE_FILE_RAW;
- else if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO_SAFE)
- meta->backingStoreFormat = VIR_STORAGE_FILE_AUTO;
- format = meta->backingStoreFormat;
+ if (backingFormat == VIR_STORAGE_FILE_AUTO && !allow_probe)
+ backingFormat = VIR_STORAGE_FILE_RAW;
+ else if (backingFormat == VIR_STORAGE_FILE_AUTO_SAFE)
+ backingFormat = VIR_STORAGE_FILE_AUTO;
if (VIR_ALLOC(backing) < 0 ||
virStorageFileGetMetadataRecurse(meta->backingStoreRaw,
meta->backingStore,
- meta->directory, format,
+ meta->directory, backingFormat,
uid, gid, allow_probe,
cycle, backing) < 0) {
/* If we failed to get backing data, mark the chain broken */
- meta->backingStoreFormat = VIR_STORAGE_FILE_NONE;
VIR_FREE(meta->backingStore);
virStorageFileFreeMetadata(backing);
} else {
* format, since a malicious guest can turn a raw file into any
* other non-raw format at will.
*
- * If the returned meta.backingStoreFormat is VIR_STORAGE_FILE_AUTO
- * it indicates the image didn't specify an explicit format for its
- * backing store. Callers are advised against using ALLOW_PROBE, as
- * it would probe the backing store format in this case.
- *
* Caller MUST free result after use via virStorageFileFreeMetadata.
*/
virStorageFileMetadataPtr
const char *expBackingStoreRaw;
const char *expBackingDirRel;
const char *expBackingDirAbs;
- enum virStorageFileFormat expBackingFormat;
unsigned long long expCapacity;
bool expEncrypted;
const char *pathRel;
expRelDir = isAbs ? data->files[i]->relDirAbs
: data->files[i]->relDirRel;
if (virAsprintf(&expect,
- "store:%s\nraw:%s\ndirectory:%s\nother:%d %lld %d\n"
+ "store:%s\nraw:%s\ndirectory:%s\nother:%lld %d\n"
"path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n",
NULLSTR(data->files[i]->expBackingStore),
NULLSTR(data->files[i]->expBackingStoreRaw),
NULLSTR(expBackingDirectory),
- data->files[i]->expBackingFormat,
data->files[i]->expCapacity,
data->files[i]->expEncrypted,
NULLSTR(expPath),
data->files[i]->type,
data->files[i]->format) < 0 ||
virAsprintf(&actual,
- "store:%s\nraw:%s\ndirectory:%s\nother:%d %lld %d\n"
+ "store:%s\nraw:%s\ndirectory:%s\nother:%lld %d\n"
"path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n",
NULLSTR(elt->backingStore),
NULLSTR(elt->backingStoreRaw),
NULLSTR(elt->directory),
- elt->backingStoreFormat,
elt->capacity, !!elt->encryption,
NULLSTR(elt->path),
NULLSTR(elt->canonPath),
/* Raw image, whether with right format or no specified format */
testFileData raw = {
- .expBackingFormat = VIR_STORAGE_FILE_NONE,
.pathRel = "raw",
.pathAbs = canonraw,
.canonPath = canonraw,
.expBackingStoreRaw = "raw",
.expBackingDirRel = ".",
.expBackingDirAbs = datadir,
- .expBackingFormat = VIR_STORAGE_FILE_RAW,
.expCapacity = 1024,
.pathRel = "qcow2",
.pathAbs = canonqcow2,
.format = VIR_STORAGE_FILE_QCOW2,
};
testFileData qcow2_as_raw = {
- .expBackingFormat = VIR_STORAGE_FILE_NONE,
.pathRel = "qcow2",
.pathAbs = canonqcow2,
.canonPath = canonqcow2,
.expBackingStoreRaw = absqcow2,
.expBackingDirRel = datadir,
.expBackingDirAbs = datadir,
- .expBackingFormat = VIR_STORAGE_FILE_QCOW2,
.expCapacity = 1024,
.pathRel = "wrap",
.pathAbs = abswrap,
"-b", absqcow2, "wrap", NULL);
if (virCommandRun(cmd, NULL) < 0)
ret = -1;
- wrap.expBackingFormat = VIR_STORAGE_FILE_AUTO;
- qcow2.expBackingFormat = VIR_STORAGE_FILE_AUTO;
qcow2_as_raw.pathRel = absqcow2;
qcow2_as_raw.relDirRel = datadir;
.expBackingStoreRaw = absqcow2,
.expBackingDirRel = datadir,
.expBackingDirAbs = datadir,
- .expBackingFormat = VIR_STORAGE_FILE_RAW,
.expCapacity = 1024,
.pathRel = "wrap",
.pathAbs = abswrap,
ret = -1;
qcow2.expBackingStore = NULL;
qcow2.expBackingStoreRaw = datadir "/bogus";
- qcow2.expBackingFormat = VIR_STORAGE_FILE_NONE;
qcow2.pathRel = "qcow2";
qcow2.relDirRel = ".";
qcow2.expBackingStoreRaw = "nbd:example.org:6000";
qcow2.expBackingDirRel = NULL;
qcow2.expBackingDirAbs = NULL;
- qcow2.expBackingFormat = VIR_STORAGE_FILE_RAW;
/* Qcow2 file with backing protocol instead of file */
testFileData nbd = {
.expBackingStoreRaw = absraw,
.expBackingDirRel = datadir,
.expBackingDirAbs = datadir,
- .expBackingFormat = VIR_STORAGE_FILE_RAW,
.expCapacity = 1024,
.pathRel = "qed",
.pathAbs = absqed,
.format = VIR_STORAGE_FILE_QED,
};
testFileData qed_as_raw = {
- .expBackingFormat = VIR_STORAGE_FILE_NONE,
.pathRel = "qed",
.pathAbs = absqed,
.canonPath = canonqed,
.expBackingStoreRaw = "../raw",
.expBackingDirRel = "sub/../sub/..",
.expBackingDirAbs = datadir "/sub/../sub/..",
- .expBackingFormat = VIR_STORAGE_FILE_RAW,
.expCapacity = 1024,
.pathRel = "../sub/link1",
.pathAbs = "../sub/link1",
.expBackingStoreRaw = "../sub/link1",
.expBackingDirRel = "sub/../sub",
.expBackingDirAbs = datadir "/sub/../sub",
- .expBackingFormat = VIR_STORAGE_FILE_QCOW2,
.expCapacity = 1024,
.pathRel = "sub/link2",
.pathAbs = abslink2,
qcow2.expBackingStoreRaw = "qcow2";
qcow2.expBackingDirRel = ".";
qcow2.expBackingDirAbs = datadir;
- qcow2.expBackingFormat= VIR_STORAGE_FILE_NONE;
/* Behavior of an infinite loop chain */
TEST_CHAIN(16, "qcow2", absqcow2, VIR_STORAGE_FILE_QCOW2,
qcow2.expBackingDirRel = datadir;
qcow2.pathRel = absqcow2;
qcow2.relDirRel = datadir;
- wrap.expBackingFormat = VIR_STORAGE_FILE_QCOW2;
/* Behavior of an infinite loop chain */
TEST_CHAIN(17, "wrap", abswrap, VIR_STORAGE_FILE_QCOW2,