Actions
Bug #63515
openmgr/dashboard: explicitly shutdown cephfs mount in controllers.cephfs and controllers.nfs
Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
% Done:
0%
Source:
Community (dev)
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Description
The controllers.cephfs and controllers.nfs modules use services.cephfs.CephFS object to mount a Ceph file system. The modules rely on the services.cephfs.CephFS.__del__() finalizer method to be called to unmount and cleanup the mount handle. However, it's not good practice to rely on python finalization method to clean up external resources. See, https://tracker.ceph.com/issues/63421 for more details. Instead, explicitly unmount and cleanup the CephFS mount once you're done using the CephFS mount.
A possible fix is the following,
diff --git a/src/pybind/mgr/dashboard/services/cephfs.py b/src/pybind/mgr/dashboard/services/cephfs.py index ffbf9d0c816..980cc931949 100644 --- a/src/pybind/mgr/dashboard/services/cephfs.py +++ b/src/pybind/mgr/dashboard/services/cephfs.py @@ -38,13 +38,20 @@ class CephFS(object): def __init__(self, fs_name=None): logger.debug("initializing cephfs connection") self.cfs = cephfs.LibCephFS(rados_inst=mgr.rados) - logger.debug("mounting cephfs filesystem: %s", fs_name) - if fs_name: - self.cfs.mount(filesystem_name=fs_name) + self.fs_name = fs_name + + def __enter__(self): + logger.debug("mounting cephfs filesystem: %s", self.fs_name) + if self.fs_name: + self.cfs.mount(filesystem_name=self.fs_name) else: self.cfs.mount() logger.debug("mounted cephfs filesystem") + def __exit__(self, exc_type, exc_val, exc_tb): + logger.debug("shutting down cephfs filesystem: %s", self.fs_name) + self.cfs.shutdown() + @contextmanager def opendir(self, dirpath): d = None diff --git a/src/pybind/mgr/dashboard/controllers/cephfs.py b/src/pybind/mgr/dashboard/controllers/cephfs.py index ed83f91d0c9..2160860c09a 100644 --- a/src/pybind/mgr/dashboard/controllers/cephfs.py +++ b/src/pybind/mgr/dashboard/controllers/cephfs.py @@ -418,7 +418,9 @@ class CephFS(RESTController): :rtype: dict """ try: - return self._get_root_directory(self._cephfs_instance(fs_id)) + cfs = self._cephfs_instance(fs_id) + with cfs: + return self._get_root_directory(cfs) except (cephfs.PermissionError, cephfs.ObjectNotFound): # pragma: no cover return None @@ -450,7 +452,8 @@ class CephFS(RESTController): path = self._set_ls_dir_path(path) try: cfs = self._cephfs_instance(fs_id) - paths = cfs.ls_dir(path, depth) + with cfs: + paths = cfs.ls_dir(path, depth) except (cephfs.PermissionError, cephfs.ObjectNotFound): # pragma: no cover paths = [] return paths @@ -479,7 +482,8 @@ class CephFS(RESTController): :param path: The path of the directory. """ cfs = self._cephfs_instance(fs_id) - cfs.mk_dirs(path) + with cfs: + cfs.mk_dirs(path)
Please note that the above fix is not complete.
Updated by Ramana Raja 6 months ago
- Status changed from New to In Progress
- Pull request ID set to 54495
Actions