From: Yan, Zheng Date: Wed, 11 Sep 2019 12:21:59 +0000 (+0800) Subject: mds: restrict path that walks into snapdir X-Git-Tag: v15.1.0~766^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=097eedbd30c4edc8b139ab3377bbeb5006cf7a39;p=ceph.git mds: restrict path that walks into snapdir The zero-length component (stands for snapdir) must be at very beginning of path. This allow us to easily check if a client request want to access snapshot Signed-off-by: "Yan, Zheng" --- diff --git a/src/include/filepath.h b/src/include/filepath.h index 832016ac1bc8..7241e5e0cf7f 100644 --- a/src/include/filepath.h +++ b/src/include/filepath.h @@ -230,6 +230,11 @@ class filepath { return false; } + + bool is_last_snap() const { + // walk into snapdir? + return depth() > 0 && bits[0].length() == 0; + } }; WRITE_CLASS_ENCODER(filepath) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index ea3c4e55de8f..7a722b19ab65 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -8107,7 +8107,7 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, // walk into snapdir? if (path[depth].length() == 0) { dout(10) << "traverse: snapdir" << dendl; - if (!mdr) + if (!mdr || depth > 0) // snapdir must be the first component return -EINVAL; snapid = CEPH_SNAPDIR; mdr->snapid = snapid;