]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/radosstriper/libradosstriper.hpp
import 15.2.0 Octopus source
[ceph.git] / ceph / src / include / radosstriper / libradosstriper.hpp
1 #ifndef __LIBRADOSSTRIPER_HPP
2 #define __LIBRADOSSTRIPER_HPP
3
4 #include <string.h>
5 #include <string>
6 #include <map>
7 #include "../rados/buffer.h"
8 #include "../rados/librados.hpp"
9
10 #include "libradosstriper.h"
11
12 namespace libradosstriper
13 {
14 struct RadosStriperImpl;
15 struct MultiAioCompletionImpl;
16
17 /*
18 * Completion object for multiple asynchronous IO
19 * It allows to internally handle several "requests"
20 */
21 struct MultiAioCompletion {
22 MultiAioCompletion(MultiAioCompletionImpl *pc_) : pc(pc_) {}
23 ~MultiAioCompletion();
24 int set_complete_callback(void *cb_arg, librados::callback_t cb);
25 int set_safe_callback(void *cb_arg, librados::callback_t cb) __attribute__ ((deprecated));
26 void wait_for_complete();
27 void wait_for_safe() __attribute__ ((deprecated));
28 void wait_for_complete_and_cb();
29 void wait_for_safe_and_cb() __attribute__ ((deprecated));
30 bool is_complete();
31 bool is_safe() __attribute__ ((deprecated));
32 bool is_complete_and_cb();
33 bool is_safe_and_cb() __attribute__ ((deprecated));
34 int get_return_value();
35 void release();
36 MultiAioCompletionImpl *pc;
37 };
38
39 /* RadosStriper : This class allows to perform read/writes on striped objects
40 *
41 * Typical use (error checking omitted):
42 *
43 * RadosStriper rs;
44 * RadosStriper.striper_create("my_cluster", rs);
45 * bufferlist bl;
46 * ... put data in bl ...
47 * rs.write(object_name, bl, len, offset);
48 * bufferlist bl2;
49 * rs.read(object_name, &bl2, len, offset);
50 * ...
51 */
52 class RadosStriper
53 {
54 public:
55
56 /*
57 * constructor
58 */
59 RadosStriper();
60
61 /*
62 * builds the C counter part of a RadosStriper
63 */
64 static void to_rados_striper_t(RadosStriper &striper,
65 rados_striper_t *s);
66
67 /*
68 * copy constructor
69 */
70 RadosStriper(const RadosStriper& rs);
71
72 /*
73 * operator=
74 */
75 RadosStriper& operator=(const RadosStriper& rs);
76
77 /*
78 * destructor
79 * Internally calling close() if an object is currently opened
80 */
81 ~RadosStriper();
82
83 /*
84 * create method
85 */
86 static int striper_create(librados::IoCtx& ioctx,
87 RadosStriper *striper);
88
89 /*
90 * set object layout's stripe unit
91 * This layout will be used when new objects are created (by writing to them)
92 * Already existing objects will be opened with their own layout.
93 */
94 int set_object_layout_stripe_unit(unsigned int stripe_unit);
95
96 /*
97 * set object layout's stripe count
98 * This layout will be used when new objects are created (by writing to them)
99 * Already existing objects will be opened with their own layout.
100 */
101 int set_object_layout_stripe_count(unsigned int stripe_count);
102
103 /*
104 * set object layout's object size
105 * This layout will be used when new objects are created (by writing to them)
106 * Already existing objects will be opened with their own layout.
107 */
108 int set_object_layout_object_size(unsigned int object_size);
109
110 /**
111 * Get the value of an extended attribute on a striped object
112 */
113 int getxattr(const std::string& oid, const char *name, ceph::bufferlist& bl);
114
115 /**
116 * Set the value of an extended attribute on a striped object
117 */
118 int setxattr(const std::string& oid, const char *name, ceph::bufferlist& bl);
119
120 /**
121 * Delete an extended attribute from a striped object
122 */
123 int rmxattr(const std::string& oid, const char *name);
124
125 /**
126 * Start iterating over xattrs on a striped object.
127 */
128 int getxattrs(const std::string& oid,
129 std::map<std::string, ceph::bufferlist>& attrset);
130
131 /**
132 * synchronously write to the striped object at the specified offset.
133 * NOTE: this call steals the contents of @param bl.
134 */
135 int write(const std::string& soid, const ceph::bufferlist& bl, size_t len, uint64_t off);
136
137 /**
138 * synchronously fill the striped object with the specified data
139 * NOTE: this call steals the contents of @param bl.
140 */
141 int write_full(const std::string& soid, const ceph::bufferlist& bl);
142
143 /**
144 * synchronously append data to the striped object
145 * NOTE: this call steals the contents of @p bl.
146 */
147 int append(const std::string& soid, const ceph::bufferlist& bl, size_t len);
148
149 /**
150 * asynchronously write to the striped object at the specified offset.
151 * NOTE: this call steals the contents of @p bl.
152 */
153 int aio_write(const std::string& soid, librados::AioCompletion *c, const ceph::bufferlist& bl, size_t len, uint64_t off);
154
155 /**
156 * asynchronously fill the striped object with the specified data
157 * NOTE: this call steals the contents of @p bl.
158 */
159 int aio_write_full(const std::string& soid, librados::AioCompletion *c, const ceph::bufferlist& bl);
160
161 /**
162 * asynchronously append data to the striped object
163 * NOTE: this call steals the contents of @p bl.
164 */
165 int aio_append(const std::string& soid, librados::AioCompletion *c, const ceph::bufferlist& bl, size_t len);
166
167 /**
168 * synchronously read from the striped object at the specified offset.
169 */
170 int read(const std::string& soid, ceph::bufferlist* pbl, size_t len, uint64_t off);
171
172 /**
173 * asynchronously read from the striped object at the specified offset.
174 */
175 int aio_read(const std::string& soid, librados::AioCompletion *c, ceph::bufferlist *pbl, size_t len, uint64_t off);
176
177 /**
178 * synchronously get striped object stats (size/mtime)
179 */
180 int stat(const std::string& soid, uint64_t *psize, time_t *pmtime);
181 int stat2(const std::string& soid, uint64_t *psize, struct timespec *pts);
182
183 /**
184 * asynchronously get striped object stats (size/mtime)
185 */
186 int aio_stat(const std::string& soid, librados::AioCompletion *c,
187 uint64_t *psize, time_t *pmtime);
188 int aio_stat2(const std::string& soid, librados::AioCompletion *c,
189 uint64_t *psize, struct timespec *pts);
190
191 /**
192 * deletes a striped object.
193 * There is no atomicity of the deletion and the striped
194 * object may be left incomplete if an error is returned (metadata
195 * all present, but some stripes missing)
196 * However, there is a atomicity of the metadata deletion and
197 * the deletion can not happen if any I/O is ongoing (it
198 * will return EBUSY). Identically, no I/O will be able to start
199 * during deletion (same EBUSY return code)
200 */
201 int remove(const std::string& soid);
202 int remove(const std::string& soid, int flags);
203
204 /**
205 * asynchronous remove of striped objects
206 * See synchronous version for comments on (lack of) atomicity
207 */
208 int aio_remove(const std::string& soid, librados::AioCompletion *c);
209 int aio_remove(const std::string& soid, librados::AioCompletion *c, int flags);
210
211 /**
212 * Resizes a striped object
213 * the truncation can not happen if any I/O is ongoing (it
214 * will return EBUSY). Identically, no I/O will be able to start
215 * during truncation (same EBUSY return code)
216 */
217 int trunc(const std::string& oid, uint64_t size);
218
219 /**
220 * Wait for all currently pending aio writes to be safe.
221 *
222 * @returns 0 on success, negative error code on failure
223 */
224 int aio_flush();
225
226 /**
227 * creation of multi aio completion objects
228 */
229 static MultiAioCompletion *multi_aio_create_completion();
230 static MultiAioCompletion *multi_aio_create_completion(void *cb_arg,
231 librados::callback_t cb_complete,
232 librados::callback_t cb_safe);
233
234 private:
235 RadosStriperImpl *rados_striper_impl;
236
237 };
238
239 }
240
241 #endif