From 2de7e88e4a956204792d5d6b6c99bf086850493f Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Wed, 1 Aug 2018 20:28:21 +0530 Subject: [PATCH] cephfs: LeaseStat versioning * Use the new feature bit CEPHFS_FEATURE_REPLY_ENCODING for encoding. * encode/decode in the new format. * Dropped LeaseStat::encode(). * The old format is maintained for backward compatibility. * Created Locker::encode_lease() 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/Locker.cc | 36 ++++++++++++++++++++++++------------ src/mds/Locker.h | 2 ++ src/mds/Server.cc | 33 +++++++++------------------------ src/mds/Server.h | 2 -- src/messages/MClientReply.h | 25 ++++++++++++++----------- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 6deeaf43759e1..128b3b7e840fe 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -1151,7 +1151,7 @@ void Client::insert_readdir_results(MetaRequest *request, MetaSession *session, LeaseStat dlease; for (unsigned i=0; iclient_lease_durations[pool]; mdcache->touch_client_lease(l, pool, now); - LeaseStat e; - e.mask = 1 | CEPH_LOCK_DN; // old and new bit values - e.seq = ++l->seq; - e.duration_ms = (int)(1000 * mdcache->client_lease_durations[pool]); - encode(e, bl); - dout(20) << "issue_client_lease seq " << e.seq << " dur " << e.duration_ms << "ms " + LeaseStat lstat; + lstat.mask = 1 | CEPH_LOCK_DN; // old and new bit values + lstat.duration_ms = (uint32_t)(1000 * mdcache->client_lease_durations[pool]); + lstat.seq = ++l->seq; + encode_lease(bl, session->info, lstat); + dout(20) << "issue_client_lease seq " << lstat.seq << " dur " << lstat.duration_ms << "ms " << " on " << *dn << dendl; } else { // null lease - LeaseStat e; - e.mask = 0; - e.seq = 0; - e.duration_ms = 0; - encode(e, bl); + LeaseStat lstat; + encode_lease(bl, session->info, lstat); dout(20) << "issue_client_lease no/null lease on " << *dn << dendl; } } @@ -3819,7 +3816,22 @@ void Locker::revoke_client_leases(SimpleLock *lock) } } - +void Locker::encode_lease(bufferlist& bl, const session_info_t& info, + const LeaseStat& ls) +{ + if (info.has_feature(CEPHFS_FEATURE_REPLY_ENCODING)) { + ENCODE_START(1, 1, bl); + encode(ls.mask, bl); + encode(ls.duration_ms, bl); + encode(ls.seq, bl); + ENCODE_FINISH(bl); + } + else { + encode(ls.mask, bl); + encode(ls.duration_ms, bl); + encode(ls.seq, bl); + } +} // locks ---------------------------------------------------------------- diff --git a/src/mds/Locker.h b/src/mds/Locker.h index 4e77ef9369d9a..74cdb45ac267b 100644 --- a/src/mds/Locker.h +++ b/src/mds/Locker.h @@ -45,6 +45,7 @@ class LocalLock; #include "SimpleLock.h" #include "MDSContext.h" #include "Mutation.h" +#include "messages/MClientReply.h" class Locker { private: @@ -287,6 +288,7 @@ public: void issue_client_lease(CDentry *dn, client_t client, bufferlist &bl, utime_t now, Session *session); void revoke_client_leases(SimpleLock *lock); + static void encode_lease(bufferlist& bl, const session_info_t& info, const LeaseStat& ls); }; diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 706a91c80a95d..2d743b23174e2 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -1658,27 +1658,6 @@ void Server::reply_client_request(MDRequestRef& mdr, MClientReply *reply) } } -void Server::encode_infinite_lease(bufferlist& bl) -{ - LeaseStat e; - e.seq = 0; - e.mask = -1; - e.duration_ms = -1; - encode(e, bl); - dout(20) << "encode_infinite_lease " << e << dendl; -} - -void Server::encode_null_lease(bufferlist& bl) -{ - LeaseStat e; - e.seq = 0; - e.mask = 0; - e.duration_ms = 0; - encode(e, bl); - dout(20) << "encode_null_lease " << e << dendl; -} - - /* * pass inode OR dentry (not both, or we may get confused) * @@ -1744,8 +1723,11 @@ void Server::set_trace_dist(Session *session, MClientReply *reply, encode(dn->get_name(), bl); if (snapid == CEPH_NOSNAP) mds->locker->issue_client_lease(dn, client, bl, now, session); - else - encode_null_lease(bl); + else { + //null lease + LeaseStat e; + mds->locker->encode_lease(bl, session->info, e); + } dout(20) << "set_trace_dist added dn " << snapid << " " << *dn << dendl; } else reply->head.is_dentry = 0; @@ -9162,7 +9144,10 @@ void Server::handle_client_lssnap(MDRequestRef& mdr) break; encode(snap_name, dnbl); - encode_infinite_lease(dnbl); + //infinite lease + LeaseStat e(-1, -1, 0); + mds->locker->encode_lease(dnbl, mdr->session->info, e); + dout(20) << "encode_infinite_lease" << dendl; int r = diri->encode_inodestat(dnbl, mdr->session, realm, p->first, max_bytes - (int)dnbl.length()); if (r < 0) { diff --git a/src/mds/Server.h b/src/mds/Server.h index c1faba068aadd..4719d4f374efe 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -160,8 +160,6 @@ public: int num_dentries_wanted, MDRequestRef& mdr); - void encode_infinite_lease(bufferlist& bl); - void encode_null_lease(bufferlist& bl); void handle_slave_request(MMDSSlaveRequest *m); void handle_slave_request_reply(MMDSSlaveRequest *m); diff --git a/src/messages/MClientReply.h b/src/messages/MClientReply.h index 6a93d9aa6b6bb..edd3d19c2bb36 100644 --- a/src/messages/MClientReply.h +++ b/src/messages/MClientReply.h @@ -52,21 +52,24 @@ struct LeaseStat { __u32 seq; LeaseStat() : mask(0), duration_ms(0), seq(0) {} + LeaseStat(__u16 msk, __u32 dur, __u32 sq) : mask{msk}, duration_ms{dur}, seq{sq} {} - void encode(bufferlist &bl) const { - using ceph::encode; - encode(mask, bl); - encode(duration_ms, bl); - encode(seq, bl); - } - void decode(bufferlist::const_iterator &bl) { + void decode(bufferlist::const_iterator &bl, const uint64_t features) { using ceph::decode; - decode(mask, bl); - decode(duration_ms, bl); - decode(seq, bl); + if (features == (uint64_t)-1) { + DECODE_START(1, bl); + decode(mask, bl); + decode(duration_ms, bl); + decode(seq, bl); + DECODE_FINISH(bl); + } + else { + decode(mask, bl); + decode(duration_ms, bl); + decode(seq, bl); + } } }; -WRITE_CLASS_ENCODER(LeaseStat) inline ostream& operator<<(ostream& out, const LeaseStat& l) { return out << "lease(mask " << l.mask << " dur " << l.duration_ms << ")"; -- 2.39.5