]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: constify some RWRef methods
authorPatrick Donnelly <pdonnell@redhat.com>
Fri, 15 Jan 2021 03:54:20 +0000 (19:54 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Sat, 16 Jan 2021 01:30:39 +0000 (17:30 -0800)
And make some Client state checks const.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/client/Client.h
src/client/RWRef.h

index 782a2eb87b7290213f07caf21f13878a7ff3469a..5278fd78b941f0d1e0c27ada68f4ba741faa51b2 100644 (file)
@@ -285,6 +285,18 @@ public:
   int mount(const std::string &mount_root, const UserPerm& perms,
            bool require_mds=false, const std::string &fs_name="");
   void unmount();
+  bool is_unmounting() const {
+    return mount_state.check_current_state(CLIENT_UNMOUNTING);
+  }
+  bool is_mounted() const {
+    return mount_state.check_current_state(CLIENT_MOUNTED);
+  }
+  bool is_mounting() const {
+    return mount_state.check_current_state(CLIENT_MOUNTING);
+  }
+  bool is_initialized() const {
+    return initialize_state.check_current_state(CLIENT_INITIALIZED);
+  }
   void abort_conn();
 
   void set_uuid(const std::string& uuid);
@@ -1038,7 +1050,7 @@ protected:
 
   struct mount_state_t : public RWRefState<state_t> {
     public:
-      bool is_valid_state(state_t state) override {
+      bool is_valid_state(state_t state) const override {
         switch (state) {
          case Client::CLIENT_MOUNTING:
          case Client::CLIENT_MOUNTED:
@@ -1050,7 +1062,7 @@ protected:
         }
       }
 
-      int check_reader_state(state_t require) override {
+      int check_reader_state(state_t require) const override {
         if (require == Client::CLIENT_MOUNTING &&
             (state == Client::CLIENT_MOUNTING || state == Client::CLIENT_MOUNTED))
           return true;
@@ -1059,7 +1071,7 @@ protected:
       }
 
       /* The state migration check */
-      int check_writer_state(state_t require) override {
+      int check_writer_state(state_t require) const override {
         if (require == Client::CLIENT_MOUNTING &&
             state == Client::CLIENT_UNMOUNTED)
           return true;
@@ -1083,7 +1095,7 @@ protected:
 
   struct initialize_state_t : public RWRefState<state_t> {
     public:
-      bool is_valid_state(state_t state) override {
+      bool is_valid_state(state_t state) const override {
         switch (state) {
          case Client::CLIENT_NEW:
           case Client::CLIENT_INITIALIZING:
@@ -1094,7 +1106,7 @@ protected:
         }
       }
 
-      int check_reader_state(state_t require) override {
+      int check_reader_state(state_t require) const override {
         if (require == Client::CLIENT_INITIALIZED &&
             state >= Client::CLIENT_INITIALIZED)
           return true;
@@ -1103,7 +1115,7 @@ protected:
       }
 
       /* The state migration check */
-      int check_writer_state(state_t require) override {
+      int check_writer_state(state_t require) const override {
         if (require == Client::CLIENT_INITIALIZING &&
             (state == Client::CLIENT_NEW))
           return true;
@@ -1123,20 +1135,7 @@ protected:
   };
 
   struct mount_state_t mount_state;
-  bool is_unmounting() {
-    return mount_state.check_current_state(CLIENT_UNMOUNTING);
-  }
-  bool is_mounted() {
-    return mount_state.check_current_state(CLIENT_MOUNTED);
-  }
-  bool is_mounting() {
-    return mount_state.check_current_state(CLIENT_MOUNTING);
-  }
-
   struct initialize_state_t initialize_state;
-  bool is_initialized() {
-    return initialize_state.check_current_state(CLIENT_INITIALIZED);
-  }
 
 private:
   struct C_Readahead : public Context {
index f63ff1bbae58b2144095c4786519c4dd6834e4fe..9035a0937f513c99cfcbfd7c64fe18236ae7e59a 100644 (file)
@@ -106,7 +106,7 @@ struct RWRefState {
      * Then the check_reader_state() should return truth if the
      * state is already in mouting or mounted state.
      */
-    virtual int check_reader_state(T require) = 0;
+    virtual int check_reader_state(T require) const = 0;
 
     /*
      * User defined method to check whether the "require" state
@@ -114,20 +114,20 @@ struct RWRefState {
      *
      * This will usually be the state migration check.
      */
-    virtual int check_writer_state(T require) = 0;
+    virtual int check_writer_state(T require) const = 0;
 
     /*
      * User defined method to check whether the "require"
      * state is valid or not.
      */
-    virtual bool is_valid_state(T require) = 0;
+    virtual bool is_valid_state(T require) const = 0;
 
-    int64_t get_state() {
+    int64_t get_state() const {
       std::scoped_lock l{lock};
       return state;
     }
 
-    bool check_current_state(T require) {
+    bool check_current_state(T require) const {
       ceph_assert(is_valid_state(require));
 
       std::scoped_lock l{lock};
@@ -139,7 +139,7 @@ struct RWRefState {
     virtual ~RWRefState() {}
 
   private:
-    ceph::mutex lock;
+    mutable ceph::mutex lock;
     ceph::condition_variable cond;
     uint64_t reader_cnt = 0;
 };
@@ -183,7 +183,7 @@ public:
    * Whether the "require" state is in the proper range of
    * the states.
    */
-  bool is_state_satisfied() {
+  bool is_state_satisfied() const {
     return satisfied;
   }
 
@@ -201,7 +201,7 @@ public:
   /*
    * For current state whether we are the first writer or not
    */
-  bool is_first_writer() {
+  bool is_first_writer() const {
     return first_writer;
   }