From 68ed47d2f67475371e8c3ead19398512346befcf Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 21 Oct 2015 22:54:10 +0800 Subject: [PATCH] client: allow user with WRITE perm to set atime/mtime to current time Signed-off-by: Yan, Zheng --- src/client/Client.cc | 22 ++++++++++++++++++++-- src/client/fuse_ll.cc | 2 ++ src/include/ceph_fs.h | 16 +++++++++------- src/test/libcephfs/access.cc | 4 ++-- src/test/libcephfs/caps.cc | 2 +- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 20b89aa28dc34..7a224d7d6f3c4 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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) { diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index 8c9bff00295d4..bc55ffdf8226f 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -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) diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 1dd333e0f8224..2d98615034b0e 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -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. diff --git a/src/test/libcephfs/access.cc b/src/test/libcephfs/access.cc index 5843eab2f0c3e..35d05739027cd 100644 --- a/src/test/libcephfs/access.cc +++ b/src/test/libcephfs/access.cc @@ -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 @@ -26,8 +28,6 @@ #include #include #include -#include "common/ceph_argparse.h" -#include "include/stringify.h" #include "json_spirit/json_spirit.h" #ifdef __linux__ diff --git a/src/test/libcephfs/caps.cc b/src/test/libcephfs/caps.cc index e49c63c3865f8..8107703461bca 100644 --- a/src/test/libcephfs/caps.cc +++ b/src/test/libcephfs/caps.cc @@ -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 #include #include -- 2.39.5