Re: [libvirt] [PATCH v2 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store
On 21.01.2015 16:29, Matthias Gatto wrote: > Replace the parts of the code where a backing store is set manually > with virStorageSourceSetBackingStore > > Signed-off-by: Matthias Gatto > --- > src/conf/domain_conf.c | 2 +- > src/conf/storage_conf.c | 4 ++-- > src/qemu/qemu_driver.c | 4 ++-- > src/storage/storage_backend_fs.c | 8 > src/storage/storage_driver.c | 2 +- > src/util/virstoragefile.c| 8 +--- > tests/virstoragetest.c | 4 ++-- > 7 files changed, 17 insertions(+), 15 deletions(-) > > diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c > index 0668a5b..9d6b888 100644 > --- a/src/conf/domain_conf.c > +++ b/src/conf/domain_conf.c > @@ -5659,7 +5659,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, > virDomainDiskBackingStoreParse(ctxt, backingStore) < 0) > goto cleanup; > > -src->backingStore = backingStore; > +virStorageSourceSetBackingStore(src, backingStore, 0); > ret = 0; > > cleanup: > diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c > index f4f7e24..fac85fa 100644 > --- a/src/conf/storage_conf.c > +++ b/src/conf/storage_conf.c > @@ -1340,10 +1340,10 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, > > if ((backingStore = virXPathString("string(./backingStore/path)", > ctxt))) { > virStorageSourcePtr backingStorePtr; > -if (VIR_ALLOC(ret->target.backingStore) < 0) > +if (VIR_ALLOC(backingStorePtr) < 0) > goto error; > > -backingStorePtr = virStorageSourceGetBackingStore(&ret->target, 0); > +backingStorePtr = virStorageSourceSetBackingStore(&ret->target, > backingStorePtr, 0); > backingStorePtr->path = backingStore; > backingStore = NULL; > > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index 547d2b5..b3afccd 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -13500,13 +13500,13 @@ > qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, > /* Update vm in place to match changes. */ > tmp = disk->src; > disk->src = virStorageSourceGetBackingStore(tmp, 0); > -tmp->backingStore = NULL; > +virStorageSourceSetBackingStore(tmp, NULL, 0); > virStorageSourceFree(tmp); > > if (persistDisk) { > tmp = persistDisk->src; > persistDisk->src = virStorageSourceGetBackingStore(tmp, 0); > -tmp->backingStore = NULL; > +virStorageSourceSetBackingStore(tmp, NULL, 0); > virStorageSourceFree(tmp); > } > } > diff --git a/src/storage/storage_backend_fs.c > b/src/storage/storage_backend_fs.c > index 56cfc56..a3b6688 100644 > --- a/src/storage/storage_backend_fs.c > +++ b/src/storage/storage_backend_fs.c > @@ -97,8 +97,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, > goto cleanup; > > if (meta->backingStoreRaw) { > -backingStore = virStorageSourceGetBackingStore(target, 0); See? this line ^^ is useless. > -if (!(backingStore = virStorageSourceNewFromBacking(meta))) > +if (!(backingStore = virStorageSourceSetBackingStore(target, > + > virStorageSourceNewFromBacking(meta), > + 0))) Well, since I squashed in my diff in 2/9 I'm getting a merge error here. But that's okay. > goto cleanup; > > backingStore->format = backingStoreFormat; > @@ -111,8 +112,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, > > if (VIR_ALLOC(backingStore) < 0) > goto cleanup; > - > -target->backingStore = backingStore; > +virStorageSourceSetBackingStore(target, backingStore, 0); > backingStore->type = VIR_STORAGE_TYPE_NETWORK; > backingStore->path = meta->backingStoreRaw; > meta->backingStoreRaw = NULL; > diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c > index 66dc994..eeb2a4c 100644 > --- a/src/storage/storage_driver.c > +++ b/src/storage/storage_driver.c > @@ -2899,7 +2899,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr > src, > goto cleanup; > } > > -src->backingStore = backingStore; > +virStorageSourceSetBackingStore(src, backingStore, 0); > backingStore = NULL; > ret = 0; > > diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c > index 84eefa3..ba38827 100644 > --- a/src/util/virstoragefile.c > +++ b/src/util/virstoragefile.c > @@ -1891,8 +1891,10 @@ virStorageSourceCopy(const virStorageSource *src, > goto error; > > if (backingChain && virStorageSourceGetBackingStore(src, 0)) { > -if (!(ret->backingStore = > virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0), > - true))) > +if (!virStorageSourceS
[libvirt] [PATCH v2 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store
Replace the parts of the code where a backing store is set manually with virStorageSourceSetBackingStore Signed-off-by: Matthias Gatto --- src/conf/domain_conf.c | 2 +- src/conf/storage_conf.c | 4 ++-- src/qemu/qemu_driver.c | 4 ++-- src/storage/storage_backend_fs.c | 8 src/storage/storage_driver.c | 2 +- src/util/virstoragefile.c| 8 +--- tests/virstoragetest.c | 4 ++-- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0668a5b..9d6b888 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5659,7 +5659,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, virDomainDiskBackingStoreParse(ctxt, backingStore) < 0) goto cleanup; -src->backingStore = backingStore; +virStorageSourceSetBackingStore(src, backingStore, 0); ret = 0; cleanup: diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index f4f7e24..fac85fa 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1340,10 +1340,10 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) { virStorageSourcePtr backingStorePtr; -if (VIR_ALLOC(ret->target.backingStore) < 0) +if (VIR_ALLOC(backingStorePtr) < 0) goto error; -backingStorePtr = virStorageSourceGetBackingStore(&ret->target, 0); +backingStorePtr = virStorageSourceSetBackingStore(&ret->target, backingStorePtr, 0); backingStorePtr->path = backingStore; backingStore = NULL; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 547d2b5..b3afccd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13500,13 +13500,13 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, /* Update vm in place to match changes. */ tmp = disk->src; disk->src = virStorageSourceGetBackingStore(tmp, 0); -tmp->backingStore = NULL; +virStorageSourceSetBackingStore(tmp, NULL, 0); virStorageSourceFree(tmp); if (persistDisk) { tmp = persistDisk->src; persistDisk->src = virStorageSourceGetBackingStore(tmp, 0); -tmp->backingStore = NULL; +virStorageSourceSetBackingStore(tmp, NULL, 0); virStorageSourceFree(tmp); } } diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 56cfc56..a3b6688 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -97,8 +97,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, goto cleanup; if (meta->backingStoreRaw) { -backingStore = virStorageSourceGetBackingStore(target, 0); -if (!(backingStore = virStorageSourceNewFromBacking(meta))) +if (!(backingStore = virStorageSourceSetBackingStore(target, + virStorageSourceNewFromBacking(meta), + 0))) goto cleanup; backingStore->format = backingStoreFormat; @@ -111,8 +112,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, if (VIR_ALLOC(backingStore) < 0) goto cleanup; - -target->backingStore = backingStore; +virStorageSourceSetBackingStore(target, backingStore, 0); backingStore->type = VIR_STORAGE_TYPE_NETWORK; backingStore->path = meta->backingStoreRaw; meta->backingStoreRaw = NULL; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 66dc994..eeb2a4c 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2899,7 +2899,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src, goto cleanup; } -src->backingStore = backingStore; +virStorageSourceSetBackingStore(src, backingStore, 0); backingStore = NULL; ret = 0; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 84eefa3..ba38827 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1891,8 +1891,10 @@ virStorageSourceCopy(const virStorageSource *src, goto error; if (backingChain && virStorageSourceGetBackingStore(src, 0)) { -if (!(ret->backingStore = virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0), - true))) +if (!virStorageSourceSetBackingStore(ret, + virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0), + true), + 0)) goto error; } @@ -2029,7 +2031,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def) /* recursively free backing chain */