1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

util: storage: Make virStorageFileChainLookup more network storage aware

Add a few checks and avoid resolving relative links on networked
storage.
This commit is contained in:
Peter Krempa 2014-06-25 13:45:54 +02:00
parent cd7b63e663
commit 09cea692b5

View File

@ -1333,13 +1333,12 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
const char *tmp; const char *tmp;
char *parentDir = NULL; char *parentDir = NULL;
bool nameIsFile = virStorageIsFile(name); bool nameIsFile = virStorageIsFile(name);
size_t i; size_t i = 0;
if (!parent) if (!parent)
parent = &tmp; parent = &tmp;
*parent = NULL; *parent = NULL;
i = 0;
if (startFrom) { if (startFrom) {
while (chain && chain != startFrom->backingStore) { while (chain && chain != startFrom->backingStore) {
chain = chain->backingStore; chain = chain->backingStore;
@ -1360,24 +1359,26 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
if (STREQ_NULLABLE(name, chain->relPath) || if (STREQ_NULLABLE(name, chain->relPath) ||
STREQ(name, chain->path)) STREQ(name, chain->path))
break; break;
if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
chain->type == VIR_STORAGE_TYPE_BLOCK)) { if (nameIsFile && virStorageSourceIsLocalStorage(chain)) {
if (prev) { if (prev && virStorageSourceIsLocalStorage(prev))
if (!(parentDir = mdir_name(prev->path))) { parentDir = mdir_name(prev->path);
else
ignore_value(VIR_STRDUP_QUIET(parentDir, "."));
if (!parentDir) {
virReportOOMError(); virReportOOMError();
goto error; 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); VIR_FREE(parentDir);
if (result < 0) if (result < 0)
goto error; goto error;
if (result > 0) if (result > 0)
break; break;
} }
@ -1390,6 +1391,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
if (!chain) if (!chain)
goto error; goto error;
return chain; return chain;
error: error: