
Cloned disks currently don't have ref_cnt stored locally, so they may be attached again to another VM - or even to the same one. When cloning a VM, set their disks' ref_cnt to 1 to prevent them from being reattached. Fix issue #628 (Storage volume ref_cnt is not updated after vm clone). Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 86c173f..af5e765 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -449,6 +449,10 @@ class VMModel(object): vir_conn = self.conn.get() + def _delete_disk_from_objstore(path): + with self.objstore as session: + session.delete('storagevolume', path) + for i, path in enumerate(all_paths): try: vir_orig_vol = vir_conn.storageVolLookupByPath(path) @@ -518,6 +522,11 @@ class VMModel(object): xml = xml_item_update(xml, XPATH_DOMAIN_DISK_BY_FILE % path, new_vol['path'], 'file') + # set the new disk's ref_cnt + with self.objstore as session: + session.store('storagevolume', new_vol['path'], {'ref_cnt': 1}) + rollback.prependDefer(_delete_disk_from_objstore, new_vol['path']) + # remove the new volume should an error occur later rollback.prependDefer(self.storagevolume.delete, new_pool_name, new_vol_name) -- 2.1.0