1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

util: storage: Return complete parent info from virStorageFileChainLookup

Instead of just returning the parent path, return the complete parent
source structure.
This commit is contained in:
Peter Krempa 2014-06-25 15:43:04 +02:00
parent 09cea692b5
commit 750177104d
4 changed files with 56 additions and 64 deletions

View File

@ -15540,7 +15540,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
unsigned int topIndex = 0;
virStorageSourcePtr baseSource;
unsigned int baseIndex = 0;
const char *top_parent = NULL;
virStorageSourcePtr top_parent = NULL;
bool clean_access = false;
char *topPath = NULL;
char *basePath = NULL;
@ -15652,10 +15652,9 @@ qemuDomainBlockCommit(virDomainPtr dom,
clean_access = true;
if (qemuDomainPrepareDiskChainElement(driver, vm, disk, baseSource,
VIR_DISK_CHAIN_READ_WRITE) < 0 ||
(top_parent && top_parent != disk->src->path &&
qemuDomainPrepareDiskChainElementPath(driver, vm, disk,
top_parent,
VIR_DISK_CHAIN_READ_WRITE) < 0))
(top_parent && top_parent != disk->src &&
qemuDomainPrepareDiskChainElement(driver, vm, disk, top_parent,
VIR_DISK_CHAIN_READ_WRITE) < 0))
goto endjob;
if (qemuGetDriveSourceString(topSource, NULL, &topPath) < 0)
@ -15699,10 +15698,9 @@ qemuDomainBlockCommit(virDomainPtr dom,
/* Revert access to read-only, if possible. */
qemuDomainPrepareDiskChainElement(driver, vm, disk, baseSource,
VIR_DISK_CHAIN_READ_ONLY);
if (top_parent && top_parent != disk->src->path)
qemuDomainPrepareDiskChainElementPath(driver, vm, disk,
top_parent,
VIR_DISK_CHAIN_READ_ONLY);
if (top_parent && top_parent != disk->src)
qemuDomainPrepareDiskChainElement(driver, vm, disk, top_parent,
VIR_DISK_CHAIN_READ_ONLY);
}
if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;

View File

@ -1326,17 +1326,16 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
virStorageSourcePtr startFrom,
const char *name,
unsigned int idx,
const char **parent)
virStorageSourcePtr *parent)
{
virStorageSourcePtr prev = NULL;
virStorageSourcePtr prev;
const char *start = chain->path;
const char *tmp;
char *parentDir = NULL;
bool nameIsFile = virStorageIsFile(name);
size_t i = 0;
if (!parent)
parent = &tmp;
parent = &prev;
*parent = NULL;
if (startFrom) {
@ -1344,7 +1343,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
chain = chain->backingStore;
i++;
}
*parent = startFrom->path;
*parent = startFrom;
}
while (chain) {
@ -1361,8 +1360,8 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
break;
if (nameIsFile && virStorageSourceIsLocalStorage(chain)) {
if (prev && virStorageSourceIsLocalStorage(prev))
parentDir = mdir_name(prev->path);
if (*parent && virStorageSourceIsLocalStorage(*parent))
parentDir = mdir_name((*parent)->path);
else
ignore_value(VIR_STRDUP_QUIET(parentDir, "."));
@ -1383,8 +1382,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
break;
}
}
*parent = chain->path;
prev = chain;
*parent = chain;
chain = chain->backingStore;
i++;
}

View File

