From: Dhairya Parmar Date: Mon, 7 Aug 2023 11:12:20 +0000 (+0530) Subject: mgr/nfs: add a helper to validate cephfs path X-Git-Tag: v20.0.0~2536^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cc7b69f90387d774c150ab5644b89804cbd9c190;p=ceph.git mgr/nfs: add a helper to validate cephfs path Fixes: https://tracker.ceph.com/issues/62077 Signed-off-by: Dhairya Parmar --- diff --git a/src/pybind/mgr/nfs/export.py b/src/pybind/mgr/nfs/export.py index 2d07cd6eab60..ed3bc1be3a44 100644 --- a/src/pybind/mgr/nfs/export.py +++ b/src/pybind/mgr/nfs/export.py @@ -71,6 +71,17 @@ def normalize_path(path: str) -> str: return path +def validate_cephfs_path(mgr: 'Module', fs_name: str, path: str) -> None: + try: + cephfs_path_is_dir(mgr, fs_name, path) + except NotADirectoryError: + raise NFSException(f"path {path} is not a dir", -errno.ENOTDIR) + except cephfs.ObjectNotFound: + raise NFSObjectNotFound(f"path {path} does not exist") + except cephfs.Error as e: + raise NFSException(e.args[1], -e.args[0]) + + class NFSRados: def __init__(self, rados: 'Rados', namespace: str) -> None: self.rados = rados