Skip to content

Commit

Permalink
mds: add session pointer to Capability
Browse files Browse the repository at this point in the history
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
(cherry picked from commit 7c62847)

 Conflicts:
	src/mds/CInode.cc
	src/mds/Capability.cc
	src/mds/Capability.h
	src/mds/Locker.cc
  • Loading branch information
ukernel committed Feb 5, 2019
1 parent cd231e2 commit bd647b2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
5 changes: 1 addition & 4 deletions src/mds/CInode.cc
Expand Up @@ -2812,14 +2812,11 @@ Capability *CInode::add_client_cap(client_t client, Session *session, SnapRealm
if (client_caps.empty())
mdcache->num_inodes_with_caps++;

Capability *cap = new Capability(this, ++mdcache->last_cap_id, client);
Capability *cap = new Capability(this, session, ++mdcache->last_cap_id);
assert(client_caps.count(client) == 0);
client_caps[client] = cap;

session->add_cap(cap);
if (session->is_stale())
cap->mark_stale();

cap->client_follows = first-1;

containing_realm->add_cap(client, cap);
Expand Down
23 changes: 23 additions & 0 deletions src/mds/Capability.cc
Expand Up @@ -13,6 +13,7 @@
*/

#include "Capability.h"
#include "SessionMap.h"

#include "common/Formatter.h"

Expand Down Expand Up @@ -140,6 +141,28 @@ void Capability::revoke_info::generate_test_instances(list<Capability::revoke_in
/*
* 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::encode(bufferlist& bl) const
{
Expand Down
35 changes: 10 additions & 25 deletions src/mds/Capability.h
Expand Up @@ -61,6 +61,7 @@
*/

class CInode;
class Session;

namespace ceph {
class Formatter;
Expand Down Expand Up @@ -110,26 +111,11 @@ class Capability : public Counter<Capability> {
};


const static unsigned STATE_STALE = (1<<0);
const static unsigned STATE_NEW = (1<<1);
const static unsigned STATE_IMPORTING = (1<<2);


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); // no copying

const Capability& operator=(const Capability& other); // no copying
Expand Down Expand Up @@ -157,14 +143,14 @@ class Capability : public Counter<Capability> {
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() {
Expand Down Expand Up @@ -238,18 +224,17 @@ class Capability : public Counter<Capability> {
void inc_suppress() { suppress++; }
void dec_suppress() { suppress--; }

bool is_stale() { return state & STATE_STALE; }
void mark_stale() { state |= STATE_STALE; }
void clear_stale() { state &= ~STATE_STALE; }
bool is_new() { return state & STATE_NEW; }
bool is_stale() const;
bool is_new() const { return state & STATE_NEW; }
void mark_new() { state |= STATE_NEW; }
void clear_new() { state &= ~STATE_NEW; }
bool is_importing() { return state & STATE_IMPORTING; }
void mark_importing() { state |= STATE_IMPORTING; }
void clear_importing() { state &= ~STATE_IMPORTING; }

CInode *get_inode() { return inode; }
client_t get_client() const { return client; }
CInode *get_inode() const { return inode; }
Session *get_session() const { return session; }
client_t get_client() const;

// caps this client wants to hold
int wanted() { return _wanted; }
Expand Down Expand Up @@ -332,7 +317,7 @@ class Capability : public Counter<Capability> {

private:
CInode *inode;
client_t client;
Session *session;

uint64_t cap_id;

Expand Down
24 changes: 10 additions & 14 deletions src/mds/Locker.cc
Expand Up @@ -2163,7 +2163,6 @@ void Locker::revoke_stale_caps(Session *session)

for (xlist<Capability*>::iterator p = session->caps.begin(); !p.end(); ++p) {
Capability *cap = *p;
cap->mark_stale();
revoke_stale_caps(cap);
}
}
Expand All @@ -2175,21 +2174,18 @@ void Locker::resume_stale_caps(Session *session)
for (xlist<Capability*>::iterator p = session->caps.begin(); !p.end(); ++p) {
Capability *cap = *p;
CInode *in = cap->get_inode();
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;
}
ceph_assert(in->is_head());
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);
}
}

Expand Down

0 comments on commit bd647b2

Please sign in to comment.