@ -315,7 +315,7 @@ virStorageSourcePtr virStorageFileChainLookup(virStorageSourcePtr chain,
virStorageSourcePtr startFrom,
const char *name,
unsigned int idx,
const char **parent)
virStorageSourcePtr *parent)
ATTRIBUTE_NONNULL(1);
int virStorageFileResize(const char *path,

View File

@ -415,7 +415,7 @@ struct testLookupData
unsigned int expIndex;
const char *expResult;
virStorageSourcePtr expMeta;
const char *expParent;
virStorageSourcePtr expParent;
};
static int
@ -424,7 +424,7 @@ testStorageLookup(const void *args)
const struct testLookupData *data = args;
int ret = 0;
virStorageSourcePtr result;
const char *actualParent;
virStorageSourcePtr actualParent;
unsigned int idx;
if (virStorageFileParseChainIndex(data->target, data->name, &idx) < 0 &&
@ -488,9 +488,10 @@ testStorageLookup(const void *args)
data->expMeta, result);
ret = -1;
}
if (STRNEQ_NULLABLE(data->expParent, actualParent)) {
if (data->expParent != actualParent) {
fprintf(stderr, "parent: expected %s, got %s\n",
NULLSTR(data->expParent), NULLSTR(actualParent));
NULLSTR(data->expParent ? data->expParent->path : NULL),
NULLSTR(actualParent ? actualParent->path : NULL));
ret = -1;
}
@ -974,25 +975,25 @@ mymain(void)
TEST_LOOKUP(5, NULL, abswrap, chain->path, chain, NULL);
TEST_LOOKUP(6, chain, abswrap, NULL, NULL, NULL);
TEST_LOOKUP(7, chain2, abswrap, NULL, NULL, NULL);
TEST_LOOKUP(8, NULL, "qcow2", chain2->path, chain2, chain->path);
TEST_LOOKUP(9, chain, "qcow2", chain2->path, chain2, chain->path);
TEST_LOOKUP(8, NULL, "qcow2", chain2->path, chain2, chain);
TEST_LOOKUP(9, chain, "qcow2", chain2->path, chain2, chain);
TEST_LOOKUP(10, chain2, "qcow2", NULL, NULL, NULL);
TEST_LOOKUP(11, chain3, "qcow2", NULL, NULL, NULL);
TEST_LOOKUP(12, NULL, absqcow2, chain2->path, chain2, chain->path);
TEST_LOOKUP(13, chain, absqcow2, chain2->path, chain2, chain->path);
TEST_LOOKUP(12, NULL, absqcow2, chain2->path, chain2, chain);
TEST_LOOKUP(13, chain, absqcow2, chain2->path, chain2, chain);
TEST_LOOKUP(14, chain2, absqcow2, NULL, NULL, NULL);
TEST_LOOKUP(15, chain3, absqcow2, NULL, NULL, NULL);
TEST_LOOKUP(16, NULL, "raw", chain3->path, chain3, chain2->path);
TEST_LOOKUP(17, chain, "raw", chain3->path, chain3, chain2->path);
TEST_LOOKUP(18, chain2, "raw", chain3->path, chain3, chain2->path);
TEST_LOOKUP(16, NULL, "raw", chain3->path, chain3, chain2);
TEST_LOOKUP(17, chain, "raw", chain3->path, chain3, chain2);
TEST_LOOKUP(18, chain2, "raw", chain3->path, chain3, chain2);
TEST_LOOKUP(19, chain3, "raw", NULL, NULL, NULL);
TEST_LOOKUP(20, NULL, absraw, chain3->path, chain3, chain2->path);
TEST_LOOKUP(21, chain, absraw, chain3->path, chain3, chain2->path);
TEST_LOOKUP(22, chain2, absraw, chain3->path, chain3, chain2->path);
TEST_LOOKUP(20, NULL, absraw, chain3->path, chain3, chain2);
TEST_LOOKUP(21, chain, absraw, chain3->path, chain3, chain2);
TEST_LOOKUP(22, chain2, absraw, chain3->path, chain3, chain2);
TEST_LOOKUP(23, chain3, absraw, NULL, NULL, NULL);
TEST_LOOKUP(24, NULL, NULL, chain3->path, chain3, chain2->path);
TEST_LOOKUP(25, chain, NULL, chain3->path, chain3, chain2->path);
TEST_LOOKUP(26, chain2, NULL, chain3->path, chain3, chain2->path);
TEST_LOOKUP(24, NULL, NULL, chain3->path, chain3, chain2);
TEST_LOOKUP(25, chain, NULL, chain3->path, chain3, chain2);
TEST_LOOKUP(26, chain2, NULL, chain3->path, chain3, chain2);
TEST_LOOKUP(27, chain3, NULL, NULL, NULL, NULL);
/* Rewrite wrap and qcow2 back to 3-deep chain, relative backing */
@ -1027,25 +1028,25 @@ mymain(void)
TEST_LOOKUP(33, NULL, abswrap, chain->path, chain, NULL);
TEST_LOOKUP(34, chain, abswrap, NULL, NULL, NULL);
TEST_LOOKUP(35, chain2, abswrap, NULL, NULL, NULL);
TEST_LOOKUP(36, NULL, "qcow2", chain2->path, chain2, chain->path);
TEST_LOOKUP(37, chain, "qcow2", chain2->path, chain2, chain->path);
TEST_LOOKUP(36, NULL, "qcow2", chain2->path, chain2, chain);
TEST_LOOKUP(37, chain, "qcow2", chain2->path, chain2, chain);
TEST_LOOKUP(38, chain2, "qcow2", NULL, NULL, NULL);
TEST_LOOKUP(39, chain3, "qcow2", NULL, NULL, NULL);
TEST_LOOKUP(40, NULL, absqcow2, chain2->path, chain2, chain->path);
TEST_LOOKUP(41, chain, absqcow2, chain2->path, chain2, chain->path);
TEST_LOOKUP(40, NULL, absqcow2, chain2->path, chain2, chain);
TEST_LOOKUP(41, chain, absqcow2, chain2->path, chain2, chain);
TEST_LOOKUP(42, chain2, absqcow2, NULL, NULL, NULL);
TEST_LOOKUP(43, chain3, absqcow2, NULL, NULL, NULL);
TEST_LOOKUP(44, NULL, "raw", chain3->path, chain3, chain2->path);
TEST_LOOKUP(45, chain, "raw", chain3->path, chain3, chain2->path);
TEST_LOOKUP(46, chain2, "raw", chain3->path, chain3, chain2->path);
TEST_LOOKUP(44, NULL, "raw", chain3->path, chain3, chain2);
TEST_LOOKUP(45, chain, "raw", chain3->path, chain3, chain2);
TEST_LOOKUP(46, chain2, "raw", chain3->path, chain3, chain2);
TEST_LOOKUP(47, chain3, "raw", NULL, NULL, NULL);
TEST_LOOKUP(48, NULL, absraw, chain3->path, chain3, chain2->path);
TEST_LOOKUP(49, chain, absraw, chain3->path, chain3, chain2->path);
TEST_LOOKUP(50, chain2, absraw, chain3->path, chain3, chain2->path);
TEST_LOOKUP(48, NULL, absraw, chain3->path, chain3, chain2);
TEST_LOOKUP(49, chain, absraw, chain3->path, chain3, chain2);
TEST_LOOKUP(50, chain2, absraw, chain3->path, chain3, chain2);
TEST_LOOKUP(51, chain3, absraw, NULL, NULL, NULL);
TEST_LOOKUP(52, NULL, NULL, chain3->path, chain3, chain2->path);
TEST_LOOKUP(53, chain, NULL, chain3->path, chain3, chain2->path);
TEST_LOOKUP(54, chain2, NULL, chain3->path, chain3, chain2->path);
TEST_LOOKUP(52, NULL, NULL, chain3->path, chain3, chain2);
TEST_LOOKUP(53, chain, NULL, chain3->path, chain3, chain2);
TEST_LOOKUP(54, chain2, NULL, chain3->path, chain3, chain2);
TEST_LOOKUP(55, chain3, NULL, NULL, NULL, NULL);
/* Use link to wrap with cross-directory relative backing */
@ -1070,12 +1071,12 @@ mymain(void)
TEST_LOOKUP(57, NULL, "sub/link2", chain->path, chain, NULL);
TEST_LOOKUP(58, NULL, "wrap", chain->path, chain, NULL);
TEST_LOOKUP(59, NULL, abswrap, chain->path, chain, NULL);
TEST_LOOKUP(60, NULL, "../qcow2", chain2->path, chain2, chain->path);
TEST_LOOKUP(60, NULL, "../qcow2", chain2->path, chain2, chain);
TEST_LOOKUP(61, NULL, "qcow2", NULL, NULL, NULL);
TEST_LOOKUP(62, NULL, absqcow2, chain2->path, chain2, chain->path);
TEST_LOOKUP(63, NULL, "raw", chain3->path, chain3, chain2->path);
TEST_LOOKUP(64, NULL, absraw, chain3->path, chain3, chain2->path);
TEST_LOOKUP(65, NULL, NULL, chain3->path, chain3, chain2->path);
TEST_LOOKUP(62, NULL, absqcow2, chain2->path, chain2, chain);
TEST_LOOKUP(63, NULL, "raw", chain3->path, chain3, chain2);
TEST_LOOKUP(64, NULL, absraw, chain3->path, chain3, chain2);
TEST_LOOKUP(65, NULL, NULL, chain3->path, chain3, chain2);
TEST_LOOKUP_TARGET(66, "vda", NULL, "bogus[1]", 0, NULL, NULL, NULL);
TEST_LOOKUP_TARGET(67, "vda", NULL, "vda[-1]", 0, NULL, NULL, NULL);
@ -1084,18 +1085,13 @@ mymain(void)
TEST_LOOKUP_TARGET(70, "vda", chain, "wrap", 0, NULL, NULL, NULL);
TEST_LOOKUP_TARGET(71, "vda", chain2, "wrap", 0, NULL, NULL, NULL);
TEST_LOOKUP_TARGET(72, "vda", NULL, "vda[0]", 0, NULL, NULL, NULL);
TEST_LOOKUP_TARGET(73, "vda", NULL, "vda[1]", 1, chain2->path, chain2,
chain->path);
TEST_LOOKUP_TARGET(74, "vda", chain, "vda[1]", 1, chain2->path, chain2,
chain->path);
TEST_LOOKUP_TARGET(73, "vda", NULL, "vda[1]", 1, chain2->path, chain2, chain);
TEST_LOOKUP_TARGET(74, "vda", chain, "vda[1]", 1, chain2->path, chain2, chain);
TEST_LOOKUP_TARGET(75, "vda", chain2, "vda[1]", 1, NULL, NULL, NULL);
TEST_LOOKUP_TARGET(76, "vda", chain3, "vda[1]", 1, NULL, NULL, NULL);
TEST_LOOKUP_TARGET(77, "vda", NULL, "vda[2]", 2, chain3->path, chain3,
chain2->path);
TEST_LOOKUP_TARGET(78, "vda", chain, "vda[2]", 2, chain3->path, chain3,
chain2->path);
TEST_LOOKUP_TARGET(79, "vda", chain2, "vda[2]", 2, chain3->path, chain3,
chain2->path);
TEST_LOOKUP_TARGET(77, "vda", NULL, "vda[2]", 2, chain3->path, chain3, chain2);
TEST_LOOKUP_TARGET(78, "vda", chain, "vda[2]", 2, chain3->path, chain3, chain2);
TEST_LOOKUP_TARGET(79, "vda", chain2, "vda[2]", 2, chain3->path, chain3, chain2);
TEST_LOOKUP_TARGET(80, "vda", chain3, "vda[2]", 2, NULL, NULL, NULL);
TEST_LOOKUP_TARGET(81, "vda", NULL, "vda[3]", 3, NULL, NULL, NULL);