]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: when zapping unmount osd directories
authorAndrew Schoen <aschoen@redhat.com>
Thu, 1 Feb 2018 20:52:46 +0000 (14:52 -0600)
committerAndrew Schoen <aschoen@redhat.com>
Tue, 13 Feb 2018 22:58:05 +0000 (16:58 -0600)
If you zap an lv, device or partition and it's currently mounted as a
ceph osd directory then it will be unmounted so the zap can complete.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
doc/ceph-volume/lvm/zap.rst
src/ceph-volume/ceph_volume/devices/lvm/zap.py

index 579cfe6e44d2b576587be44ae8c0649b2dc233d0..e0c190242acbebd1eca637c0273cfaf0db901143 100644 (file)
@@ -10,6 +10,9 @@ on the given lv or partition will be removed and all data will be purged.
 
 .. note:: The lv or partition will be kept intact.
 
+.. note:: If the logicial volume, raw device or partition is being used for any ceph related
+          mountpoints they will be unmounted.
+
 Zapping a logical volume::
 
       ceph-volume lvm zap {vg name/lv name}
index dda21d2b89c979fc53865f82ff0c2eb379f1698a..16ebc76f6b55f77da4cefcd82ff330553752a29e 100644 (file)
@@ -5,6 +5,7 @@ from textwrap import dedent
 
 from ceph_volume import decorators, terminal, process
 from ceph_volume.api import lvm as api
+from ceph_volume.util import system
 
 logger = logging.getLogger(__name__)
 
@@ -59,27 +60,37 @@ class Zap(object):
         logger.info("Zapping: %s", path)
         terminal.write("Zapping: %s" % path)
 
-        if args.destroy and not lv:
-            # check if there was a pv created with the
-            # name of device
-            pv = api.PVolumes().get(pv_name=device)
-            if pv:
-                logger.info("Found a physical volume created from %s, will destroy all it's vgs and lvs", device)
-                vg_name = pv.vg_name
-                logger.info("Destroying volume group %s because --destroy was given", vg_name)
-                terminal.write("Destroying volume group %s because --destroy was given" % vg_name)
-                api.remove_vg(vg_name)
-                logger.info("Destroying physical volume %s because --destroy was given", device)
-                terminal.write("Destroying physical volume %s because --destroy was given" % device)
-                api.remove_pv(device)
-            else:
-                logger.info("Skipping --destroy because no associated physical volumes are found for %s", device)
-                terminal.write("Skipping --destroy because no associated physical volumes are found for %s" % device)
+        # check if there was a pv created with the
+        # name of device
+        pv = api.PVolumes().get(pv_name=device)
+        if pv:
+            vg_name = pv.vg_name
+            lv = api.Volumes().get(vg_name=vg_name)
+
+        if lv:
+            osd_path = "/var/lib/ceph/osd/{}-{}".format(lv.tags['ceph.cluster_name'], lv.tags['ceph.osd_id'])
+            if system.path_is_mounted(osd_path):
+                logger.info("Unmounting %s", osd_path)
+                terminal.write("Unmounting %s" % osd_path)
+                system.unmount(osd_path)
+
+        if args.destroy and pv:
+            logger.info("Found a physical volume created from %s, will destroy all it's vgs and lvs", device)
+            vg_name = pv.vg_name
+            logger.info("Destroying volume group %s because --destroy was given", vg_name)
+            terminal.write("Destroying volume group %s because --destroy was given" % vg_name)
+            api.remove_vg(vg_name)
+            logger.info("Destroying physical volume %s because --destroy was given", device)
+            terminal.write("Destroying physical volume %s because --destroy was given" % device)
+            api.remove_pv(device)
+        elif args.destroy and not pv:
+            logger.info("Skipping --destroy because no associated physical volumes are found for %s", device)
+            terminal.write("Skipping --destroy because no associated physical volumes are found for %s" % device)
 
         wipefs(path)
         zap_data(path)
 
-        if lv:
+        if lv and not pv:
             # remove all lvm metadata
             lv.clear_tags()
 
@@ -92,6 +103,9 @@ class Zap(object):
         filesystems present on the given device, vg/lv, or partition will be removed and
         all data will be purged.
 
+        If the logicial volume, raw device or partition is being used for any ceph related
+        mountpoints they will be unmounted.
+
         However, the lv or partition will be kept intact.
 
         Example calls for supported scenarios: