From: Varsha Rao Date: Fri, 27 Dec 2019 11:06:46 +0000 (+0530) Subject: mds: Reorganize structure and class members in mdstypes header X-Git-Tag: v15.1.1~386^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=88762afe727cb202fed3d0c67c48537ece98b5f9;p=ceph.git mds: Reorganize structure and class members in mdstypes header Fixes: https://tracker.ceph.com/issues/43426 Signed-off-by: Varsha Rao --- diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 8b51161fc84b..c3e741cb6a9e 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -80,20 +80,14 @@ constexpr fs_cluster_id_t FS_CLUSTER_ID_NONE = -1; // The namespace ID of the anonymous default filesystem from legacy systems constexpr fs_cluster_id_t FS_CLUSTER_ID_ANONYMOUS = 0; -class mds_role_t -{ - public: - fs_cluster_id_t fscid; - mds_rank_t rank; - +class mds_role_t { +public: mds_role_t(fs_cluster_id_t fscid_, mds_rank_t rank_) : fscid(fscid_), rank(rank_) {} - mds_role_t() - : fscid(FS_CLUSTER_ID_NONE), rank(MDS_RANK_NONE) - {} - bool operator<(mds_role_t const &rhs) const - { + mds_role_t() {} + + bool operator<(mds_role_t const &rhs) const { if (fscid < rhs.fscid) { return true; } else if (fscid == rhs.fscid) { @@ -103,16 +97,16 @@ class mds_role_t } } - bool is_none() const - { + bool is_none() const { return (rank == MDS_RANK_NONE); } + + fs_cluster_id_t fscid = FS_CLUSTER_ID_NONE; + mds_rank_t rank = MDS_RANK_NONE; }; std::ostream& operator<<(std::ostream &out, const mds_role_t &role); - // CAPS - inline string gcap_string(int cap) { string s; @@ -148,22 +142,11 @@ inline string ccap_string(int cap) return s; } - struct scatter_info_t { version_t version = 0; - - scatter_info_t() {} }; struct frag_info_t : public scatter_info_t { - // this frag - utime_t mtime; - uint64_t change_attr = 0; - int64_t nfiles = 0; // files - int64_t nsubdirs = 0; // subdirs - - frag_info_t() {} - int64_t size() const { return nfiles + nsubdirs; } void zero() { @@ -205,6 +188,12 @@ struct frag_info_t : public scatter_info_t { void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + // this frag + utime_t mtime; + uint64_t change_attr = 0; + int64_t nfiles = 0; // files + int64_t nsubdirs = 0; // subdirs }; WRITE_CLASS_ENCODER(frag_info_t) @@ -219,17 +208,8 @@ std::ostream& operator<<(std::ostream &out, const frag_info_t &f); struct nest_info_t : public scatter_info_t { - // this frag + children - utime_t rctime; - int64_t rbytes = 0; - int64_t rfiles = 0; - int64_t rsubdirs = 0; int64_t rsize() const { return rfiles + rsubdirs; } - int64_t rsnaps = 0; - - nest_info_t() {} - void zero() { *this = nest_info_t(); } @@ -268,6 +248,13 @@ struct nest_info_t : public scatter_info_t { void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + // this frag + children + utime_t rctime; + int64_t rbytes = 0; + int64_t rfiles = 0; + int64_t rsubdirs = 0; + int64_t rsnaps = 0; }; WRITE_CLASS_ENCODER(nest_info_t) @@ -280,10 +267,7 @@ inline bool operator!=(const nest_info_t &l, const nest_info_t &r) { std::ostream& operator<<(std::ostream &out, const nest_info_t &n); - struct vinodeno_t { - inodeno_t ino; - snapid_t snapid; vinodeno_t() {} vinodeno_t(inodeno_t i, snapid_t s) : ino(i), snapid(s) {} @@ -297,6 +281,9 @@ struct vinodeno_t { decode(ino, p); decode(snapid, p); } + + inodeno_t ino; + snapid_t snapid; }; WRITE_CLASS_ENCODER(vinodeno_t) @@ -314,11 +301,6 @@ inline bool operator<(const vinodeno_t &l, const vinodeno_t &r) { struct quota_info_t { - int64_t max_bytes = 0; - int64_t max_files = 0; - - quota_info_t() {} - void encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); encode(max_bytes, bl); @@ -341,6 +323,9 @@ struct quota_info_t bool is_enable() const { return max_bytes || max_files; } + + int64_t max_bytes = 0; + int64_t max_files = 0; }; WRITE_CLASS_ENCODER(quota_info_t) @@ -358,10 +343,7 @@ namespace std { return H(vino.ino) ^ I(vino.snapid); } }; -} // namespace std - - - +} inline std::ostream& operator<<(std::ostream &out, const vinodeno_t &vino) { out << vino.ino; @@ -372,25 +354,18 @@ inline std::ostream& operator<<(std::ostream &out, const vinodeno_t &vino) { return out; } - -/* - * client_writeable_range_t - */ struct client_writeable_range_t { struct byte_range_t { uint64_t first = 0, last = 0; // interval client can write to - byte_range_t() {} }; - byte_range_t range; - snapid_t follows = 0; // aka "data+metadata flushed thru" - - client_writeable_range_t() {} - void encode(bufferlist &bl) const; void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + byte_range_t range; + snapid_t follows = 0; // aka "data+metadata flushed thru" }; inline void decode(client_writeable_range_t::byte_range_t& range, bufferlist::const_iterator& bl) { @@ -409,21 +384,7 @@ inline bool operator==(const client_writeable_range_t& l, } struct inline_data_t { -private: - std::unique_ptr blp; public: - version_t version = 1; - - void free_data() { - blp.reset(); - } - bufferlist& get_data() { - if (!blp) - blp.reset(new bufferlist); - return *blp; - } - size_t length() const { return blp ? blp->length() : 0; } - inline_data_t() {} inline_data_t(const inline_data_t& o) : version(o.version) { if (o.blp) @@ -437,6 +398,17 @@ public: free_data(); return *this; } + + void free_data() { + blp.reset(); + } + bufferlist& get_data() { + if (!blp) + blp.reset(new bufferlist); + return *blp; + } + size_t length() const { return blp ? blp->length() : 0; } + bool operator==(const inline_data_t& o) const { return length() == o.length() && (length() == 0 || @@ -447,6 +419,11 @@ public: } void encode(bufferlist &bl) const; void decode(bufferlist::const_iterator& bl); + + version_t version = 1; + +private: + std::unique_ptr blp; }; WRITE_CLASS_ENCODER(inline_data_t) @@ -457,9 +434,6 @@ enum { }; typedef uint32_t damage_flags_t; -/* - * inode_t - */ template class Allocator = std::allocator> struct inode_t { /** @@ -467,70 +441,11 @@ struct inode_t { * Do not forget to add any new fields to the compare() function. * *************** */ - // base (immutable) - inodeno_t ino = 0; - uint32_t rdev = 0; // if special file - - // affected by any inode change... - utime_t ctime; // inode change time - utime_t btime; // birth time - - // perm (namespace permissions) - uint32_t mode = 0; - uid_t uid = 0; - gid_t gid = 0; - - // nlink - int32_t nlink = 0; - - // file (data access) - ceph_dir_layout dir_layout; // [dir only] - file_layout_t layout; - compact_set, Allocator> old_pools; - uint64_t size = 0; // on directory, # dentries - uint64_t max_size_ever = 0; // max size the file has ever been - uint32_t truncate_seq = 0; - uint64_t truncate_size = 0, truncate_from = 0; - uint32_t truncate_pending = 0; - utime_t mtime; // file data modify time. - utime_t atime; // file data access time. - uint32_t time_warp_seq = 0; // count of (potential) mtime/atime timewarps (i.e., utimes()) - inline_data_t inline_data; // FIXME check - - // change attribute - uint64_t change_attr = 0; - using client_range_map = std::map,Allocator>>; - client_range_map client_ranges; // client(s) can write to these ranges - - // dirfrag, recursive accountin - frag_info_t dirstat; // protected by my filelock - nest_info_t rstat; // protected by my nestlock - nest_info_t accounted_rstat; // protected by parent's nestlock - - quota_info_t quota; - - mds_rank_t export_pin = MDS_RANK_NONE; - - // special stuff - version_t version = 0; // auth only - version_t file_data_version = 0; // auth only - version_t xattr_version = 0; - - utime_t last_scrub_stamp; // start time of last complete scrub - version_t last_scrub_version = 0;// (parent) start version of last complete scrub - - version_t backtrace_version = 0; - - snapid_t oldest_snap; - - std::basic_string,Allocator> stray_prior_path; //stores path before unlink inode_t() { clear_layout(); - // FIPS zeroization audit 20191117: this memset is not security related. - memset(&dir_layout, 0, sizeof(dir_layout)); } // file type @@ -624,6 +539,65 @@ struct inode_t { * @returns 1 if we are newer than the other, 0 if equal, -1 if older. */ int compare(const inode_t &other, bool *divergent) const; + + // base (immutable) + inodeno_t ino = 0; + uint32_t rdev = 0; // if special file + + // affected by any inode change... + utime_t ctime; // inode change time + utime_t btime; // birth time + + // perm (namespace permissions) + uint32_t mode = 0; + uid_t uid = 0; + gid_t gid = 0; + + // nlink + int32_t nlink = 0; + + // file (data access) + ceph_dir_layout dir_layout = {}; // [dir only] + file_layout_t layout; + compact_set, Allocator> old_pools; + uint64_t size = 0; // on directory, # dentries + uint64_t max_size_ever = 0; // max size the file has ever been + uint32_t truncate_seq = 0; + uint64_t truncate_size = 0, truncate_from = 0; + uint32_t truncate_pending = 0; + utime_t mtime; // file data modify time. + utime_t atime; // file data access time. + uint32_t time_warp_seq = 0; // count of (potential) mtime/atime timewarps (i.e., utimes()) + inline_data_t inline_data; // FIXME check + + // change attribute + uint64_t change_attr = 0; + + client_range_map client_ranges; // client(s) can write to these ranges + + // dirfrag, recursive accountin + frag_info_t dirstat; // protected by my filelock + nest_info_t rstat; // protected by my nestlock + nest_info_t accounted_rstat; // protected by parent's nestlock + + quota_info_t quota; + + mds_rank_t export_pin = MDS_RANK_NONE; + + // special stuff + version_t version = 0; // auth only + version_t file_data_version = 0; // auth only + version_t xattr_version = 0; + + utime_t last_scrub_stamp; // start time of last complete scrub + version_t last_scrub_version = 0;// (parent) start version of last complete scrub + + version_t backtrace_version = 0; + + snapid_t oldest_snap; + + std::basic_string,Allocator> stray_prior_path; //stores path before unlink + private: bool older_is_consistent(const inode_t &other) const; }; @@ -949,9 +923,6 @@ using alloc_string = std::basic_string,Allocator class Allocator> using xattr_map = compact_map, bufferptr, std::less>, Allocator, bufferptr>>>; // FIXME bufferptr not in mempool -/* - * old_inode_t - */ template class Allocator = std::allocator> struct old_inode_t { snapid_t first; @@ -1024,11 +995,15 @@ inline void decode(old_inode_t &c, ::ceph::bufferlist::const_iterator c.decode(p); } - /* * like an inode, but for a dir frag */ struct fnode_t { + void encode(bufferlist &bl) const; + void decode(bufferlist::const_iterator& bl); + void dump(Formatter *f) const; + static void generate_test_instances(std::list& ls); + version_t version = 0; snapid_t snap_purged_thru; // the max_last_destroy snapid we've been purged thru frag_info_t fragstat, accounted_fragstat; @@ -1041,24 +1016,18 @@ struct fnode_t { // version at which we last scrubbed our personal data structures version_t localized_scrub_version = 0; utime_t localized_scrub_stamp; - - void encode(bufferlist &bl) const; - void decode(bufferlist::const_iterator& bl); - void dump(Formatter *f) const; - static void generate_test_instances(std::list& ls); - fnode_t() {} }; WRITE_CLASS_ENCODER(fnode_t) struct old_rstat_t { - snapid_t first; - nest_info_t rstat, accounted_rstat; - void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& p); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + snapid_t first; + nest_info_t rstat, accounted_rstat; }; WRITE_CLASS_ENCODER(old_rstat_t) @@ -1066,9 +1035,6 @@ inline std::ostream& operator<<(std::ostream& out, const old_rstat_t& o) { return out << "old_rstat(first " << o.first << " " << o.rstat << " " << o.accounted_rstat << ")"; } -/* - * feature_bitset_t - */ class feature_bitset_t { public: typedef uint64_t block_type; @@ -1086,6 +1052,7 @@ public: _vec = std::move(other._vec); return *this; } + feature_bitset_t& operator-=(const feature_bitset_t& other); bool empty() const { //block_type is a uint64_t. If the vector is only composed of 0s, then it's still "empty" for (auto& v : _vec) { @@ -1102,7 +1069,6 @@ public: void clear() { _vec.clear(); } - feature_bitset_t& operator-=(const feature_bitset_t& other); void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator &p); void dump(Formatter *f) const; @@ -1117,13 +1083,7 @@ inline std::ostream& operator<<(std::ostream& out, const feature_bitset_t& s) { return out; } -/* - * metric_spec_t - */ struct metric_spec_t { - // set of metrics that a client is capable of forwarding - feature_bitset_t metric_flags; - metric_spec_t() {} metric_spec_t(const metric_spec_t& other) : metric_flags(other.metric_flags) {} @@ -1155,6 +1115,9 @@ struct metric_spec_t { void decode(bufferlist::const_iterator& p); void dump(Formatter *f) const; void print(ostream& out) const; + + // set of metrics that a client is capable of forwarding + feature_bitset_t metric_flags; }; WRITE_CLASS_ENCODER(metric_spec_t) @@ -1170,23 +1133,7 @@ struct client_metadata_t { using kv_map_t = std::map; using iterator = kv_map_t::const_iterator; - kv_map_t kv_map; - feature_bitset_t features; - metric_spec_t metric_spec; - client_metadata_t() {} - client_metadata_t(const client_metadata_t& other) : - kv_map(other.kv_map), - features(other.features), - metric_spec(other.metric_spec) {} - client_metadata_t(client_metadata_t&& other) : - kv_map(std::move(other.kv_map)), - features(std::move(other.features)), - metric_spec(std::move(other.metric_spec)) {} - client_metadata_t(kv_map_t&& kv, feature_bitset_t &&f, metric_spec_t &&mst) : - kv_map(std::move(kv)), - features(std::move(f)), - metric_spec(std::move(mst)) {} client_metadata_t(const kv_map_t& kv, const feature_bitset_t &f, const metric_spec_t &mst) : kv_map(kv), features(f), @@ -1218,6 +1165,10 @@ struct client_metadata_t { void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& p); void dump(Formatter *f) const; + + kv_map_t kv_map; + feature_bitset_t features; + metric_spec_t metric_spec; }; WRITE_CLASS_ENCODER(client_metadata_t) @@ -1225,14 +1176,6 @@ WRITE_CLASS_ENCODER(client_metadata_t) * session_info_t - durable part of a Session */ struct session_info_t { - entity_inst_t inst; - std::map completed_requests; - interval_set prealloc_inos; // preallocated, ready to use. - interval_set used_inos; // journaling use - client_metadata_t client_metadata; - std::set completed_flushes; - EntityName auth_name; - client_t get_client() const { return client_t(inst.name.num()); } bool has_feature(size_t bit) const { return client_metadata.features.test(bit); } const entity_name_t& get_source() const { return inst.name; } @@ -1249,17 +1192,19 @@ struct session_info_t { void decode(bufferlist::const_iterator& p); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + entity_inst_t inst; + std::map completed_requests; + interval_set prealloc_inos; // preallocated, ready to use. + interval_set used_inos; // journaling use + client_metadata_t client_metadata; + std::set completed_flushes; + EntityName auth_name; }; WRITE_CLASS_ENCODER_FEATURES(session_info_t) - -// ======= // dentries - struct dentry_key_t { - snapid_t snapid = 0; - std::string_view name; - __u32 hash = 0; dentry_key_t() {} dentry_key_t(snapid_t s, std::string_view n, __u32 h=0) : snapid(s), name(n), hash(h) {} @@ -1303,9 +1248,13 @@ struct dentry_key_t { std::string x_str(key.substr(i+1)); sscanf(x_str.c_str(), "%llx", &x); sn = x; - } + } nm = key.substr(0, i); } + + snapid_t snapid = 0; + std::string_view name; + __u32 hash = 0; }; inline std::ostream& operator<<(std::ostream& out, const dentry_key_t &k) @@ -1327,13 +1276,10 @@ inline bool operator<(const dentry_key_t& k1, const dentry_key_t& k2) return k1.snapid < k2.snapid; } - /* * string_snap_t is a simple (string, snapid_t) pair */ struct string_snap_t { - string name; - snapid_t snapid; string_snap_t() {} string_snap_t(std::string_view n, snapid_t s) : name(n), snapid(s) {} @@ -1341,6 +1287,9 @@ struct string_snap_t { void decode(bufferlist::const_iterator& p); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + string name; + snapid_t snapid; }; WRITE_CLASS_ENCODER(string_snap_t) @@ -1357,28 +1306,23 @@ inline std::ostream& operator<<(std::ostream& out, const string_snap_t &k) /* * mds_table_pending_t * - * mds's requesting any pending ops. child needs to encode the corresponding + * For mds's requesting any pending ops, child needs to encode the corresponding * pending mutation state in the table. */ struct mds_table_pending_t { - uint64_t reqid = 0; - __s32 mds = 0; - version_t tid = 0; - mds_table_pending_t() {} void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + uint64_t reqid = 0; + __s32 mds = 0; + version_t tid = 0; }; WRITE_CLASS_ENCODER(mds_table_pending_t) - -// ========= // requests - struct metareqid_t { - entity_name_t name; - uint64_t tid = 0; metareqid_t() {} metareqid_t(entity_name_t n, ceph_tid_t t) : name(n), tid(t) {} void encode(bufferlist& bl) const { @@ -1391,6 +1335,9 @@ struct metareqid_t { decode(name, p); decode(tid, p); } + + entity_name_t name; + uint64_t tid = 0; }; WRITE_CLASS_ENCODER(metareqid_t) @@ -1424,19 +1371,9 @@ namespace std { }; } // namespace std - // cap info for client reconnect struct cap_reconnect_t { - string path; - mutable ceph_mds_cap_reconnect capinfo; - snapid_t snap_follows; - bufferlist flockbl; - - cap_reconnect_t() { - // FIPS zeroization audit 20191117: this memset is not security related. - memset(&capinfo, 0, sizeof(capinfo)); - snap_follows = 0; - } + cap_reconnect_t() {} cap_reconnect_t(uint64_t cap_id, inodeno_t pino, std::string_view p, int w, int i, inodeno_t sr, snapid_t sf, bufferlist& lb) : path(p) { @@ -1456,16 +1393,16 @@ struct cap_reconnect_t { void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + string path; + mutable ceph_mds_cap_reconnect capinfo = {}; + snapid_t snap_follows = 0; + bufferlist flockbl; }; WRITE_CLASS_ENCODER(cap_reconnect_t) struct snaprealm_reconnect_t { - mutable ceph_mds_snaprealm_reconnect realm; - - snaprealm_reconnect_t() { - // FIPS zeroization audit 20191117: this memset is not security related. - memset(&realm, 0, sizeof(realm)); - } + snaprealm_reconnect_t() {} snaprealm_reconnect_t(inodeno_t ino, snapid_t seq, inodeno_t parent) { realm.ino = ino; realm.seq = seq; @@ -1478,6 +1415,8 @@ struct snaprealm_reconnect_t { void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + mutable ceph_mds_snaprealm_reconnect realm = {}; }; WRITE_CLASS_ENCODER(snaprealm_reconnect_t) @@ -1494,9 +1433,6 @@ struct old_ceph_mds_cap_reconnect { WRITE_RAW_ENCODER(old_ceph_mds_cap_reconnect) struct old_cap_reconnect_t { - string path; - old_ceph_mds_cap_reconnect capinfo; - const old_cap_reconnect_t& operator=(const cap_reconnect_t& n) { path = n.path; capinfo.cap_id = n.capinfo.cap_id; @@ -1527,17 +1463,14 @@ struct old_cap_reconnect_t { decode(path, bl); decode(capinfo, bl); } + + string path; + old_ceph_mds_cap_reconnect capinfo; }; WRITE_CLASS_ENCODER(old_cap_reconnect_t) - -// ================================================================ // dir frag - struct dirfrag_t { - inodeno_t ino = 0; - frag_t frag; - dirfrag_t() {} dirfrag_t(inodeno_t i, frag_t f) : ino(i), frag(f) { } @@ -1551,10 +1484,12 @@ struct dirfrag_t { decode(ino, bl); decode(frag, bl); } + + inodeno_t ino = 0; + frag_t frag; }; WRITE_CLASS_ENCODER(dirfrag_t) - inline std::ostream& operator<<(std::ostream& out, const dirfrag_t &df) { out << df.ino; if (!df.frag.is_root()) out << "." << df.frag; @@ -1579,10 +1514,7 @@ namespace std { }; } // namespace std - - // ================================================================ - #define META_POP_IRD 0 #define META_POP_IWR 1 #define META_POP_READDIR 2 @@ -1722,11 +1654,6 @@ inline std::ostream& operator<<(std::ostream& out, const dirfrag_load_vec_t& dl) return out << ss.str() << std::endl; } - -/* mds_load_t - * mds load - */ - struct mds_load_t { using clock = dirfrag_load_vec_t::clock; using time = dirfrag_load_vec_t::time; @@ -1771,17 +1698,11 @@ public: using time = DecayCounter::time; using clock = DecayCounter::clock; static const int MAX = 4; - int last[MAX]; - int p = 0, n = 0; - DecayCounter count; -public: - load_spread_t() = delete; load_spread_t(const DecayRate &rate) : count(rate) - { - for (int i=0; i last = {-1, -1, -1, -1}; + int p = 0, n = 0; + DecayCounter count; +}; // ================================================================ typedef std::pair mds_authority_t; @@ -1818,17 +1741,15 @@ typedef std::pair mds_authority_t; class MDSCacheObjectInfo { public: - inodeno_t ino = 0; - dirfrag_t dirfrag; - string dname; - snapid_t snapid; - - MDSCacheObjectInfo() {} - void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list& ls); + + inodeno_t ino = 0; + dirfrag_t dirfrag; + string dname; + snapid_t snapid; }; inline std::ostream& operator<<(std::ostream& out, const MDSCacheObjectInfo &info) { @@ -1846,7 +1767,6 @@ inline bool operator==(const MDSCacheObjectInfo& l, const MDSCacheObjectInfo& r) } WRITE_CLASS_ENCODER(MDSCacheObjectInfo) - // parse a map of keys/values. namespace qi = boost::spirit::qi;