Skip to content

Commit

Permalink
mds: quiescelock as local lock + cap masking
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
Signed-off-by: Leonid Usov <leonid.usov@ibm.com>
(cherry picked from commit 7fa8bc8)
  • Loading branch information
batrick committed Mar 22, 2024
1 parent 7dacd28 commit a8cbcde
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 195 deletions.
2 changes: 1 addition & 1 deletion src/common/options/mds.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ options:
type: bool
level: advanced
desc: allow recursive quiesce across auth boundaries
default: false
default: true
services:
- mds
flags:
Expand Down
5 changes: 5 additions & 0 deletions src/mds/CDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,11 @@ void CDir::link_inode_work( CDentry *dn, CInode *in)
in->snaprealm->adjust_parent();
else if (in->is_any_caps())
in->move_to_realm(inode->find_snaprealm());

bool is_quiesced = inode->is_quiesced();
if (is_quiesced) {
mdcache->add_quiesce(inode, in);
}
}

void CDir::unlink_inode(CDentry *dn, bool adjust_lru)
Expand Down
43 changes: 32 additions & 11 deletions src/mds/CInode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ ostream& operator<<(ostream& out, const CInode& in)
out << " " << in.filelock;
if (!in.xattrlock.is_sync_and_unlocked())
out << " " << in.xattrlock;
if (!in.versionlock.is_sync_and_unlocked())
if (in.versionlock.is_locked())
out << " " << in.versionlock;
if (!in.quiescelock.is_sync_and_unlocked())
if (in.quiescelock.is_locked())
out << " " << in.quiescelock;

// hack: spit out crap on which clients have caps
Expand Down Expand Up @@ -2882,6 +2882,7 @@ bool CInode::freeze_inode(int auth_pin_allowance)
const static int lock_types[] = {
CEPH_LOCK_IVERSION, CEPH_LOCK_IFILE, CEPH_LOCK_IAUTH, CEPH_LOCK_ILINK, CEPH_LOCK_IDFT,
CEPH_LOCK_IXATTR, CEPH_LOCK_ISNAP, CEPH_LOCK_INEST, CEPH_LOCK_IFLOCK, CEPH_LOCK_IPOLICY, 0
//TODO: add iquiesce here?
};
for (int i = 0; lock_types[i]; ++i) {
auto lock = get_lock(lock_types[i]);
Expand Down Expand Up @@ -3532,13 +3533,23 @@ void CInode::export_client_caps(map<client_t,Capability::Export>& cl)
}
}

int CInode::get_caps_quiesce_mask() const
{
if (is_quiesced()) {
// what we allow to our clients for a quiesced node
return CEPH_CAP_ANY_RD | CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_BUFFER | CEPH_CAP_PIN;
} else {
return CEPH_CAP_ANY;
}
}

// caps allowed
int CInode::get_caps_liked() const
{
if (is_dir())
return CEPH_CAP_PIN | CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_SHARED; // but not, say, FILE_RD|WR|WRBUFFER
return get_caps_quiesce_mask() & (CEPH_CAP_PIN | CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_SHARED); // but not, say, FILE_RD|WR|WRBUFFER
else
return CEPH_CAP_ANY & ~CEPH_CAP_FILE_LAZYIO;
return get_caps_quiesce_mask() & (CEPH_CAP_ANY & ~CEPH_CAP_FILE_LAZYIO);
}

int CInode::get_caps_allowed_ever() const
Expand All @@ -3558,30 +3569,33 @@ int CInode::get_caps_allowed_ever() const

int CInode::get_caps_allowed_by_type(int type) const
{
return
return get_caps_quiesce_mask() & (
CEPH_CAP_PIN |
(filelock.gcaps_allowed(type) << filelock.get_cap_shift()) |
(authlock.gcaps_allowed(type) << authlock.get_cap_shift()) |
(xattrlock.gcaps_allowed(type) << xattrlock.get_cap_shift()) |
(linklock.gcaps_allowed(type) << linklock.get_cap_shift());
(linklock.gcaps_allowed(type) << linklock.get_cap_shift())
);
}

int CInode::get_caps_careful() const
{
return
return get_caps_quiesce_mask() & (
(filelock.gcaps_careful() << filelock.get_cap_shift()) |
(authlock.gcaps_careful() << authlock.get_cap_shift()) |
(xattrlock.gcaps_careful() << xattrlock.get_cap_shift()) |
(linklock.gcaps_careful() << linklock.get_cap_shift());
(linklock.gcaps_careful() << linklock.get_cap_shift())
);
}

int CInode::get_xlocker_mask(client_t client) const
{
return
return get_caps_quiesce_mask() & (
(filelock.gcaps_xlocker_mask(client) << filelock.get_cap_shift()) |
(authlock.gcaps_xlocker_mask(client) << authlock.get_cap_shift()) |
(xattrlock.gcaps_xlocker_mask(client) << xattrlock.get_cap_shift()) |
(linklock.gcaps_xlocker_mask(client) << linklock.get_cap_shift());
(linklock.gcaps_xlocker_mask(client) << linklock.get_cap_shift())
);
}

int CInode::get_caps_allowed_for_client(Session *session, Capability *cap,
Expand Down Expand Up @@ -3679,6 +3693,14 @@ int CInode::get_caps_wanted(int *ploner, int *pother, int shift, int mask) const
other |= p.second;
//cout << " get_caps_wanted mds " << it->first << " " << cap_string(it->second) << endl;
}

// we adjust wanted caps to prevent unnecessary lock transitions
// don't worry, when the quiesce lock is dropped
// the whole thing will get evaluated again, with a fixed mask
loner &= get_caps_quiesce_mask();
other &= get_caps_quiesce_mask();
w &= get_caps_quiesce_mask();

if (ploner) *ploner = (loner >> shift) & mask;
if (pother) *pother = (other >> shift) & mask;
return (w >> shift) & mask;
Expand Down Expand Up @@ -4370,7 +4392,6 @@ void CInode::_decode_locks_state_for_replica(bufferlist::const_iterator& p, bool
snaplock.mark_need_recover();
flocklock.mark_need_recover();
policylock.mark_need_recover();
quiescelock.mark_need_recover();
}
DECODE_FINISH(p);
}
Expand Down
5 changes: 4 additions & 1 deletion src/mds/CInode.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno
bool is_file() const { return get_inode()->is_file(); }
bool is_symlink() const { return get_inode()->is_symlink(); }
bool is_dir() const { return get_inode()->is_dir(); }
bool is_quiesced() const { return quiescelock.is_xlocked(); }

bool is_head() const { return last == CEPH_NOSNAP; }

Expand Down Expand Up @@ -867,6 +868,8 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno
int count_nonstale_caps();
bool multiple_nonstale_caps();

int get_caps_quiesce_mask() const;

bool is_any_caps() { return !client_caps.empty(); }
bool is_any_nonstale_caps() { return count_nonstale_caps(); }

Expand Down Expand Up @@ -1106,7 +1109,7 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno
* quiescelock.
*/

SimpleLock quiescelock; // FIXME not part of mempool
LocalLockC quiescelock; // FIXME not part of mempool
LocalLockC versionlock; // FIXME not part of mempool
SimpleLock authlock; // FIXME not part of mempool
SimpleLock linklock; // FIXME not part of mempool
Expand Down

0 comments on commit a8cbcde

Please sign in to comment.