From: neeraj pratap singh Date: Thu, 29 Feb 2024 09:46:36 +0000 (+0530) Subject: mgr/volumes: handling dangling symlinks gracefully X-Git-Tag: v20.0.0~17^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=efb119eb51a8ddc5755245d48601b011a93691ab;p=ceph.git mgr/volumes: handling dangling symlinks gracefully If we come across situations where we encounter dangling symlinks for clones due to any reason,like older versions may have produced dangling clone symlinks which remained post-upgrade, it needs to be handled gracefully by deleting it, presence of which may not allow deletion of the snapshot. We are now cleaning those up in the snapshot info command. Fixes: https://tracker.ceph.com/issues/58090 Signed-off-by: Neeraj Pratap Singh --- diff --git a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py index 90f35a4c90b3..05257394a963 100644 --- a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py +++ b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py @@ -743,6 +743,20 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate): return False raise + def remove_non_existent_pending_clones(self, path, link_path, track_id): + try: + self.fs.lstat(link_path) + except cephfs.Error as e: + if e.args[0] == errno.ENOENT: + try: + log.info(f"Cleaning up dangling symlink for the clone: {path}") + self.fs.unlink(path) + self._remove_snap_clone(track_id) + except (cephfs.Error, MetadataMgrException) as e: + log.warning(f'Removing of dangling symlink for the clone {path}' + f' failed with the exception:"{e}"') + pass + def get_pending_clones(self, snapname): pending_clones_info: Dict[str, Any] = {"has_pending_clones": "no"} pending_track_id_list = [] @@ -768,7 +782,9 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate): for track_id in pending_track_id_list: try: - link_path = self.fs.readlink(os.path.join(index_path, track_id), 4096) + t_path = os.path.join(index_path, track_id) + link_path = self.fs.readlink(t_path, 4096) + self.remove_non_existent_pending_clones(t_path, link_path, track_id) except cephfs.Error as e: if e.errno != errno.ENOENT: raise VolumeException(-e.args[0], e.args[1])