def non_leaf_coalesce(node, parent, uri, cb): node_vhd = node.vhd parent_vhd = parent.vhd log.debug("non_leaf_coalesce key={}, parent={}".format(node_vhd.id, parent_vhd.id)) opq = cb.volumeStartOperations(uri, 'w') meta_path = cb.volumeMetadataGetPath(opq) node_path = cb.volumeGetPath(opq, str(node_vhd.id)) log.debug("Running vhd-coalesce on {}".format(node_vhd.id)) VHDUtil.coalesce(GC, node_path) db = VHDMetabase(meta_path) with Lock(opq, 'gl', cb): # reparent all of the children to this node's parent children = db.get_children(node_vhd.id) with db.write_context(): journal_entries = db.add_journal_entries(node_vhd.id, parent_vhd.id, children) __reparent_children(opq, db, cb, journal_entries) # remove key log.debug("Destroy {}".format(node_vhd.id)) cb.volumeDestroy(opq, str(node_vhd.id)) with db.write_context(): db.delete_vhd(node_vhd.id) cb.volumeUnlock(opq, node.lock) cb.volumeUnlock(opq, parent.lock) db.close() cb.volumeStopOperations(opq)
def remove_garbage_vhds(uri, cb): opq = cb.volumeStartOperations(uri, 'w') meta_path = cb.volumeMetadataGetPath(opq) db = VHDMetabase(meta_path) garbage = db.get_garbage_vhds() if len(garbage) > 0: for vhd in garbage: cb.volumeDestroy(opq, str(vhd.id)) with db.write_context(): db.delete_vhd(vhd.id) db.close() cb.volumeStopOperations(opq)