]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: invalidate all write mode filp after reconnect
authorYan, Zheng <zyan@redhat.com>
Thu, 7 Nov 2019 09:17:35 +0000 (17:17 +0800)
committerYan, Zheng <zyan@redhat.com>
Mon, 30 Mar 2020 02:24:47 +0000 (10:24 +0800)
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/Fh.cc
src/client/Fh.h

index eecc57ebb6810aadeaf5a997eab202d87ab54edd..32b23dde28372aab20442648d3e471224acb4f73 100644 (file)
@@ -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<bool>("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 <<
index 52eda962b291eff92ab4f81978a1fd408aaba539..b698ecc79113a762658effbb29549784d5cde052 100644 (file)
@@ -1245,6 +1245,7 @@ private:
   ceph::unordered_map<int, Fh*> fd_map;
   set<Fh*> ll_unclosed_fh_set;
   ceph::unordered_set<dir_result_t*> opened_dirs;
+  uint64_t fd_gen = 1;
 
   bool   initialized = false;
   bool   mounted = false;
index a51dca3121ad876f19140cfe2212821f023dda36..62bd261404e213f626dc647f30757b6dc9da62e3 100644 (file)
@@ -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);
 }
index 5511585c1141793ba1cd0f8308c239cf74468f64..c3355ba6c52660930227e6e1b5a5c7a02a7a0d88 100644 (file)
@@ -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; }