]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: restrict path that walks into snapdir
authorYan, Zheng <zyan@redhat.com>
Wed, 11 Sep 2019 12:21:59 +0000 (20:21 +0800)
committerYan, Zheng <zyan@redhat.com>
Sat, 9 Nov 2019 03:03:15 +0000 (11:03 +0800)
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" <zyan@redhat.com>
src/include/filepath.h
src/mds/MDCache.cc

index 832016ac1bc89e21ac202b71ba83ee778e748adf..7241e5e0cf7fcfb50a24c2448fe5e5dfa0c093d3 100644 (file)
@@ -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)
index ea3c4e55de8f263ace5ca3a4512d3b6aca9e262a..7a722b19ab6596036ee8e749a2468063be58b31d 100644 (file)
@@ -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;