From: Rafi Khardalian <rafi@metacloud.com>
Date: Wed, 5 Sep 2012 05:51:43 +0000 (+0000)
Subject: Fix volume deletion when device mapper is used
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f9cf780678078c77881fee41addc093abb15c136;p=openstack-build%2Fcinder-build.git

Fix volume deletion when device mapper is used

Call dmsetup remove if there is a /dev/mapper/nova--volumes-
element present.

Resolves bug 979020

Change-Id: Iddaaed411a77dda4bd32f9a97687ff17744119eb
---

diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py
index 435e023e4..a0bc3941b 100644
--- a/cinder/volume/driver.py
+++ b/cinder/volume/driver.py
@@ -148,6 +148,10 @@ class VolumeDriver(object):
         # zero out old volumes to prevent data leaking between users
         # TODO(ja): reclaiming space should be done lazy and low priority
         self._copy_volume('/dev/zero', self.local_path(volume), size_in_g)
+        dev_path = self.local_path(volume)
+        if os.path.exists(dev_path):
+            self._try_execute('dmsetup', 'remove', '-f', dev_path,
+                              run_as_root=True)
         self._try_execute('lvremove', '-f', "%s/%s" %
                           (FLAGS.volume_group,
                            self._escape_snapshot(volume['name'])),
diff --git a/etc/cinder/rootwrap.d/volume.filters b/etc/cinder/rootwrap.d/volume.filters
index 24cc56202..20d7e9bad 100644
--- a/etc/cinder/rootwrap.d/volume.filters
+++ b/etc/cinder/rootwrap.d/volume.filters
@@ -30,3 +30,7 @@ iscsiadm_usr: CommandFilter, /usr/bin/iscsiadm, root
 
 #cinder/volume/.py: utils.temporary_chown(path, 0), ...
 chown: CommandFilter, /bin/chown, root
+
+# cinder/volume/driver.py
+dmsetup: CommandFilter, /sbin/dmsetup, root
+dmsetup_usr: CommandFilter, /usr/sbin/dmsetup, root