]>
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 | #ifndef CEPH_CLS_LOCK_CLIENT_H | |
5 | #define CEPH_CLS_LOCK_CLIENT_H | |
6 | ||
f64942e4 AA |
7 | #include <chrono> |
8 | ||
11fdf7f2 | 9 | #include "include/rados/librados_fwd.hpp" |
7c673cae FG |
10 | #include "cls/lock/cls_lock_types.h" |
11 | ||
7c673cae FG |
12 | namespace rados { |
13 | namespace cls { | |
14 | namespace lock { | |
15 | extern void lock(librados::ObjectWriteOperation *rados_op, | |
16 | const std::string& name, ClsLockType type, | |
17 | const std::string& cookie, const std::string& tag, | |
18 | const std::string& description, const utime_t& duration, | |
19 | uint8_t flags); | |
20 | ||
21 | extern int lock(librados::IoCtx *ioctx, | |
22 | const std::string& oid, | |
23 | const std::string& name, ClsLockType type, | |
24 | const std::string& cookie, const std::string& tag, | |
25 | const std::string& description, const utime_t& duration, | |
26 | uint8_t flags); | |
27 | ||
28 | extern void unlock(librados::ObjectWriteOperation *rados_op, | |
29 | const std::string& name, const std::string& cookie); | |
30 | ||
31 | extern int unlock(librados::IoCtx *ioctx, const std::string& oid, | |
32 | const std::string& name, const std::string& cookie); | |
33 | ||
34 | extern int aio_unlock(librados::IoCtx *ioctx, const std::string& oid, | |
35 | const std::string& name, const std::string& cookie, | |
36 | librados::AioCompletion *completion); | |
37 | ||
38 | extern void break_lock(librados::ObjectWriteOperation *op, | |
39 | const std::string& name, const std::string& cookie, | |
40 | const entity_name_t& locker); | |
41 | ||
42 | extern int break_lock(librados::IoCtx *ioctx, const std::string& oid, | |
43 | const std::string& name, const std::string& cookie, | |
44 | const entity_name_t& locker); | |
45 | ||
46 | extern int list_locks(librados::IoCtx *ioctx, const std::string& oid, | |
47 | list<std::string> *locks); | |
48 | extern void get_lock_info_start(librados::ObjectReadOperation *rados_op, | |
49 | const std::string& name); | |
11fdf7f2 | 50 | extern int get_lock_info_finish(ceph::bufferlist::const_iterator *out, |
7c673cae FG |
51 | map<locker_id_t, locker_info_t> *lockers, |
52 | ClsLockType *type, std::string *tag); | |
53 | ||
54 | extern int get_lock_info(librados::IoCtx *ioctx, const std::string& oid, | |
55 | const std::string& name, | |
56 | map<locker_id_t, locker_info_t> *lockers, | |
57 | ClsLockType *type, std::string *tag); | |
58 | ||
59 | extern void assert_locked(librados::ObjectOperation *rados_op, | |
60 | const std::string& name, ClsLockType type, | |
61 | const std::string& cookie, | |
62 | const std::string& tag); | |
63 | ||
64 | extern void set_cookie(librados::ObjectWriteOperation *rados_op, | |
65 | const std::string& name, ClsLockType type, | |
66 | const std::string& cookie, const std::string& tag, | |
67 | const std::string& new_cookie); | |
68 | ||
69 | class Lock { | |
70 | std::string name; | |
71 | std::string cookie; | |
72 | std::string tag; | |
73 | std::string description; | |
74 | utime_t duration; | |
75 | uint8_t flags; | |
76 | ||
77 | public: | |
78 | ||
79 | Lock(const std::string& _n) : name(_n), flags(0) {} | |
80 | ||
81 | void set_cookie(const std::string& c) { cookie = c; } | |
82 | void set_tag(const std::string& t) { tag = t; } | |
83 | void set_description(const std::string& desc) { description = desc; } | |
84 | void set_duration(const utime_t& e) { duration = e; } | |
f64942e4 | 85 | void set_duration(const ceph::timespan& d) { |
11fdf7f2 | 86 | duration = utime_t(ceph::real_clock::zero() + d); |
f64942e4 AA |
87 | } |
88 | ||
89 | void set_may_renew(bool renew) { | |
7c673cae | 90 | if (renew) { |
f64942e4 AA |
91 | flags |= LOCK_FLAG_MAY_RENEW; |
92 | flags &= ~LOCK_FLAG_MUST_RENEW; // if may then not must | |
7c673cae | 93 | } else { |
f64942e4 AA |
94 | flags &= ~LOCK_FLAG_MAY_RENEW; |
95 | } | |
96 | } | |
97 | ||
98 | void set_must_renew(bool renew) { | |
99 | if (renew) { | |
100 | flags |= LOCK_FLAG_MUST_RENEW; | |
101 | flags &= ~LOCK_FLAG_MAY_RENEW; // if must then not may | |
102 | } else { | |
103 | flags &= ~LOCK_FLAG_MUST_RENEW; | |
7c673cae FG |
104 | } |
105 | } | |
106 | ||
7c673cae | 107 | void assert_locked_shared(librados::ObjectOperation *rados_op); |
f64942e4 AA |
108 | void assert_locked_exclusive(librados::ObjectOperation *rados_op); |
109 | void assert_locked_exclusive_ephemeral(librados::ObjectOperation *rados_op); | |
7c673cae FG |
110 | |
111 | /* ObjectWriteOperation */ | |
7c673cae | 112 | void lock_shared(librados::ObjectWriteOperation *ioctx); |
f64942e4 AA |
113 | void lock_exclusive(librados::ObjectWriteOperation *ioctx); |
114 | ||
115 | // Be careful when using an exclusive ephemeral lock; it is | |
116 | // intended strictly for cases when a lock object exists | |
117 | // solely for a lock in a given process and the object is no | |
118 | // longer needed when the lock is unlocked or expired, as the | |
119 | // cls back-end will make an effort to delete it. | |
120 | void lock_exclusive_ephemeral(librados::ObjectWriteOperation *ioctx); | |
7c673cae | 121 | void unlock(librados::ObjectWriteOperation *ioctx); |
f64942e4 AA |
122 | void break_lock(librados::ObjectWriteOperation *ioctx, |
123 | const entity_name_t& locker); | |
7c673cae FG |
124 | |
125 | /* IoCtx */ | |
7c673cae | 126 | int lock_shared(librados::IoCtx *ioctx, const std::string& oid); |
f64942e4 AA |
127 | int lock_exclusive(librados::IoCtx *ioctx, const std::string& oid); |
128 | ||
129 | // NB: see above comment on exclusive ephemeral locks | |
130 | int lock_exclusive_ephemeral(librados::IoCtx *ioctx, | |
131 | const std::string& oid); | |
7c673cae FG |
132 | int unlock(librados::IoCtx *ioctx, const std::string& oid); |
133 | int break_lock(librados::IoCtx *ioctx, const std::string& oid, | |
134 | const entity_name_t& locker); | |
135 | }; | |
136 | ||
137 | } // namespace lock | |
138 | } // namespace cls | |
139 | } // namespace rados | |
140 | ||
141 | #endif |