From: Venky Shankar Date: Mon, 26 Aug 2024 10:14:53 +0000 (+0530) Subject: Merge pull request #54620 from rishabh-d-dave/mgr-vol-clone-stats X-Git-Tag: testing/wip-vshankar-testing-20240826.122843-debug~5 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=409001969eb39b314591ba4d70d754bea06aa050;p=ceph-ci.git Merge pull request #54620 from rishabh-d-dave/mgr-vol-clone-stats mgr/vol: show progress and stats for the subvolume snapshot clones Reviewed-by: Venky Shankar --- 409001969eb39b314591ba4d70d754bea06aa050 diff --cc src/pybind/mgr/volumes/fs/operations/clone_index.py index 1f16500a6bd,edcc01921c6..f8ab7e2b294 --- a/src/pybind/mgr/volumes/fs/operations/clone_index.py +++ b/src/pybind/mgr/volumes/fs/operations/clone_index.py @@@ -47,27 -49,45 +49,47 @@@ class CloneIndex(Index) except cephfs.Error as e: raise IndexException(-e.args[0], e.args[1]) + def list_entries_by_ctime_order(self): + entry_names = listdir(self.fs, self.path, filter_files=False) + if not entry_names: + return [] + + # clone entries with ctime obtained by statig them. basically, + # following is a list of tuples where each tuple has 2 memebers. + ens_with_ctime = [] + for en in entry_names: + d_path = os.path.join(self.path, en) + stb = self.fs.lstat(d_path) + + # add ctime next to clone entry + ens_with_ctime.append((en, stb.st_ctime)) + + ens_with_ctime.sort(key=lambda ctime: en[1]) + + # remove ctime and return list of clone entries sorted by ctime. + return [i[0] for i in ens_with_ctime] + def get_oldest_clone_entry(self, exclude=[]): - min_ctime_entry = None - exclude_tracking_ids = [v[0] for v in exclude] - log.debug("excluded tracking ids: {0}".format(exclude_tracking_ids)) - 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 dname not in exclude_tracking_ids and stat.S_ISLNK(st.st_mode): - if min_ctime_entry is None or st.st_ctime < min_ctime_entry[1].st_ctime: - min_ctime_entry = (dname, st) - if min_ctime_entry: - try: + try: + min_ctime_entry = None + exclude_tracking_ids = [v[0] for v in exclude] + log.debug("excluded tracking ids: {0}".format(exclude_tracking_ids)) + 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 dname not in exclude_tracking_ids and stat.S_ISLNK(st.st_mode): + if min_ctime_entry is None or st.st_ctime < min_ctime_entry[1].st_ctime: + min_ctime_entry = (dname, st) + if min_ctime_entry: linklen = min_ctime_entry[1].st_size - sink_path = self.fs.readlink(os.path.join(self.path, min_ctime_entry[0]), CloneIndex.PATH_MAX) + sink_path = self.fs.readlink(os.path.join(self.path, min_ctime_entry[0]), PATH_MAX) return (min_ctime_entry[0], sink_path[:linklen]) - except cephfs.Error as e: - raise IndexException(-e.args[0], e.args[1]) - return None + return None + except cephfs.Error as e: + log.debug('Exception cephfs.Error has been caught. Printing ' + f'the exception - {e}') + raise IndexException(-e.args[0], e.args[1]) def find_clone_entry_index(self, sink_path): try: