提交 9a39f504 编写于 作者: P Peter Krempa

storage: Don't store parent directory of an image explicitly

The parent directory doesn't necessarily need to be stored after we
don't mangle the path stored in the image. Remove it and tweak the code
to avoid using it.
上级 e71437ff
...@@ -2837,8 +2837,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src, ...@@ -2837,8 +2837,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
virStorageSourcePtr backingStore = NULL; virStorageSourcePtr backingStore = NULL;
int backingFormat; int backingFormat;
VIR_DEBUG("path=%s dir=%s format=%d uid=%d gid=%d probe=%d", VIR_DEBUG("path=%s format=%d uid=%d gid=%d probe=%d",
src->path, NULLSTR(src->relDir), src->format, src->path, src->format,
(int)uid, (int)gid, allow_probe); (int)uid, (int)gid, allow_probe);
/* exit if we can't load information about the current image */ /* exit if we can't load information about the current image */
...@@ -2945,19 +2945,12 @@ virStorageFileGetMetadata(virStorageSourcePtr src, ...@@ -2945,19 +2945,12 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
if (!(cycle = virHashCreate(5, NULL))) if (!(cycle = virHashCreate(5, NULL)))
return -1; return -1;
if (!src->relDir &&
!(src->relDir = mdir_name(src->path))) {
virReportOOMError();
goto cleanup;
}
if (src->format <= VIR_STORAGE_FILE_NONE) if (src->format <= VIR_STORAGE_FILE_NONE)
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, cycle);
cleanup:
VIR_FREE(canonPath); VIR_FREE(canonPath);
virHashFree(cycle); virHashFree(cycle);
return ret; return ret;
......
...@@ -1339,9 +1339,10 @@ virStorageFileChainLookup(virStorageSourcePtr chain, ...@@ -1339,9 +1339,10 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
unsigned int idx, unsigned int idx,
const char **parent) const char **parent)
{ {
virStorageSourcePtr prev = NULL;
const char *start = chain->path; const char *start = chain->path;
const char *tmp; const char *tmp;
const char *parentDir = "."; char *parentDir = NULL;
bool nameIsFile = virStorageIsFile(name); bool nameIsFile = virStorageIsFile(name);
size_t i; size_t i;
...@@ -1372,8 +1373,20 @@ virStorageFileChainLookup(virStorageSourcePtr chain, ...@@ -1372,8 +1373,20 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
break; break;
if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE || if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
chain->type == VIR_STORAGE_TYPE_BLOCK)) { chain->type == VIR_STORAGE_TYPE_BLOCK)) {
if (prev) {
if (!(parentDir = mdir_name(prev->path))) {
virReportOOMError();
goto error;
}
} else {
if (VIR_STRDUP(parentDir, ".") < 0)
goto error;
}
int result = virFileRelLinkPointsTo(parentDir, name, int result = virFileRelLinkPointsTo(parentDir, name,
chain->path); chain->path);
VIR_FREE(parentDir);
if (result < 0) if (result < 0)
goto error; goto error;
if (result > 0) if (result > 0)
...@@ -1381,7 +1394,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain, ...@@ -1381,7 +1394,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
} }
} }
*parent = chain->path; *parent = chain->path;
parentDir = chain->relDir; prev = chain;
chain = chain->backingStore; chain = chain->backingStore;
i++; i++;
} }
...@@ -1551,7 +1564,6 @@ virStorageSourceClearBackingStore(virStorageSourcePtr def) ...@@ -1551,7 +1564,6 @@ virStorageSourceClearBackingStore(virStorageSourcePtr def)
return; return;
VIR_FREE(def->relPath); VIR_FREE(def->relPath);
VIR_FREE(def->relDir);
VIR_FREE(def->backingStoreRaw); VIR_FREE(def->backingStoreRaw);
/* recursively free backing chain */ /* recursively free backing chain */
...@@ -1607,7 +1619,6 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, ...@@ -1607,7 +1619,6 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
const char *rel) const char *rel)
{ {
char *dirname = NULL; char *dirname = NULL;
const char *parentdir = "";
virStorageSourcePtr ret; virStorageSourcePtr ret;
if (VIR_ALLOC(ret) < 0) if (VIR_ALLOC(ret) < 0)
...@@ -1617,23 +1628,20 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, ...@@ -1617,23 +1628,20 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
if (VIR_STRDUP(ret->relPath, parent->backingStoreRaw) < 0) if (VIR_STRDUP(ret->relPath, parent->backingStoreRaw) < 0)
goto error; goto error;
/* XXX Once we get rid of the need to use canonical names in path, we will be if (!(dirname = mdir_name(parent->path))) {
* able to use mdir_name on parent->path instead of using parent->relDir */ virReportOOMError();
if (STRNEQ(parent->relDir, "/"))
parentdir = parent->relDir;
if (virAsprintf(&ret->path, "%s/%s", parentdir, rel) < 0)
goto error; goto error;
}
if (virStorageSourceGetActualType(parent) != VIR_STORAGE_TYPE_NETWORK) { if (STRNEQ(dirname, "/")) {
ret->type = VIR_STORAGE_TYPE_FILE; if (virAsprintf(&ret->path, "%s/%s", dirname, rel) < 0)
/* XXX store the relative directory name for test's sake */
if (!(ret->relDir = mdir_name(ret->path))) {
virReportOOMError();
goto error; goto error;
}
} else { } else {
if (virAsprintf(&ret->path, "/%s", rel) < 0)
goto error;
}
if (virStorageSourceGetActualType(parent) == VIR_STORAGE_TYPE_NETWORK) {
ret->type = VIR_STORAGE_TYPE_NETWORK; ret->type = VIR_STORAGE_TYPE_NETWORK;
/* copy the host network part */ /* copy the host network part */
...@@ -1644,12 +1652,9 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, ...@@ -1644,12 +1652,9 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
if (VIR_STRDUP(ret->volume, parent->volume) < 0) if (VIR_STRDUP(ret->volume, parent->volume) < 0)
goto error; goto error;
} else {
/* XXX store the relative directory name for test's sake */ /* set the type to _FILE, the caller shall update it to the actual type */
if (!(ret->relDir = mdir_name(ret->path))) { ret->type = VIR_STORAGE_TYPE_FILE;
virReportOOMError();
goto error;
}
} }
cleanup: cleanup:
...@@ -1865,12 +1870,6 @@ virStorageSourceNewFromBackingAbsolute(const char *path) ...@@ -1865,12 +1870,6 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
if (virStorageIsFile(path)) { if (virStorageIsFile(path)) {
ret->type = VIR_STORAGE_TYPE_FILE; ret->type = VIR_STORAGE_TYPE_FILE;
/* XXX store the relative directory name for test's sake */
if (!(ret->relDir = mdir_name(path))) {
virReportOOMError();
goto error;
}
if (VIR_STRDUP(ret->path, path) < 0) if (VIR_STRDUP(ret->path, path) < 0)
goto error; goto error;
} else { } else {
...@@ -1884,17 +1883,6 @@ virStorageSourceNewFromBackingAbsolute(const char *path) ...@@ -1884,17 +1883,6 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
if (virStorageSourceParseBackingColon(ret, path) < 0) if (virStorageSourceParseBackingColon(ret, path) < 0)
goto error; goto error;
} }
/* XXX fill relative path so that relative names work with network storage too */
if (ret->path) {
if (!(ret->relDir = mdir_name(ret->path))) {
virReportOOMError();
goto error;
}
} else {
if (VIR_STRDUP(ret->relDir, "") < 0)
goto error;
}
} }
return ret; return ret;
......
...@@ -250,9 +250,6 @@ struct _virStorageSource { ...@@ -250,9 +250,6 @@ struct _virStorageSource {
/* Relative name by which this image was opened from its parent, or NULL /* Relative name by which this image was opened from its parent, or NULL
* if this image was opened by absolute name */ * if this image was opened by absolute name */
char *relPath; char *relPath;
/* Directory to start from if backingStoreRaw is a relative file
* name. */
char *relDir;
/* Name of the child backing store recorded in metadata of the /* Name of the child backing store recorded in metadata of the
* current file. */ * current file. */
char *backingStoreRaw; char *backingStoreRaw;
......
...@@ -116,11 +116,6 @@ testStorageFileGetMetadata(const char *path, ...@@ -116,11 +116,6 @@ testStorageFileGetMetadata(const char *path,
} }
} }
if (!(ret->relDir = mdir_name(path))) {
virReportOOMError();
goto error;
}
if (VIR_STRDUP(ret->path, path) < 0) if (VIR_STRDUP(ret->path, path) < 0)
goto error; goto error;
...@@ -282,7 +277,6 @@ struct _testFileData ...@@ -282,7 +277,6 @@ struct _testFileData
bool expEncrypted; bool expEncrypted;
const char *pathRel; const char *pathRel;
const char *path; const char *path;
const char *relDir;
int type; int type;
int format; int format;
}; };
...@@ -311,7 +305,6 @@ static const char testStorageChainFormat[] = ...@@ -311,7 +305,6 @@ static const char testStorageChainFormat[] =
"capacity: %lld\n" "capacity: %lld\n"
"encryption: %d\n" "encryption: %d\n"
"relPath:%s\n" "relPath:%s\n"
"relDir:%s\n"
"type:%d\n" "type:%d\n"
"format:%d\n"; "format:%d\n";
...@@ -375,7 +368,6 @@ testStorageChain(const void *args) ...@@ -375,7 +368,6 @@ testStorageChain(const void *args)
data->files[i]->expCapacity, data->files[i]->expCapacity,
data->files[i]->expEncrypted, data->files[i]->expEncrypted,
NULLSTR(data->files[i]->pathRel), NULLSTR(data->files[i]->pathRel),
NULLSTR(data->files[i]->relDir),
data->files[i]->type, data->files[i]->type,
data->files[i]->format) < 0 || data->files[i]->format) < 0 ||
virAsprintf(&actual, virAsprintf(&actual,
...@@ -385,7 +377,6 @@ testStorageChain(const void *args) ...@@ -385,7 +377,6 @@ testStorageChain(const void *args)
elt->capacity, elt->capacity,
!!elt->encryption, !!elt->encryption,
NULLSTR(elt->relPath), NULLSTR(elt->relPath),
NULLSTR(elt->relDir),
elt->type, elt->type,
elt->format) < 0) { elt->format) < 0) {
VIR_FREE(expect); VIR_FREE(expect);
...@@ -713,7 +704,6 @@ mymain(void) ...@@ -713,7 +704,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 = {
.path = canonraw, .path = canonraw,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_RAW, .format = VIR_STORAGE_FILE_RAW,
}; };
...@@ -730,13 +720,11 @@ mymain(void) ...@@ -730,13 +720,11 @@ mymain(void)
.expBackingStoreRaw = "raw", .expBackingStoreRaw = "raw",
.expCapacity = 1024, .expCapacity = 1024,
.path = canonqcow2, .path = canonqcow2,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_QCOW2, .format = VIR_STORAGE_FILE_QCOW2,
}; };
testFileData qcow2_as_raw = { testFileData qcow2_as_raw = {
.path = canonqcow2, .path = canonqcow2,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_RAW, .format = VIR_STORAGE_FILE_RAW,
}; };
...@@ -769,7 +757,6 @@ mymain(void) ...@@ -769,7 +757,6 @@ mymain(void)
.expBackingStoreRaw = absqcow2, .expBackingStoreRaw = absqcow2,
.expCapacity = 1024, .expCapacity = 1024,
.path = canonwrap, .path = canonwrap,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_QCOW2, .format = VIR_STORAGE_FILE_QCOW2,
}; };
...@@ -795,7 +782,6 @@ mymain(void) ...@@ -795,7 +782,6 @@ mymain(void)
.expBackingStoreRaw = absqcow2, .expBackingStoreRaw = absqcow2,
.expCapacity = 1024, .expCapacity = 1024,
.path = canonwrap, .path = canonwrap,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_QCOW2, .format = VIR_STORAGE_FILE_QCOW2,
}; };
...@@ -843,7 +829,6 @@ mymain(void) ...@@ -843,7 +829,6 @@ mymain(void)
.path = "blah", .path = "blah",
.type = VIR_STORAGE_TYPE_NETWORK, .type = VIR_STORAGE_TYPE_NETWORK,
.format = VIR_STORAGE_FILE_RAW, .format = VIR_STORAGE_FILE_RAW,
.relDir = ".",
}; };
TEST_CHAIN(11, absqcow2, VIR_STORAGE_FILE_QCOW2, TEST_CHAIN(11, absqcow2, VIR_STORAGE_FILE_QCOW2,
(&qcow2, &nbd), EXP_PASS, (&qcow2, &nbd), EXP_PASS,
...@@ -854,13 +839,11 @@ mymain(void) ...@@ -854,13 +839,11 @@ mymain(void)
.expBackingStoreRaw = absraw, .expBackingStoreRaw = absraw,
.expCapacity = 1024, .expCapacity = 1024,
.path = canonqed, .path = canonqed,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_QED, .format = VIR_STORAGE_FILE_QED,
}; };
testFileData qed_as_raw = { testFileData qed_as_raw = {
.path = canonqed, .path = canonqed,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_RAW, .format = VIR_STORAGE_FILE_RAW,
}; };
...@@ -871,7 +854,6 @@ mymain(void) ...@@ -871,7 +854,6 @@ mymain(void)
/* directory */ /* directory */
testFileData dir = { testFileData dir = {
.path = canondir, .path = canondir,
.relDir = datadir,
.type = VIR_STORAGE_TYPE_DIR, .type = VIR_STORAGE_TYPE_DIR,
.format = VIR_STORAGE_FILE_DIR, .format = VIR_STORAGE_FILE_DIR,
}; };
...@@ -904,7 +886,6 @@ mymain(void) ...@@ -904,7 +886,6 @@ mymain(void)
.expCapacity = 1024, .expCapacity = 1024,
.pathRel = "../sub/link1", .pathRel = "../sub/link1",
.path = datadir "/sub/../sub/link1", .path = datadir "/sub/../sub/link1",
.relDir = datadir "/sub/../sub",
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_QCOW2, .format = VIR_STORAGE_FILE_QCOW2,
}; };
...@@ -912,14 +893,12 @@ mymain(void) ...@@ -912,14 +893,12 @@ mymain(void)
.expBackingStoreRaw = "../sub/link1", .expBackingStoreRaw = "../sub/link1",
.expCapacity = 1024, .expCapacity = 1024,
.path = abslink2, .path = abslink2,
.relDir = datadir "/sub",
.type = VIR_STORAGE_TYPE_FILE, .type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_QCOW2, .format = VIR_STORAGE_FILE_QCOW2,
}; };
raw.path = datadir "/sub/../sub/../raw"; raw.path = datadir "/sub/../sub/../raw";
raw.pathRel = "../raw"; raw.pathRel = "../raw";
raw.relDir = datadir "/sub/../sub/..";
TEST_CHAIN(15, abslink2, VIR_STORAGE_FILE_QCOW2, TEST_CHAIN(15, abslink2, VIR_STORAGE_FILE_QCOW2,
(&link2, &link1, &raw), EXP_PASS, (&link2, &link1, &raw), EXP_PASS,
(&link2, &link1, &raw), ALLOW_PROBE | EXP_PASS); (&link2, &link1, &raw), ALLOW_PROBE | EXP_PASS);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册