]>
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 | ||
f67539c2 | 19 | void SimpleLock::dump(ceph::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())); |
aee94f69 | 34 | f->dump_string("type", get_lock_type_name(get_type())); |
b32b8144 | 35 | f->dump_bool("is_leased", is_leased()); |
7c673cae FG |
36 | f->dump_int("num_rdlocks", get_num_rdlocks()); |
37 | f->dump_int("num_wrlocks", get_num_wrlocks()); | |
38 | f->dump_int("num_xlocks", get_num_xlocks()); | |
39 | f->open_object_section("xlock_by"); | |
aee94f69 TL |
40 | if (auto mut = get_xlock_by(); mut) { |
41 | f->dump_object("reqid", mut->reqid); | |
7c673cae FG |
42 | } |
43 | f->close_section(); | |
44 | } | |
9f95a23c TL |
45 | |
46 | int SimpleLock::get_wait_shift() const { | |
47 | switch (get_type()) { | |
48 | case CEPH_LOCK_DN: return 8; | |
49 | case CEPH_LOCK_DVERSION: return 8 + 1*SimpleLock::WAIT_BITS; | |
50 | case CEPH_LOCK_IAUTH: return 8 + 2*SimpleLock::WAIT_BITS; | |
51 | case CEPH_LOCK_ILINK: return 8 + 3*SimpleLock::WAIT_BITS; | |
52 | case CEPH_LOCK_IDFT: return 8 + 4*SimpleLock::WAIT_BITS; | |
53 | case CEPH_LOCK_IFILE: return 8 + 5*SimpleLock::WAIT_BITS; | |
54 | case CEPH_LOCK_IVERSION: return 8 + 6*SimpleLock::WAIT_BITS; | |
55 | case CEPH_LOCK_IXATTR: return 8 + 7*SimpleLock::WAIT_BITS; | |
56 | case CEPH_LOCK_ISNAP: return 8 + 8*SimpleLock::WAIT_BITS; | |
57 | case CEPH_LOCK_INEST: return 8 + 9*SimpleLock::WAIT_BITS; | |
58 | case CEPH_LOCK_IFLOCK: return 8 +10*SimpleLock::WAIT_BITS; | |
59 | case CEPH_LOCK_IPOLICY: return 8 +11*SimpleLock::WAIT_BITS; | |
60 | default: | |
61 | ceph_abort(); | |
62 | } | |
63 | } | |
64 | ||
65 | int SimpleLock::get_cap_shift() const { | |
66 | switch (get_type()) { | |
67 | case CEPH_LOCK_IAUTH: return CEPH_CAP_SAUTH; | |
68 | case CEPH_LOCK_ILINK: return CEPH_CAP_SLINK; | |
69 | case CEPH_LOCK_IFILE: return CEPH_CAP_SFILE; | |
70 | case CEPH_LOCK_IXATTR: return CEPH_CAP_SXATTR; | |
71 | default: return 0; | |
72 | } | |
73 | } | |
74 | ||
75 | int SimpleLock::get_cap_mask() const { | |
76 | switch (get_type()) { | |
77 | case CEPH_LOCK_IFILE: return (1 << CEPH_CAP_FILE_BITS) - 1; | |
78 | default: return (1 << CEPH_CAP_SIMPLE_BITS) - 1; | |
79 | } | |
80 | } | |
81 | ||
82 | SimpleLock::unstable_bits_t::unstable_bits_t() : | |
83 | lock_caches(member_offset(MDLockCache::LockItem, item_lock)) {} | |
84 | ||
85 | void SimpleLock::add_cache(MDLockCacheItem& item) { | |
86 | more()->lock_caches.push_back(&item.item_lock); | |
87 | state_flags |= CACHED; | |
88 | } | |
89 | ||
90 | void SimpleLock::remove_cache(MDLockCacheItem& item) { | |
91 | auto& lock_caches = more()->lock_caches; | |
92 | item.item_lock.remove_myself(); | |
93 | if (lock_caches.empty()) { | |
94 | state_flags &= ~CACHED; | |
95 | try_clear_more(); | |
96 | } | |
97 | } | |
98 | ||
1911f103 TL |
99 | std::vector<MDLockCache*> SimpleLock::get_active_caches() { |
100 | std::vector<MDLockCache*> result; | |
9f95a23c | 101 | if (have_more()) { |
1911f103 TL |
102 | for (auto it = more()->lock_caches.begin_use_current(); !it.end(); ++it) { |
103 | auto lock_cache = (*it)->parent; | |
104 | if (!lock_cache->invalidating) | |
105 | result.push_back(lock_cache); | |
9f95a23c TL |
106 | } |
107 | } | |
1911f103 | 108 | return result; |
9f95a23c | 109 | } |