]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/lock/cls_lock_client.h
update sources to v12.1.0
[ceph.git] / ceph / src / cls / lock / cls_lock_client.h
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
7 #include "cls/lock/cls_lock_types.h"
8
9 namespace librados {
10 class AioCompletion;
11 class ObjectWriteOperation;
12 class IoCtx;
13 class ObjectReadOperation;
14 class ObjectOperation;
15 }
16
17 namespace rados {
18 namespace cls {
19 namespace lock {
20 extern void lock(librados::ObjectWriteOperation *rados_op,
21 const std::string& name, ClsLockType type,
22 const std::string& cookie, const std::string& tag,
23 const std::string& description, const utime_t& duration,
24 uint8_t flags);
25
26 extern int lock(librados::IoCtx *ioctx,
27 const std::string& oid,
28 const std::string& name, ClsLockType type,
29 const std::string& cookie, const std::string& tag,
30 const std::string& description, const utime_t& duration,
31 uint8_t flags);
32
33 extern void unlock(librados::ObjectWriteOperation *rados_op,
34 const std::string& name, const std::string& cookie);
35
36 extern int unlock(librados::IoCtx *ioctx, const std::string& oid,
37 const std::string& name, const std::string& cookie);
38
39 extern int aio_unlock(librados::IoCtx *ioctx, const std::string& oid,
40 const std::string& name, const std::string& cookie,
41 librados::AioCompletion *completion);
42
43 extern void break_lock(librados::ObjectWriteOperation *op,
44 const std::string& name, const std::string& cookie,
45 const entity_name_t& locker);
46
47 extern int break_lock(librados::IoCtx *ioctx, const std::string& oid,
48 const std::string& name, const std::string& cookie,
49 const entity_name_t& locker);
50
51 extern int list_locks(librados::IoCtx *ioctx, const std::string& oid,
52 list<std::string> *locks);
53 extern void get_lock_info_start(librados::ObjectReadOperation *rados_op,
54 const std::string& name);
55 extern int get_lock_info_finish(ceph::bufferlist::iterator *out,
56 map<locker_id_t, locker_info_t> *lockers,
57 ClsLockType *type, std::string *tag);
58
59 extern int get_lock_info(librados::IoCtx *ioctx, const std::string& oid,
60 const std::string& name,
61 map<locker_id_t, locker_info_t> *lockers,
62 ClsLockType *type, std::string *tag);
63
64 extern void assert_locked(librados::ObjectOperation *rados_op,
65 const std::string& name, ClsLockType type,
66 const std::string& cookie,
67 const std::string& tag);
68
69 extern void set_cookie(librados::ObjectWriteOperation *rados_op,
70 const std::string& name, ClsLockType type,
71 const std::string& cookie, const std::string& tag,
72 const std::string& new_cookie);
73
74 class Lock {
75 std::string name;
76 std::string cookie;
77 std::string tag;
78 std::string description;
79 utime_t duration;
80 uint8_t flags;
81
82 public:
83
84 Lock(const std::string& _n) : name(_n), flags(0) {}
85
86 void set_cookie(const std::string& c) { cookie = c; }
87 void set_tag(const std::string& t) { tag = t; }
88 void set_description(const std::string& desc) { description = desc; }
89 void set_duration(const utime_t& e) { duration = e; }
90 void set_renew(bool renew) {
91 if (renew) {
92 flags |= LOCK_FLAG_RENEW;
93 } else {
94 flags &= ~LOCK_FLAG_RENEW;
95 }
96 }
97
98 void assert_locked_exclusive(librados::ObjectOperation *rados_op);
99 void assert_locked_shared(librados::ObjectOperation *rados_op);
100
101 /* ObjectWriteOperation */
102 void lock_exclusive(librados::ObjectWriteOperation *ioctx);
103 void lock_shared(librados::ObjectWriteOperation *ioctx);
104 void unlock(librados::ObjectWriteOperation *ioctx);
105 void break_lock(librados::ObjectWriteOperation *ioctx, const entity_name_t& locker);
106
107 /* IoCtx */
108 int lock_exclusive(librados::IoCtx *ioctx, const std::string& oid);
109 int lock_shared(librados::IoCtx *ioctx, const std::string& oid);
110 int unlock(librados::IoCtx *ioctx, const std::string& oid);
111 int break_lock(librados::IoCtx *ioctx, const std::string& oid,
112 const entity_name_t& locker);
113 };
114
115 } // namespace lock
116 } // namespace cls
117 } // namespace rados
118
119 #endif