From aa9db2ef73ca4c5e8e09637ddcbbe26df4922797 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Thu, 7 Nov 2019 17:17:35 +0800 Subject: [PATCH] client: invalidate all write mode filp after reconnect Signed-off-by: "Yan, Zheng" --- src/client/Client.cc | 8 ++++++-- src/client/Client.h | 1 + src/client/Fh.cc | 6 +++--- src/client/Fh.h | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index eecc57ebb68..32b23dde283 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -3219,6 +3219,9 @@ int Client::get_caps(Fh *fh, int need, int want, int *phave, loff_t endoff) return -EBADF; } + if ((fh->mode & CEPH_FILE_MODE_WR) && fh->gen != fd_gen) + return -EBADF; + if ((in->flags & I_ERROR_FILELOCK) && fh->has_any_filelocks()) return -EIO; @@ -6263,6 +6266,7 @@ void Client::tick() last_auto_reconnect + 30 * 60 < now && cct->_conf.get_val("client_reconnect_stale")) { messenger->client_reset(); + fd_gen++; // invalidate open files blacklisted = false; _kick_stale_sessions(); last_auto_reconnect = now; @@ -8699,7 +8703,7 @@ int Client::lookup_name(Inode *ino, Inode *parent, const UserPerm& perms) Fh *Client::_create_fh(Inode *in, int flags, int cmode, const UserPerm& perms) { ceph_assert(in); - Fh *f = new Fh(in, flags, cmode, perms); + Fh *f = new Fh(in, flags, cmode, fd_gen, perms); ldout(cct, 10) << __func__ << " " << in->ino << " mode " << cmode << dendl; @@ -8827,7 +8831,7 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, if (cmode & CEPH_FILE_MODE_RD) need |= CEPH_CAP_FILE_RD; - Fh fh(in, flags, cmode, perms); + Fh fh(in, flags, cmode, fd_gen, perms); result = get_caps(&fh, need, want, &have, -1); if (result < 0) { ldout(cct, 8) << "Unable to get caps after open of inode " << *in << diff --git a/src/client/Client.h b/src/client/Client.h index 52eda962b29..b698ecc7911 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1245,6 +1245,7 @@ private: ceph::unordered_map fd_map; set ll_unclosed_fh_set; ceph::unordered_set opened_dirs; + uint64_t fd_gen = 1; bool initialized = false; bool mounted = false; diff --git a/src/client/Fh.cc b/src/client/Fh.cc index a51dca3121a..62bd261404e 100644 --- a/src/client/Fh.cc +++ b/src/client/Fh.cc @@ -18,9 +18,9 @@ #include "Fh.h" -Fh::Fh(InodeRef in, int flags, int cmode, const UserPerm &perms) : - inode(in), _ref(1), pos(0), mds(0), mode(cmode), flags(flags), pos_locked(false), - actor_perms(perms), readahead() +Fh::Fh(InodeRef in, int flags, int cmode, uint64_t _gen, const UserPerm &perms) : + inode(in), _ref(1), pos(0), mds(0), mode(cmode), gen(_gen), flags(flags), + pos_locked(false), actor_perms(perms), readahead() { inode->add_fh(this); } diff --git a/src/client/Fh.h b/src/client/Fh.h index 5511585c114..c3355ba6c52 100644 --- a/src/client/Fh.h +++ b/src/client/Fh.h @@ -17,6 +17,7 @@ struct Fh { loff_t pos; int mds; // have to talk to mds we opened with (for now) int mode; // the mode i opened the file with + uint64_t gen; int flags; bool pos_locked; // pos is currently in use @@ -50,7 +51,7 @@ struct Fh { } Fh() = delete; - Fh(InodeRef in, int flags, int cmode, const UserPerm &perms); + Fh(InodeRef in, int flags, int cmode, uint64_t gen, const UserPerm &perms); ~Fh(); void get() { ++_ref; } -- 2.39.5