From 28b1c539c4428e9a90e0942afede786df1657170 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Thu, 14 Jan 2021 19:54:20 -0800 Subject: [PATCH] client: constify some RWRef methods And make some Client state checks const. Signed-off-by: Patrick Donnelly --- src/client/Client.h | 37 ++++++++++++++++++------------------- src/client/RWRef.h | 16 ++++++++-------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/client/Client.h b/src/client/Client.h index 782a2eb87b7..5278fd78b94 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -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 { 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 { 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 { diff --git a/src/client/RWRef.h b/src/client/RWRef.h index f63ff1bbae5..9035a0937f5 100644 --- a/src/client/RWRef.h +++ b/src/client/RWRef.h @@ -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; } -- 2.39.5