]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef CEPH_CLS_LOCK_TYPES_H |
2 | #define CEPH_CLS_LOCK_TYPES_H | |
3 | ||
4 | #include "include/encoding.h" | |
5 | #include "include/types.h" | |
6 | #include "include/utime.h" | |
7 | #include "msg/msg_types.h" | |
8 | ||
9 | /* lock flags */ | |
10 | #define LOCK_FLAG_RENEW 0x1 /* idempotent lock acquire */ | |
11 | ||
12 | enum ClsLockType { | |
13 | LOCK_NONE = 0, | |
14 | LOCK_EXCLUSIVE = 1, | |
15 | LOCK_SHARED = 2, | |
16 | }; | |
17 | ||
18 | static inline const char *cls_lock_type_str(ClsLockType type) | |
19 | { | |
20 | switch (type) { | |
21 | case LOCK_NONE: | |
22 | return "none"; | |
23 | case LOCK_EXCLUSIVE: | |
24 | return "exclusive"; | |
25 | case LOCK_SHARED: | |
26 | return "shared"; | |
27 | default: | |
28 | return "<unknown>"; | |
29 | } | |
30 | } | |
31 | ||
32 | namespace rados { | |
33 | namespace cls { | |
34 | namespace lock { | |
35 | ||
36 | /* | |
37 | * locker_id_t: the locker id, needs to be unique in a single lock | |
38 | */ | |
39 | struct locker_id_t { | |
40 | entity_name_t locker; // locker's client name | |
41 | string cookie; // locker's cookie. | |
42 | ||
43 | locker_id_t() {} | |
44 | locker_id_t(entity_name_t& _n, const string& _c) : locker(_n), cookie(_c) {} | |
45 | ||
46 | void encode(bufferlist &bl) const { | |
47 | ENCODE_START(1, 1, bl); | |
48 | ::encode(locker, bl); | |
49 | ::encode(cookie, bl); | |
50 | ENCODE_FINISH(bl); | |
51 | } | |
52 | void decode(bufferlist::iterator &bl) { | |
53 | DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl); | |
54 | ::decode(locker, bl); | |
55 | ::decode(cookie, bl); | |
56 | DECODE_FINISH(bl); | |
57 | } | |
58 | ||
59 | bool operator<(const locker_id_t& rhs) const { | |
60 | if (locker == rhs.locker) | |
61 | return cookie.compare(rhs.cookie) < 0; | |
62 | if (locker < rhs.locker) | |
63 | return true; | |
64 | return false; | |
65 | } | |
66 | void dump(Formatter *f) const; | |
67 | static void generate_test_instances(list<locker_id_t*>& o); | |
68 | }; | |
69 | WRITE_CLASS_ENCODER(rados::cls::lock::locker_id_t) | |
70 | ||
71 | struct locker_info_t | |
72 | { | |
73 | utime_t expiration; // expiration: non-zero means epoch of locker expiration | |
74 | entity_addr_t addr; // addr: locker address | |
75 | string description; // description: locker description, may be empty | |
76 | ||
77 | locker_info_t() {} | |
78 | locker_info_t(const utime_t& _e, const entity_addr_t& _a, | |
79 | const string& _d) : expiration(_e), addr(_a), description(_d) {} | |
80 | ||
81 | void encode(bufferlist &bl, uint64_t features) const { | |
82 | ENCODE_START(1, 1, bl); | |
83 | ::encode(expiration, bl); | |
84 | ::encode(addr, bl, features); | |
85 | ::encode(description, bl); | |
86 | ENCODE_FINISH(bl); | |
87 | } | |
88 | void decode(bufferlist::iterator &bl) { | |
89 | DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl); | |
90 | ::decode(expiration, bl); | |
91 | ::decode(addr, bl); | |
92 | ::decode(description, bl); | |
93 | DECODE_FINISH(bl); | |
94 | } | |
95 | void dump(Formatter *f) const; | |
96 | static void generate_test_instances(list<locker_info_t *>& o); | |
97 | }; | |
98 | WRITE_CLASS_ENCODER_FEATURES(rados::cls::lock::locker_info_t) | |
224ce89b WB |
99 | |
100 | struct lock_info_t { | |
101 | map<locker_id_t, locker_info_t> lockers; // map of lockers | |
102 | ClsLockType lock_type; // lock type (exclusive / shared) | |
103 | string tag; // tag: operations on lock can only succeed with this tag | |
104 | // as long as set of non expired lockers | |
105 | // is bigger than 0. | |
106 | ||
107 | void encode(bufferlist &bl, uint64_t features) const { | |
108 | ENCODE_START(1, 1, bl); | |
109 | ::encode(lockers, bl, features); | |
110 | uint8_t t = (uint8_t)lock_type; | |
111 | ::encode(t, bl); | |
112 | ::encode(tag, bl); | |
113 | ENCODE_FINISH(bl); | |
114 | } | |
115 | void decode(bufferlist::iterator &bl) { | |
116 | DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl); | |
117 | ::decode(lockers, bl); | |
118 | uint8_t t; | |
119 | ::decode(t, bl); | |
120 | lock_type = (ClsLockType)t; | |
121 | ::decode(tag, bl); | |
122 | DECODE_FINISH(bl); | |
123 | } | |
124 | lock_info_t() : lock_type(LOCK_NONE) {} | |
125 | void dump(Formatter *f) const; | |
126 | static void generate_test_instances(list<lock_info_t *>& o); | |
127 | }; | |
128 | WRITE_CLASS_ENCODER_FEATURES(rados::cls::lock::lock_info_t) | |
7c673cae FG |
129 | } |
130 | } | |
131 | } | |
132 | WRITE_CLASS_ENCODER_FEATURES(rados::cls::lock::locker_info_t) | |
133 | WRITE_CLASS_ENCODER(rados::cls::lock::locker_id_t) | |
224ce89b | 134 | WRITE_CLASS_ENCODER_FEATURES(rados::cls::lock::lock_info_t) |
7c673cae FG |
135 | |
136 | #endif |