]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume lvm.zap iterate over multiple lvs on a pv
authorAlfredo Deza <adeza@redhat.com>
Sat, 11 Aug 2018 12:58:20 +0000 (08:58 -0400)
committerAndrew Schoen <aschoen@redhat.com>
Wed, 29 Aug 2018 18:31:59 +0000 (13:31 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit 21d4f4afcefb6b2510ae67d1ca5e3bf1d510cdfb)

src/ceph-volume/ceph_volume/devices/lvm/zap.py

index 65af440bf2f9b12304562cda9cff1c67246cdfff..121119adeee8d2e0741a099f05c225f3186a0039 100644 (file)
@@ -65,55 +65,58 @@ class Zap(object):
 
         # check if there was a pv created with the
         # name of device
-        pv = api.get_pv(pv_name=device)
-        if pv:
+        pvs = api.PVolumes()
+        pvs.filter(pv_name=device)
+        for pv in pvs:
             vg_name = pv.vg_name
-            lv = api.get_lv(vg_name=vg_name)
-
-        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)
+            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
-                dmcrypt = True
+                self.dmcrypt_close(dmcrypt_uuid)
 
-        if dmcrypt and dmcrypt_uuid:
-            dmcrypt_path = "/dev/mapper/{}".format(dmcrypt_uuid)
-            mlogger.info("Closing encrypted path %s", dmcrypt_path)
-            encryption.dmcrypt_close(dmcrypt_path)
-
-        if args.destroy and pv:
+        if args.destroy and pvs:
             logger.info("Found a physical volume created from %s, will destroy all it's vgs and lvs", device)
             vg_name = pv.vg_name
             mlogger.info("Destroying volume group %s because --destroy was given", vg_name)
             api.remove_vg(vg_name)
             mlogger.info("Destroying physical volume %s because --destroy was given", device)
             api.remove_pv(device)
-        elif args.destroy and not pv:
+        elif args.destroy and not pvs:
             mlogger.info("Skipping --destroy because no associated physical volumes are found for %s", device)
 
         wipefs(path)
         zap_data(path)
 
-        if lv and not pv:
+        if lv and not pvs:
             # remove all lvm metadata
             lv.clear_tags()
 
         terminal.success("Zapping successful for: %s" % path)
 
+    def dmcrypt_close(self, dmcrypt_uuid):
+        dmcrypt_path = "/dev/mapper/{}".format(dmcrypt_uuid)
+        mlogger.info("Closing encrypted path %s", dmcrypt_path)
+        encryption.dmcrypt_close(dmcrypt_path)
+
     def main(self):
         sub_command_help = dedent("""
         Zaps the given logical volume, raw device or partition for reuse by ceph-volume.