From 38ed0523125efeaf8383b36d1db169b42e2f5eb6 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Wed, 16 Jul 2014 08:49:37 -0600 Subject: [PATCH] Don't leave snapshots on the floor The current cloning process in the LVM driver uses a snapshot to do the data copy in the background. Trouble here is that if the creation or activation of the new volume fails, we don't cleanup the snapshot we created. Just move the create_volume and activate calls down into the try block so the finally clause can do the cleanup for us. Change-Id: If0fbab9d9f39102cdc7d287527be22c4a2b35934 Closes-Bug: #1312718 --- cinder/volume/drivers/lvm.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index bdfe12d24..47ac5910f 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -291,16 +291,17 @@ class LVMVolumeDriver(driver.VolumeDriver): 'id': temp_id} self.create_snapshot(temp_snapshot) - self._create_volume(volume['name'], - self._sizestr(volume['size']), - self.configuration.lvm_type, - mirror_count) - - self.vg.activate_lv(temp_snapshot['name'], is_snapshot=True) # copy_volume expects sizes in MiB, we store integer GiB # be sure to convert before passing in try: + self._create_volume(volume['name'], + self._sizestr(volume['size']), + self.configuration.lvm_type, + mirror_count) + + self.vg.activate_lv(temp_snapshot['name'], is_snapshot=True) + volutils.copy_volume( self.local_path(temp_snapshot), self.local_path(volume), -- 2.45.2