]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/SimpleLock.h
update sources to v12.2.3
[ceph.git] / ceph / src / mds / SimpleLock.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15
16#ifndef CEPH_SIMPLELOCK_H
17#define CEPH_SIMPLELOCK_H
18
19#include <boost/intrusive_ptr.hpp>
20
21#include "MDSCacheObject.h"
22#include "MDSContext.h"
23
24// -- lock types --
25// see CEPH_LOCK_*
26
27inline const char *get_lock_type_name(int t) {
28 switch (t) {
29 case CEPH_LOCK_DN: return "dn";
30 case CEPH_LOCK_DVERSION: return "dversion";
31 case CEPH_LOCK_IVERSION: return "iversion";
32 case CEPH_LOCK_IFILE: return "ifile";
33 case CEPH_LOCK_IAUTH: return "iauth";
34 case CEPH_LOCK_ILINK: return "ilink";
35 case CEPH_LOCK_IDFT: return "idft";
36 case CEPH_LOCK_INEST: return "inest";
37 case CEPH_LOCK_IXATTR: return "ixattr";
38 case CEPH_LOCK_ISNAP: return "isnap";
39 case CEPH_LOCK_INO: return "ino";
40 case CEPH_LOCK_IFLOCK: return "iflock";
41 case CEPH_LOCK_IPOLICY: return "ipolicy";
42 default: ceph_abort(); return 0;
43 }
44}
45
46#include "include/memory.h"
47
48struct MutationImpl;
49typedef boost::intrusive_ptr<MutationImpl> MutationRef;
50
51extern "C" {
52#include "locks.h"
53}
54
55
56#define CAP_ANY 0
57#define CAP_LONER 1
58#define CAP_XLOCKER 2
59
60struct LockType {
61 int type;
62 const sm_t *sm;
63
64 explicit LockType(int t) : type(t) {
65 switch (type) {
66 case CEPH_LOCK_DN:
67 case CEPH_LOCK_IAUTH:
68 case CEPH_LOCK_ILINK:
69 case CEPH_LOCK_IXATTR:
70 case CEPH_LOCK_ISNAP:
71 case CEPH_LOCK_IFLOCK:
72 case CEPH_LOCK_IPOLICY:
73 sm = &sm_simplelock;
74 break;
75 case CEPH_LOCK_IDFT:
76 case CEPH_LOCK_INEST:
77 sm = &sm_scatterlock;
78 break;
79 case CEPH_LOCK_IFILE:
80 sm = &sm_filelock;
81 break;
82 case CEPH_LOCK_DVERSION:
83 case CEPH_LOCK_IVERSION:
84 sm = &sm_locallock;
85 break;
86 default:
87 sm = 0;
88 }
89 }
90
91};
92
93
94class SimpleLock {
95public:
96 LockType *type;
97
98 const char *get_state_name(int n) const {
99 switch (n) {
100 case LOCK_UNDEF: return "UNDEF";
101 case LOCK_SYNC: return "sync";
102 case LOCK_LOCK: return "lock";
103
104 case LOCK_PREXLOCK: return "prexlock";
105 case LOCK_XLOCK: return "xlock";
106 case LOCK_XLOCKDONE: return "xlockdone";
107 case LOCK_XLOCKSNAP: return "xlocksnap";
108 case LOCK_LOCK_XLOCK: return "lock->xlock";
109
110 case LOCK_SYNC_LOCK: return "sync->lock";
111 case LOCK_LOCK_SYNC: return "lock->sync";
112 case LOCK_REMOTEXLOCK: return "remote_xlock";
113 case LOCK_EXCL: return "excl";
114 case LOCK_EXCL_SYNC: return "excl->sync";
115 case LOCK_EXCL_LOCK: return "excl->lock";
116 case LOCK_SYNC_EXCL: return "sync->excl";
117 case LOCK_LOCK_EXCL: return "lock->excl";
118
119 case LOCK_XSYN: return "xsyn";
120 case LOCK_XSYN_EXCL: return "xsyn->excl";
121 case LOCK_EXCL_XSYN: return "excl->xsyn";
122 case LOCK_XSYN_SYNC: return "xsyn->sync";
b32b8144
FG
123 case LOCK_XSYN_LOCK: return "xsyn->lock";
124 case LOCK_XSYN_MIX: return "xsyn->mix";
7c673cae
FG
125
126 case LOCK_SYNC_MIX: return "sync->mix";
127 case LOCK_SYNC_MIX2: return "sync->mix(2)";
128 case LOCK_LOCK_TSYN: return "lock->tsyn";
129
130 case LOCK_MIX_LOCK: return "mix->lock";
131 case LOCK_MIX_LOCK2: return "mix->lock(2)";
132 case LOCK_MIX: return "mix";
133 case LOCK_MIX_TSYN: return "mix->tsyn";
134
135 case LOCK_TSYN_MIX: return "tsyn->mix";
136 case LOCK_TSYN_LOCK: return "tsyn->lock";
137 case LOCK_TSYN: return "tsyn";
138
139 case LOCK_MIX_SYNC: return "mix->sync";
140 case LOCK_MIX_SYNC2: return "mix->sync(2)";
141 case LOCK_EXCL_MIX: return "excl->mix";
142 case LOCK_MIX_EXCL: return "mix->excl";
143
144 case LOCK_PRE_SCAN: return "*->scan";
145 case LOCK_SCAN: return "scan";
146
147 case LOCK_SNAP_SYNC: return "snap->sync";
148
149 default: ceph_abort(); return 0;
150 }
151 }
152
153
154 // waiting
155 static const uint64_t WAIT_RD = (1<<0); // to read
156 static const uint64_t WAIT_WR = (1<<1); // to write
157 static const uint64_t WAIT_XLOCK = (1<<2); // to xlock (** dup)
158 static const uint64_t WAIT_STABLE = (1<<2); // for a stable state
159 static const uint64_t WAIT_REMOTEXLOCK = (1<<3); // for a remote xlock
160 static const int WAIT_BITS = 4;
161 static const uint64_t WAIT_ALL = ((1<<WAIT_BITS)-1);
162
163
164protected:
165 // parent (what i lock)
166 MDSCacheObject *parent;
167
168 // lock state
169 __s16 state;
b32b8144
FG
170 __s16 state_flags;
171
172 enum {
173 LEASED = 1 << 0,
174 NEED_RECOVER = 1 << 1,
175 };
7c673cae
FG
176
177private:
b32b8144 178 int num_rdlock;
7c673cae
FG
179
180 struct unstable_bits_t {
181 set<__s32> gather_set; // auth+rep. >= 0 is mds, < 0 is client
182
183 // local state
184 int num_wrlock, num_xlock;
185 MutationRef xlock_by;
186 client_t xlock_by_client;
187 client_t excl_client;
188
189 bool empty() {
190 return
191 gather_set.empty() &&
192 num_wrlock == 0 &&
193 num_xlock == 0 &&
194 xlock_by.get() == NULL &&
195 xlock_by_client == -1 &&
196 excl_client == -1;
197 }
198
199 unstable_bits_t() : num_wrlock(0),
200 num_xlock(0),
201 xlock_by(),
202 xlock_by_client(-1),
203 excl_client(-1) {}
204 };
205
206 mutable std::unique_ptr<unstable_bits_t> _unstable;
207
208 bool have_more() const { return _unstable ? true : false; }
209 unstable_bits_t *more() const {
210 if (!_unstable)
211 _unstable.reset(new unstable_bits_t);
212 return _unstable.get();
213 }
214 void try_clear_more() {
215 if (_unstable && _unstable->empty()) {
216 _unstable.reset();
217 }
218 }
219
220public:
221
222 client_t get_excl_client() const {
223 return have_more() ? more()->excl_client : -1;
224 }
225 void set_excl_client(client_t c) {
226 if (c < 0 && !have_more())
227 return; // default is -1
228 more()->excl_client = c;
229 }
230
231 SimpleLock(MDSCacheObject *o, LockType *lt) :
232 type(lt),
233 parent(o),
234 state(LOCK_SYNC),
b32b8144
FG
235 state_flags(0),
236 num_rdlock(0)
7c673cae
FG
237 {}
238 virtual ~SimpleLock() {}
239
240 virtual bool is_scatterlock() const {
241 return false;
242 }
243 virtual bool is_locallock() const {
244 return false;
245 }
246
247 // parent
248 MDSCacheObject *get_parent() { return parent; }
249 int get_type() const { return type->type; }
250 const sm_t* get_sm() const { return type->sm; }
251
252 int get_wait_shift() const {
253 switch (get_type()) {
254 case CEPH_LOCK_DN: return 8;
255 case CEPH_LOCK_DVERSION: return 8 + 1*SimpleLock::WAIT_BITS;
256 case CEPH_LOCK_IAUTH: return 8 + 2*SimpleLock::WAIT_BITS;
257 case CEPH_LOCK_ILINK: return 8 + 3*SimpleLock::WAIT_BITS;
258 case CEPH_LOCK_IDFT: return 8 + 4*SimpleLock::WAIT_BITS;
259 case CEPH_LOCK_IFILE: return 8 + 5*SimpleLock::WAIT_BITS;
260 case CEPH_LOCK_IVERSION: return 8 + 6*SimpleLock::WAIT_BITS;
261 case CEPH_LOCK_IXATTR: return 8 + 7*SimpleLock::WAIT_BITS;
262 case CEPH_LOCK_ISNAP: return 8 + 8*SimpleLock::WAIT_BITS;
263 case CEPH_LOCK_INEST: return 8 + 9*SimpleLock::WAIT_BITS;
264 case CEPH_LOCK_IFLOCK: return 8 +10*SimpleLock::WAIT_BITS;
265 case CEPH_LOCK_IPOLICY: return 8 +11*SimpleLock::WAIT_BITS;
266 default:
267 ceph_abort();
268 }
269 }
270
271 int get_cap_shift() const {
272 switch (get_type()) {
273 case CEPH_LOCK_IAUTH: return CEPH_CAP_SAUTH;
274 case CEPH_LOCK_ILINK: return CEPH_CAP_SLINK;
275 case CEPH_LOCK_IFILE: return CEPH_CAP_SFILE;
276 case CEPH_LOCK_IXATTR: return CEPH_CAP_SXATTR;
277 default: return 0;
278 }
279 }
280 int get_cap_mask() const {
281 switch (get_type()) {
282 case CEPH_LOCK_IFILE: return (1 << CEPH_CAP_FILE_BITS) - 1;
283 default: return (1 << CEPH_CAP_SIMPLE_BITS) - 1;
284 }
285 }
286
287 struct ptr_lt {
288 bool operator()(const SimpleLock* l, const SimpleLock* r) const {
289 // first sort by object type (dn < inode)
290 if (!(l->type->type > CEPH_LOCK_DN) && (r->type->type > CEPH_LOCK_DN)) return true;
291 if ((l->type->type > CEPH_LOCK_DN) == (r->type->type > CEPH_LOCK_DN)) {
292 // then sort by object
293 if (l->parent->is_lt(r->parent)) return true;
294 if (l->parent == r->parent) {
295 // then sort by (inode) lock type
296 if (l->type->type < r->type->type) return true;
297 }
298 }
299 return false;
300 }
301 };
302
303 void decode_locked_state(bufferlist& bl) {
304 parent->decode_lock_state(type->type, bl);
305 }
306 void encode_locked_state(bufferlist& bl) {
307 parent->encode_lock_state(type->type, bl);
308 }
309 void finish_waiters(uint64_t mask, int r=0) {
310 parent->finish_waiting(mask << get_wait_shift(), r);
311 }
312 void take_waiting(uint64_t mask, list<MDSInternalContextBase*>& ls) {
313 parent->take_waiting(mask << get_wait_shift(), ls);
314 }
315 void add_waiter(uint64_t mask, MDSInternalContextBase *c) {
316 parent->add_waiter((mask << get_wait_shift()) | MDSCacheObject::WAIT_ORDERED, c);
317 }
318 bool is_waiter_for(uint64_t mask) const {
319 return parent->is_waiter_for(mask << get_wait_shift());
320 }
321
322
323
324 // state
325 int get_state() const { return state; }
326 int set_state(int s) {
327 state = s;
328 //assert(!is_stable() || gather_set.size() == 0); // gather should be empty in stable states.
329 return s;
330 }
b32b8144
FG
331 void set_state_rejoin(int s, list<MDSInternalContextBase*>& waiters, bool survivor) {
332 assert(!get_parent()->is_auth());
333
334 // If lock in the replica object was not in SYNC state when auth mds of the object failed.
335 // Auth mds of the object may take xlock on the lock and change the object when replaying
336 // unsafe requests.
337 if (!survivor || state != LOCK_SYNC)
338 mark_need_recover();
339
340 state = s;
341
7c673cae
FG
342 if (is_stable())
343 take_waiting(SimpleLock::WAIT_ALL, waiters);
344 }
345
346 bool is_stable() const {
347 return get_sm()->states[state].next == 0;
348 }
349 bool is_unstable_and_locked() const {
350 if (is_stable())
351 return false;
352 return is_rdlocked() || is_wrlocked() || is_xlocked();
353 }
354 int get_next_state() {
355 return get_sm()->states[state].next;
356 }
357
358
359 bool is_sync_and_unlocked() const {
360 return
361 get_state() == LOCK_SYNC &&
362 !is_rdlocked() &&
363 !is_leased() &&
364 !is_wrlocked() &&
365 !is_xlocked();
366 }
367
368
369 /*
370 bool fw_rdlock_to_auth() {
371 return get_sm()->states[state].can_rdlock == FW;
372 }
373 */
374 bool req_rdlock_from_auth() {
375 return get_sm()->states[state].can_rdlock == REQ;
376 }
377
378 // gather set
379 static set<int32_t> empty_gather_set;
380
381 // int32_t: <0 is client, >=0 is MDS rank
382 const set<int32_t>& get_gather_set() const {
383 return have_more() ? more()->gather_set : empty_gather_set;
384 }
385
386 void init_gather() {
181888fb
FG
387 for (const auto p : parent->get_replicas()) {
388 more()->gather_set.insert(p.first);
389 }
7c673cae
FG
390 }
391 bool is_gathering() const {
392 return have_more() && !more()->gather_set.empty();
393 }
394 bool is_gathering(int32_t i) const {
395 return have_more() && more()->gather_set.count(i);
396 }
397 void clear_gather() {
398 if (have_more())
399 more()->gather_set.clear();
400 }
401 void remove_gather(int32_t i) {
402 if (have_more())
403 more()->gather_set.erase(i);
404 }
405
406
407
408 virtual bool is_dirty() const { return false; }
409 virtual bool is_stale() const { return false; }
410 virtual bool is_flushing() const { return false; }
411 virtual bool is_flushed() const { return false; }
412 virtual void clear_flushed() { }
413
414 // can_*
415 bool can_lease(client_t client) const {
416 return get_sm()->states[state].can_lease == ANY ||
417 (get_sm()->states[state].can_lease == AUTH && parent->is_auth()) ||
418 (get_sm()->states[state].can_lease == XCL && client >= 0 && get_xlock_by_client() == client);
419 }
420 bool can_read(client_t client) const {
421 return get_sm()->states[state].can_read == ANY ||
422 (get_sm()->states[state].can_read == AUTH && parent->is_auth()) ||
423 (get_sm()->states[state].can_read == XCL && client >= 0 && get_xlock_by_client() == client);
424 }
425 bool can_read_projected(client_t client) const {
426 return get_sm()->states[state].can_read_projected == ANY ||
427 (get_sm()->states[state].can_read_projected == AUTH && parent->is_auth()) ||
428 (get_sm()->states[state].can_read_projected == XCL && client >= 0 && get_xlock_by_client() == client);
429 }
430 bool can_rdlock(client_t client) const {
431 return get_sm()->states[state].can_rdlock == ANY ||
432 (get_sm()->states[state].can_rdlock == AUTH && parent->is_auth()) ||
433 (get_sm()->states[state].can_rdlock == XCL && client >= 0 && get_xlock_by_client() == client);
434 }
435 bool can_wrlock(client_t client) const {
436 return get_sm()->states[state].can_wrlock == ANY ||
437 (get_sm()->states[state].can_wrlock == AUTH && parent->is_auth()) ||
438 (get_sm()->states[state].can_wrlock == XCL && client >= 0 && (get_xlock_by_client() == client ||
439 get_excl_client() == client));
440 }
441 bool can_force_wrlock(client_t client) const {
442 return get_sm()->states[state].can_force_wrlock == ANY ||
443 (get_sm()->states[state].can_force_wrlock == AUTH && parent->is_auth()) ||
444 (get_sm()->states[state].can_force_wrlock == XCL && client >= 0 && (get_xlock_by_client() == client ||
445 get_excl_client() == client));
446 }
447 bool can_xlock(client_t client) const {
448 return get_sm()->states[state].can_xlock == ANY ||
449 (get_sm()->states[state].can_xlock == AUTH && parent->is_auth()) ||
450 (get_sm()->states[state].can_xlock == XCL && client >= 0 && get_xlock_by_client() == client);
451 }
452
453 // rdlock
454 bool is_rdlocked() const { return num_rdlock > 0; }
455 int get_rdlock() {
456 if (!num_rdlock)
457 parent->get(MDSCacheObject::PIN_LOCK);
458 return ++num_rdlock;
459 }
460 int put_rdlock() {
461 assert(num_rdlock>0);
462 --num_rdlock;
463 if (num_rdlock == 0)
464 parent->put(MDSCacheObject::PIN_LOCK);
465 return num_rdlock;
466 }
467 int get_num_rdlocks() const {
468 return num_rdlock;
469 }
470
471 // wrlock
472 void get_wrlock(bool force=false) {
473 //assert(can_wrlock() || force);
474 if (more()->num_wrlock == 0)
475 parent->get(MDSCacheObject::PIN_LOCK);
476 ++more()->num_wrlock;
477 }
478 void put_wrlock() {
479 --more()->num_wrlock;
480 if (more()->num_wrlock == 0) {
481 parent->put(MDSCacheObject::PIN_LOCK);
482 try_clear_more();
483 }
484 }
485 bool is_wrlocked() const {
486 return have_more() && more()->num_wrlock > 0;
487 }
488 int get_num_wrlocks() const {
489 return have_more() ? more()->num_wrlock : 0;
490 }
491
492 // xlock
493 void get_xlock(MutationRef who, client_t client) {
494 assert(get_xlock_by() == MutationRef());
495 assert(state == LOCK_XLOCK || is_locallock() ||
496 state == LOCK_LOCK /* if we are a slave */);
497 parent->get(MDSCacheObject::PIN_LOCK);
498 more()->num_xlock++;
499 more()->xlock_by = who;
500 more()->xlock_by_client = client;
501 }
502 void set_xlock_done() {
503 assert(more()->xlock_by);
504 assert(state == LOCK_XLOCK || is_locallock() ||
505 state == LOCK_LOCK /* if we are a slave */);
506 if (!is_locallock())
507 state = LOCK_XLOCKDONE;
508 more()->xlock_by.reset();
509 }
510 void put_xlock() {
511 assert(state == LOCK_XLOCK || state == LOCK_XLOCKDONE ||
512 state == LOCK_XLOCKSNAP || is_locallock() ||
513 state == LOCK_LOCK /* if we are a master of a slave */);
514 --more()->num_xlock;
515 parent->put(MDSCacheObject::PIN_LOCK);
516 if (more()->num_xlock == 0) {
517 more()->xlock_by.reset();
518 more()->xlock_by_client = -1;
519 try_clear_more();
520 }
521 }
522 bool is_xlocked() const {
523 return have_more() && more()->num_xlock > 0;
524 }
525 int get_num_xlocks() const {
526 return have_more() ? more()->num_xlock : 0;
527 }
528 client_t get_xlock_by_client() const {
529 return have_more() ? more()->xlock_by_client : -1;
530 }
531 bool is_xlocked_by_client(client_t c) const {
532 return have_more() ? more()->xlock_by_client == c : false;
533 }
534 MutationRef get_xlock_by() const {
535 return have_more() ? more()->xlock_by : MutationRef();
536 }
537
538 // lease
b32b8144
FG
539 bool is_leased() const {
540 return state_flags & LEASED;
541 }
7c673cae 542 void get_client_lease() {
b32b8144
FG
543 assert(!is_leased());
544 state_flags |= LEASED;
7c673cae
FG
545 }
546 void put_client_lease() {
b32b8144
FG
547 assert(is_leased());
548 state_flags &= ~LEASED;
7c673cae
FG
549 }
550
551 bool is_used() const {
b32b8144
FG
552 return is_xlocked() || is_rdlocked() || is_wrlocked() || is_leased();
553 }
554
555 bool needs_recover() const {
556 return state_flags & NEED_RECOVER;
557 }
558 void mark_need_recover() {
559 state_flags |= NEED_RECOVER;
560 }
561 void clear_need_recover() {
562 state_flags &= ~NEED_RECOVER;
7c673cae
FG
563 }
564
565 // encode/decode
566 void encode(bufferlist& bl) const {
567 ENCODE_START(2, 2, bl);
568 ::encode(state, bl);
569 if (have_more())
570 ::encode(more()->gather_set, bl);
571 else
572 ::encode(empty_gather_set, bl);
573 ENCODE_FINISH(bl);
574 }
575 void decode(bufferlist::iterator& p) {
576 DECODE_START(2, p);
577 ::decode(state, p);
578 set<__s32> g;
579 ::decode(g, p);
580 if (!g.empty())
581 more()->gather_set.swap(g);
582 DECODE_FINISH(p);
583 }
584 void encode_state_for_replica(bufferlist& bl) const {
585 __s16 s = get_replica_state();
586 ::encode(s, bl);
587 }
588 void decode_state(bufferlist::iterator& p, bool is_new=true) {
589 __s16 s;
590 ::decode(s, p);
591 if (is_new)
592 state = s;
593 }
b32b8144 594 void decode_state_rejoin(bufferlist::iterator& p, list<MDSInternalContextBase*>& waiters, bool survivor) {
7c673cae
FG
595 __s16 s;
596 ::decode(s, p);
b32b8144 597 set_state_rejoin(s, waiters, survivor);
7c673cae
FG
598 }
599
600
601 // caps
602 bool is_loner_mode() const {
603 return get_sm()->states[state].loner;
604 }
605 int gcaps_allowed_ever() const {
606 return parent->is_auth() ? get_sm()->allowed_ever_auth : get_sm()->allowed_ever_replica;
607 }
608 int gcaps_allowed(int who, int s=-1) const {
609 if (s < 0) s = state;
610 if (parent->is_auth()) {
611 if (get_xlock_by_client() >= 0 && who == CAP_XLOCKER)
612 return get_sm()->states[s].xlocker_caps | get_sm()->states[s].caps; // xlocker always gets more
613 else if (is_loner_mode() && who == CAP_ANY)
614 return get_sm()->states[s].caps;
615 else
616 return get_sm()->states[s].loner_caps | get_sm()->states[s].caps; // loner always gets more
617 } else
618 return get_sm()->states[s].replica_caps;
619 }
620 int gcaps_careful() const {
621 if (get_num_wrlocks())
622 return get_sm()->careful;
623 return 0;
624 }
625
626
627 int gcaps_xlocker_mask(client_t client) const {
628 if (client == get_xlock_by_client())
629 return type->type == CEPH_LOCK_IFILE ? 0xf : (CEPH_CAP_GSHARED|CEPH_CAP_GEXCL);
630 return 0;
631 }
632
633 // simplelock specifics
634 int get_replica_state() const {
635 return get_sm()->states[state].replica_state;
636 }
637 void export_twiddle() {
638 clear_gather();
639 state = get_replica_state();
640 }
641
642 /** replicate_relax
643 * called on first replica creation.
644 */
645 void replicate_relax() {
646 assert(parent->is_auth());
647 assert(!parent->is_replicated());
648 if (state == LOCK_LOCK && !is_used())
649 state = LOCK_SYNC;
650 }
651 bool remove_replica(int from) {
652 if (is_gathering(from)) {
653 remove_gather(from);
654 if (!is_gathering())
655 return true;
656 }
657 return false;
658 }
659 bool do_import(int from, int to) {
660 if (!is_stable()) {
661 remove_gather(from);
662 remove_gather(to);
663 if (!is_gathering())
664 return true;
665 }
666 if (!is_stable() && !is_gathering())
667 return true;
668 return false;
669 }
670
671 void _print(ostream& out) const {
672 out << get_lock_type_name(get_type()) << " ";
673 out << get_state_name(get_state());
674 if (!get_gather_set().empty())
675 out << " g=" << get_gather_set();
b32b8144
FG
676 if (is_leased())
677 out << " l";
7c673cae
FG
678 if (is_rdlocked())
679 out << " r=" << get_num_rdlocks();
680 if (is_wrlocked())
681 out << " w=" << get_num_wrlocks();
682 if (is_xlocked()) {
683 out << " x=" << get_num_xlocks();
684 if (get_xlock_by())
685 out << " by " << get_xlock_by();
686 }
687 /*if (is_stable())
688 out << " stable";
689 else
690 out << " unstable";
691 */
692 }
693
694 /**
695 * Write bare values (caller must be in an object section)
696 * to formatter, or nothing if is_sync_and_unlocked.
697 */
698 void dump(Formatter *f) const;
699
700 virtual void print(ostream& out) const {
701 out << "(";
702 _print(out);
703 out << ")";
704 }
705};
706WRITE_CLASS_ENCODER(SimpleLock)
707
708inline ostream& operator<<(ostream& out, const SimpleLock& l)
709{
710 l.print(out);
711 return out;
712}
713
714
715#endif