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