]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: Fix pending_subvolume_deletions in volume info 52765/head
authorKotresh HR <khiremat@redhat.com>
Wed, 2 Aug 2023 10:37:56 +0000 (16:07 +0530)
committerKotresh HR <khiremat@redhat.com>
Fri, 4 Aug 2023 07:17:35 +0000 (12:47 +0530)
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 <khiremat@redhat.com>
Fixes: https://tracker.ceph.com/issues/62278
src/pybind/mgr/volumes/fs/fs_util.py
src/pybind/mgr/volumes/fs/operations/volume.py
src/pybind/mgr/volumes/fs/volume.py

index be0a06acdd8997d2d7de06dffe653038e6d58c39..f6121ca2b29613d004111b9eb21ce78816a333ce 100644 (file)
@@ -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):
index e6e374992fb0bf6bd090a117bfaf870743f7cfed..9eee329d1d65a96e593da0789b8b88d474ceb92e 100644 (file)
@@ -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}
index 99764bfcfd2c31c8a87cace688c71584f662d369..5c6642444b116b2f4b4f4cc109c3a356ee5190f7 100644 (file)
@@ -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: