]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: SimpleLock and subclasses: const cleanup
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 13 Oct 2010 17:33:50 +0000 (10:33 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 13 Oct 2010 17:33:50 +0000 (10:33 -0700)
Const cleanup for SimpleLock, ScatterLock, and LocalLock.

Make SimpleLock::get_state_name() nonvirtual, since nobody overrides it.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/mds/LocalLock.h
src/mds/ScatterLock.h
src/mds/SimpleLock.h

index a4c9d61119f230545e0853ddccad825c145d3d55..70a5482808665de68f8d8163097e56dfecfcdcc9 100644 (file)
@@ -31,11 +31,11 @@ public:
     return true;
   }
 
-  bool can_xlock_local() {
+  bool can_xlock_local() const {
     return !is_wrlocked();
   }
 
-  bool can_wrlock() {
+  bool can_wrlock() const {
     return !is_xlocked();
   }
   void get_wrlock(client_t client) {
@@ -48,9 +48,11 @@ public:
     if (get_num_wrlocks() == 0)
       last_wrlock_client = client_t();
   }
-  client_t get_last_wrlock_client() { return last_wrlock_client; }
+  client_t get_last_wrlock_client() const {
+    return last_wrlock_client;
+  }
   
-  virtual void print(ostream& out) {
+  virtual void print(ostream& out) const {
     out << "(";
     _print(out);
     if (last_wrlock_client >= 0)
index ad1c0aa96b8a1c9aaca54f2873bea42eba2468b2..4c418f3bf8b95896fe58b517c62f2f0dbbf0650d 100644 (file)
@@ -31,7 +31,7 @@ class ScatterLock : public SimpleLock {
       item_updated(lock)
     {}
 
-    bool empty() {
+    bool empty() const {
       return dirty == false &&
        flushing == false &&
        scatter_wanted == false &&
@@ -75,12 +75,16 @@ public:
       !is_flushing();
   }
 
-  bool can_scatter_pin(client_t loner) {
+  bool can_scatter_pin(client_t loner) const {
     return can_rdlock(-1) || can_wrlock(loner);
   }
 
   xlist<ScatterLock*>::item *get_updated_item() { return &more()->item_updated; }
-  utime_t get_update_stamp() { return more()->update_stamp; }
+
+  utime_t get_update_stamp() {
+    return more()->update_stamp;
+  }
+
   void set_update_stamp(utime_t t) { more()->update_stamp = t; }
 
   void set_scatter_wanted() {
@@ -90,7 +94,7 @@ public:
     if (have_more())
       _more->scatter_wanted = false;
   }
-  bool get_scatter_wanted() {
+  bool get_scatter_wanted() const {
     return have_more() ? _more->scatter_wanted : false; 
   }
 
@@ -127,7 +131,9 @@ public:
   }
   
   void set_last_scatter(utime_t t) { more()->last_scatter = t; }
-  utime_t get_last_scatter() { return more()->last_scatter; }
+  utime_t get_last_scatter() {
+    return more()->last_scatter;
+  }
 
   void infer_state_from_strong_rejoin(int rstate, bool locktoo) {
     if (rstate == LOCK_MIX || 
@@ -139,7 +145,7 @@ public:
       state = LOCK_LOCK;
   }
 
-  void print(ostream& out) {
+  virtual void print(ostream& out) const {
     out << "(";
     _print(out);
     if (is_dirty())
index ec7fb7d96e9b8156129260cdef6379e2692c91f8..60870ded21ebad9c7b336e5df429aa3a778707e4 100644 (file)
@@ -87,7 +87,7 @@ class SimpleLock {
 public:
   LockType *type;
   
-  virtual const char *get_state_name(int n) {
+  const char *get_state_name(int n) const {
     switch (n) {
     case LOCK_UNDEF: return "UNDEF";
     case LOCK_SYNC: return "sync";
@@ -206,9 +206,10 @@ private:
 public:
 
   void set_excl_client(client_t c) { more()->excl_client = c; }
-  client_t get_excl_client() { return have_more() ? more()->excl_client : -1; }
-
 
+  client_t get_excl_client() const {
+    return have_more() ? more()->excl_client : -1;
+  }
 
   SimpleLock(MDSCacheObject *o, LockType *lt) :
     type(lt),
@@ -231,10 +232,10 @@ public:
 
   // parent
   MDSCacheObject *get_parent() { return parent; }
-  int get_type() { return type->type; }
+  int get_type() const { return type->type; }
   const sm_t* get_sm() const { return type->sm; }
 
-  int get_wait_shift() {
+  int get_wait_shift() const {
     switch (get_type()) {
     case CEPH_LOCK_DN:       return 8;
     case CEPH_LOCK_DVERSION: return 8 + 1*SimpleLock::WAIT_BITS;
@@ -253,7 +254,7 @@ public:
     }
   }
 
-  int get_cap_shift() {
+  int get_cap_shift() const {
     switch (get_type()) {
     case CEPH_LOCK_IAUTH: return CEPH_CAP_SAUTH;
     case CEPH_LOCK_ILINK: return CEPH_CAP_SLINK;
@@ -262,7 +263,7 @@ public:
     default: return 0;
     }
   }
-  int get_cap_mask() {
+  int get_cap_mask() const {
     switch (get_type()) {
     case CEPH_LOCK_IFILE: return 0xf;
     default: return 0x3;
@@ -300,7 +301,7 @@ public:
   void add_waiter(uint64_t mask, Context *c) {
     parent->add_waiter(mask << get_wait_shift(), c);
   }
-  bool is_waiter_for(uint64_t mask) {
+  bool is_waiter_for(uint64_t mask) const {
     return parent->is_waiter_for(mask << get_wait_shift());
   }
   
@@ -352,7 +353,11 @@ public:
 
   // gather set
   static set<int> empty_gather_set;
-  const set<int>& get_gather_set() { return have_more() ? more()->gather_set : empty_gather_set; }
+
+  const set<int>& get_gather_set() const {
+    return have_more() ? more()->gather_set : empty_gather_set;
+  }
+
   void init_gather() {
     for (map<int,int>::const_iterator p = parent->replicas_begin(); 
         p != parent->replicas_end(); 
@@ -378,39 +383,39 @@ public:
 
 
   // can_*
-  bool can_lease(client_t client) {
+  bool can_lease(client_t client) const {
     return get_sm()->states[state].can_lease == ANY ||
       (get_sm()->states[state].can_lease == AUTH && parent->is_auth()) ||
       (get_sm()->states[state].can_lease == XCL && client >= 0 && get_xlock_by_client() == client);
   }
-  bool can_read(client_t client) {
+  bool can_read(client_t client) const {
     return get_sm()->states[state].can_read == ANY ||
       (get_sm()->states[state].can_read == AUTH && parent->is_auth()) ||
       (get_sm()->states[state].can_read == XCL && client >= 0 && get_xlock_by_client() == client);
   }
-  bool can_read_projected(client_t client) {
+  bool can_read_projected(client_t client) const {
     return get_sm()->states[state].can_read_projected == ANY ||
       (get_sm()->states[state].can_read_projected == AUTH && parent->is_auth()) ||
       (get_sm()->states[state].can_read_projected == XCL && client >= 0 && get_xlock_by_client() == client);
   }
-  bool can_rdlock(client_t client) {
+  bool can_rdlock(client_t client) const {
     return get_sm()->states[state].can_rdlock == ANY ||
       (get_sm()->states[state].can_rdlock == AUTH && parent->is_auth()) ||
       (get_sm()->states[state].can_rdlock == XCL && client >= 0 && get_xlock_by_client() == client);
   }
-  bool can_wrlock(client_t client) {
+  bool can_wrlock(client_t client) const {
     return get_sm()->states[state].can_wrlock == ANY ||
       (get_sm()->states[state].can_wrlock == AUTH && parent->is_auth()) ||
       (get_sm()->states[state].can_wrlock == XCL && client >= 0 && (get_xlock_by_client() == client ||
                                                                    get_excl_client() == client));
   }
-  bool can_force_wrlock(client_t client) {
+  bool can_force_wrlock(client_t client) const {
     return get_sm()->states[state].can_force_wrlock == ANY ||
       (get_sm()->states[state].can_force_wrlock == AUTH && parent->is_auth()) ||
       (get_sm()->states[state].can_force_wrlock == XCL && client >= 0 && (get_xlock_by_client() == client ||
                                                                          get_excl_client() == client));
   }
-  bool can_xlock(client_t client) {
+  bool can_xlock(client_t client) const {
     return get_sm()->states[state].can_xlock == ANY ||
       (get_sm()->states[state].can_xlock == AUTH && parent->is_auth()) ||
       (get_sm()->states[state].can_xlock == XCL && client >= 0 && get_xlock_by_client() == client);
@@ -430,7 +435,9 @@ public:
       parent->put(MDSCacheObject::PIN_LOCK);
     return num_rdlock;
   }
-  int get_num_rdlocks() { return num_rdlock; }
+  int get_num_rdlocks() const {
+    return num_rdlock;
+  }
 
   // wrlock
   void get_wrlock(bool force=false) {
@@ -446,8 +453,12 @@ public:
       try_clear_more();
     }
   }
-  bool is_wrlocked() const { return have_more() && more()->num_wrlock > 0; }
-  int get_num_wrlocks() { return have_more() ? more()->num_wrlock : 0; }
+  bool is_wrlocked() const {
+    return have_more() && more()->num_wrlock > 0;
+  }
+  int get_num_wrlocks() const {
+    return have_more() ? more()->num_wrlock : 0;
+  }
 
   // xlock
   void get_xlock(Mutation *who, client_t client) { 
@@ -475,15 +486,24 @@ public:
       try_clear_more();
     }
   }
-  bool is_xlocked() const { return have_more() && more()->num_xlock > 0; }
-  int get_num_xlocks() { return have_more() ? more()->num_xlock : 0; }
-  client_t get_xlock_by_client() {
+  bool is_xlocked() const {
+    return have_more() && more()->num_xlock > 0;
+  }
+  int get_num_xlocks() const {
+    return have_more() ? more()->num_xlock : 0;
+  }
+  client_t get_xlock_by_client() const {
     return have_more() ? more()->xlock_by_client : -1;
   }
-  bool is_xlocked_by_client(client_t c) {
+  bool is_xlocked_by_client(client_t c) const {
     return have_more() ? more()->xlock_by_client == c : false;
   }
-  Mutation *get_xlock_by() { return have_more() ? more()->xlock_by : NULL; }
+  Mutation *get_xlock_by() {
+    return have_more() ? more()->xlock_by : NULL;
+  }
+  const Mutation *get_xlock_by() const {
+    return have_more() ? more()->xlock_by : NULL;
+  }
   
   // lease
   void get_client_lease() {
@@ -501,7 +521,7 @@ public:
     return num_client_lease;
   }
 
-  bool is_used() {
+  bool is_used() const {
     return is_xlocked() || is_rdlocked() || is_wrlocked() || num_client_lease;
   }
 
@@ -611,7 +631,7 @@ public:
     return false;
   }
 
-  void _print(ostream& out) {
+  void _print(ostream& out) const {
     out << get_lock_type_name(get_type()) << " ";
     out << get_state_name(get_state());
     if (!get_gather_set().empty())
@@ -634,7 +654,7 @@ public:
     */
   }
 
-  virtual void print(ostream& out) {
+  virtual void print(ostream& out) const {
     out << "(";
     _print(out);
     out << ")";
@@ -642,7 +662,7 @@ public:
 };
 WRITE_CLASS_ENCODER(SimpleLock)
 
-inline ostream& operator<<(ostream& out, SimpleLock& l) 
+inline ostream& operator<<(ostream& out, const SimpleLock& l) 
 {
   l.print(out);
   return out;