From 160668cefedfe919476e7870e68b0541d5d45fc2 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 1 May 2024 20:51:59 -0400 Subject: [PATCH] client: allow overriding client features For testing purposes. Signed-off-by: Patrick Donnelly (cherry picked from commit d9239f9375c1ae92a4990950f40078766bd912e8) Conflicts: src/client/Client.h Resolve a minor conflict involving Client::cap_auths --- src/client/Client.cc | 8 +++++++- src/client/Client.h | 2 ++ src/common/options/mds-client.yaml.in | 8 ++++++++ src/mds/mdstypes.cc | 26 +++++++++++++++++++++++++- src/mds/mdstypes.h | 3 +++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 9b397cb1e5194..1cb58c815f9e3 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -391,6 +391,12 @@ Client::Client(Messenger *m, MonClient *mc, Objecter *objecter_) if (cct->_conf->client_acl_type == "posix_acl") acl_type = POSIX_ACL; + if (auto str = cct->_conf->client_debug_inject_features; !str.empty()) { + myfeatures = feature_bitset_t(str); + } else { + myfeatures = feature_bitset_t(CEPHFS_FEATURES_CLIENT_SUPPORTED); + } + lru.lru_set_midpoint(cct->_conf->client_cache_mid); // file handles @@ -2301,7 +2307,7 @@ MetaSessionRef Client::_open_mds_session(mds_rank_t mds) auto m = make_message(CEPH_SESSION_REQUEST_OPEN); m->metadata = metadata; - m->supported_features = feature_bitset_t(CEPHFS_FEATURES_CLIENT_SUPPORTED); + m->supported_features = myfeatures; m->metric_spec = feature_bitset_t(CEPHFS_METRIC_FEATURES_ALL); session->con->send_message2(std::move(m)); return session; diff --git a/src/client/Client.h b/src/client/Client.h index 59353fd718e9c..28d3c63956d3f 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1600,6 +1600,8 @@ private: uint64_t nr_metadata_request = 0; uint64_t nr_read_request = 0; uint64_t nr_write_request = 0; + + feature_bitset_t myfeatures; }; /** diff --git a/src/common/options/mds-client.yaml.in b/src/common/options/mds-client.yaml.in index 7725901a42db5..2abbd517e23e3 100644 --- a/src/common/options/mds-client.yaml.in +++ b/src/common/options/mds-client.yaml.in @@ -251,6 +251,14 @@ options: default: 0 services: - mds_client +- name: client_debug_inject_features + type: str + level: dev + services: + - mds_client + flags: + - startup + with_legacy: true - name: client_max_inline_size type: size level: dev diff --git a/src/mds/mdstypes.cc b/src/mds/mdstypes.cc index 2b1e037a6dd78..0d481a4f659aa 100644 --- a/src/mds/mdstypes.cc +++ b/src/mds/mdstypes.cc @@ -6,6 +6,10 @@ #include "common/Formatter.h" #include "common/StackStringStream.h" +#include +#include +#include + const mds_gid_t MDS_GID_NONE = mds_gid_t(0); using std::list; @@ -428,7 +432,7 @@ feature_bitset_t::feature_bitset_t(unsigned long value) } } -feature_bitset_t::feature_bitset_t(const vector& array) +void feature_bitset_t::init_array(const vector& array) { if (!array.empty()) { size_t n = array.back(); @@ -447,6 +451,26 @@ feature_bitset_t::feature_bitset_t(const vector& array) } } +feature_bitset_t::feature_bitset_t(std::string_view str) +{ + std::stringstream ss; + std::vector v; + std::string atom; + + ss << str; + while (std::getline(ss, atom, ',')) { + v.push_back(std::stoul(atom)); + } + std::sort(v.begin(), v.end()); + + init_array(v); +} + +feature_bitset_t::feature_bitset_t(const vector& array) +{ + init_array(array); +} + feature_bitset_t& feature_bitset_t::operator-=(const feature_bitset_t& other) { for (size_t i = 0; i < _vec.size(); ++i) { diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index b20e28bc54f02..34556668d8326 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -1169,6 +1169,7 @@ public: feature_bitset_t(const feature_bitset_t& other) : _vec(other._vec) {} feature_bitset_t(feature_bitset_t&& other) : _vec(std::move(other._vec)) {} feature_bitset_t(unsigned long value = 0); + feature_bitset_t(std::string_view); feature_bitset_t(const std::vector& array); feature_bitset_t& operator=(const feature_bitset_t& other) { _vec = other._vec; @@ -1222,6 +1223,8 @@ public: void dump(ceph::Formatter *f) const; void print(std::ostream& out) const; private: + void init_array(const std::vector& v); + std::vector _vec; }; WRITE_CLASS_ENCODER(feature_bitset_t) -- 2.39.5