]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: helper for looking up a clone entry index
authorVenky Shankar <vshankar@redhat.com>
Tue, 14 Jan 2020 09:10:22 +0000 (04:10 -0500)
committerRamana Raja <rraja@redhat.com>
Wed, 18 Mar 2020 05:32:56 +0000 (11:02 +0530)
... this would be used when canceling a clone operation to
find the clone index for a given clone.

Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/pybind/mgr/volumes/fs/operations/clone_index.py

index 068a97a9de58be47213c370ddbb53b9b99055b09..a2b31f858e067328aefcf08619ee6d6bb09e0e7c 100644 (file)
@@ -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: