Skip to content

Commit 842fb60

Browse files
Merge pull request ceph#55838 from neesingh-rh/wip-58090
mgr/volumes: fix dangling symlink in clone index Reviewed-by: Venky Shankar <[email protected]> Reviewed-by: Kotresh HR <[email protected]> Reviewed-by: Rishabh Dave <[email protected]>
2 parents bd50666 + 82d4647 commit 842fb60

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

qa/tasks/cephfs/test_volumes.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from tasks.cephfs.fuse_mount import FuseMount
1616
from teuthology.contextutil import safe_while
1717
from teuthology.exceptions import CommandFailedError
18+
from teuthology import contextutil
1819

1920
log = logging.getLogger(__name__)
2021

@@ -9127,6 +9128,51 @@ def test_unparseable_metafile_on_legacy_to_v1_upgrade(self):
91279128
# remove group
91289129
self._fs_cmd("subvolumegroup", "rm", self.volname, group)
91299130

9131+
def test_dangling_symlink(self):
9132+
"""
9133+
test_dangling_symlink
9134+
Tests for the presence of any dangling symlink, if yes,
9135+
will remove it.
9136+
"""
9137+
subvolume = self._gen_subvol_name()
9138+
snapshot = self._gen_subvol_snap_name()
9139+
clone = self._gen_subvol_clone_name()
9140+
9141+
self._fs_cmd("subvolume", "create", self.volname, subvolume)
9142+
9143+
self._fs_cmd("subvolume", "snapshot", "create", self.volname, subvolume, snapshot)
9144+
9145+
self.config_set('mgr', 'mgr/volumes/snapshot_clone_delay', 60)
9146+
9147+
self.config_set('mgr', 'mgr/volumes/snapshot_clone_no_wait', False)
9148+
9149+
self._fs_cmd("subvolume", "snapshot", "clone", self.volname, subvolume, snapshot, clone)
9150+
9151+
result = json.loads(self._fs_cmd("subvolume", "snapshot", "info", self.volname, subvolume, snapshot))
9152+
9153+
# verify snapshot info
9154+
self.assertEqual(result['has_pending_clones'], "yes")
9155+
9156+
clone_path = f'./volumes/_nogroup/{clone}'
9157+
self.mount_a.run_shell(['sudo', 'rm', '-rf', clone_path], omit_sudo=False)
9158+
9159+
with contextutil.safe_while(sleep=5, tries=6) as proceed:
9160+
while proceed():
9161+
try:
9162+
result = json.loads(self._fs_cmd("subvolume", "snapshot", "info", self.volname, subvolume, snapshot))
9163+
# verify snapshot info
9164+
self.assertEqual(result['has_pending_clones'], "no")
9165+
break
9166+
except AssertionError as e:
9167+
log.debug(f'{e}, retrying')
9168+
9169+
self._fs_cmd("subvolume", "snapshot", "rm", self.volname, subvolume, snapshot)
9170+
9171+
self._fs_cmd("subvolume", "rm", self.volname, subvolume)
9172+
9173+
self._wait_for_trash_empty()
9174+
9175+
91309176
class TestPerModuleFinsherThread(TestVolumesHelper):
91319177
"""
91329178
Per module finisher thread tests related to mgr/volume cmds.

src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,20 @@ def has_pending_clones(self, snapname):
749749
return False
750750
raise
751751

752+
def remove_non_existent_pending_clones(self, path, link_path, track_id):
753+
try:
754+
self.fs.lstat(link_path)
755+
except cephfs.Error as e:
756+
if e.args[0] == errno.ENOENT:
757+
try:
758+
log.info(f"Cleaning up dangling symlink for the clone: {path}")
759+
self.fs.unlink(path)
760+
self._remove_snap_clone(track_id)
761+
except (cephfs.Error, MetadataMgrException) as e:
762+
log.warning(f'Removing of dangling symlink for the clone {path}'
763+
f' failed with the exception:"{e}"')
764+
pass
765+
752766
def get_pending_clones(self, snapname):
753767
pending_clones_info: Dict[str, Any] = {"has_pending_clones": "no"}
754768
pending_track_id_list = []
@@ -774,7 +788,9 @@ def get_pending_clones(self, snapname):
774788

775789
for track_id in pending_track_id_list:
776790
try:
777-
link_path = self.fs.readlink(os.path.join(index_path, track_id), 4096)
791+
t_path = os.path.join(index_path, track_id)
792+
link_path = self.fs.readlink(t_path, 4096)
793+
self.remove_non_existent_pending_clones(t_path, link_path, track_id)
778794
except cephfs.Error as e:
779795
if e.errno != errno.ENOENT:
780796
raise VolumeException(-e.args[0], e.args[1])

0 commit comments

Comments
 (0)