]>
git.proxmox.com Git - ceph.git/blob - ceph/src/cls/lock/cls_lock_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_CLS_LOCK_TYPES_H
5 #define CEPH_CLS_LOCK_TYPES_H
7 #include "include/encoding.h"
8 #include "include/types.h"
9 #include "include/utime.h"
10 #include "msg/msg_types.h"
13 #define LOCK_FLAG_MAY_RENEW 0x1 /* idempotent lock acquire */
14 #define LOCK_FLAG_MUST_RENEW 0x2 /* lock must already be acquired */
20 LOCK_EXCLUSIVE_EPHEMERAL
= 3, /* lock object is removed @ unlock */
23 inline const char *cls_lock_type_str(ClsLockType type
)
32 case LOCK_EXCLUSIVE_EPHEMERAL
:
33 return "exclusive-ephemeral";
39 inline bool cls_lock_is_exclusive(ClsLockType type
) {
40 return LOCK_EXCLUSIVE
== type
|| LOCK_EXCLUSIVE_EPHEMERAL
== type
;
43 inline bool cls_lock_is_ephemeral(ClsLockType type
) {
44 return LOCK_EXCLUSIVE_EPHEMERAL
== type
;
47 inline bool cls_lock_is_valid(ClsLockType type
) {
48 return LOCK_SHARED
== type
||
49 LOCK_EXCLUSIVE
== type
||
50 LOCK_EXCLUSIVE_EPHEMERAL
== type
;
58 * locker_id_t: the locker id, needs to be unique in a single lock
61 entity_name_t locker
; // locker's client name
62 string cookie
; // locker's cookie.
65 locker_id_t(entity_name_t
& _n
, const string
& _c
) : locker(_n
), cookie(_c
) {}
67 void encode(bufferlist
&bl
) const {
68 ENCODE_START(1, 1, bl
);
73 void decode(bufferlist::const_iterator
&bl
) {
74 DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl
);
80 bool operator<(const locker_id_t
& rhs
) const {
81 if (locker
== rhs
.locker
)
82 return cookie
.compare(rhs
.cookie
) < 0;
83 if (locker
< rhs
.locker
)
87 void dump(Formatter
*f
) const;
88 static void generate_test_instances(list
<locker_id_t
*>& o
);
90 WRITE_CLASS_ENCODER(locker_id_t
)
94 utime_t expiration
; // expiration: non-zero means epoch of locker expiration
95 entity_addr_t addr
; // addr: locker address
96 string description
; // description: locker description, may be empty
99 locker_info_t(const utime_t
& _e
, const entity_addr_t
& _a
,
100 const string
& _d
) : expiration(_e
), addr(_a
), description(_d
) {}
102 void encode(bufferlist
&bl
, uint64_t features
) const {
103 ENCODE_START(1, 1, bl
);
104 encode(expiration
, bl
);
105 encode(addr
, bl
, features
);
106 encode(description
, bl
);
109 void decode(bufferlist::const_iterator
&bl
) {
110 DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl
);
111 decode(expiration
, bl
);
113 decode(description
, bl
);
116 void dump(Formatter
*f
) const;
117 static void generate_test_instances(list
<locker_info_t
*>& o
);
119 WRITE_CLASS_ENCODER_FEATURES(locker_info_t
)
122 map
<locker_id_t
, locker_info_t
> lockers
; // map of lockers
123 ClsLockType lock_type
; // lock type (exclusive / shared)
124 string tag
; // tag: operations on lock can only succeed with this tag
125 // as long as set of non expired lockers
128 void encode(bufferlist
&bl
, uint64_t features
) const {
129 ENCODE_START(1, 1, bl
);
130 encode(lockers
, bl
, features
);
131 uint8_t t
= (uint8_t)lock_type
;
136 void decode(bufferlist::const_iterator
&bl
) {
137 DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl
);
141 lock_type
= (ClsLockType
)t
;
145 lock_info_t() : lock_type(LOCK_NONE
) {}
146 void dump(Formatter
*f
) const;
147 static void generate_test_instances(list
<lock_info_t
*>& o
);
149 WRITE_CLASS_ENCODER_FEATURES(lock_info_t
);