]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: allow user with WRITE perm to set atime/mtime to current time
authorYan, Zheng <zyan@redhat.com>
Wed, 21 Oct 2015 14:54:10 +0000 (22:54 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 12 Jan 2016 13:57:21 +0000 (21:57 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/client/Client.cc
src/client/fuse_ll.cc
src/include/ceph_fs.h
src/test/libcephfs/access.cc
src/test/libcephfs/caps.cc

index 20b89aa28dc3474ea5862f2bca0e8f46b87086ab..7a224d7d6f3c454a5b98a9a35b6255a7f72052e4 100644 (file)
@@ -4911,8 +4911,20 @@ int Client::may_setattr(Inode *in, struct stat *st, int mask, int uid, int gid)
   }
 
   if (mask & (CEPH_SETATTR_CTIME | CEPH_SETATTR_MTIME | CEPH_SETATTR_ATIME)) {
-    if (uid != 0 && (uid_t)uid != in->uid)
-      goto out;
+    if (uid != 0 && (uid_t)uid != in->uid) {
+      int check_mask = CEPH_SETATTR_CTIME;
+      if (!(mask & CEPH_SETATTR_MTIME_NOW))
+       check_mask |= CEPH_SETATTR_MTIME;
+      if (!(mask & CEPH_SETATTR_ATIME_NOW))
+       check_mask |= CEPH_SETATTR_ATIME;
+      if (check_mask & mask) {
+       goto out;
+      } else {
+       r = inode_permission(in, uid, groups, MAY_WRITE);
+       if (r < 0)
+         goto out;
+      }
+    }
   }
   r = 0;
 out:
@@ -6301,6 +6313,10 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid,
 
 int Client::_setattr(InodeRef &in, struct stat *attr, int mask)
 {
+  mask &= (CEPH_SETATTR_MODE | CEPH_SETATTR_UID |
+          CEPH_SETATTR_GID | CEPH_SETATTR_MTIME |
+          CEPH_SETATTR_ATIME | CEPH_SETATTR_SIZE |
+          CEPH_SETATTR_CTIME);
   if (cct->_conf->client_permissions) {
     int r = may_setattr(in.get(), attr, mask);
     if (r < 0)
@@ -9366,6 +9382,8 @@ int Client::ll_setattr(Inode *in, struct stat *attr, int mask, int uid,
       return res;
   }
 
+  mask &= ~(CEPH_SETATTR_MTIME_NOW | CEPH_SETATTR_ATIME_NOW);
+
   InodeRef target(in);
   int res = _setattr(in, attr, mask, uid, gid, &target);
   if (res == 0) {
index 8c9bff00295d4e14e2cbcd8fa0261f41bce74430..bc55ffdf8226fa92c89bbf9f2e0eb75078104fa3 100644 (file)
@@ -172,6 +172,8 @@ static void fuse_ll_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
   if (to_set & FUSE_SET_ATTR_MTIME) mask |= CEPH_SETATTR_MTIME;
   if (to_set & FUSE_SET_ATTR_ATIME) mask |= CEPH_SETATTR_ATIME;
   if (to_set & FUSE_SET_ATTR_SIZE) mask |= CEPH_SETATTR_SIZE;
+  if (to_set & FUSE_SET_ATTR_MTIME_NOW) mask |= CEPH_SETATTR_MTIME_NOW;
+  if (to_set & FUSE_SET_ATTR_ATIME_NOW) mask |= CEPH_SETATTR_ATIME_NOW;
 
   int r = cfuse->client->ll_setattr(in, attr, mask, ctx->uid, ctx->gid);
   if (r == 0)
index 1dd333e0f8224780ba63720e6e222f4cba6618d9..2d98615034b0ea94ca61586ec7cb83e5b228a0e3 100644 (file)
@@ -358,13 +358,15 @@ enum {
 extern const char *ceph_mds_op_name(int op);
 
 
-#define CEPH_SETATTR_MODE   1
-#define CEPH_SETATTR_UID    2
-#define CEPH_SETATTR_GID    4
-#define CEPH_SETATTR_MTIME  8
-#define CEPH_SETATTR_ATIME 16
-#define CEPH_SETATTR_SIZE  32
-#define CEPH_SETATTR_CTIME 64
+#define CEPH_SETATTR_MODE      (1 << 0)
+#define CEPH_SETATTR_UID       (1 << 1)
+#define CEPH_SETATTR_GID       (1 << 2)
+#define CEPH_SETATTR_MTIME     (1 << 3)
+#define CEPH_SETATTR_ATIME     (1 << 4)
+#define CEPH_SETATTR_SIZE      (1 << 5)
+#define CEPH_SETATTR_CTIME     (1 << 6)
+#define CEPH_SETATTR_MTIME_NOW (1 << 7)
+#define CEPH_SETATTR_ATIME_NOW (1 << 8)
 
 /*
  * Ceph setxattr request flags.
index 5843eab2f0c3e1dc540fa3999944fa78436c9a8c..35d05739027cd41f6a6d19c1c89167936f3f7c41 100644 (file)
@@ -13,7 +13,9 @@
  */
 
 #include "gtest/gtest.h"
+#include "common/ceph_argparse.h"
 #include "include/buffer.h"
+#include "include/stringify.h"
 #include "include/cephfs/libcephfs.h"
 #include "include/rados/librados.h"
 #include <errno.h>
@@ -26,8 +28,6 @@
 #include <sys/uio.h>
 #include <iostream>
 #include <vector>
-#include "common/ceph_argparse.h"
-#include "include/stringify.h"
 #include "json_spirit/json_spirit.h"
 
 #ifdef __linux__
index e49c63c3865f8532f22558b4f6872f1630a352e5..8107703461bcafc2aaee0f8a820fd17126165fcc 100644 (file)
@@ -14,8 +14,8 @@
 #include "include/int_types.h"
 
 #include "gtest/gtest.h"
-#include "include/cephfs/libcephfs.h"
 #include "include/ceph_fs.h"
+#include "include/cephfs/libcephfs.h"
 #include <errno.h>
 #include <sys/fcntl.h>
 #include <unistd.h>