From ee6debb8056afdf0eba505af38189c34c2d7dd06 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 6 Jan 2009 16:08:50 -0800 Subject: [PATCH] mds: keep caps in lru; put ttl in cap issue to clients --- src/config.cc | 2 ++ src/config.h | 2 ++ src/include/ceph_fs.h | 1 + src/include/xlist.h | 10 ++++++++++ src/mds/CInode.cc | 4 ++++ src/mds/Capability.h | 38 +++++++++++++++++++++++++------------- src/mds/MDCache.cc | 1 + 7 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/config.cc b/src/config.cc index c3d9437ca53f..77b0b8183e02 100644 --- a/src/config.cc +++ b/src/config.cc @@ -343,6 +343,8 @@ md_config_t g_conf = { mds_client_prealloc_inos: 20, mds_early_reply: true, + mds_rdcap_ttl_ms: 30 * 10000, + mds_log: true, mds_log_max_events: -1, mds_log_max_segments: 100, // segment size defined by FileLayout, above diff --git a/src/config.h b/src/config.h index a3dce298368d..ecac33887ad5 100644 --- a/src/config.h +++ b/src/config.h @@ -212,6 +212,8 @@ struct md_config_t { int mds_client_prealloc_inos; bool mds_early_reply; + int mds_rdcap_ttl_ms; + bool mds_log; int mds_log_max_events; int mds_log_max_segments; diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 9d9684e88ae9..8a9eec946354 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -822,6 +822,7 @@ struct ceph_mds_reply_cap { __le32 caps; __le32 seq, mseq; __le64 realm; + __le32 ttl_ms; /* ttl, in ms. if readonly and unwanted. */ } __attribute__ ((packed)); struct ceph_mds_reply_inode { diff --git a/src/include/xlist.h b/src/include/xlist.h index bc1d29410b3a..8bcace6c067b 100644 --- a/src/include/xlist.h +++ b/src/include/xlist.h @@ -43,6 +43,16 @@ public: } else return false; } + void move_to_front() { + assert(_list); + _list->remove(this); + _list->push_front(this); + } + void move_to_back() { + assert(_list); + _list->remove(this); + _list->push_back(this); + } }; private: diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 3d9d0b23c3a9..d7723349d242 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -1358,16 +1358,20 @@ bool CInode::encode_inodestat(bufferlist& bl, Session *session, int likes = get_caps_liked(); int issue = (cap->wanted() | likes) & get_caps_allowed(loner); cap->issue(issue); + cap->set_last_issue_stamp(g_clock.recent_now()); + cap->touch(); e.cap.caps = issue; e.cap.seq = cap->get_last_seq(); dout(10) << "encode_inodestat issueing " << ccap_string(issue) << " seq " << cap->get_last_seq() << dendl; e.cap.mseq = cap->get_mseq(); e.cap.realm = find_snaprealm()->inode->ino(); + e.cap.ttl_ms = g_conf.mds_rdcap_ttl_ms; } else { e.cap.caps = 0; e.cap.seq = 0; e.cap.mseq = 0; e.cap.realm = 0; + e.cap.ttl_ms = 0; } } dout(10) << "encode_inodestat caps " << ccap_string(e.cap.caps) diff --git a/src/mds/Capability.h b/src/mds/Capability.h index 61107b8d7948..781d46e0a330 100644 --- a/src/mds/Capability.h +++ b/src/mds/Capability.h @@ -76,15 +76,17 @@ public: int32_t pending; snapid_t client_follows; capseq_t mseq; + utime_t last_issue_stamp; Export() {} - Export(int w, int i, int p, snapid_t cf, capseq_t s) : - wanted(w), issued(i), pending(p), client_follows(cf), mseq(s) {} + Export(int w, int i, int p, snapid_t cf, capseq_t s, utime_t lis) : + wanted(w), issued(i), pending(p), client_follows(cf), mseq(s), last_issue_stamp(lis) {} void encode(bufferlist &bl) const { ::encode(wanted, bl); ::encode(issued, bl); ::encode(pending, bl); ::encode(client_follows, bl); ::encode(mseq, bl); + ::encode(last_issue_stamp, bl); } void decode(bufferlist::iterator &p) { ::decode(wanted, p); @@ -92,6 +94,7 @@ public: ::decode(pending, p); ::decode(client_follows, p); ::decode(mseq, p); + ::decode(last_issue_stamp, p); } }; @@ -100,6 +103,7 @@ private: __u32 wanted_caps; // what the client wants (ideally) //::decode(cap_history, bl); + utime_t last_issue_stamp; // simplest -------------------------- #if 0 @@ -116,14 +120,15 @@ public: capseq_t issue(int c) { _pending = c; _issued |= c; - last_issue = ++last_sent; + //last_issue = + ++last_sent; return last_sent; } void confirm_receipt(capseq_t seq, int caps) { if (seq == last_sent) _pending = _issued = caps; } - bool is_null() { return !_issued && !_pending; } + bool is_null() { rinclude/eturn !_issued && !_pending; } #endif // track up to N revocations --------- @@ -153,7 +158,8 @@ public: _revoke_seq[_num_revoke] = last_sent; } _pending = c; - last_issue = ++last_sent; + //last_issue = + ++last_sent; return last_sent; } void confirm_receipt(capseq_t seq, int caps) { @@ -185,8 +191,8 @@ public: private: - capseq_t last_sent, last_recv; - capseq_t last_issue; + capseq_t last_sent; + //capseq_t last_issue; capseq_t mseq; int suppress; @@ -207,8 +213,7 @@ public: //_pending(0), _issued(0), _pending(0), _issued(0), _num_revoke(0), last_sent(s), - last_recv(s), - last_issue(0), + //last_issue(0), mseq(0), suppress(0), stale(false), releasing(0), client_follows(0), @@ -217,8 +222,14 @@ public: capseq_t get_mseq() { return mseq; } capseq_t get_last_sent() { return last_sent; } + utime_t get_last_issue_stamp() { return last_issue_stamp; } + void touch() { + session_caps_item.move_to_back(); + } + + void set_last_issue_stamp(utime_t t) { last_issue_stamp = t; } - capseq_t get_last_issue() { return last_issue; } + //capseq_t get_last_issue() { return last_issue; } bool is_suppress() { return suppress > 0; } void inc_suppress() { suppress++; } @@ -241,7 +252,7 @@ public: Export make_export() { - return Export(wanted_caps, issued(), pending(), client_follows, mseq+1); + return Export(wanted_caps, issued(), pending(), client_follows, mseq+1, last_issue_stamp); } void merge(Export& other) { // issued + pending @@ -249,6 +260,7 @@ public: if (other.issued & ~newpending) issue(other.issued | newpending); issue(newpending); + last_issue_stamp = other.last_issue_stamp; client_follows = other.client_follows; @@ -277,7 +289,7 @@ public: void encode(bufferlist &bl) const { ::encode(wanted_caps, bl); ::encode(last_sent, bl); - ::encode(last_recv, bl); + ::encode(last_issue_stamp, bl); ::encode(_pending, bl); ::encode(_issued, bl); @@ -288,7 +300,7 @@ public: void decode(bufferlist::iterator &bl) { ::decode(wanted_caps, bl); ::decode(last_sent, bl); - ::decode(last_recv, bl); + ::decode(last_issue_stamp, bl); ::decode(_pending, bl); ::decode(_issued, bl); diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 843e8461c238..1410a1093d2d 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -1010,6 +1010,7 @@ CInode *MDCache::cow_inode(CInode *in, snapid_t last) int client = p->first; Capability *newcap = oldin->add_client_cap(client, in->containing_realm); newcap->issue(cap->issued()); + newcap->set_last_issue_stamp(cap->get_last_issue_stamp()); newcap->client_follows = cap->client_follows; dout(10) << " cloning client" << client << " wr cap " << cap << " to " << newcap << " on cloned inode" << dendl; -- 2.47.3