From c5f1a83831734f67c858d00bbd07da10ca6c4688 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Tue, 14 Jan 2020 04:10:22 -0500 Subject: [PATCH] mgr/volumes: helper for looking up a clone entry index ... this would be used when canceling a clone operation to find the clone index for a given clone. Signed-off-by: Venky Shankar (cherry picked from commit 2dc41ea2db423b1e8178d41ce2fef6ca0eeccf32) --- .../mgr/volumes/fs/operations/clone_index.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pybind/mgr/volumes/fs/operations/clone_index.py b/src/pybind/mgr/volumes/fs/operations/clone_index.py index 068a97a9de58b..a2b31f858e067 100644 --- a/src/pybind/mgr/volumes/fs/operations/clone_index.py +++ b/src/pybind/mgr/volumes/fs/operations/clone_index.py @@ -67,6 +67,20 @@ class CloneIndex(Index): raise IndexException(-e.args[0], e.args[1]) return None + def find_clone_entry_index(self, sink_path): + try: + for entry in list_one_entry_at_a_time(self.fs, self.path): + dname = entry.d_name + dpath = os.path.join(self.path, dname) + st = self.fs.lstat(dpath) + if stat.S_ISLNK(st.st_mode): + target_path = self.fs.readlink(dpath, CloneIndex.PATH_MAX) + if sink_path == target_path[:st.st_size]: + return dname + return None + except cephfs.Error as e: + raise IndexException(-e.args[0], e.args[1]) + def create_clone_index(fs, vol_spec): clone_index = CloneIndex(fs, vol_spec) try: -- 2.39.5