From b576cebb65ef519732fa0e32c3988484ce9581ae Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Wed, 1 Aug 2018 09:48:48 +0530 Subject: [PATCH] cephfs: DirStat versioning * Use the new feature bit CEPHFS_FEATURE_REPLY_ENCODING for encoding. * encode/decode in the new format. * Dropped DirStat::encode(). * The old format is maintained for backward compatibility. * Created CDir::encode_dirstat() for encoding and dropped the duplicates. Fixes: http://tracker.ceph.com/issues/24444 Signed-off-by: Jos Collin --- src/client/Client.cc | 4 ++-- src/mds/CDir.cc | 15 ++++++++++++++- src/mds/CDir.h | 21 +++++---------------- src/mds/Server.cc | 27 +++++++++++++++++---------- src/mds/Server.h | 1 - src/messages/MClientReply.h | 27 +++++++++++++++------------ 6 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 14880f8cc2130..6deeaf43759e1 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -1093,7 +1093,7 @@ void Client::insert_readdir_results(MetaRequest *request, MetaSession *session, assert(dir); // dirstat - DirStat dst(p); + DirStat dst(p, features); __u32 numdn; __u16 flags; decode(numdn, p); @@ -1299,7 +1299,7 @@ Inode* Client::insert_trace(MetaRequest *request, MetaSession *session) if (reply->head.is_dentry) { dirst.decode(p, features); - dst.decode(p); + dst.decode(p, features); decode(dname, p); decode(dlease, p); } diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index d0b231e1fc9c5..b1ad938061981 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -2590,6 +2590,20 @@ void CDir::abort_import() pop_auth_subtree.zero(); } +void CDir::encode_dirstat(bufferlist& bl, const session_info_t& info, const DirStat& ds) { + if (info.has_feature(CEPHFS_FEATURE_REPLY_ENCODING)) { + ENCODE_START(1, 1, bl); + encode(ds.frag, bl); + encode(ds.auth, bl); + encode(ds.dist, bl); + ENCODE_FINISH(bl); + } + else { + encode(ds.frag, bl); + encode(ds.auth, bl); + encode(ds.dist, bl); + } +} /******************************** * AUTHORITY @@ -2704,7 +2718,6 @@ void CDir::set_dir_auth(const mds_authority_t &a) } } - /***************************************** * AUTH PINS and FREEZING * diff --git a/src/mds/CDir.h b/src/mds/CDir.h index 0bbd3f1caff74..6234327d05015 100644 --- a/src/mds/CDir.h +++ b/src/mds/CDir.h @@ -33,6 +33,9 @@ #include "CInode.h" #include "MDSCacheObject.h" #include "MDSContext.h" +#include "cephfs_features.h" +#include "SessionMap.h" +#include "messages/MClientReply.h" class CDentry; class MDCache; @@ -562,22 +565,8 @@ private: ls.insert(auth); } } - void encode_dirstat(bufferlist& bl, mds_rank_t whoami) { - /* - * note: encoding matches struct ceph_client_reply_dirfrag - */ - frag_t frag = get_frag(); - mds_rank_t auth; - std::set dist; - - auth = dir_auth.first; - if (is_auth()) - get_dist_spec(dist, whoami); - - encode(frag, bl); - encode(auth, bl); - encode(dist, bl); - } + + static void encode_dirstat(bufferlist& bl, const session_info_t& info, const DirStat& ds); void _encode_base(bufferlist& bl) { encode(first, bl); diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 722ce887011d4..706a91c80a95d 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -1658,13 +1658,6 @@ void Server::reply_client_request(MDRequestRef& mdr, MClientReply *reply) } } - -void Server::encode_empty_dirstat(bufferlist& bl) -{ - static DirStat empty; - empty.encode(bl); -} - void Server::encode_infinite_lease(bufferlist& bl) { LeaseStat e; @@ -1739,7 +1732,13 @@ void Server::set_trace_dist(Session *session, MClientReply *reply, if (dir->is_complete()) dir->verify_fragstat(); #endif - dir->encode_dirstat(bl, whoami); + DirStat ds; + ds.frag = dir->get_frag(); + ds.auth = dir->get_dir_auth().first; + if (dir->is_auth()) + dir->get_dist_spec(ds.dist, whoami); + + dir->encode_dirstat(bl, session->info, ds); dout(20) << "set_trace_dist added dir " << *dir << dendl; encode(dn->get_name(), bl); @@ -3971,7 +3970,13 @@ void Server::handle_client_readdir(MDRequestRef& mdr) // start final blob bufferlist dirbl; - dir->encode_dirstat(dirbl, mds->get_nodeid()); + DirStat ds; + ds.frag = dir->get_frag(); + ds.auth = dir->get_dir_auth().first; + if (dir->is_auth()) + dir->get_dist_spec(ds.dist, mds->get_nodeid()); + + dir->encode_dirstat(dirbl, mdr->session->info, ds); // count bytes available. // this isn't perfect, but we should capture the main variable/unbounded size items! @@ -9132,8 +9137,10 @@ void Server::handle_client_lssnap(MDRequestRef& mdr) if (!offset_str.empty()) last_snapid = realm->resolve_snapname(offset_str, diri->ino()); + //Empty DirStat bufferlist dirbl; - encode_empty_dirstat(dirbl); + static DirStat empty; + CDir::encode_dirstat(dirbl, mdr->session->info, empty); max_bytes -= dirbl.length() - sizeof(__u32) + sizeof(__u8) * 2; diff --git a/src/mds/Server.h b/src/mds/Server.h index 0b78858721b64..c1faba068aadd 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -160,7 +160,6 @@ public: int num_dentries_wanted, MDRequestRef& mdr); - void encode_empty_dirstat(bufferlist& bl); void encode_infinite_lease(bufferlist& bl); void encode_null_lease(bufferlist& bl); diff --git a/src/messages/MClientReply.h b/src/messages/MClientReply.h index 8706aec172039..6a93d9aa6b6bb 100644 --- a/src/messages/MClientReply.h +++ b/src/messages/MClientReply.h @@ -79,21 +79,24 @@ struct DirStat { set<__s32> dist; DirStat() : auth(CDIR_AUTH_PARENT) {} - DirStat(bufferlist::const_iterator& p) { - decode(p); + DirStat(bufferlist::const_iterator& p, const uint64_t features) { + decode(p, features); } - void encode(bufferlist& bl) { - using ceph::encode; - encode(frag, bl); - encode(auth, bl); - encode(dist, bl); - } - void decode(bufferlist::const_iterator& p) { + void decode(bufferlist::const_iterator& p, const uint64_t features) { using ceph::decode; - decode(frag, p); - decode(auth, p); - decode(dist, p); + if (features == (uint64_t)-1) { + DECODE_START(1, p); + decode(frag, p); + decode(auth, p); + decode(dist, p); + DECODE_FINISH(p); + } + else { + decode(frag, p); + decode(auth, p); + decode(dist, p); + } } // see CDir::encode_dirstat for encoder. -- 2.39.5