]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: simplify stale semantics a bit
authorSage Weil <sage@newdream.net>
Sat, 6 Nov 2010 14:58:32 +0000 (07:58 -0700)
committerSage Weil <sage@newdream.net>
Sat, 6 Nov 2010 14:58:32 +0000 (07:58 -0700)
is_stale() => next MIX is MIX_STALE. Stale flag is then cleared.  Then we
special case the import to preserve stale-ness.

TODO: add_replica_inode likely has this same problem.

Signed-off-by: Sage Weil <sage@newdream.net>
src/mds/CDir.cc
src/mds/CInode.cc
src/mds/CInode.h
src/mds/Locker.cc
src/mds/MDCache.cc
src/mds/ScatterLock.h

index d6354691f399b42774dbc00d1affafe6b30f6c32..b4dbfdbf094853415335f534740d3f39cf975a24 100644 (file)
@@ -1194,9 +1194,9 @@ void CDir::_fetched(bufferlist &bl, const string& want_dn)
     projected_version = committing_version = committed_version = got_fnode.version;
 
     if (fnode.rstat.version < inode->inode.rstat.version)
-      inode->nestlock.set_and_apply_stale();
+      inode->nestlock.set_or_apply_stale();
     if (fnode.fragstat.version < inode->inode.dirstat.version)
-      inode->filelock.set_and_apply_stale();
+      inode->filelock.set_or_apply_stale();
   }
 
   // purge stale snaps?
@@ -1876,13 +1876,13 @@ void CDir::decode_import(bufferlist::iterator& blp, utime_t now)
   inode_t *pi = inode->get_projected_inode();
   if (fnode.fragstat.version != pi->dirstat.version) {
     dout(10) << " got stale fragstat " << fnode.fragstat << " vs inode " << pi->dirstat << dendl;
-    inode->filelock.set_and_apply_stale();
+    inode->filelock.set_or_apply_stale();
   }
 
   // stale rstat?
   if (fnode.rstat.version != pi->rstat.version) {
     dout(10) << " got stale rstat " << fnode.rstat << " vs inode " << pi->rstat << dendl;
-    inode->nestlock.set_and_apply_stale();
+    inode->nestlock.set_or_apply_stale();
   }
 }
 
index 595dab8b2381c4c6ead96bd2fb86ea125f87d36e..8b1cd5e7420d5cbbc17d5c6b59d97260261c01dc 100644 (file)
@@ -2372,12 +2372,20 @@ void CInode::_decode_locks_full(bufferlist::iterator& p)
   ::decode(authlock, p);
   ::decode(linklock, p);
   ::decode(dirfragtreelock, p);
+
+  if (filelock.get_state() == LOCK_MIX_STALE)
+    filelock.set_stale();
   ::decode(filelock, p);
   filelock.apply_stale();
+
   ::decode(xattrlock, p);
   ::decode(snaplock, p);
+
+  if (nestlock.get_state() == LOCK_MIX_STALE)
+    nestlock.set_stale();
   ::decode(nestlock, p);
   nestlock.apply_stale();
+
   ::decode(flocklock, p);
   ::decode(policylock, p);
 }
index b1e6ac9dc6ebc558da684b826942426b69638a31..527e1ffe385665226fad428c3ad6f2ec0084016f 100644 (file)
@@ -806,10 +806,8 @@ public:
       if (issued & CEPH_CAP_GEXCL)
        lock->set_state(LOCK_EXCL);
       else if (issued & CEPH_CAP_GWR) {
-        if (lock->is_stale())
-          lock->set_state(LOCK_MIX_STALE);
-        else
-          lock->set_state(LOCK_MIX);
+       lock->set_state(LOCK_MIX);
+       ((ScatterLock *)lock)->apply_stale();
       }
       else if (lock->is_dirty()) {
        if (is_replicated())
index b97af0c4c0a3acca588e46ee829f8252eb4e22fc..6c364a9c0324e59ea455b83c6ef7f36610c0f4b2 100644 (file)
@@ -3736,10 +3736,8 @@ void Locker::scatter_mix(ScatterLock *lock, bool *need_issue)
     }
 
     // change lock
-    if (lock->is_stale())
-      lock->set_state(LOCK_MIX_STALE);
-    else
-      lock->set_state(LOCK_MIX);
+    lock->set_state(LOCK_MIX);
+    lock->apply_stale();
     lock->clear_scatter_wanted();
     if (need_issue)
       *need_issue = true;
@@ -3785,10 +3783,8 @@ void Locker::scatter_mix(ScatterLock *lock, bool *need_issue)
       lock->get_parent()->auth_pin(lock);
     else {
       in->start_scatter(lock);
-      if (lock->is_stale())
-        lock->set_state(LOCK_MIX_STALE);
-      else
-        lock->set_state(LOCK_MIX);
+      lock->set_state(LOCK_MIX);
+      lock->apply_stale();
       lock->clear_scatter_wanted();
       if (in->is_replicated()) {
        bufferlist softdata;
@@ -3965,11 +3961,8 @@ void Locker::handle_file_lock(ScatterLock *lock, MLock *m)
     
     // ok
     lock->decode_locked_state(m->get_data());
-    if (!lock->is_stale()) {
-      dout(15) << "setting state to LOCK_MIX_STALE instead of LOCK_MIX" << dendl;
-      lock->set_state(LOCK_MIX_STALE);
-    } else
-      lock->set_state(LOCK_MIX);
+    lock->set_state(LOCK_MIX);
+    lock->apply_stale();
 
     ((ScatterLock *)lock)->finish_flush();
 
index 38ae101ec3e1756e925c2b2c4df41aef697e361d..3f6bb08cbeb795cb4f7a8b6585ddb167bd934bb1 100644 (file)
@@ -3313,10 +3313,8 @@ void MDCache::handle_cache_rejoin_weak(MMDSCacheRejoin *weak)
 
       // scatter the dirlock, just in case?
       if (!survivor && in->is_dir() && in->has_subtree_root_dirfrag()) {
-        if (in->filelock.is_stale())
-          in->filelock.set_state(LOCK_MIX_STALE);
-        else
-          in->filelock.set_state(LOCK_MIX);
+       in->filelock.set_state(LOCK_MIX);
+        in->filelock.apply_stale();
       }
 
       if (ack) {
index d9ffada083f5c30c67b2e7e7166646cc6b1a0af8..f52bd1425cbd7a8329f46a42e361f2350322398f 100644 (file)
@@ -164,15 +164,18 @@ public:
     }
   }
   void apply_stale() {
-    if (state == LOCK_MIX_STALE)
-      set_stale();
-    else if (is_stale() && state == LOCK_MIX)
+    if (state == LOCK_MIX && is_stale()) {
       state = LOCK_MIX_STALE;
+      clear_stale();
+    }
   }
-  void set_and_apply_stale() {
-    set_stale();
-    if (state == LOCK_MIX)
+  void set_or_apply_stale() {
+    if (state == LOCK_MIX) {
       state = LOCK_MIX_STALE;
+      clear_stale();
+    } else {
+      set_stale();
+    }
   }
 
   void set_last_scatter(utime_t t) { more()->last_scatter = t; }