From 768bab6ae948d1f2ab1ea712843b2ce6415a4172 Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Fri, 9 Oct 2020 13:39:15 -0500 Subject: [PATCH] ceph-volume: scan the system for lvs and vgs after zapping Sometimes when `lvm zap` destroys an lv or vg the lvm cache does not get updated and the deleted lv or vg will show up as available. This runs `vgscan --cache` and `lvscan --cache` to reset the that cache. Resolves: rhbz#1886534 Signed-off-by: Andrew Schoen --- src/ceph-volume/ceph_volume/api/lvm.py | 12 ++++++++++++ src/ceph-volume/ceph_volume/devices/lvm/zap.py | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/ceph-volume/ceph_volume/api/lvm.py b/src/ceph-volume/ceph_volume/api/lvm.py index 461e010506c2f..5e77ba5518bdf 100644 --- a/src/ceph-volume/ceph_volume/api/lvm.py +++ b/src/ceph-volume/ceph_volume/api/lvm.py @@ -740,6 +740,18 @@ def get_device_vgs(device, name_prefix=''): return [VolumeGroup(**vg) for vg in vgs if vg['vg_name'] and vg['vg_name'].startswith(name_prefix)] +def scan(): + """ + Scan the system for lvs and vgs. Sometimes + the cache can become stale when an lv or vg + is deleted. This will rescan the system + and ensure that `lvs` and `vgs` return + the actual state of the system. + """ + process.run(['lvscan', '--cache']) + process.run(['vgscan', '--cache']) + + ################################# # # Code for LVM Logical Volumes diff --git a/src/ceph-volume/ceph_volume/devices/lvm/zap.py b/src/ceph-volume/ceph_volume/devices/lvm/zap.py index 21b54b6c0c419..e50d8055e719f 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/zap.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/zap.py @@ -188,6 +188,11 @@ class Zap(object): mlogger.info('Removing LV because --destroy was given: %s', device.abspath) api.remove_lv(device.abspath) + + # scan the system for lvs and vgs after deleting. + # this avoids and issue where stale lvm cache can + # show deleted lvs and vgs as available. + api.scan() elif lv: # just remove all lvm metadata, leaving the LV around lv.clear_tags() -- 2.39.5