]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: Fix pending_subvolume_deletions in volume info
authorKotresh HR <khiremat@redhat.com>
Wed, 2 Aug 2023 10:37:56 +0000 (16:07 +0530)
committerKotresh HR <khiremat@redhat.com>
Thu, 21 Sep 2023 07:59:09 +0000 (13:29 +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
(cherry picked from commit 6ca1bffe57224a84da00a6f714c0535703d45e0d)

Conflicts:
  src/pybind/mgr/volumes/fs/operations/volume.py - 'fs volume rename' is
not present in pacific (70697629bf91b325112e319027bb2c89ce10dca0)

src/pybind/mgr/volumes/fs/fs_util.py
src/pybind/mgr/volumes/fs/operations/volume.py
src/pybind/mgr/volumes/fs/volume.py

index fb80c651f7670bcc9d0b262de8cf0fe2938924b4..96e7b9fae2ef8e8ab6f6fcd8d906e6b04c6eb5ea 100644 (file)
@@ -59,11 +59,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:
@@ -72,12 +73,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 9f651c40ffa909cd4ad3aedb90c2310a98d83bae..c013596f10bc36b76332654740388d3531f12f33 100644 (file)
@@ -11,7 +11,7 @@ import orchestrator
 from .lock import GlobalLock
 from ..exception import VolumeException
 from ..fs_util import create_pool, remove_pool, create_filesystem, \
-    remove_filesystem, create_mds, volume_exists
+    remove_filesystem, create_mds, volume_exists, listdir
 from .trash import Trash
 from mgr_util import open_filesystem, CephfsConnectionException
 
@@ -150,15 +150,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 816b7ea8a082ddf7f92db75752ce005f46d8abdf..b7319c75301f547721332d4d2880687f86501525 100644 (file)
@@ -140,7 +140,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: