]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume lvm.zap unmount lvs and close dmcrypt on partitions
authorAlfredo Deza <adeza@redhat.com>
Mon, 13 Aug 2018 16:12:46 +0000 (12:12 -0400)
committerAlfredo Deza <adeza@redhat.com>
Tue, 14 Aug 2018 14:47:13 +0000 (10:47 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/devices/lvm/zap.py

index 121119adeee8d2e0741a099f05c225f3186a0039..475be18a6b83de9f2e55d03ca284d9f8ee99bb99 100644 (file)
@@ -46,6 +46,19 @@ class Zap(object):
     def __init__(self, argv):
         self.argv = argv
 
+    def unmount_lv(self, lv):
+        if lv.tags.get('ceph.cluster_name') and lv.tags.get('ceph.osd_id'):
+            lv_path = "/var/lib/ceph/osd/{}-{}".format(lv.tags['ceph.cluster_name'], lv.tags['ceph.osd_id'])
+        else:
+            lv_path = lv.path
+        dmcrypt_uuid = lv.lv_uuid
+        dmcrypt = lv.encrypted
+        if system.path_is_mounted(lv_path):
+            mlogger.info("Unmounting %s", lv_path)
+            system.unmount(lv_path)
+        if dmcrypt and dmcrypt_uuid:
+            self.dmcrypt_close(dmcrypt_uuid)
+
     @decorators.needs_root
     def zap(self, args):
         device = args.device
@@ -56,10 +69,16 @@ class Zap(object):
         if lv:
             # we are zapping a logical volume
             path = lv.lv_path
+            self.unmount_lv(lv)
         else:
             # we are zapping a partition
             #TODO: ensure device is a partition
             path = device
+            # check to if it is encrypted to close
+            partuuid = disk.get_partuuid(device)
+            if encryption.status("/dev/mapper/{}".format(partuuid)):
+                dmcrypt_uuid = partuuid
+                self.dmcrypt_close(dmcrypt_uuid)
 
         mlogger.info("Zapping: %s", path)
 
@@ -71,27 +90,8 @@ class Zap(object):
             vg_name = pv.vg_name
             lv = api.get_lv(vg_name=vg_name, lv_uuid=pv.lv_uuid)
 
-            dmcrypt = False
-            dmcrypt_uuid = None
             if lv:
-                if lv.tags.get('ceph.cluster_name') and lv.tags.get('ceph.osd_id'):
-                    lv_path = "/var/lib/ceph/osd/{}-{}".format(lv.tags['ceph.cluster_name'], lv.tags['ceph.osd_id'])
-                else:
-                    lv_path = lv.path
-                dmcrypt_uuid = lv.lv_uuid
-                dmcrypt = lv.encrypted
-                if system.path_is_mounted(lv_path):
-                    mlogger.info("Unmounting %s", lv_path)
-                    system.unmount(lv_path)
-                if dmcrypt and dmcrypt_uuid:
-                    self.dmcrypt_close(dmcrypt_uuid)
-        else:
-            # we're most likely dealing with a partition here, check to
-            # see if it was encrypted
-            partuuid = disk.get_partuuid(device)
-            if encryption.status("/dev/mapper/{}".format(partuuid)):
-                dmcrypt_uuid = partuuid
-                self.dmcrypt_close(dmcrypt_uuid)
+                self.unmount_lv(lv)
 
         if args.destroy and pvs:
             logger.info("Found a physical volume created from %s, will destroy all it's vgs and lvs", device)