uint64_t cap_id = ++mdcache->last_cap_id;
auto ret = client_caps.emplace(std::piecewise_construct, std::forward_as_tuple(client),
- std::forward_as_tuple(this, cap_id, client));
+ std::forward_as_tuple(this, session, cap_id));
ceph_assert(ret.second == true);
Capability *cap = &ret.first->second;
session->add_cap(cap);
- if (session->is_stale())
- cap->mark_stale();
cap->client_follows = first-1;
containing_realm->add_cap(client, cap);
#include "Capability.h"
#include "CInode.h"
+#include "SessionMap.h"
#include "common/Formatter.h"
/*
* Capability
*/
+Capability::Capability(CInode *i, Session *s, uint64_t id) :
+ client_follows(0),
+ client_xattr_version(0), client_inline_version(0),
+ last_rbytes(0), last_rsize(0),
+ item_session_caps(this), item_snaprealm_caps(this),
+ item_revoking_caps(this), item_client_revoking_caps(this),
+ inode(i), session(s),
+ cap_id(id), _wanted(0), num_revoke_warnings(0),
+ _pending(0), _issued(0), last_sent(0), last_issue(0), mseq(0),
+ suppress(0), state(0)
+{
+}
+
+client_t Capability::get_client() const
+{
+ return session ? session->get_client() : client_t(-1);
+}
+
+bool Capability::is_stale() const
+{
+ return session ? session->is_stale() : false;
+}
void Capability::set_wanted(int w) {
CInode *in = get_inode();
*/
class CInode;
+class Session;
namespace ceph {
class Formatter;
};
- const static unsigned STATE_STALE = (1<<0);
const static unsigned STATE_NEW = (1<<1);
const static unsigned STATE_IMPORTING = (1<<2);
const static unsigned STATE_NEEDSNAPFLUSH = (1<<3);
- Capability(CInode *i = NULL, uint64_t id = 0, client_t c = 0) :
- client_follows(0), client_xattr_version(0),
- client_inline_version(0),
- last_rbytes(0), last_rsize(0),
- item_session_caps(this), item_snaprealm_caps(this),
- item_revoking_caps(this), item_client_revoking_caps(this),
- inode(i), client(c),
- cap_id(id),
- _wanted(0), num_revoke_warnings(0),
- _pending(0), _issued(0),
- last_sent(0),
- last_issue(0),
- mseq(0),
- suppress(0), state(0) {
- }
+ Capability(CInode *i=nullptr, Session *s=nullptr, uint64_t id=0);
Capability(const Capability& other) = delete;
const Capability& operator=(const Capability& other) = delete;
ceph_assert(_pending == c);
}
//last_issue =
- ++last_sent;
+ inc_last_seq();
return last_sent;
}
ceph_seq_t issue_norevoke(unsigned c) {
_pending |= c;
_issued |= c;
//check_rdcaps_list();
- ++last_sent;
+ inc_last_seq();
return last_sent;
}
void _calc_issued() {
void inc_suppress() { suppress++; }
void dec_suppress() { suppress--; }
- bool is_stale() const { return state & STATE_STALE; }
- void mark_stale() { state |= STATE_STALE; }
- void clear_stale() { state &= ~STATE_STALE; }
+ bool is_stale() const;
bool is_new() const { return state & STATE_NEW; }
void mark_new() { state |= STATE_NEW; }
void clear_new() { state &= ~STATE_NEW; }
void clear_needsnapflush() { state &= ~STATE_NEEDSNAPFLUSH; }
CInode *get_inode() const { return inode; }
- client_t get_client() const { return client; }
+ Session *get_session() const { return session; }
+ client_t get_client() const;
// caps this client wants to hold
int wanted() const { return _wanted; }
private:
CInode *inode;
- client_t client;
+ Session *session;
uint64_t cap_id;
for (xlist<Capability*>::iterator p = session->caps.begin(); !p.end(); ++p) {
Capability *cap = *p;
- cap->mark_stale();
revoke_stale_caps(cap);
}
}
Capability *cap = *p;
CInode *in = cap->get_inode();
ceph_assert(in->is_head());
- if (cap->is_stale()) {
- dout(10) << " clearing stale flag on " << *in << dendl;
- cap->clear_stale();
-
- if (in->state_test(CInode::STATE_EXPORTINGCAPS)) {
- // if export succeeds, the cap will be removed. if export fails,
- // we need to re-issue the cap if it's not stale.
- in->state_set(CInode::STATE_EVALSTALECAPS);
- continue;
- }
+ dout(10) << " clearing stale flag on " << *in << dendl;
- if (!in->is_auth() || !eval(in, CEPH_CAP_LOCKS))
- issue_caps(in, cap);
+ if (in->state_test(CInode::STATE_EXPORTINGCAPS)) {
+ // if export succeeds, the cap will be removed. if export fails,
+ // we need to re-issue the cap if it's not stale.
+ in->state_set(CInode::STATE_EVALSTALECAPS);
+ continue;
}
+
+ if (!in->is_auth() || !eval(in, CEPH_CAP_LOCKS))
+ issue_caps(in, cap);
}
}