blob: da266e30dab74c642b71695415cc95d4b55422e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2015 Red Hat
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "SimpleLock.h"
#include "Mutation.h"
void SimpleLock::dump(ceph::Formatter *f) const {
ceph_assert(f != NULL);
if (is_sync_and_unlocked()) {
return;
}
f->open_array_section("gather_set");
if (have_more()) {
for(const auto &i : more()->gather_set) {
f->dump_int("rank", i);
}
}
f->close_section();
f->dump_string("state", get_state_name(get_state()));
f->dump_string("type", get_lock_type_name(get_type()));
f->dump_bool("is_leased", is_leased());
f->dump_int("num_rdlocks", get_num_rdlocks());
f->dump_int("num_wrlocks", get_num_wrlocks());
f->dump_int("num_xlocks", get_num_xlocks());
f->open_object_section("xlock_by");
if (auto mut = get_xlock_by(); mut) {
f->dump_object("reqid", mut->reqid);
}
f->close_section();
}
int SimpleLock::get_wait_shift() const {
switch (get_type()) {
case CEPH_LOCK_DN: return 0;
case CEPH_LOCK_DVERSION: return 1*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IAUTH: return 2*SimpleLock::WAIT_BITS;
case CEPH_LOCK_ILINK: return 3*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IDFT: return 4*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IFILE: return 5*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IVERSION: return 6*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IXATTR: return 7*SimpleLock::WAIT_BITS;
case CEPH_LOCK_ISNAP: return 8*SimpleLock::WAIT_BITS;
case CEPH_LOCK_INEST: return 9*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IFLOCK: return 10*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IPOLICY: return 11*SimpleLock::WAIT_BITS;
case CEPH_LOCK_IQUIESCE: return 12*SimpleLock::WAIT_BITS;
default:
ceph_abort();
}
}
int SimpleLock::get_cap_shift() const {
switch (get_type()) {
case CEPH_LOCK_IAUTH: return CEPH_CAP_SAUTH;
case CEPH_LOCK_ILINK: return CEPH_CAP_SLINK;
case CEPH_LOCK_IFILE: return CEPH_CAP_SFILE;
case CEPH_LOCK_IXATTR: return CEPH_CAP_SXATTR;
default: return 0;
}
}
int SimpleLock::get_cap_mask() const {
switch (get_type()) {
case CEPH_LOCK_IFILE: return (1 << CEPH_CAP_FILE_BITS) - 1;
default: return (1 << CEPH_CAP_SIMPLE_BITS) - 1;
}
}
SimpleLock::unstable_bits_t::unstable_bits_t() :
lock_caches(member_offset(MDLockCache::LockItem, item_lock)) {}
void SimpleLock::add_cache(MDLockCacheItem& item) {
more()->lock_caches.push_back(&item.item_lock);
state_flags |= CACHED;
}
void SimpleLock::remove_cache(MDLockCacheItem& item) {
auto& lock_caches = more()->lock_caches;
item.item_lock.remove_myself();
if (lock_caches.empty()) {
state_flags &= ~CACHED;
try_clear_more();
}
}
std::vector<MDLockCache*> SimpleLock::get_active_caches() {
std::vector<MDLockCache*> result;
if (have_more()) {
for (auto it = more()->lock_caches.begin_use_current(); !it.end(); ++it) {
auto lock_cache = (*it)->parent;
if (!lock_cache->invalidating)
result.push_back(lock_cache);
}
}
return result;
}
void SimpleLock::_print(std::ostream& out) const
{
out << get_lock_type_name(get_type()) << " ";
out << get_state_name(get_state());
if (!get_gather_set().empty())
out << " g=" << get_gather_set();
{
std::string flags;
if (is_leased())
flags += "l";
if (is_cached())
flags += "c";
if (needs_recover())
flags += "r";
if (!flags.empty()) {
out << " " << flags;
}
}
if (is_rdlocked())
out << " r=" << get_num_rdlocks();
if (is_wrlocked())
out << " w=" << get_num_wrlocks();
if (is_xlocked()) {
out << " x=" << get_num_xlocks();
if (auto mut = get_xlock_by(); mut) {
out << " by " << *mut;
}
}
#if 0
if (is_stable())
out << " stable";
else
out << " unstable";
#endif
}
|