]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: disallow 'open truncate' non-regular inode 10198/head
authorYan, Zheng <zyan@redhat.com>
Fri, 15 Apr 2016 12:15:14 +0000 (20:15 +0800)
committerNathan Cutler <ncutler@suse.com>
Fri, 8 Jul 2016 07:26:08 +0000 (09:26 +0200)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
(cherry picked from commit 0e4b6f2332bb4822cf324587a94144f1c98e4b97)

Conflicts:
src/mds/Server.cc (hammer has cur->inode.inline_version - in master
this has been changed to cur->inode.inline_data.version)

src/mds/Server.cc

index 3b1426958c3b2e0b2886ff666fa13aecff1c6cef..da9ad31de9b72064168f6cf3f03843759a48b3e6 100644 (file)
@@ -2732,9 +2732,13 @@ void Server::handle_client_open(MDRequestRef& mdr)
     return;
   }
 
-  // can only open non-regular inode with mode FILE_MODE_PIN, at least for now.
-  if (!cur->inode.is_file())
+  if (!cur->inode.is_file()) {
+    // can only open non-regular inode with mode FILE_MODE_PIN, at least for now.
     cmode = CEPH_FILE_MODE_PIN;
+    // the inode is symlink and client wants to follow it, ignore the O_TRUNC flag.
+    if (cur->inode.is_symlink() && !(flags & O_NOFOLLOW))
+      flags &= ~O_TRUNC;
+  }
 
   dout(10) << "open flags = " << flags
           << ", filemode = " << cmode
@@ -2753,6 +2757,13 @@ void Server::handle_client_open(MDRequestRef& mdr)
     return;
   }
 
+  if ((flags & O_TRUNC) && !cur->inode.is_file()) {
+    dout(7) << "specified O_TRUNC on !(file|symlink) " << *cur << dendl;
+    // we should return -EISDIR for directory, return -EINVAL for other non-regular
+    respond_to_request(mdr, cur->inode.is_dir() ? EISDIR : -EINVAL);
+    return;
+  }
+
   if (cur->inode.inline_version != CEPH_INLINE_NONE &&
       !mdr->session->connection->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)) {
     dout(7) << "old client cannot open inline data file " << *cur << dendl;