From 63ba651c128907fc9c95a8d3b8c2a599657e4c41 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 (cherry picked from commit 38ed0523125efeaf8383b36d1db169b42e2f5eb6) --- 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 2dc2fdaf2f6..0b31a275334 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),