diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 55b016d187..4cfaefc044 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1865,6 +1865,7 @@ virStorageNetHostTransportTypeToString; virStorageNetProtocolTypeToString; virStorageSourceAuthClear; virStorageSourceClear; +virStorageSourceClearBackingStore; virStorageSourceFree; virStorageSourceGetActualType; virStorageSourcePoolDefFree; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8fa58f33dd..a3c1b1c98d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2421,12 +2421,10 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, goto cleanup; if (disk->src.backingStore) { - if (force) { - virStorageSourceFree(disk->src.backingStore); - disk->src.backingStore = NULL; - } else { + if (force) + virStorageSourceClearBackingStore(&disk->src); + else goto cleanup; - } } qemuDomainGetImageIds(cfg, vm, disk, &uid, &gid); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 75cf8cb450..bf19c6e48a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12734,8 +12734,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, * recompute it. Better would be storing the chain ourselves rather than * reprobing, but this requires modifying domain_conf and our XML to fully * track the chain across libvirtd restarts. */ - virStorageSourceFree(disk->src.backingStore); - disk->src.backingStore = NULL; + virStorageSourceClearBackingStore(&disk->src); if (virStorageFileInit(&snap->src) < 0) goto cleanup; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index dcce1ef13a..5c43665731 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1726,6 +1726,29 @@ virStorageSourceGetActualType(virStorageSourcePtr def) } +/** + * virStorageSourceClearBackingStore: + * + * @src: disk source to clear + * + * Clears information about backing store of the current storage file. + */ +void +virStorageSourceClearBackingStore(virStorageSourcePtr def) +{ + if (!def) + return; + + VIR_FREE(def->relPath); + VIR_FREE(def->relDir); + VIR_FREE(def->backingStoreRaw); + + /* recursively free backing chain */ + virStorageSourceFree(def->backingStore); + def->backingStore = NULL; +} + + void virStorageSourceClear(virStorageSourcePtr def) { @@ -1755,12 +1778,7 @@ virStorageSourceClear(virStorageSourcePtr def) virStorageNetHostDefFree(def->nhosts, def->hosts); virStorageSourceAuthClear(def); - VIR_FREE(def->relPath); - VIR_FREE(def->relDir); - VIR_FREE(def->backingStoreRaw); - - /* recursively free backing chain */ - virStorageSourceFree(def->backingStore); + virStorageSourceClearBackingStore(def); } diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 148776ea8a..9e6cdbaf5c 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -316,5 +316,6 @@ void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def); void virStorageSourceClear(virStorageSourcePtr def); int virStorageSourceGetActualType(virStorageSourcePtr def); void virStorageSourceFree(virStorageSourcePtr def); +void virStorageSourceClearBackingStore(virStorageSourcePtr def); #endif /* __VIR_STORAGE_FILE_H__ */