]> git.proxmox.com Git - ceph.git/blame - ceph/src/include/rbd/librbd.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / include / rbd / librbd.hpp
CommitLineData
11fdf7f2 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
7c673cae
FG
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#ifndef __LIBRBD_HPP
16#define __LIBRBD_HPP
17
7c673cae
FG
18#include <string>
19#include <list>
20#include <map>
21#include <vector>
22#include "../rados/buffer.h"
23#include "../rados/librados.hpp"
24#include "librbd.h"
25
26namespace librbd {
27
28 using librados::IoCtx;
29
30 class Image;
31 class ImageOptions;
11fdf7f2 32 class PoolStats;
7c673cae
FG
33 typedef void *image_ctx_t;
34 typedef void *completion_t;
35 typedef void (*callback_t)(completion_t cb, void *arg);
36
11fdf7f2
TL
37 typedef struct {
38 std::string id;
39 std::string name;
40 } image_spec_t;
41
42 typedef struct {
43 int64_t pool_id;
44 std::string pool_name;
45 std::string pool_namespace;
46 std::string image_id;
47 std::string image_name;
48 bool trash;
49 } linked_image_spec_t;
50
51 typedef rbd_snap_namespace_type_t snap_namespace_type_t;
52
53 typedef struct {
54 uint64_t id;
55 snap_namespace_type_t namespace_type;
56 std::string name;
57 } snap_spec_t;
58
7c673cae
FG
59 typedef struct {
60 uint64_t id;
61 uint64_t size;
62 std::string name;
63 } snap_info_t;
64
11fdf7f2
TL
65 typedef struct {
66 int64_t group_pool;
67 std::string group_name;
68 std::string group_snap_name;
69 } snap_group_namespace_t;
70
7c673cae
FG
71 typedef struct {
72 std::string client;
73 std::string cookie;
74 std::string address;
75 } locker_t;
76
77 typedef struct {
78 std::string uuid;
79 std::string cluster_name;
80 std::string client_name;
81 } mirror_peer_t;
82
83 typedef rbd_mirror_image_state_t mirror_image_state_t;
84
85 typedef struct {
86 std::string global_id;
87 mirror_image_state_t state;
88 bool primary;
89 } mirror_image_info_t;
90
91 typedef rbd_mirror_image_status_state_t mirror_image_status_state_t;
92
93 typedef struct {
94 std::string name;
95 mirror_image_info_t info;
96 mirror_image_status_state_t state;
97 std::string description;
98 time_t last_update;
99 bool up;
100 } mirror_image_status_t;
101
11fdf7f2
TL
102 typedef rbd_group_image_state_t group_image_state_t;
103
104 typedef struct {
105 std::string name;
106 int64_t pool;
107 group_image_state_t state;
108 } group_image_info_t;
109
110 typedef struct {
111 std::string name;
112 int64_t pool;
113 } group_info_t;
114
115 typedef rbd_group_snap_state_t group_snap_state_t;
116
117 typedef struct {
118 std::string name;
119 group_snap_state_t state;
120 } group_snap_info_t;
121
7c673cae
FG
122 typedef rbd_image_info_t image_info_t;
123
124 class CEPH_RBD_API ProgressContext
125 {
126 public:
127 virtual ~ProgressContext();
128 virtual int update_progress(uint64_t offset, uint64_t total) = 0;
129 };
130
131 typedef struct {
132 std::string id;
133 std::string name;
134 rbd_trash_image_source_t source;
135 time_t deletion_time;
136 time_t deferment_end_time;
137 } trash_image_info_t;
138
11fdf7f2
TL
139 typedef struct {
140 std::string pool_name;
141 std::string image_name;
142 std::string image_id;
143 bool trash;
144 } child_info_t;
145
146 typedef struct {
147 std::string addr;
148 int64_t id;
149 uint64_t cookie;
150 } image_watcher_t;
151
152 typedef rbd_image_migration_state_t image_migration_state_t;
153
154 typedef struct {
155 int64_t source_pool_id;
156 std::string source_pool_namespace;
157 std::string source_image_name;
158 std::string source_image_id;
159 int64_t dest_pool_id;
160 std::string dest_pool_namespace;
161 std::string dest_image_name;
162 std::string dest_image_id;
163 image_migration_state_t state;
164 std::string state_description;
165 } image_migration_status_t;
166
167 typedef rbd_config_source_t config_source_t;
168
169 typedef struct {
170 std::string name;
171 std::string value;
172 config_source_t source;
173 } config_option_t;
174
7c673cae
FG
175class CEPH_RBD_API RBD
176{
177public:
178 RBD();
179 ~RBD();
180
181 // This must be dynamically allocated with new, and
182 // must be released with release().
183 // Do not use delete.
184 struct AioCompletion {
185 void *pc;
186 AioCompletion(void *cb_arg, callback_t complete_cb);
187 bool is_complete();
188 int wait_for_complete();
189 ssize_t get_return_value();
190 void *get_arg();
191 void release();
192 };
193
194 void version(int *major, int *minor, int *extra);
195
196 int open(IoCtx& io_ctx, Image& image, const char *name);
197 int open(IoCtx& io_ctx, Image& image, const char *name, const char *snapname);
198 int open_by_id(IoCtx& io_ctx, Image& image, const char *id);
199 int open_by_id(IoCtx& io_ctx, Image& image, const char *id, const char *snapname);
200 int aio_open(IoCtx& io_ctx, Image& image, const char *name,
201 const char *snapname, RBD::AioCompletion *c);
202 int aio_open_by_id(IoCtx& io_ctx, Image& image, const char *id,
203 const char *snapname, RBD::AioCompletion *c);
204 // see librbd.h
205 int open_read_only(IoCtx& io_ctx, Image& image, const char *name,
206 const char *snapname);
207 int open_by_id_read_only(IoCtx& io_ctx, Image& image, const char *id,
208 const char *snapname);
209 int aio_open_read_only(IoCtx& io_ctx, Image& image, const char *name,
210 const char *snapname, RBD::AioCompletion *c);
211 int aio_open_by_id_read_only(IoCtx& io_ctx, Image& image, const char *id,
212 const char *snapname, RBD::AioCompletion *c);
11fdf7f2
TL
213
214 int list(IoCtx& io_ctx, std::vector<std::string>& names)
215 __attribute__((deprecated));
216 int list2(IoCtx& io_ctx, std::vector<image_spec_t>* images);
217
7c673cae
FG
218 int create(IoCtx& io_ctx, const char *name, uint64_t size, int *order);
219 int create2(IoCtx& io_ctx, const char *name, uint64_t size,
220 uint64_t features, int *order);
221 int create3(IoCtx& io_ctx, const char *name, uint64_t size,
222 uint64_t features, int *order,
223 uint64_t stripe_unit, uint64_t stripe_count);
224 int create4(IoCtx& io_ctx, const char *name, uint64_t size,
225 ImageOptions& opts);
226 int clone(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
227 IoCtx& c_ioctx, const char *c_name, uint64_t features,
228 int *c_order);
229 int clone2(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
230 IoCtx& c_ioctx, const char *c_name, uint64_t features,
231 int *c_order, uint64_t stripe_unit, int stripe_count);
232 int clone3(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
233 IoCtx& c_ioctx, const char *c_name, ImageOptions& opts);
234 int remove(IoCtx& io_ctx, const char *name);
235 int remove_with_progress(IoCtx& io_ctx, const char *name, ProgressContext& pctx);
236 int rename(IoCtx& src_io_ctx, const char *srcname, const char *destname);
237
238 int trash_move(IoCtx &io_ctx, const char *name, uint64_t delay);
239 int trash_get(IoCtx &io_ctx, const char *id, trash_image_info_t *info);
240 int trash_list(IoCtx &io_ctx, std::vector<trash_image_info_t> &entries);
11fdf7f2
TL
241 int trash_purge(IoCtx &io_ctx, time_t expire_ts, float threshold);
242 int trash_purge_with_progress(IoCtx &io_ctx, time_t expire_ts, float threshold,
243 ProgressContext &pctx);
7c673cae
FG
244 int trash_remove(IoCtx &io_ctx, const char *image_id, bool force);
245 int trash_remove_with_progress(IoCtx &io_ctx, const char *image_id,
246 bool force, ProgressContext &pctx);
247 int trash_restore(IoCtx &io_ctx, const char *id, const char *name);
248
11fdf7f2
TL
249 // Migration
250 int migration_prepare(IoCtx& io_ctx, const char *image_name,
251 IoCtx& dest_io_ctx, const char *dest_image_name,
252 ImageOptions& opts);
253 int migration_execute(IoCtx& io_ctx, const char *image_name);
254 int migration_execute_with_progress(IoCtx& io_ctx, const char *image_name,
255 ProgressContext &prog_ctx);
256 int migration_abort(IoCtx& io_ctx, const char *image_name);
257 int migration_abort_with_progress(IoCtx& io_ctx, const char *image_name,
258 ProgressContext &prog_ctx);
259 int migration_commit(IoCtx& io_ctx, const char *image_name);
260 int migration_commit_with_progress(IoCtx& io_ctx, const char *image_name,
261 ProgressContext &prog_ctx);
262 int migration_status(IoCtx& io_ctx, const char *image_name,
263 image_migration_status_t *status, size_t status_size);
264
7c673cae
FG
265 // RBD pool mirroring support functions
266 int mirror_mode_get(IoCtx& io_ctx, rbd_mirror_mode_t *mirror_mode);
267 int mirror_mode_set(IoCtx& io_ctx, rbd_mirror_mode_t mirror_mode);
268 int mirror_peer_add(IoCtx& io_ctx, std::string *uuid,
269 const std::string &cluster_name,
270 const std::string &client_name);
271 int mirror_peer_remove(IoCtx& io_ctx, const std::string &uuid);
272 int mirror_peer_list(IoCtx& io_ctx, std::vector<mirror_peer_t> *peers);
273 int mirror_peer_set_client(IoCtx& io_ctx, const std::string &uuid,
274 const std::string &client_name);
275 int mirror_peer_set_cluster(IoCtx& io_ctx, const std::string &uuid,
276 const std::string &cluster_name);
11fdf7f2
TL
277 int mirror_peer_get_attributes(
278 IoCtx& io_ctx, const std::string &uuid,
279 std::map<std::string, std::string> *key_vals);
280 int mirror_peer_set_attributes(
281 IoCtx& io_ctx, const std::string &uuid,
282 const std::map<std::string, std::string>& key_vals);
283
7c673cae
FG
284 int mirror_image_status_list(IoCtx& io_ctx, const std::string &start_id,
285 size_t max, std::map<std::string, mirror_image_status_t> *images);
286 int mirror_image_status_summary(IoCtx& io_ctx,
287 std::map<mirror_image_status_state_t, int> *states);
11fdf7f2
TL
288 int mirror_image_instance_id_list(IoCtx& io_ctx, const std::string &start_id,
289 size_t max, std::map<std::string, std::string> *sevice_ids);
290
291 // RBD groups support functions
292 int group_create(IoCtx& io_ctx, const char *group_name);
293 int group_remove(IoCtx& io_ctx, const char *group_name);
294 int group_list(IoCtx& io_ctx, std::vector<std::string> *names);
295 int group_rename(IoCtx& io_ctx, const char *src_group_name,
296 const char *dest_group_name);
297
298 int group_image_add(IoCtx& io_ctx, const char *group_name,
299 IoCtx& image_io_ctx, const char *image_name);
300 int group_image_remove(IoCtx& io_ctx, const char *group_name,
301 IoCtx& image_io_ctx, const char *image_name);
302 int group_image_remove_by_id(IoCtx& io_ctx, const char *group_name,
303 IoCtx& image_io_ctx, const char *image_id);
304 int group_image_list(IoCtx& io_ctx, const char *group_name,
305 std::vector<group_image_info_t> *images,
306 size_t group_image_info_size);
307
308 int group_snap_create(IoCtx& io_ctx, const char *group_name,
309 const char *snap_name);
310 int group_snap_remove(IoCtx& io_ctx, const char *group_name,
311 const char *snap_name);
312 int group_snap_rename(IoCtx& group_ioctx, const char *group_name,
313 const char *old_snap_name, const char *new_snap_name);
314 int group_snap_list(IoCtx& group_ioctx, const char *group_name,
315 std::vector<group_snap_info_t> *snaps,
316 size_t group_snap_info_size);
317 int group_snap_rollback(IoCtx& io_ctx, const char *group_name,
318 const char *snap_name);
319 int group_snap_rollback_with_progress(IoCtx& io_ctx, const char *group_name,
320 const char *snap_name,
321 ProgressContext& pctx);
322
323 int namespace_create(IoCtx& ioctx, const char *namespace_name);
324 int namespace_remove(IoCtx& ioctx, const char *namespace_name);
325 int namespace_list(IoCtx& io_ctx, std::vector<std::string>* namespace_names);
326 int namespace_exists(IoCtx& io_ctx, const char *namespace_name, bool *exists);
327
328 int pool_init(IoCtx& io_ctx, bool force);
329 int pool_stats_get(IoCtx& io_ctx, PoolStats *pool_stats);
330
331 int pool_metadata_get(IoCtx &io_ctx, const std::string &key,
332 std::string *value);
333 int pool_metadata_set(IoCtx &io_ctx, const std::string &key,
334 const std::string &value);
335 int pool_metadata_remove(IoCtx &io_ctx, const std::string &key);
336 int pool_metadata_list(IoCtx &io_ctx, const std::string &start, uint64_t max,
337 std::map<std::string, ceph::bufferlist> *pairs);
338
339 int config_list(IoCtx& io_ctx, std::vector<config_option_t> *options);
7c673cae 340
7c673cae
FG
341private:
342 /* We don't allow assignment or copying */
343 RBD(const RBD& rhs);
344 const RBD& operator=(const RBD& rhs);
345};
346
347class CEPH_RBD_API ImageOptions {
348public:
349 ImageOptions();
350 ImageOptions(rbd_image_options_t opts);
351 ImageOptions(const ImageOptions &imgopts);
352 ~ImageOptions();
353
354 int set(int optname, const std::string& optval);
355 int set(int optname, uint64_t optval);
356 int get(int optname, std::string* optval) const;
357 int get(int optname, uint64_t* optval) const;
358 int is_set(int optname, bool* is_set);
359 int unset(int optname);
360 void clear();
361 bool empty() const;
362
363private:
364 friend class RBD;
365 friend class Image;
366
367 rbd_image_options_t opts;
368};
369
11fdf7f2
TL
370class CEPH_RBD_API PoolStats {
371public:
372 PoolStats();
373 ~PoolStats();
374
375 PoolStats(const PoolStats&) = delete;
376 PoolStats& operator=(const PoolStats&) = delete;
377
378 int add(rbd_pool_stat_option_t option, uint64_t* opt_val);
379
380private:
381 friend class RBD;
382
383 rbd_pool_stats_t pool_stats;
384};
385
7c673cae
FG
386class CEPH_RBD_API UpdateWatchCtx {
387public:
388 virtual ~UpdateWatchCtx() {}
389 /**
390 * Callback activated when we receive a notify event.
391 */
392 virtual void handle_notify() = 0;
393};
394
395class CEPH_RBD_API Image
396{
397public:
398 Image();
399 ~Image();
400
401 int close();
402 int aio_close(RBD::AioCompletion *c);
403
404 int resize(uint64_t size);
405 int resize2(uint64_t size, bool allow_shrink, ProgressContext& pctx);
406 int resize_with_progress(uint64_t size, ProgressContext& pctx);
407 int stat(image_info_t &info, size_t infosize);
11fdf7f2 408 int get_name(std::string *name);
7c673cae
FG
409 int get_id(std::string *id);
410 std::string get_block_name_prefix();
411 int64_t get_data_pool_id();
412 int parent_info(std::string *parent_poolname, std::string *parent_name,
11fdf7f2
TL
413 std::string *parent_snapname)
414 __attribute__((deprecated));
7c673cae 415 int parent_info2(std::string *parent_poolname, std::string *parent_name,
11fdf7f2
TL
416 std::string *parent_id, std::string *parent_snapname)
417 __attribute__((deprecated));
418 int get_parent(linked_image_spec_t *parent_image, snap_spec_t *parent_snap);
419
7c673cae
FG
420 int old_format(uint8_t *old);
421 int size(uint64_t *size);
11fdf7f2 422 int get_group(group_info_t *group_info, size_t group_info_size);
7c673cae
FG
423 int features(uint64_t *features);
424 int update_features(uint64_t features, bool enabled);
11fdf7f2 425 int get_op_features(uint64_t *op_features);
7c673cae
FG
426 int overlap(uint64_t *overlap);
427 int get_flags(uint64_t *flags);
428 int set_image_notification(int fd, int type);
429
430 /* exclusive lock feature */
431 int is_exclusive_lock_owner(bool *is_owner);
432 int lock_acquire(rbd_lock_mode_t lock_mode);
433 int lock_release();
434 int lock_get_owners(rbd_lock_mode_t *lock_mode,
435 std::list<std::string> *lock_owners);
436 int lock_break(rbd_lock_mode_t lock_mode, const std::string &lock_owner);
437
438 /* object map feature */
439 int rebuild_object_map(ProgressContext &prog_ctx);
440
441 int check_object_map(ProgressContext &prog_ctx);
442
443 int copy(IoCtx& dest_io_ctx, const char *destname);
444 int copy2(Image& dest);
445 int copy3(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts);
446 int copy4(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts,
447 size_t sparse_size);
448 int copy_with_progress(IoCtx& dest_io_ctx, const char *destname,
449 ProgressContext &prog_ctx);
450 int copy_with_progress2(Image& dest, ProgressContext &prog_ctx);
451 int copy_with_progress3(IoCtx& dest_io_ctx, const char *destname,
452 ImageOptions& opts, ProgressContext &prog_ctx);
453 int copy_with_progress4(IoCtx& dest_io_ctx, const char *destname,
454 ImageOptions& opts, ProgressContext &prog_ctx,
455 size_t sparse_size);
456
11fdf7f2
TL
457 /* deep copy */
458 int deep_copy(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts);
459 int deep_copy_with_progress(IoCtx& dest_io_ctx, const char *destname,
460 ImageOptions& opts, ProgressContext &prog_ctx);
461
7c673cae
FG
462 /* striping */
463 uint64_t get_stripe_unit() const;
464 uint64_t get_stripe_count() const;
465
31f18b77 466 int get_create_timestamp(struct timespec *timestamp);
11fdf7f2
TL
467 int get_access_timestamp(struct timespec *timestamp);
468 int get_modify_timestamp(struct timespec *timestamp);
31f18b77 469
7c673cae
FG
470 int flatten();
471 int flatten_with_progress(ProgressContext &prog_ctx);
11fdf7f2
TL
472
473 int sparsify(size_t sparse_size);
474 int sparsify_with_progress(size_t sparse_size, ProgressContext &prog_ctx);
7c673cae
FG
475 /**
476 * Returns a pair of poolname, imagename for each clone
477 * of this image at the currently set snapshot.
478 */
11fdf7f2
TL
479 int list_children(std::set<std::pair<std::string, std::string> > *children)
480 __attribute__((deprecated));
481 /**
482 * Returns a structure of poolname, imagename, imageid and trash flag
483 * for each clone of this image at the currently set snapshot.
484 */
485 int list_children2(std::vector<librbd::child_info_t> *children)
486 __attribute__((deprecated));
487 int list_children3(std::vector<linked_image_spec_t> *images);
488 int list_descendants(std::vector<linked_image_spec_t> *images);
7c673cae
FG
489
490 /* advisory locking (see librbd.h for details) */
491 int list_lockers(std::list<locker_t> *lockers,
492 bool *exclusive, std::string *tag);
493 int lock_exclusive(const std::string& cookie);
494 int lock_shared(const std::string& cookie, const std::string& tag);
495 int unlock(const std::string& cookie);
496 int break_lock(const std::string& client, const std::string& cookie);
497
498 /* snapshots */
499 int snap_list(std::vector<snap_info_t>& snaps);
500 /* DEPRECATED; use snap_exists2 */
501 bool snap_exists(const char *snapname) __attribute__ ((deprecated));
502 int snap_exists2(const char *snapname, bool *exists);
503 int snap_create(const char *snapname);
504 int snap_remove(const char *snapname);
505 int snap_remove2(const char *snapname, uint32_t flags, ProgressContext& pctx);
11fdf7f2 506 int snap_remove_by_id(uint64_t snap_id);
7c673cae
FG
507 int snap_rollback(const char *snap_name);
508 int snap_rollback_with_progress(const char *snap_name, ProgressContext& pctx);
509 int snap_protect(const char *snap_name);
510 int snap_unprotect(const char *snap_name);
511 int snap_is_protected(const char *snap_name, bool *is_protected);
512 int snap_set(const char *snap_name);
11fdf7f2 513 int snap_set_by_id(uint64_t snap_id);
7c673cae
FG
514 int snap_rename(const char *srcname, const char *dstname);
515 int snap_get_limit(uint64_t *limit);
516 int snap_set_limit(uint64_t limit);
517 int snap_get_timestamp(uint64_t snap_id, struct timespec *timestamp);
11fdf7f2
TL
518 int snap_get_namespace_type(uint64_t snap_id,
519 snap_namespace_type_t *namespace_type);
520 int snap_get_group_namespace(uint64_t snap_id,
521 snap_group_namespace_t *group_namespace,
522 size_t snap_group_namespace_size);
523 int snap_get_trash_namespace(uint64_t snap_id, std::string* original_name);
7c673cae
FG
524
525 /* I/O */
526 ssize_t read(uint64_t ofs, size_t len, ceph::bufferlist& bl);
527 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
528 ssize_t read2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags);
529 int64_t read_iterate(uint64_t ofs, size_t len,
530 int (*cb)(uint64_t, size_t, const char *, void *), void *arg);
531 int read_iterate2(uint64_t ofs, uint64_t len,
532 int (*cb)(uint64_t, size_t, const char *, void *), void *arg);
533 /**
534 * get difference between two versions of an image
535 *
536 * This will return the differences between two versions of an image
537 * via a callback, which gets the offset and length and a flag
538 * indicating whether the extent exists (1), or is known/defined to
539 * be zeros (a hole, 0). If the source snapshot name is NULL, we
540 * interpret that as the beginning of time and return all allocated
541 * regions of the image. The end version is whatever is currently
542 * selected for the image handle (either a snapshot or the writeable
543 * head).
544 *
545 * @param fromsnapname start snapshot name, or NULL
546 * @param ofs start offset
547 * @param len len in bytes of region to report on
548 * @param include_parent true if full history diff should include parent
549 * @param whole_object 1 if diff extents should cover whole object
550 * @param cb callback to call for each allocated region
551 * @param arg argument to pass to the callback
552 * @returns 0 on success, or negative error code on error
553 */
554 int diff_iterate(const char *fromsnapname,
555 uint64_t ofs, uint64_t len,
556 int (*cb)(uint64_t, size_t, int, void *), void *arg);
557 int diff_iterate2(const char *fromsnapname,
558 uint64_t ofs, uint64_t len,
559 bool include_parent, bool whole_object,
560 int (*cb)(uint64_t, size_t, int, void *), void *arg);
561
562 ssize_t write(uint64_t ofs, size_t len, ceph::bufferlist& bl);
563 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
564 ssize_t write2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags);
565 int discard(uint64_t ofs, uint64_t len);
566 ssize_t writesame(uint64_t ofs, size_t len, ceph::bufferlist &bl, int op_flags);
c07f9fc5
FG
567 ssize_t compare_and_write(uint64_t ofs, size_t len, ceph::bufferlist &cmp_bl,
568 ceph::bufferlist& bl, uint64_t *mismatch_off, int op_flags);
7c673cae
FG
569
570 int aio_write(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
571 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
572 int aio_write2(uint64_t off, size_t len, ceph::bufferlist& bl,
573 RBD::AioCompletion *c, int op_flags);
574 int aio_writesame(uint64_t off, size_t len, ceph::bufferlist& bl,
575 RBD::AioCompletion *c, int op_flags);
c07f9fc5
FG
576 int aio_compare_and_write(uint64_t off, size_t len, ceph::bufferlist& cmp_bl,
577 ceph::bufferlist& bl, RBD::AioCompletion *c,
578 uint64_t *mismatch_off, int op_flags);
7c673cae
FG
579 /**
580 * read async from image
581 *
582 * The target bufferlist is populated with references to buffers
583 * that contain the data for the given extent of the image.
584 *
585 * NOTE: If caching is enabled, the bufferlist will directly
586 * reference buffers in the cache to avoid an unnecessary data copy.
587 * As a result, if the user intends to modify the buffer contents
588 * directly, they should make a copy first (unconditionally, or when
589 * the reference count on ther underlying buffer is more than 1).
590 *
591 * @param off offset in image
592 * @param len length of read
593 * @param bl bufferlist to read into
594 * @param c aio completion to notify when read is complete
595 */
596 int aio_read(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
597 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
598 int aio_read2(uint64_t off, size_t len, ceph::bufferlist& bl,
599 RBD::AioCompletion *c, int op_flags);
600 int aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c);
601
602 int flush();
603 /**
604 * Start a flush if caching is enabled. Get a callback when
605 * the currently pending writes are on disk.
606 *
607 * @param image the image to flush writes to
608 * @param c what to call when flushing is complete
609 * @returns 0 on success, negative error code on failure
610 */
611 int aio_flush(RBD::AioCompletion *c);
612
613 /**
614 * Drop any cached data for this image
615 *
616 * @returns 0 on success, negative error code on failure
617 */
618 int invalidate_cache();
619
620 int poll_io_events(RBD::AioCompletion **comps, int numcomp);
621
622 int metadata_get(const std::string &key, std::string *value);
623 int metadata_set(const std::string &key, const std::string &value);
624 int metadata_remove(const std::string &key);
625 /**
626 * Returns a pair of key/value for this image
627 */
628 int metadata_list(const std::string &start, uint64_t max, std::map<std::string, ceph::bufferlist> *pairs);
629
630 // RBD image mirroring support functions
631 int mirror_image_enable();
632 int mirror_image_disable(bool force);
633 int mirror_image_promote(bool force);
634 int mirror_image_demote();
635 int mirror_image_resync();
636 int mirror_image_get_info(mirror_image_info_t *mirror_image_info,
637 size_t info_size);
638 int mirror_image_get_status(mirror_image_status_t *mirror_image_status,
639 size_t status_size);
11fdf7f2 640 int mirror_image_get_instance_id(std::string *instance_id);
7c673cae
FG
641 int aio_mirror_image_promote(bool force, RBD::AioCompletion *c);
642 int aio_mirror_image_demote(RBD::AioCompletion *c);
643 int aio_mirror_image_get_info(mirror_image_info_t *mirror_image_info,
644 size_t info_size, RBD::AioCompletion *c);
645 int aio_mirror_image_get_status(mirror_image_status_t *mirror_image_status,
646 size_t status_size, RBD::AioCompletion *c);
647
648 int update_watch(UpdateWatchCtx *ctx, uint64_t *handle);
649 int update_unwatch(uint64_t handle);
650
11fdf7f2
TL
651 int list_watchers(std::list<image_watcher_t> &watchers);
652
653 int config_list(std::vector<config_option_t> *options);
654
7c673cae
FG
655private:
656 friend class RBD;
657
658 Image(const Image& rhs);
659 const Image& operator=(const Image& rhs);
660
661 image_ctx_t ctx;
662};
663
664}
665
666#endif