X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fpybind%2Fmgr%2Fvolumes%2Ffs%2Ffs_util.py;h=2adec83f5aafc4d0b6adcbf525bb407c6439576b;hb=cd265ab1e2bb0c89e7a1001629426438754333f4;hp=44e8d279a8a659272b506a17cad5f58674de3eec;hpb=7b3df4a1b15c5a048c237733c797a2667f08196e;p=ceph.git diff --git a/ceph/src/pybind/mgr/volumes/fs/fs_util.py b/ceph/src/pybind/mgr/volumes/fs/fs_util.py index 44e8d279a..2adec83f5 100644 --- a/ceph/src/pybind/mgr/volumes/fs/fs_util.py +++ b/ceph/src/pybind/mgr/volumes/fs/fs_util.py @@ -75,6 +75,34 @@ def listdir(fs, dirpath): raise VolumeException(-e.args[0], e.args[1]) return dirs +def is_inherited_snap(snapname): + """ + Returns True if the snapname is inherited else False + """ + return snapname.startswith("_") + +def listsnaps(fs, volspec, snapdirpath, filter_inherited_snaps=False): + """ + Get the snap names from a given snap directory path + """ + if os.path.basename(snapdirpath) != volspec.snapshot_prefix.encode('utf-8'): + raise VolumeException(-errno.EINVAL, "Not a snap directory: {0}".format(snapdirpath)) + snaps = [] + try: + with fs.opendir(snapdirpath) as dir_handle: + d = fs.readdir(dir_handle) + while d: + if (d.d_name not in (b".", b"..")) and d.is_dir(): + d_name = d.d_name.decode('utf-8') + if not is_inherited_snap(d_name): + snaps.append(d.d_name) + elif is_inherited_snap(d_name) and not filter_inherited_snaps: + snaps.append(d.d_name) + d = fs.readdir(dir_handle) + except cephfs.Error as e: + raise VolumeException(-e.args[0], e.args[1]) + return snaps + def list_one_entry_at_a_time(fs, dirpath): """ Get a directory entry (one entry a time)