From 05b192faab609e90ff5c9d23cb46463af8394f44 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Tue, 26 Nov 2013 18:32:18 +0800 Subject: [PATCH] mds: simplify how to export non-auth caps Introduce a new flag in cap import message. If client finds the flag is set, it releases exporter's caps (send release to the exporter). This saves the cap export message and a "mds to mds" message. Signed-off-by: Yan, Zheng --- src/include/ceph_fs.h | 3 ++- src/mds/Migrator.cc | 59 +++++++++++++------------------------------ src/mds/Migrator.h | 7 ++--- 3 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index dabc40a9d84db..0ed6d0a02f2d1 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -464,7 +464,8 @@ struct ceph_mds_reply_cap { __u8 flags; /* CEPH_CAP_FLAG_* */ } __attribute__ ((packed)); -#define CEPH_CAP_FLAG_AUTH 1 /* cap is issued by auth mds */ +#define CEPH_CAP_FLAG_AUTH (1 << 0) /* cap is issued by auth mds */ +#define CEPH_CAP_FLAG_RELEASE (1 << 1) /* ask client to release the cap */ /* inode record, for bundling with mds reply */ struct ceph_mds_reply_inode { diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index d2e97d234e632..cca2c357e1e0e 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -124,9 +124,6 @@ void Migrator::dispatch(Message *m) case MSG_MDS_EXPORTCAPS: handle_export_caps(static_cast(m)); break; - case MSG_MDS_EXPORTCAPSACK: - handle_export_caps_ack(static_cast(m)); - break; default: assert(0); @@ -1168,10 +1165,10 @@ void Migrator::encode_export_inode(CInode *in, bufferlist& enc_state, in->encode_export(enc_state); // caps - encode_export_inode_caps(in, enc_state, exported_client_map); + encode_export_inode_caps(in, true, enc_state, exported_client_map); } -void Migrator::encode_export_inode_caps(CInode *in, bufferlist& bl, +void Migrator::encode_export_inode_caps(CInode *in, bool auth_cap, bufferlist& bl, map& exported_client_map) { dout(20) << "encode_export_inode_caps " << *in << dendl; @@ -1180,10 +1177,12 @@ void Migrator::encode_export_inode_caps(CInode *in, bufferlist& bl, map cap_map; in->export_client_caps(cap_map); ::encode(cap_map, bl); - ::encode(in->get_mds_caps_wanted(), bl); + if (auth_cap) { + ::encode(in->get_mds_caps_wanted(), bl); - in->state_set(CInode::STATE_EXPORTINGCAPS); - in->get(CInode::PIN_EXPORTINGCAPS); + in->state_set(CInode::STATE_EXPORTINGCAPS); + in->get(CInode::PIN_EXPORTINGCAPS); + } // make note of clients named by exported capabilities for (map::iterator it = in->client_caps.begin(); @@ -2579,7 +2578,7 @@ void Migrator::decode_import_inode(CDentry *dn, bufferlist::iterator& blp, int o in->last_journaled = log_offset; // caps - decode_import_inode_caps(in, blp, peer_exports); + decode_import_inode_caps(in, true, blp, peer_exports); // link before state -- or not! -sage if (dn->get_linkage()->get_inode() != in) { @@ -2613,14 +2612,16 @@ void Migrator::decode_import_inode(CDentry *dn, bufferlist::iterator& blp, int o } -void Migrator::decode_import_inode_caps(CInode *in, +void Migrator::decode_import_inode_caps(CInode *in, bool auth_cap, bufferlist::iterator &blp, map >& peer_exports) { map cap_map; ::decode(cap_map, blp); - ::decode(in->get_mds_caps_wanted(), blp); - if (!cap_map.empty() || !in->get_mds_caps_wanted().empty()) { + if (auth_cap) + ::decode(in->get_mds_caps_wanted(), blp); + if (!cap_map.empty() || + (auth_cap && !in->get_mds_caps_wanted().empty())) { peer_exports[in].swap(cap_map); in->get(CInode::PIN_IMPORTINGCAPS); } @@ -2653,7 +2654,7 @@ void Migrator::finish_import_inode_caps(CInode *in, int peer, bool auth_cap, cap->merge(it->second, auth_cap); mds->mdcache->do_cap_import(session, in, cap, it->second.cap_id, it->second.seq, it->second.mseq - 1, peer, - auth_cap ? CEPH_CAP_FLAG_AUTH : 0); + auth_cap ? CEPH_CAP_FLAG_AUTH : CEPH_CAP_FLAG_RELEASE); } } @@ -2828,17 +2829,7 @@ void Migrator::handle_export_notify(MExportDirNotify *m) m->put(); } - - - - - - - /** cap exports **/ - - - void Migrator::export_caps(CInode *in) { int dest = in->authority().first; @@ -2852,25 +2843,11 @@ void Migrator::export_caps(CInode *in) MExportCaps *ex = new MExportCaps; ex->ino = in->ino(); - encode_export_inode_caps(in, ex->cap_bl, ex->client_map); + encode_export_inode_caps(in, false, ex->cap_bl, ex->client_map); mds->send_message_mds(ex, dest); } -/* This function DOES put the passed message before returning*/ -void Migrator::handle_export_caps_ack(MExportCapsAck *ack) -{ - CInode *in = cache->get_inode(ack->ino); - assert(in); - dout(10) << "handle_export_caps_ack " << *ack << " from " << ack->get_source() - << " on " << *in - << dendl; - - finish_export_inode_caps(in); - ack->put(); -} - - class C_M_LoggedImportCaps : public Context { Migrator *migrator; CInode *in; @@ -2904,7 +2881,7 @@ void Migrator::handle_export_caps(MExportCaps *ex) // decode new caps bufferlist::iterator blp = ex->cap_bl.begin(); - decode_import_inode_caps(in, blp, finish->peer_exports); + decode_import_inode_caps(in, false, blp, finish->peer_exports); assert(!finish->peer_exports.empty()); // thus, inode is pinned. // journal open client sessions @@ -2934,9 +2911,7 @@ void Migrator::logged_import_caps(CInode *in, map imported_caps; assert(peer_exports.count(in)); + // clients will release caps from the exporter when they receive the cap import message. finish_import_inode_caps(in, from, false, peer_exports[in], imported_caps); mds->locker->eval(in, CEPH_CAP_LOCKS, true); - - mds->send_message_mds(new MExportCapsAck(in->ino()), from); } - diff --git a/src/mds/Migrator.h b/src/mds/Migrator.h index 9007a85019df7..39542a3748797 100644 --- a/src/mds/Migrator.h +++ b/src/mds/Migrator.h @@ -239,7 +239,7 @@ public: void encode_export_inode(CInode *in, bufferlist& bl, map& exported_client_map); - void encode_export_inode_caps(CInode *in, bufferlist& bl, + void encode_export_inode_caps(CInode *in, bool auth_cap, bufferlist& bl, map& exported_client_map); void finish_export_inode(CInode *in, utime_t now, int target, map& peer_imported, @@ -281,8 +281,6 @@ public: void export_unlock(CDir *dir); void export_finish(CDir *dir); - void handle_export_caps_ack(MExportCapsAck *m); - void export_freeze_finish(CDir *dir) { utime_t start = export_freezing_state[dir].start_time; export_freezing_dirs.erase(make_pair(start, dir)); @@ -305,8 +303,7 @@ public: LogSegment *ls, uint64_t log_offset, map >& cap_imports, list& updated_scatterlocks); - void decode_import_inode_caps(CInode *in, - bufferlist::iterator &blp, + void decode_import_inode_caps(CInode *in, bool auth_cap, bufferlist::iterator &blp, map >& cap_imports); void finish_import_inode_caps(CInode *in, int from, bool auth_cap, map &export_map, -- 2.39.5