From 097eedbd30c4edc8b139ab3377bbeb5006cf7a39 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 11 Sep 2019 20:21:59 +0800 Subject: [PATCH] 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" --- src/include/filepath.h | 5 +++++ src/mds/MDCache.cc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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; -- 2.47.3