Instead of just returning the parent path, return the complete parent
source structure.
---
src/qemu/qemu_driver.c | 16 ++++-----
src/util/virstoragefile.c | 17 ++++------
src/util/virstoragefile.h | 2 +-
tests/virstoragetest.c | 86 ++++++++++++++++++++++-------------------------
4 files changed, 56 insertions(+), 65 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 66b287c..c092494 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15494,7 +15494,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;
/* XXX Add support for COMMIT_ACTIVE, COMMIT_DELETE */
@@ -15602,10 +15602,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 != disk->src &&
+ qemuDomainPrepareDiskChainElement(driver, vm, disk, top_parent,
+ VIR_DISK_CHAIN_READ_WRITE) < 0))
goto endjob;
/* Start the commit operation. Pass the user's original spelling,
@@ -15625,10 +15624,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 != disk->src)
+ qemuDomainPrepareDiskChainElement(driver, vm, disk, top_parent,
+ VIR_DISK_CHAIN_READ_ONLY);
}
if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index b7ae570..e4058a5 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1337,17 +1337,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) {
@@ -1355,7 +1354,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
chain = chain->backingStore;
i++;
}
- *parent = startFrom->path;
+ *parent = startFrom;
}
while (chain) {
@@ -1372,8 +1371,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(parentDir, "."));
@@ -1382,7 +1381,6 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
goto error;
}
-
int result = virFileRelLinkPointsTo(parentDir, name,
chain->path);
@@ -1395,8 +1393,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
break;
}
}
- *parent = chain->path;
- prev = chain;
+ *parent = chain;
chain = chain->backingStore;
i++;
}
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 78646ba..7c9260b 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -297,7 +297,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,
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index fb2837f..e2ee3ff 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -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);
--
1.9.3