Skip to content

Commit

Permalink
cephfs: worm state transition in open op
Browse files Browse the repository at this point in the history
Signed-off-by: weiqiaomiao <wei.qiaomiao@zte.com.cn>
  • Loading branch information
weiqiaomiao committed Mar 2, 2019
1 parent 0580f2b commit bcfb8f0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/client/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6867,7 +6867,7 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask,
return -EROFS;
}

if (mask & CEPH_SETATTR_SIZE) {
if (!(mask & CEPH_SETATTR_ATIME) && !(mask & CEPH_SETATTR_MODE)) {
if (in->worm.is_enable()) {
int res = worm_state_transition(in, perms, CEPH_MDS_OP_SETATTR);
if (res) {
Expand Down Expand Up @@ -8836,14 +8836,21 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp,
return -EROFS;
}

int result = 0;
if (in->is_file() && (flags & (O_WRONLY | O_RDWR | O_TRUNC | O_APPEND))&& in->worm.is_enable()) {
result = worm_state_transition(in, perms, CEPH_MDS_OP_OPEN);
if (result) {
return result;
}
}

// use normalized flags to generate cmode
int cflags = ceph_flags_sys2wire(flags);
if (cct->_conf.get_val<bool>("client_force_lazyio"))
cflags |= CEPH_O_LAZY;

int cmode = ceph_flags_to_mode(cflags);
int want = ceph_caps_for_mode(cmode);
int result = 0;

in->get_open_ref(cmode); // make note of pending open, since it effects _wanted_ caps.

Expand Down Expand Up @@ -11792,6 +11799,8 @@ int Client::worm_state_transition(Inode *in, const UserPerm& perms, int op){
struct ceph_statx statx;

utime_t now = ceph_clock_now();

ldout(cct, 10) << "worm_state_transition " << "(" << now << ":" <<in->mtime << ")" << dendl;
if (!in->worm.is_retain() && (( now.tv.tv_sec - in->mtime.sec()) >= in->worm.auto_commit_period)) {
char xattr_name[] = "ceph.worm.state";
uint32_t worm_state = in->worm.worm_state | WORM_RETAIN;
Expand Down

0 comments on commit bcfb8f0

Please sign in to comment.