From 4095aefadeef592780786fe0dc1db89203157fab Mon Sep 17 00:00:00 2001 From: dongdong tao Date: Thu, 4 Jan 2018 15:05:41 +0800 Subject: [PATCH] client: make mark_caps_clean and mark_caps_dirty as member function to Inode Signed-off-by: dongdong tao (cherry picked from commit 06ce613779a810dd979cb2eb15b510131a81fd74) --- src/client/Client.cc | 55 +++++++++++++++----------------------------- src/client/Client.h | 3 +-- src/client/Inode.cc | 29 +++++++++++++++++++++++ src/client/Inode.h | 2 ++ 4 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index b1b61757bd4bd..cb828c6f39673 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4019,7 +4019,7 @@ void Client::remove_session_caps(MetaSession *s) in->flushing_cap_tids.clear(); } in->flushing_caps = 0; - mark_caps_clean(in); + in->mark_caps_clean(); put_inode(in); } } @@ -4158,23 +4158,6 @@ void Client::force_session_readonly(MetaSession *s) } } -void Client::mark_caps_dirty(Inode *in, int caps) -{ - ldout(cct, 10) << __func__ << " " << *in << " " << ccap_string(in->dirty_caps) << " -> " - << ccap_string(in->dirty_caps | caps) << dendl; - if (caps && !in->caps_dirty()) - in->get(); - in->dirty_caps |= caps; - dirty_list.push_back(&in->dirty_cap_item); -} - -void Client::mark_caps_clean(Inode *in) -{ - ldout(cct, 10) << __func__ << " " << *in << dendl; - in->dirty_caps = 0; - in->dirty_cap_item.remove_myself(); -} - int Client::mark_caps_flushing(Inode *in, ceph_tid_t* ptid) { MetaSession *session = in->auth_cap->session; @@ -4193,7 +4176,7 @@ int Client::mark_caps_flushing(Inode *in, ceph_tid_t* ptid) } in->flushing_caps |= flushing; - mark_caps_clean(in); + in->mark_caps_clean(); if (!in->flushing_cap_item.is_on_list()) session->flushing_caps.push_back(&in->flushing_cap_item); @@ -6726,11 +6709,11 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, in->cap_dirtier_uid = perms.uid(); in->cap_dirtier_gid = perms.gid(); if (issued & CEPH_CAP_AUTH_EXCL) - mark_caps_dirty(in, CEPH_CAP_AUTH_EXCL); + in->mark_caps_dirty(CEPH_CAP_AUTH_EXCL); else if (issued & CEPH_CAP_FILE_EXCL) - mark_caps_dirty(in, CEPH_CAP_FILE_EXCL); + in->mark_caps_dirty(CEPH_CAP_FILE_EXCL); else if (issued & CEPH_CAP_XATTR_EXCL) - mark_caps_dirty(in, CEPH_CAP_XATTR_EXCL); + in->mark_caps_dirty(CEPH_CAP_XATTR_EXCL); else mask |= CEPH_SETATTR_CTIME; } @@ -6745,7 +6728,7 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, in->cap_dirtier_uid = perms.uid(); in->cap_dirtier_gid = perms.gid(); in->uid = stx->stx_uid; - mark_caps_dirty(in, CEPH_CAP_AUTH_EXCL); + in->mark_caps_dirty(CEPH_CAP_AUTH_EXCL); mask &= ~CEPH_SETATTR_UID; kill_sguid = true; ldout(cct,10) << "changing uid to " << stx->stx_uid << dendl; @@ -6755,7 +6738,7 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, in->cap_dirtier_uid = perms.uid(); in->cap_dirtier_gid = perms.gid(); in->gid = stx->stx_gid; - mark_caps_dirty(in, CEPH_CAP_AUTH_EXCL); + in->mark_caps_dirty(CEPH_CAP_AUTH_EXCL); mask &= ~CEPH_SETATTR_GID; kill_sguid = true; ldout(cct,10) << "changing gid to " << stx->stx_gid << dendl; @@ -6766,13 +6749,13 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, in->cap_dirtier_uid = perms.uid(); in->cap_dirtier_gid = perms.gid(); in->mode = (in->mode & ~07777) | (stx->stx_mode & 07777); - mark_caps_dirty(in, CEPH_CAP_AUTH_EXCL); + in->mark_caps_dirty(CEPH_CAP_AUTH_EXCL); mask &= ~CEPH_SETATTR_MODE; ldout(cct,10) << "changing mode to " << stx->stx_mode << dendl; } else if (kill_sguid && S_ISREG(in->mode) && (in->mode & (S_IXUSR|S_IXGRP|S_IXOTH))) { /* Must squash the any setuid/setgid bits with an ownership change */ in->mode &= ~(S_ISUID|S_ISGID); - mark_caps_dirty(in, CEPH_CAP_AUTH_EXCL); + in->mark_caps_dirty(CEPH_CAP_AUTH_EXCL); } if (mask & CEPH_SETATTR_BTIME) { @@ -6780,7 +6763,7 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, in->cap_dirtier_uid = perms.uid(); in->cap_dirtier_gid = perms.gid(); in->btime = utime_t(stx->stx_btime); - mark_caps_dirty(in, CEPH_CAP_AUTH_EXCL); + in->mark_caps_dirty(CEPH_CAP_AUTH_EXCL); mask &= ~CEPH_SETATTR_BTIME; ldout(cct,10) << "changing btime to " << in->btime << dendl; } @@ -6799,7 +6782,7 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, in->cap_dirtier_uid = perms.uid(); in->cap_dirtier_gid = perms.gid(); in->time_warp_seq++; - mark_caps_dirty(in, CEPH_CAP_FILE_EXCL); + in->mark_caps_dirty(CEPH_CAP_FILE_EXCL); mask &= ~(CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME); } } @@ -8908,7 +8891,7 @@ done: if (uninline_ret >= 0 || uninline_ret == -ECANCELED) { in->inline_data.clear(); in->inline_version = CEPH_INLINE_NONE; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); check_caps(in, 0); } else r = uninline_ret; @@ -9368,7 +9351,7 @@ success: // extend file? if (totalwritten + offset > in->size) { in->size = totalwritten + offset; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); if (is_quota_bytes_approaching(in, f->actor_perms)) { check_caps(in, CHECK_CAPS_NODELAY); @@ -9384,7 +9367,7 @@ success: // mtime in->mtime = ceph_clock_now(); in->change_attr++; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); done: @@ -9399,7 +9382,7 @@ done: if (uninline_ret >= 0 || uninline_ret == -ECANCELED) { in->inline_data.clear(); in->inline_version = CEPH_INLINE_NONE; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); check_caps(in, 0); } else r = uninline_ret; @@ -12994,7 +12977,7 @@ int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length) } in->mtime = ceph_clock_now(); in->change_attr++; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); } else { if (in->inline_version < CEPH_INLINE_NONE) { onuninline = new C_SafeCond(&uninline_flock, @@ -13020,7 +13003,7 @@ int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length) 0, true, onfinish); in->mtime = ceph_clock_now(); in->change_attr++; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); client_lock.Unlock(); flock.Lock(); @@ -13036,7 +13019,7 @@ int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length) in->size = size; in->mtime = ceph_clock_now(); in->change_attr++; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); if (is_quota_bytes_approaching(in, fh->actor_perms)) { check_caps(in, CHECK_CAPS_NODELAY); @@ -13057,7 +13040,7 @@ int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length) if (uninline_ret >= 0 || uninline_ret == -ECANCELED) { in->inline_data.clear(); in->inline_version = CEPH_INLINE_NONE; - mark_caps_dirty(in, CEPH_CAP_FILE_WR); + in->mark_caps_dirty(CEPH_CAP_FILE_WR); check_caps(in, 0); } else r = uninline_ret; diff --git a/src/client/Client.h b/src/client/Client.h index 6940053f87ceb..b90afec587531 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -635,8 +635,6 @@ protected: void remove_cap(Cap *cap, bool queue_release); void remove_all_caps(Inode *in); void remove_session_caps(MetaSession *session); - void mark_caps_dirty(Inode *in, int caps); - void mark_caps_clean(Inode *in); int mark_caps_flushing(Inode *in, ceph_tid_t *ptid); void adjust_session_flushing_caps(Inode *in, MetaSession *old_s, MetaSession *new_s); void flush_caps_sync(); @@ -734,6 +732,7 @@ protected: void flush_mdlog_sync(); void flush_mdlog(MetaSession *session); + xlist &get_dirty_list() { return dirty_list; } // ---------------------- // fs ops. private: diff --git a/src/client/Inode.cc b/src/client/Inode.cc index d877757faa1e1..be898cbd89dc9 100644 --- a/src/client/Inode.cc +++ b/src/client/Inode.cc @@ -749,3 +749,32 @@ void Inode::unset_deleg(Fh *fh) } } } + +/** +* mark_caps_dirty - mark some caps dirty +* @caps: the dirty caps +* +* note that if there is no dirty and flushing caps before, we need to pin this inode. +* it will be unpined by handle_cap_flush_ack when there are no dirty and flushing caps. +*/ +void Inode::mark_caps_dirty(int caps) +{ + lsubdout(client->cct, client, 10) << __func__ << " " << *this << " " << ccap_string(dirty_caps) << " -> " + << ccap_string(dirty_caps | caps) << dendl; + if (caps && !caps_dirty()) + get(); + dirty_caps |= caps; + client->get_dirty_list().push_back(&dirty_cap_item); +} + +/** +* mark_caps_clean - only clean the dirty_caps and caller should start flushing the dirty caps. +*/ +void Inode::mark_caps_clean() +{ + lsubdout(client->cct, client, 10) << __func__ << " " << *this << dendl; + dirty_caps = 0; + dirty_cap_item.remove_myself(); +} + + diff --git a/src/client/Inode.h b/src/client/Inode.h index 9c9ebe0c37704..614d84a306d05 100644 --- a/src/client/Inode.h +++ b/src/client/Inode.h @@ -306,6 +306,8 @@ struct Inode { int set_deleg(Fh *fh, unsigned type, ceph_deleg_cb_t cb, void *priv); void unset_deleg(Fh *fh); + void mark_caps_dirty(int caps); + void mark_caps_clean(); private: // how many opens for write on this Inode? long open_count_for_write() -- 2.39.5