mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
conf: delete useless backingStoreFormat field
Drop another redundant field from virStorageFileMetadata. * src/util/virstoragefile.h (_virStorageFileMetadata): Drop field. * src/util/virstoragefile.c (virStorageFileGetMetadataFromFDInternal) (virStorageFileGetMetadataFromFD) (virStorageFileGetMetadataRecurse): Adjust callers. * tests/virstoragetest.c (_testFileData, testStorageChain) (mymain): Simplify test. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
a4dfc8d31d
commit
86cfa1f603
@ -1035,13 +1035,18 @@ virStorageFileGetMetadataFromFDInternal(const char *path,
|
|||||||
const char *directory,
|
const char *directory,
|
||||||
int fd,
|
int fd,
|
||||||
int format,
|
int format,
|
||||||
virStorageFileMetadataPtr meta)
|
virStorageFileMetadataPtr meta,
|
||||||
|
int *backingFormat)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
ssize_t len = VIR_STORAGE_MAX_HEADER;
|
ssize_t len = VIR_STORAGE_MAX_HEADER;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
int dummy;
|
||||||
|
|
||||||
|
if (!backingFormat)
|
||||||
|
backingFormat = &dummy;
|
||||||
|
*backingFormat = VIR_STORAGE_FILE_NONE;
|
||||||
if (fstat(fd, &sb) < 0) {
|
if (fstat(fd, &sb) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot stat file '%s'"),
|
_("cannot stat file '%s'"),
|
||||||
@ -1074,7 +1079,7 @@ virStorageFileGetMetadataFromFDInternal(const char *path,
|
|||||||
ret = virStorageFileGetMetadataInternal(path, canonPath, directory,
|
ret = virStorageFileGetMetadataInternal(path, canonPath, directory,
|
||||||
buf, len, format, meta,
|
buf, len, format, meta,
|
||||||
&meta->backingStoreRaw,
|
&meta->backingStoreRaw,
|
||||||
&meta->backingStoreFormat);
|
backingFormat);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
if (S_ISREG(sb.st_mode))
|
if (S_ISREG(sb.st_mode))
|
||||||
@ -1099,11 +1104,6 @@ virStorageFileGetMetadataFromFDInternal(const char *path,
|
|||||||
* 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 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.
|
* Caller MUST free the result after use via virStorageFileFreeMetadata.
|
||||||
*/
|
*/
|
||||||
virStorageFileMetadataPtr
|
virStorageFileMetadataPtr
|
||||||
@ -1121,7 +1121,7 @@ virStorageFileGetMetadataFromFD(const char *path,
|
|||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (virStorageFileGetMetadataFromFDInternal(path, canonPath, ".",
|
if (virStorageFileGetMetadataFromFDInternal(path, canonPath, ".",
|
||||||
fd, format, ret) < 0) {
|
fd, format, ret, NULL) < 0) {
|
||||||
virStorageFileFreeMetadata(ret);
|
virStorageFileFreeMetadata(ret);
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
}
|
}
|
||||||
@ -1142,6 +1142,8 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
int backingFormat;
|
||||||
|
|
||||||
VIR_DEBUG("path=%s canonPath=%s dir=%s format=%d uid=%d gid=%d probe=%d",
|
VIR_DEBUG("path=%s canonPath=%s dir=%s format=%d uid=%d gid=%d probe=%d",
|
||||||
path, canonPath, NULLSTR(directory), format,
|
path, canonPath, NULLSTR(directory), format,
|
||||||
(int)uid, (int)gid, allow_probe);
|
(int)uid, (int)gid, allow_probe);
|
||||||
@ -1163,7 +1165,8 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
|
|||||||
|
|
||||||
ret = virStorageFileGetMetadataFromFDInternal(path, canonPath,
|
ret = virStorageFileGetMetadataFromFDInternal(path, canonPath,
|
||||||
directory,
|
directory,
|
||||||
fd, format, meta);
|
fd, format, meta,
|
||||||
|
&backingFormat);
|
||||||
|
|
||||||
if (VIR_CLOSE(fd) < 0)
|
if (VIR_CLOSE(fd) < 0)
|
||||||
VIR_WARN("could not close file %s", path);
|
VIR_WARN("could not close file %s", path);
|
||||||
@ -1183,19 +1186,17 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
|
|||||||
if (ret == 0 && meta->backingStore) {
|
if (ret == 0 && meta->backingStore) {
|
||||||
virStorageFileMetadataPtr backing;
|
virStorageFileMetadataPtr backing;
|
||||||
|
|
||||||
if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO && !allow_probe)
|
if (backingFormat == VIR_STORAGE_FILE_AUTO && !allow_probe)
|
||||||
meta->backingStoreFormat = VIR_STORAGE_FILE_RAW;
|
backingFormat = VIR_STORAGE_FILE_RAW;
|
||||||
else if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO_SAFE)
|
else if (backingFormat == VIR_STORAGE_FILE_AUTO_SAFE)
|
||||||
meta->backingStoreFormat = VIR_STORAGE_FILE_AUTO;
|
backingFormat = VIR_STORAGE_FILE_AUTO;
|
||||||
format = meta->backingStoreFormat;
|
|
||||||
if (VIR_ALLOC(backing) < 0 ||
|
if (VIR_ALLOC(backing) < 0 ||
|
||||||
virStorageFileGetMetadataRecurse(meta->backingStoreRaw,
|
virStorageFileGetMetadataRecurse(meta->backingStoreRaw,
|
||||||
meta->backingStore,
|
meta->backingStore,
|
||||||
meta->directory, format,
|
meta->directory, backingFormat,
|
||||||
uid, gid, allow_probe,
|
uid, gid, allow_probe,
|
||||||
cycle, backing) < 0) {
|
cycle, backing) < 0) {
|
||||||
/* If we failed to get backing data, mark the chain broken */
|
/* If we failed to get backing data, mark the chain broken */
|
||||||
meta->backingStoreFormat = VIR_STORAGE_FILE_NONE;
|
|
||||||
VIR_FREE(meta->backingStore);
|
VIR_FREE(meta->backingStore);
|
||||||
virStorageFileFreeMetadata(backing);
|
virStorageFileFreeMetadata(backing);
|
||||||
} else {
|
} else {
|
||||||
@ -1220,11 +1221,6 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
|
|||||||
* 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 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.
|
* Caller MUST free result after use via virStorageFileFreeMetadata.
|
||||||
*/
|
*/
|
||||||
virStorageFileMetadataPtr
|
virStorageFileMetadataPtr
|
||||||
|
@ -147,7 +147,6 @@ struct _virStorageFileMetadata {
|
|||||||
* store. */
|
* store. */
|
||||||
char *backingStore; /* Canonical name (absolute file, or protocol). Should be same as backingMeta->canonPath */
|
char *backingStore; /* Canonical name (absolute file, or protocol). Should be same as backingMeta->canonPath */
|
||||||
char *directory; /* The directory containing basename of backingStoreRaw. Should be same as backingMeta->relDir */
|
char *directory; /* The directory containing basename of backingStoreRaw. Should be same as backingMeta->relDir */
|
||||||
int backingStoreFormat; /* enum virStorageFileFormat. Should be same as backingMeta->format */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,7 +235,6 @@ struct _testFileData
|
|||||||
const char *expBackingStoreRaw;
|
const char *expBackingStoreRaw;
|
||||||
const char *expBackingDirRel;
|
const char *expBackingDirRel;
|
||||||
const char *expBackingDirAbs;
|
const char *expBackingDirAbs;
|
||||||
enum virStorageFileFormat expBackingFormat;
|
|
||||||
unsigned long long expCapacity;
|
unsigned long long expCapacity;
|
||||||
bool expEncrypted;
|
bool expEncrypted;
|
||||||
const char *pathRel;
|
const char *pathRel;
|
||||||
@ -328,12 +327,11 @@ testStorageChain(const void *args)
|
|||||||
expRelDir = isAbs ? data->files[i]->relDirAbs
|
expRelDir = isAbs ? data->files[i]->relDirAbs
|
||||||
: data->files[i]->relDirRel;
|
: data->files[i]->relDirRel;
|
||||||
if (virAsprintf(&expect,
|
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",
|
"path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n",
|
||||||
NULLSTR(data->files[i]->expBackingStore),
|
NULLSTR(data->files[i]->expBackingStore),
|
||||||
NULLSTR(data->files[i]->expBackingStoreRaw),
|
NULLSTR(data->files[i]->expBackingStoreRaw),
|
||||||
NULLSTR(expBackingDirectory),
|
NULLSTR(expBackingDirectory),
|
||||||
data->files[i]->expBackingFormat,
|
|
||||||
data->files[i]->expCapacity,
|
data->files[i]->expCapacity,
|
||||||
data->files[i]->expEncrypted,
|
data->files[i]->expEncrypted,
|
||||||
NULLSTR(expPath),
|
NULLSTR(expPath),
|
||||||
@ -342,12 +340,11 @@ testStorageChain(const void *args)
|
|||||||
data->files[i]->type,
|
data->files[i]->type,
|
||||||
data->files[i]->format) < 0 ||
|
data->files[i]->format) < 0 ||
|
||||||
virAsprintf(&actual,
|
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",
|
"path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n",
|
||||||
NULLSTR(elt->backingStore),
|
NULLSTR(elt->backingStore),
|
||||||
NULLSTR(elt->backingStoreRaw),
|
NULLSTR(elt->backingStoreRaw),
|
||||||
NULLSTR(elt->directory),
|
NULLSTR(elt->directory),
|
||||||
elt->backingStoreFormat,
|
|
||||||
elt->capacity, !!elt->encryption,
|
elt->capacity, !!elt->encryption,
|
||||||
NULLSTR(elt->path),
|
NULLSTR(elt->path),
|
||||||
NULLSTR(elt->canonPath),
|
NULLSTR(elt->canonPath),
|
||||||
@ -431,7 +428,6 @@ mymain(void)
|
|||||||
|
|
||||||
/* Raw image, whether with right format or no specified format */
|
/* Raw image, whether with right format or no specified format */
|
||||||
testFileData raw = {
|
testFileData raw = {
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_NONE,
|
|
||||||
.pathRel = "raw",
|
.pathRel = "raw",
|
||||||
.pathAbs = canonraw,
|
.pathAbs = canonraw,
|
||||||
.canonPath = canonraw,
|
.canonPath = canonraw,
|
||||||
@ -458,7 +454,6 @@ mymain(void)
|
|||||||
.expBackingStoreRaw = "raw",
|
.expBackingStoreRaw = "raw",
|
||||||
.expBackingDirRel = ".",
|
.expBackingDirRel = ".",
|
||||||
.expBackingDirAbs = datadir,
|
.expBackingDirAbs = datadir,
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_RAW,
|
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "qcow2",
|
.pathRel = "qcow2",
|
||||||
.pathAbs = canonqcow2,
|
.pathAbs = canonqcow2,
|
||||||
@ -469,7 +464,6 @@ mymain(void)
|
|||||||
.format = VIR_STORAGE_FILE_QCOW2,
|
.format = VIR_STORAGE_FILE_QCOW2,
|
||||||
};
|
};
|
||||||
testFileData qcow2_as_raw = {
|
testFileData qcow2_as_raw = {
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_NONE,
|
|
||||||
.pathRel = "qcow2",
|
.pathRel = "qcow2",
|
||||||
.pathAbs = canonqcow2,
|
.pathAbs = canonqcow2,
|
||||||
.canonPath = canonqcow2,
|
.canonPath = canonqcow2,
|
||||||
@ -519,7 +513,6 @@ mymain(void)
|
|||||||
.expBackingStoreRaw = absqcow2,
|
.expBackingStoreRaw = absqcow2,
|
||||||
.expBackingDirRel = datadir,
|
.expBackingDirRel = datadir,
|
||||||
.expBackingDirAbs = datadir,
|
.expBackingDirAbs = datadir,
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_QCOW2,
|
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "wrap",
|
.pathRel = "wrap",
|
||||||
.pathAbs = abswrap,
|
.pathAbs = abswrap,
|
||||||
@ -549,8 +542,6 @@ mymain(void)
|
|||||||
"-b", absqcow2, "wrap", NULL);
|
"-b", absqcow2, "wrap", NULL);
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
wrap.expBackingFormat = VIR_STORAGE_FILE_AUTO;
|
|
||||||
qcow2.expBackingFormat = VIR_STORAGE_FILE_AUTO;
|
|
||||||
qcow2_as_raw.pathRel = absqcow2;
|
qcow2_as_raw.pathRel = absqcow2;
|
||||||
qcow2_as_raw.relDirRel = datadir;
|
qcow2_as_raw.relDirRel = datadir;
|
||||||
|
|
||||||
@ -560,7 +551,6 @@ mymain(void)
|
|||||||
.expBackingStoreRaw = absqcow2,
|
.expBackingStoreRaw = absqcow2,
|
||||||
.expBackingDirRel = datadir,
|
.expBackingDirRel = datadir,
|
||||||
.expBackingDirAbs = datadir,
|
.expBackingDirAbs = datadir,
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_RAW,
|
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "wrap",
|
.pathRel = "wrap",
|
||||||
.pathAbs = abswrap,
|
.pathAbs = abswrap,
|
||||||
@ -585,7 +575,6 @@ mymain(void)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
qcow2.expBackingStore = NULL;
|
qcow2.expBackingStore = NULL;
|
||||||
qcow2.expBackingStoreRaw = datadir "/bogus";
|
qcow2.expBackingStoreRaw = datadir "/bogus";
|
||||||
qcow2.expBackingFormat = VIR_STORAGE_FILE_NONE;
|
|
||||||
qcow2.pathRel = "qcow2";
|
qcow2.pathRel = "qcow2";
|
||||||
qcow2.relDirRel = ".";
|
qcow2.relDirRel = ".";
|
||||||
|
|
||||||
@ -621,7 +610,6 @@ mymain(void)
|
|||||||
qcow2.expBackingStoreRaw = "nbd:example.org:6000";
|
qcow2.expBackingStoreRaw = "nbd:example.org:6000";
|
||||||
qcow2.expBackingDirRel = NULL;
|
qcow2.expBackingDirRel = NULL;
|
||||||
qcow2.expBackingDirAbs = NULL;
|
qcow2.expBackingDirAbs = NULL;
|
||||||
qcow2.expBackingFormat = VIR_STORAGE_FILE_RAW;
|
|
||||||
|
|
||||||
/* Qcow2 file with backing protocol instead of file */
|
/* Qcow2 file with backing protocol instead of file */
|
||||||
testFileData nbd = {
|
testFileData nbd = {
|
||||||
@ -643,7 +631,6 @@ mymain(void)
|
|||||||
.expBackingStoreRaw = absraw,
|
.expBackingStoreRaw = absraw,
|
||||||
.expBackingDirRel = datadir,
|
.expBackingDirRel = datadir,
|
||||||
.expBackingDirAbs = datadir,
|
.expBackingDirAbs = datadir,
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_RAW,
|
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "qed",
|
.pathRel = "qed",
|
||||||
.pathAbs = absqed,
|
.pathAbs = absqed,
|
||||||
@ -654,7 +641,6 @@ mymain(void)
|
|||||||
.format = VIR_STORAGE_FILE_QED,
|
.format = VIR_STORAGE_FILE_QED,
|
||||||
};
|
};
|
||||||
testFileData qed_as_raw = {
|
testFileData qed_as_raw = {
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_NONE,
|
|
||||||
.pathRel = "qed",
|
.pathRel = "qed",
|
||||||
.pathAbs = absqed,
|
.pathAbs = absqed,
|
||||||
.canonPath = canonqed,
|
.canonPath = canonqed,
|
||||||
@ -709,7 +695,6 @@ mymain(void)
|
|||||||
.expBackingStoreRaw = "../raw",
|
.expBackingStoreRaw = "../raw",
|
||||||
.expBackingDirRel = "sub/../sub/..",
|
.expBackingDirRel = "sub/../sub/..",
|
||||||
.expBackingDirAbs = datadir "/sub/../sub/..",
|
.expBackingDirAbs = datadir "/sub/../sub/..",
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_RAW,
|
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "../sub/link1",
|
.pathRel = "../sub/link1",
|
||||||
.pathAbs = "../sub/link1",
|
.pathAbs = "../sub/link1",
|
||||||
@ -724,7 +709,6 @@ mymain(void)
|
|||||||
.expBackingStoreRaw = "../sub/link1",
|
.expBackingStoreRaw = "../sub/link1",
|
||||||
.expBackingDirRel = "sub/../sub",
|
.expBackingDirRel = "sub/../sub",
|
||||||
.expBackingDirAbs = datadir "/sub/../sub",
|
.expBackingDirAbs = datadir "/sub/../sub",
|
||||||
.expBackingFormat = VIR_STORAGE_FILE_QCOW2,
|
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "sub/link2",
|
.pathRel = "sub/link2",
|
||||||
.pathAbs = abslink2,
|
.pathAbs = abslink2,
|
||||||
@ -755,7 +739,6 @@ mymain(void)
|
|||||||
qcow2.expBackingStoreRaw = "qcow2";
|
qcow2.expBackingStoreRaw = "qcow2";
|
||||||
qcow2.expBackingDirRel = ".";
|
qcow2.expBackingDirRel = ".";
|
||||||
qcow2.expBackingDirAbs = datadir;
|
qcow2.expBackingDirAbs = datadir;
|
||||||
qcow2.expBackingFormat= VIR_STORAGE_FILE_NONE;
|
|
||||||
|
|
||||||
/* Behavior of an infinite loop chain */
|
/* Behavior of an infinite loop chain */
|
||||||
TEST_CHAIN(16, "qcow2", absqcow2, VIR_STORAGE_FILE_QCOW2,
|
TEST_CHAIN(16, "qcow2", absqcow2, VIR_STORAGE_FILE_QCOW2,
|
||||||
@ -780,7 +763,6 @@ mymain(void)
|
|||||||
qcow2.expBackingDirRel = datadir;
|
qcow2.expBackingDirRel = datadir;
|
||||||
qcow2.pathRel = absqcow2;
|
qcow2.pathRel = absqcow2;
|
||||||
qcow2.relDirRel = datadir;
|
qcow2.relDirRel = datadir;
|
||||||
wrap.expBackingFormat = VIR_STORAGE_FILE_QCOW2;
|
|
||||||
|
|
||||||
/* Behavior of an infinite loop chain */
|
/* Behavior of an infinite loop chain */
|
||||||
TEST_CHAIN(17, "wrap", abswrap, VIR_STORAGE_FILE_QCOW2,
|
TEST_CHAIN(17, "wrap", abswrap, VIR_STORAGE_FILE_QCOW2,
|
||||||
|
Loading…
Reference in New Issue
Block a user