From: Kotresh HR Date: Wed, 2 Aug 2023 10:37:56 +0000 (+0530) Subject: mgr/volumes: Fix pending_subvolume_deletions in volume info X-Git-Tag: v19.0.0~709^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6ca1bffe57224a84da00a6f714c0535703d45e0d;p=ceph-ci.git mgr/volumes: Fix pending_subvolume_deletions in volume info Problem: The pending_subvolume_deletions field in 'fs volume info' output is always zero Cause: The 'os.listdir' being used to list the trash directory didn't have subvolume basdir context. Hence it was always failing with ENOENT. Fix: Modify the fs_util's listdir function to list the files as well and use it. Signed-off-by: Kotresh HR Fixes: https://tracker.ceph.com/issues/62278 --- diff --git a/src/pybind/mgr/volumes/fs/fs_util.py b/src/pybind/mgr/volumes/fs/fs_util.py index be0a06acdd8..f6121ca2b29 100644 --- a/src/pybind/mgr/volumes/fs/fs_util.py +++ b/src/pybind/mgr/volumes/fs/fs_util.py @@ -68,11 +68,12 @@ def volume_exists(mgr, fs_name): return True return False -def listdir(fs, dirpath, filter_entries=None): +def listdir(fs, dirpath, filter_entries=None, filter_files=True): """ - Get the directory names (only dirs) for a given path + Get the directory entries for a given path. List only dirs if 'filter_files' is True. + Don't list the entries passed in 'filter_entries' """ - dirs = [] + entries = [] if filter_entries is None: filter_entries = [b".", b".."] else: @@ -81,12 +82,15 @@ def listdir(fs, dirpath, filter_entries=None): with fs.opendir(dirpath) as dir_handle: d = fs.readdir(dir_handle) while d: - if (d.d_name not in filter_entries) and d.is_dir(): - dirs.append(d.d_name) + if (d.d_name not in filter_entries): + if not filter_files: + entries.append(d.d_name) + elif d.is_dir(): + entries.append(d.d_name) d = fs.readdir(dir_handle) except cephfs.Error as e: raise VolumeException(-e.args[0], e.args[1]) - return dirs + return entries def has_subdir(fs, dirpath, filter_entries=None): diff --git a/src/pybind/mgr/volumes/fs/operations/volume.py b/src/pybind/mgr/volumes/fs/operations/volume.py index e6e374992fb..9eee329d1d6 100644 --- a/src/pybind/mgr/volumes/fs/operations/volume.py +++ b/src/pybind/mgr/volumes/fs/operations/volume.py @@ -11,7 +11,7 @@ import orchestrator from .lock import GlobalLock from ..exception import VolumeException from ..fs_util import create_pool, remove_pool, rename_pool, create_filesystem, \ - remove_filesystem, rename_filesystem, create_mds, volume_exists + remove_filesystem, rename_filesystem, create_mds, volume_exists, listdir from .trash import Trash from mgr_util import open_filesystem, CephfsConnectionException @@ -244,15 +244,15 @@ def list_volumes(mgr): return result -def get_pending_subvol_deletions_count(path): +def get_pending_subvol_deletions_count(fs, path): """ Get the number of pending subvolumes deletions. """ trashdir = os.path.join(path, Trash.GROUP_NAME) try: - num_pending_subvol_del = len(os.listdir(trashdir)) - except OSError as e: - if e.errno == errno.ENOENT: + num_pending_subvol_del = len(listdir(fs, trashdir, filter_entries=None, filter_files=False)) + except VolumeException as ve: + if ve.errno == -errno.ENOENT: num_pending_subvol_del = 0 return {'pending_subvolume_deletions': num_pending_subvol_del} diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index 99764bfcfd2..5c6642444b1 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -152,7 +152,7 @@ class VolumeClient(CephfsClient["Module"]): cephfs.AT_SYMLINK_NOFOLLOW) usedbytes = st['size'] - vol_info_dict = get_pending_subvol_deletions_count(path) + vol_info_dict = get_pending_subvol_deletions_count(fs_handle, path) if human_readable: vol_info_dict['used_size'] = mgr_util.format_bytes(int(usedbytes), 5) else: