]>
Commit | Line | Data |
---|---|---|
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) 2015 Red Hat | |
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 | #include "SimpleLock.h" | |
17 | #include "Mutation.h" | |
18 | ||
19 | void SimpleLock::dump(Formatter *f) const { | |
11fdf7f2 | 20 | ceph_assert(f != NULL); |
7c673cae FG |
21 | if (is_sync_and_unlocked()) { |
22 | return; | |
23 | } | |
24 | ||
25 | f->open_array_section("gather_set"); | |
26 | if (have_more()) { | |
94b18763 FG |
27 | for(const auto &i : more()->gather_set) { |
28 | f->dump_int("rank", i); | |
7c673cae FG |
29 | } |
30 | } | |
31 | f->close_section(); | |
32 | ||
81eedcae | 33 | f->dump_string("state", get_state_name(get_state())); |
b32b8144 | 34 | f->dump_bool("is_leased", is_leased()); |
7c673cae FG |
35 | f->dump_int("num_rdlocks", get_num_rdlocks()); |
36 | f->dump_int("num_wrlocks", get_num_wrlocks()); | |
37 | f->dump_int("num_xlocks", get_num_xlocks()); | |
38 | f->open_object_section("xlock_by"); | |
39 | if (get_xlock_by()) { | |
40 | get_xlock_by()->dump(f); | |
41 | } | |
42 | f->close_section(); | |
43 | } | |
9f95a23c TL |
44 | |
45 | int SimpleLock::get_wait_shift() const { | |
46 | switch (get_type()) { | |
47 | case CEPH_LOCK_DN: return 8; | |
48 | case CEPH_LOCK_DVERSION: return 8 + 1*SimpleLock::WAIT_BITS; | |
49 | case CEPH_LOCK_IAUTH: return 8 + 2*SimpleLock::WAIT_BITS; | |
50 | case CEPH_LOCK_ILINK: return 8 + 3*SimpleLock::WAIT_BITS; | |
51 | case CEPH_LOCK_IDFT: return 8 + 4*SimpleLock::WAIT_BITS; | |
52 | case CEPH_LOCK_IFILE: return 8 + 5*SimpleLock::WAIT_BITS; | |
53 | case CEPH_LOCK_IVERSION: return 8 + 6*SimpleLock::WAIT_BITS; | |
54 | case CEPH_LOCK_IXATTR: return 8 + 7*SimpleLock::WAIT_BITS; | |
55 | case CEPH_LOCK_ISNAP: return 8 + 8*SimpleLock::WAIT_BITS; | |
56 | case CEPH_LOCK_INEST: return 8 + 9*SimpleLock::WAIT_BITS; | |
57 | case CEPH_LOCK_IFLOCK: return 8 +10*SimpleLock::WAIT_BITS; | |
58 | case CEPH_LOCK_IPOLICY: return 8 +11*SimpleLock::WAIT_BITS; | |
59 | default: | |
60 | ceph_abort(); | |
61 | } | |
62 | } | |
63 | ||
64 | int SimpleLock::get_cap_shift() const { | |
65 | switch (get_type()) { | |
66 | case CEPH_LOCK_IAUTH: return CEPH_CAP_SAUTH; | |
67 | case CEPH_LOCK_ILINK: return CEPH_CAP_SLINK; | |
68 | case CEPH_LOCK_IFILE: return CEPH_CAP_SFILE; | |
69 | case CEPH_LOCK_IXATTR: return CEPH_CAP_SXATTR; | |
70 | default: return 0; | |
71 | } | |
72 | } | |
73 | ||
74 | int SimpleLock::get_cap_mask() const { | |
75 | switch (get_type()) { | |
76 | case CEPH_LOCK_IFILE: return (1 << CEPH_CAP_FILE_BITS) - 1; | |
77 | default: return (1 << CEPH_CAP_SIMPLE_BITS) - 1; | |
78 | } | |
79 | } | |
80 | ||
81 | SimpleLock::unstable_bits_t::unstable_bits_t() : | |
82 | lock_caches(member_offset(MDLockCache::LockItem, item_lock)) {} | |
83 | ||
84 | void SimpleLock::add_cache(MDLockCacheItem& item) { | |
85 | more()->lock_caches.push_back(&item.item_lock); | |
86 | state_flags |= CACHED; | |
87 | } | |
88 | ||
89 | void SimpleLock::remove_cache(MDLockCacheItem& item) { | |
90 | auto& lock_caches = more()->lock_caches; | |
91 | item.item_lock.remove_myself(); | |
92 | if (lock_caches.empty()) { | |
93 | state_flags &= ~CACHED; | |
94 | try_clear_more(); | |
95 | } | |
96 | } | |
97 | ||
98 | MDLockCache* SimpleLock::get_first_cache() { | |
99 | if (have_more()) { | |
100 | auto& lock_caches = more()->lock_caches; | |
101 | if (!lock_caches.empty()) { | |
102 | return lock_caches.front()->parent; | |
103 | } | |
104 | } | |
105 | return nullptr; | |
106 | } |