]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/rbd/librbd.hpp
f1ddc2965e5451143fd09d8097481af519413ed3
[ceph.git] / ceph / src / include / rbd / librbd.hpp
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
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
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
26 #if __GNUC__ >= 4
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
29 #endif
30
31 namespace librbd {
32
33 using librados::IoCtx;
34
35 class Image;
36 class ImageOptions;
37 class PoolStats;
38 typedef void *image_ctx_t;
39 typedef void *completion_t;
40 typedef void (*callback_t)(completion_t cb, void *arg);
41
42 typedef struct {
43 std::string id;
44 std::string name;
45 } image_spec_t;
46
47 typedef struct {
48 int64_t pool_id;
49 std::string pool_name;
50 std::string pool_namespace;
51 std::string image_id;
52 std::string image_name;
53 bool trash;
54 } linked_image_spec_t;
55
56 typedef rbd_snap_namespace_type_t snap_namespace_type_t;
57
58 typedef struct {
59 uint64_t id;
60 snap_namespace_type_t namespace_type;
61 std::string name;
62 } snap_spec_t;
63
64 typedef struct {
65 uint64_t id;
66 uint64_t size;
67 std::string name;
68 } snap_info_t;
69
70 typedef struct {
71 int64_t group_pool;
72 std::string group_name;
73 std::string group_snap_name;
74 } snap_group_namespace_t;
75
76 typedef rbd_snap_mirror_state_t snap_mirror_state_t;
77
78 typedef struct {
79 snap_mirror_state_t state;
80 std::set<std::string> mirror_peer_uuids;
81 bool complete;
82 std::string primary_mirror_uuid;
83 uint64_t primary_snap_id;
84 uint64_t last_copied_object_number;
85 } snap_mirror_namespace_t;
86
87 typedef struct {
88 std::string client;
89 std::string cookie;
90 std::string address;
91 } locker_t;
92
93 typedef rbd_mirror_peer_direction_t mirror_peer_direction_t;
94
95 typedef struct {
96 std::string uuid;
97 std::string cluster_name;
98 std::string client_name;
99 } mirror_peer_t CEPH_RBD_DEPRECATED;
100
101 typedef struct {
102 std::string uuid;
103 mirror_peer_direction_t direction;
104 std::string site_name;
105 std::string mirror_uuid;
106 std::string client_name;
107 time_t last_seen;
108 } mirror_peer_site_t;
109
110 typedef rbd_mirror_image_mode_t mirror_image_mode_t;
111 typedef rbd_mirror_image_state_t mirror_image_state_t;
112
113 typedef struct {
114 std::string global_id;
115 mirror_image_state_t state;
116 bool primary;
117 } mirror_image_info_t;
118
119 typedef rbd_mirror_image_status_state_t mirror_image_status_state_t;
120
121 typedef struct {
122 std::string name;
123 mirror_image_info_t info;
124 mirror_image_status_state_t state;
125 std::string description;
126 time_t last_update;
127 bool up;
128 } mirror_image_status_t CEPH_RBD_DEPRECATED;
129
130 typedef struct {
131 std::string mirror_uuid;
132 mirror_image_status_state_t state;
133 std::string description;
134 time_t last_update;
135 bool up;
136 } mirror_image_site_status_t;
137
138 typedef struct {
139 std::string name;
140 mirror_image_info_t info;
141 std::vector<mirror_image_site_status_t> site_statuses;
142 } mirror_image_global_status_t;
143
144 typedef rbd_group_image_state_t group_image_state_t;
145
146 typedef struct {
147 std::string name;
148 int64_t pool;
149 group_image_state_t state;
150 } group_image_info_t;
151
152 typedef struct {
153 std::string name;
154 int64_t pool;
155 } group_info_t;
156
157 typedef rbd_group_snap_state_t group_snap_state_t;
158
159 typedef struct {
160 std::string name;
161 group_snap_state_t state;
162 } group_snap_info_t;
163
164 typedef rbd_image_info_t image_info_t;
165
166 class CEPH_RBD_API ProgressContext
167 {
168 public:
169 virtual ~ProgressContext();
170 virtual int update_progress(uint64_t offset, uint64_t total) = 0;
171 };
172
173 typedef struct {
174 std::string id;
175 std::string name;
176 rbd_trash_image_source_t source;
177 time_t deletion_time;
178 time_t deferment_end_time;
179 } trash_image_info_t;
180
181 typedef struct {
182 std::string pool_name;
183 std::string image_name;
184 std::string image_id;
185 bool trash;
186 } child_info_t;
187
188 typedef struct {
189 std::string addr;
190 int64_t id;
191 uint64_t cookie;
192 } image_watcher_t;
193
194 typedef rbd_image_migration_state_t image_migration_state_t;
195
196 typedef struct {
197 int64_t source_pool_id;
198 std::string source_pool_namespace;
199 std::string source_image_name;
200 std::string source_image_id;
201 int64_t dest_pool_id;
202 std::string dest_pool_namespace;
203 std::string dest_image_name;
204 std::string dest_image_id;
205 image_migration_state_t state;
206 std::string state_description;
207 } image_migration_status_t;
208
209 typedef rbd_config_source_t config_source_t;
210
211 typedef struct {
212 std::string name;
213 std::string value;
214 config_source_t source;
215 } config_option_t;
216
217 typedef rbd_encryption_format_t encryption_format_t;
218 typedef rbd_encryption_algorithm_t encryption_algorithm_t;
219 typedef rbd_encryption_options_t encryption_options_t;
220
221 typedef struct {
222 encryption_algorithm_t alg;
223 std::string passphrase;
224 } encryption_luks1_format_options_t;
225
226 typedef struct {
227 encryption_algorithm_t alg;
228 std::string passphrase;
229 } encryption_luks2_format_options_t;
230
231 class CEPH_RBD_API RBD
232 {
233 public:
234 RBD();
235 ~RBD();
236
237 // This must be dynamically allocated with new, and
238 // must be released with release().
239 // Do not use delete.
240 struct AioCompletion {
241 void *pc;
242 AioCompletion(void *cb_arg, callback_t complete_cb);
243 bool is_complete();
244 int wait_for_complete();
245 ssize_t get_return_value();
246 void *get_arg();
247 void release();
248 };
249
250 void version(int *major, int *minor, int *extra);
251
252 int open(IoCtx& io_ctx, Image& image, const char *name);
253 int open(IoCtx& io_ctx, Image& image, const char *name, const char *snapname);
254 int open_by_id(IoCtx& io_ctx, Image& image, const char *id);
255 int open_by_id(IoCtx& io_ctx, Image& image, const char *id, const char *snapname);
256 int aio_open(IoCtx& io_ctx, Image& image, const char *name,
257 const char *snapname, RBD::AioCompletion *c);
258 int aio_open_by_id(IoCtx& io_ctx, Image& image, const char *id,
259 const char *snapname, RBD::AioCompletion *c);
260 // see librbd.h
261 int open_read_only(IoCtx& io_ctx, Image& image, const char *name,
262 const char *snapname);
263 int open_by_id_read_only(IoCtx& io_ctx, Image& image, const char *id,
264 const char *snapname);
265 int aio_open_read_only(IoCtx& io_ctx, Image& image, const char *name,
266 const char *snapname, RBD::AioCompletion *c);
267 int aio_open_by_id_read_only(IoCtx& io_ctx, Image& image, const char *id,
268 const char *snapname, RBD::AioCompletion *c);
269 int features_to_string(uint64_t features, std::string *str_features);
270 int features_from_string(const std::string str_features, uint64_t *features);
271
272 int list(IoCtx& io_ctx, std::vector<std::string>& names)
273 CEPH_RBD_DEPRECATED;
274 int list2(IoCtx& io_ctx, std::vector<image_spec_t>* images);
275
276 int create(IoCtx& io_ctx, const char *name, uint64_t size, int *order);
277 int create2(IoCtx& io_ctx, const char *name, uint64_t size,
278 uint64_t features, int *order);
279 int create3(IoCtx& io_ctx, const char *name, uint64_t size,
280 uint64_t features, int *order,
281 uint64_t stripe_unit, uint64_t stripe_count);
282 int create4(IoCtx& io_ctx, const char *name, uint64_t size,
283 ImageOptions& opts);
284 int clone(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
285 IoCtx& c_ioctx, const char *c_name, uint64_t features,
286 int *c_order);
287 int clone2(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
288 IoCtx& c_ioctx, const char *c_name, uint64_t features,
289 int *c_order, uint64_t stripe_unit, int stripe_count);
290 int clone3(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
291 IoCtx& c_ioctx, const char *c_name, ImageOptions& opts);
292 int remove(IoCtx& io_ctx, const char *name);
293 int remove_with_progress(IoCtx& io_ctx, const char *name, ProgressContext& pctx);
294 int rename(IoCtx& src_io_ctx, const char *srcname, const char *destname);
295
296 int trash_move(IoCtx &io_ctx, const char *name, uint64_t delay);
297 int trash_get(IoCtx &io_ctx, const char *id, trash_image_info_t *info);
298 int trash_list(IoCtx &io_ctx, std::vector<trash_image_info_t> &entries);
299 int trash_purge(IoCtx &io_ctx, time_t expire_ts, float threshold);
300 int trash_purge_with_progress(IoCtx &io_ctx, time_t expire_ts, float threshold,
301 ProgressContext &pctx);
302 int trash_remove(IoCtx &io_ctx, const char *image_id, bool force);
303 int trash_remove_with_progress(IoCtx &io_ctx, const char *image_id,
304 bool force, ProgressContext &pctx);
305 int trash_restore(IoCtx &io_ctx, const char *id, const char *name);
306
307 // Migration
308 int migration_prepare(IoCtx& io_ctx, const char *image_name,
309 IoCtx& dest_io_ctx, const char *dest_image_name,
310 ImageOptions& opts);
311 int migration_prepare_import(const char *source_spec, IoCtx& dest_io_ctx,
312 const char *dest_image_name, ImageOptions& opts);
313 int migration_execute(IoCtx& io_ctx, const char *image_name);
314 int migration_execute_with_progress(IoCtx& io_ctx, const char *image_name,
315 ProgressContext &prog_ctx);
316 int migration_abort(IoCtx& io_ctx, const char *image_name);
317 int migration_abort_with_progress(IoCtx& io_ctx, const char *image_name,
318 ProgressContext &prog_ctx);
319 int migration_commit(IoCtx& io_ctx, const char *image_name);
320 int migration_commit_with_progress(IoCtx& io_ctx, const char *image_name,
321 ProgressContext &prog_ctx);
322 int migration_status(IoCtx& io_ctx, const char *image_name,
323 image_migration_status_t *status, size_t status_size);
324
325 // RBD pool mirroring support functions
326 int mirror_site_name_get(librados::Rados& rados, std::string* site_name);
327 int mirror_site_name_set(librados::Rados& rados,
328 const std::string& site_name);
329
330 int mirror_mode_get(IoCtx& io_ctx, rbd_mirror_mode_t *mirror_mode);
331 int mirror_mode_set(IoCtx& io_ctx, rbd_mirror_mode_t mirror_mode);
332
333 int mirror_uuid_get(IoCtx& io_ctx, std::string* mirror_uuid);
334
335 int mirror_peer_bootstrap_create(IoCtx& io_ctx, std::string* token);
336 int mirror_peer_bootstrap_import(IoCtx& io_ctx,
337 mirror_peer_direction_t direction,
338 const std::string &token);
339
340 int mirror_peer_site_add(IoCtx& io_ctx, std::string *uuid,
341 mirror_peer_direction_t direction,
342 const std::string &site_name,
343 const std::string &client_name);
344 int mirror_peer_site_set_name(IoCtx& io_ctx, const std::string& uuid,
345 const std::string &site_name);
346 int mirror_peer_site_set_client_name(IoCtx& io_ctx, const std::string& uuid,
347 const std::string &client_name);
348 int mirror_peer_site_set_direction(IoCtx& io_ctx, const std::string& uuid,
349 mirror_peer_direction_t direction);
350 int mirror_peer_site_remove(IoCtx& io_ctx, const std::string& uuid);
351 int mirror_peer_site_list(IoCtx& io_ctx,
352 std::vector<mirror_peer_site_t> *peers);
353 int mirror_peer_site_get_attributes(
354 IoCtx& io_ctx, const std::string &uuid,
355 std::map<std::string, std::string> *key_vals);
356 int mirror_peer_site_set_attributes(
357 IoCtx& io_ctx, const std::string &uuid,
358 const std::map<std::string, std::string>& key_vals);
359
360 int mirror_image_global_status_list(
361 IoCtx& io_ctx, const std::string &start_id, size_t max,
362 std::map<std::string, mirror_image_global_status_t> *images);
363 int mirror_image_status_summary(IoCtx& io_ctx,
364 std::map<mirror_image_status_state_t, int> *states);
365 int mirror_image_instance_id_list(IoCtx& io_ctx, const std::string &start_id,
366 size_t max, std::map<std::string, std::string> *sevice_ids);
367 int mirror_image_info_list(IoCtx& io_ctx, mirror_image_mode_t *mode_filter,
368 const std::string &start_id, size_t max,
369 std::map<std::string, std::pair<mirror_image_mode_t,
370 mirror_image_info_t>> *entries);
371
372 /// mirror_peer_ commands are deprecated to mirror_peer_site_ equivalents
373 int mirror_peer_add(IoCtx& io_ctx, std::string *uuid,
374 const std::string &cluster_name,
375 const std::string &client_name)
376 CEPH_RBD_DEPRECATED;
377 int mirror_peer_remove(IoCtx& io_ctx, const std::string &uuid)
378 CEPH_RBD_DEPRECATED;
379 int mirror_peer_list(IoCtx& io_ctx, std::vector<mirror_peer_t> *peers)
380 CEPH_RBD_DEPRECATED;
381 int mirror_peer_set_client(IoCtx& io_ctx, const std::string &uuid,
382 const std::string &client_name)
383 CEPH_RBD_DEPRECATED;
384 int mirror_peer_set_cluster(IoCtx& io_ctx, const std::string &uuid,
385 const std::string &cluster_name)
386 CEPH_RBD_DEPRECATED;
387 int mirror_peer_get_attributes(
388 IoCtx& io_ctx, const std::string &uuid,
389 std::map<std::string, std::string> *key_vals)
390 CEPH_RBD_DEPRECATED;
391 int mirror_peer_set_attributes(
392 IoCtx& io_ctx, const std::string &uuid,
393 const std::map<std::string, std::string>& key_vals)
394 CEPH_RBD_DEPRECATED;
395
396 /// mirror_image_status_list command is deprecated to
397 /// mirror_image_global_status_list
398
399 int mirror_image_status_list(
400 IoCtx& io_ctx, const std::string &start_id, size_t max,
401 std::map<std::string, mirror_image_status_t> *images)
402 CEPH_RBD_DEPRECATED;
403
404 // RBD groups support functions
405 int group_create(IoCtx& io_ctx, const char *group_name);
406 int group_remove(IoCtx& io_ctx, const char *group_name);
407 int group_list(IoCtx& io_ctx, std::vector<std::string> *names);
408 int group_rename(IoCtx& io_ctx, const char *src_group_name,
409 const char *dest_group_name);
410
411 int group_image_add(IoCtx& io_ctx, const char *group_name,
412 IoCtx& image_io_ctx, const char *image_name);
413 int group_image_remove(IoCtx& io_ctx, const char *group_name,
414 IoCtx& image_io_ctx, const char *image_name);
415 int group_image_remove_by_id(IoCtx& io_ctx, const char *group_name,
416 IoCtx& image_io_ctx, const char *image_id);
417 int group_image_list(IoCtx& io_ctx, const char *group_name,
418 std::vector<group_image_info_t> *images,
419 size_t group_image_info_size);
420
421 int group_snap_create(IoCtx& io_ctx, const char *group_name,
422 const char *snap_name);
423 int group_snap_create2(IoCtx& io_ctx, const char *group_name,
424 const char *snap_name, uint32_t flags);
425 int group_snap_remove(IoCtx& io_ctx, const char *group_name,
426 const char *snap_name);
427 int group_snap_rename(IoCtx& group_ioctx, const char *group_name,
428 const char *old_snap_name, const char *new_snap_name);
429 int group_snap_list(IoCtx& group_ioctx, const char *group_name,
430 std::vector<group_snap_info_t> *snaps,
431 size_t group_snap_info_size);
432 int group_snap_rollback(IoCtx& io_ctx, const char *group_name,
433 const char *snap_name);
434 int group_snap_rollback_with_progress(IoCtx& io_ctx, const char *group_name,
435 const char *snap_name,
436 ProgressContext& pctx);
437
438 int namespace_create(IoCtx& ioctx, const char *namespace_name);
439 int namespace_remove(IoCtx& ioctx, const char *namespace_name);
440 int namespace_list(IoCtx& io_ctx, std::vector<std::string>* namespace_names);
441 int namespace_exists(IoCtx& io_ctx, const char *namespace_name, bool *exists);
442
443 int pool_init(IoCtx& io_ctx, bool force);
444 int pool_stats_get(IoCtx& io_ctx, PoolStats *pool_stats);
445
446 int pool_metadata_get(IoCtx &io_ctx, const std::string &key,
447 std::string *value);
448 int pool_metadata_set(IoCtx &io_ctx, const std::string &key,
449 const std::string &value);
450 int pool_metadata_remove(IoCtx &io_ctx, const std::string &key);
451 int pool_metadata_list(IoCtx &io_ctx, const std::string &start, uint64_t max,
452 std::map<std::string, ceph::bufferlist> *pairs);
453
454 int config_list(IoCtx& io_ctx, std::vector<config_option_t> *options);
455
456 private:
457 /* We don't allow assignment or copying */
458 RBD(const RBD& rhs);
459 const RBD& operator=(const RBD& rhs);
460 };
461
462 class CEPH_RBD_API ImageOptions {
463 public:
464 ImageOptions();
465 ImageOptions(rbd_image_options_t opts);
466 ImageOptions(const ImageOptions &imgopts);
467 ~ImageOptions();
468
469 int set(int optname, const std::string& optval);
470 int set(int optname, uint64_t optval);
471 int get(int optname, std::string* optval) const;
472 int get(int optname, uint64_t* optval) const;
473 int is_set(int optname, bool* is_set);
474 int unset(int optname);
475 void clear();
476 bool empty() const;
477
478 private:
479 friend class RBD;
480 friend class Image;
481
482 rbd_image_options_t opts;
483 };
484
485 class CEPH_RBD_API PoolStats {
486 public:
487 PoolStats();
488 ~PoolStats();
489
490 PoolStats(const PoolStats&) = delete;
491 PoolStats& operator=(const PoolStats&) = delete;
492
493 int add(rbd_pool_stat_option_t option, uint64_t* opt_val);
494
495 private:
496 friend class RBD;
497
498 rbd_pool_stats_t pool_stats;
499 };
500
501 class CEPH_RBD_API UpdateWatchCtx {
502 public:
503 virtual ~UpdateWatchCtx() {}
504 /**
505 * Callback activated when we receive a notify event.
506 */
507 virtual void handle_notify() = 0;
508 };
509
510 class CEPH_RBD_API QuiesceWatchCtx {
511 public:
512 virtual ~QuiesceWatchCtx() {}
513 /**
514 * Callback activated when we want to quiesce.
515 */
516 virtual void handle_quiesce() = 0;
517
518 /**
519 * Callback activated when we want to unquiesce.
520 */
521 virtual void handle_unquiesce() = 0;
522 };
523
524 class CEPH_RBD_API Image
525 {
526 public:
527 Image();
528 ~Image();
529
530 int close();
531 int aio_close(RBD::AioCompletion *c);
532
533 int resize(uint64_t size);
534 int resize2(uint64_t size, bool allow_shrink, ProgressContext& pctx);
535 int resize_with_progress(uint64_t size, ProgressContext& pctx);
536 int stat(image_info_t &info, size_t infosize);
537 int get_name(std::string *name);
538 int get_id(std::string *id);
539 std::string get_block_name_prefix();
540 int64_t get_data_pool_id();
541 int parent_info(std::string *parent_poolname, std::string *parent_name,
542 std::string *parent_snapname)
543 CEPH_RBD_DEPRECATED;
544 int parent_info2(std::string *parent_poolname, std::string *parent_name,
545 std::string *parent_id, std::string *parent_snapname)
546 CEPH_RBD_DEPRECATED;
547 int get_parent(linked_image_spec_t *parent_image, snap_spec_t *parent_snap);
548
549 int get_migration_source_spec(std::string* source_spec);
550
551 int old_format(uint8_t *old);
552 int size(uint64_t *size);
553 int get_group(group_info_t *group_info, size_t group_info_size);
554 int features(uint64_t *features);
555 int update_features(uint64_t features, bool enabled);
556 int get_op_features(uint64_t *op_features);
557 int overlap(uint64_t *overlap);
558 int get_flags(uint64_t *flags);
559 int set_image_notification(int fd, int type);
560
561 /* exclusive lock feature */
562 int is_exclusive_lock_owner(bool *is_owner);
563 int lock_acquire(rbd_lock_mode_t lock_mode);
564 int lock_release();
565 int lock_get_owners(rbd_lock_mode_t *lock_mode,
566 std::list<std::string> *lock_owners);
567 int lock_break(rbd_lock_mode_t lock_mode, const std::string &lock_owner);
568
569 /* object map feature */
570 int rebuild_object_map(ProgressContext &prog_ctx);
571
572 int check_object_map(ProgressContext &prog_ctx);
573
574 int copy(IoCtx& dest_io_ctx, const char *destname);
575 int copy2(Image& dest);
576 int copy3(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts);
577 int copy4(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts,
578 size_t sparse_size);
579 int copy_with_progress(IoCtx& dest_io_ctx, const char *destname,
580 ProgressContext &prog_ctx);
581 int copy_with_progress2(Image& dest, ProgressContext &prog_ctx);
582 int copy_with_progress3(IoCtx& dest_io_ctx, const char *destname,
583 ImageOptions& opts, ProgressContext &prog_ctx);
584 int copy_with_progress4(IoCtx& dest_io_ctx, const char *destname,
585 ImageOptions& opts, ProgressContext &prog_ctx,
586 size_t sparse_size);
587
588 /* deep copy */
589 int deep_copy(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts);
590 int deep_copy_with_progress(IoCtx& dest_io_ctx, const char *destname,
591 ImageOptions& opts, ProgressContext &prog_ctx);
592
593 /* encryption */
594 int encryption_format(encryption_format_t format, encryption_options_t opts,
595 size_t opts_size);
596 int encryption_load(encryption_format_t format, encryption_options_t opts,
597 size_t opts_size);
598
599 /* striping */
600 uint64_t get_stripe_unit() const;
601 uint64_t get_stripe_count() const;
602
603 int get_create_timestamp(struct timespec *timestamp);
604 int get_access_timestamp(struct timespec *timestamp);
605 int get_modify_timestamp(struct timespec *timestamp);
606
607 int flatten();
608 int flatten_with_progress(ProgressContext &prog_ctx);
609
610 int sparsify(size_t sparse_size);
611 int sparsify_with_progress(size_t sparse_size, ProgressContext &prog_ctx);
612 /**
613 * Returns a pair of poolname, imagename for each clone
614 * of this image at the currently set snapshot.
615 */
616 int list_children(std::set<std::pair<std::string, std::string> > *children)
617 CEPH_RBD_DEPRECATED;
618 /**
619 * Returns a structure of poolname, imagename, imageid and trash flag
620 * for each clone of this image at the currently set snapshot.
621 */
622 int list_children2(std::vector<librbd::child_info_t> *children)
623 CEPH_RBD_DEPRECATED;
624 int list_children3(std::vector<linked_image_spec_t> *images);
625 int list_descendants(std::vector<linked_image_spec_t> *images);
626
627 /* advisory locking (see librbd.h for details) */
628 int list_lockers(std::list<locker_t> *lockers,
629 bool *exclusive, std::string *tag);
630 int lock_exclusive(const std::string& cookie);
631 int lock_shared(const std::string& cookie, const std::string& tag);
632 int unlock(const std::string& cookie);
633 int break_lock(const std::string& client, const std::string& cookie);
634
635 /* snapshots */
636 int snap_list(std::vector<snap_info_t>& snaps);
637 /* DEPRECATED; use snap_exists2 */
638 bool snap_exists(const char *snapname) CEPH_RBD_DEPRECATED;
639 int snap_exists2(const char *snapname, bool *exists);
640 int snap_create(const char *snapname);
641 int snap_create2(const char *snapname, uint32_t flags, ProgressContext& pctx);
642 int snap_remove(const char *snapname);
643 int snap_remove2(const char *snapname, uint32_t flags, ProgressContext& pctx);
644 int snap_remove_by_id(uint64_t snap_id);
645 int snap_rollback(const char *snap_name);
646 int snap_rollback_with_progress(const char *snap_name, ProgressContext& pctx);
647 int snap_protect(const char *snap_name);
648 int snap_unprotect(const char *snap_name);
649 int snap_is_protected(const char *snap_name, bool *is_protected);
650 int snap_set(const char *snap_name);
651 int snap_set_by_id(uint64_t snap_id);
652 int snap_get_name(uint64_t snap_id, std::string *snap_name);
653 int snap_get_id(const std::string snap_name, uint64_t *snap_id);
654 int snap_rename(const char *srcname, const char *dstname);
655 int snap_get_limit(uint64_t *limit);
656 int snap_set_limit(uint64_t limit);
657 int snap_get_timestamp(uint64_t snap_id, struct timespec *timestamp);
658 int snap_get_namespace_type(uint64_t snap_id,
659 snap_namespace_type_t *namespace_type);
660 int snap_get_group_namespace(uint64_t snap_id,
661 snap_group_namespace_t *group_namespace,
662 size_t snap_group_namespace_size);
663 int snap_get_trash_namespace(uint64_t snap_id, std::string* original_name);
664 int snap_get_mirror_namespace(
665 uint64_t snap_id, snap_mirror_namespace_t *mirror_namespace,
666 size_t snap_mirror_namespace_size);
667
668 /* I/O */
669 ssize_t read(uint64_t ofs, size_t len, ceph::bufferlist& bl);
670 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
671 ssize_t read2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags);
672 int64_t read_iterate(uint64_t ofs, size_t len,
673 int (*cb)(uint64_t, size_t, const char *, void *), void *arg);
674 int read_iterate2(uint64_t ofs, uint64_t len,
675 int (*cb)(uint64_t, size_t, const char *, void *), void *arg);
676 /**
677 * get difference between two versions of an image
678 *
679 * This will return the differences between two versions of an image
680 * via a callback, which gets the offset and length and a flag
681 * indicating whether the extent exists (1), or is known/defined to
682 * be zeros (a hole, 0). If the source snapshot name is NULL, we
683 * interpret that as the beginning of time and return all allocated
684 * regions of the image. The end version is whatever is currently
685 * selected for the image handle (either a snapshot or the writeable
686 * head).
687 *
688 * @param fromsnapname start snapshot name, or NULL
689 * @param ofs start offset
690 * @param len len in bytes of region to report on
691 * @param include_parent true if full history diff should include parent
692 * @param whole_object 1 if diff extents should cover whole object
693 * @param cb callback to call for each allocated region
694 * @param arg argument to pass to the callback
695 * @returns 0 on success, or negative error code on error
696 */
697 int diff_iterate(const char *fromsnapname,
698 uint64_t ofs, uint64_t len,
699 int (*cb)(uint64_t, size_t, int, void *), void *arg);
700 int diff_iterate2(const char *fromsnapname,
701 uint64_t ofs, uint64_t len,
702 bool include_parent, bool whole_object,
703 int (*cb)(uint64_t, size_t, int, void *), void *arg);
704
705 ssize_t write(uint64_t ofs, size_t len, ceph::bufferlist& bl);
706 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
707 ssize_t write2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags);
708
709 int discard(uint64_t ofs, uint64_t len);
710 ssize_t writesame(uint64_t ofs, size_t len, ceph::bufferlist &bl, int op_flags);
711 ssize_t write_zeroes(uint64_t ofs, size_t len, int zero_flags, int op_flags);
712
713 ssize_t compare_and_write(uint64_t ofs, size_t len, ceph::bufferlist &cmp_bl,
714 ceph::bufferlist& bl, uint64_t *mismatch_off, int op_flags);
715
716 int aio_write(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
717 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
718 int aio_write2(uint64_t off, size_t len, ceph::bufferlist& bl,
719 RBD::AioCompletion *c, int op_flags);
720
721 int aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c);
722 int aio_writesame(uint64_t off, size_t len, ceph::bufferlist& bl,
723 RBD::AioCompletion *c, int op_flags);
724 int aio_write_zeroes(uint64_t ofs, size_t len, RBD::AioCompletion *c,
725 int zero_flags, int op_flags);
726
727 int aio_compare_and_write(uint64_t off, size_t len, ceph::bufferlist& cmp_bl,
728 ceph::bufferlist& bl, RBD::AioCompletion *c,
729 uint64_t *mismatch_off, int op_flags);
730
731 /**
732 * read async from image
733 *
734 * The target bufferlist is populated with references to buffers
735 * that contain the data for the given extent of the image.
736 *
737 * NOTE: If caching is enabled, the bufferlist will directly
738 * reference buffers in the cache to avoid an unnecessary data copy.
739 * As a result, if the user intends to modify the buffer contents
740 * directly, they should make a copy first (unconditionally, or when
741 * the reference count on ther underlying buffer is more than 1).
742 *
743 * @param off offset in image
744 * @param len length of read
745 * @param bl bufferlist to read into
746 * @param c aio completion to notify when read is complete
747 */
748 int aio_read(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
749 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
750 int aio_read2(uint64_t off, size_t len, ceph::bufferlist& bl,
751 RBD::AioCompletion *c, int op_flags);
752
753 int flush();
754 /**
755 * Start a flush if caching is enabled. Get a callback when
756 * the currently pending writes are on disk.
757 *
758 * @param image the image to flush writes to
759 * @param c what to call when flushing is complete
760 * @returns 0 on success, negative error code on failure
761 */
762 int aio_flush(RBD::AioCompletion *c);
763
764 /**
765 * Drop any cached data for this image
766 *
767 * @returns 0 on success, negative error code on failure
768 */
769 int invalidate_cache();
770
771 int poll_io_events(RBD::AioCompletion **comps, int numcomp);
772
773 int metadata_get(const std::string &key, std::string *value);
774 int metadata_set(const std::string &key, const std::string &value);
775 int metadata_remove(const std::string &key);
776 /**
777 * Returns a pair of key/value for this image
778 */
779 int metadata_list(const std::string &start, uint64_t max, std::map<std::string, ceph::bufferlist> *pairs);
780
781 // RBD image mirroring support functions
782 int mirror_image_enable() CEPH_RBD_DEPRECATED;
783 int mirror_image_enable2(mirror_image_mode_t mode);
784 int mirror_image_disable(bool force);
785 int mirror_image_promote(bool force);
786 int mirror_image_demote();
787 int mirror_image_resync();
788 int mirror_image_create_snapshot(uint64_t *snap_id);
789 int mirror_image_create_snapshot2(uint32_t flags, uint64_t *snap_id);
790 int mirror_image_get_info(mirror_image_info_t *mirror_image_info,
791 size_t info_size);
792 int mirror_image_get_mode(mirror_image_mode_t *mode);
793 int mirror_image_get_global_status(
794 mirror_image_global_status_t *mirror_image_global_status,
795 size_t status_size);
796 int mirror_image_get_status(
797 mirror_image_status_t *mirror_image_status, size_t status_size)
798 CEPH_RBD_DEPRECATED;
799 int mirror_image_get_instance_id(std::string *instance_id);
800 int aio_mirror_image_promote(bool force, RBD::AioCompletion *c);
801 int aio_mirror_image_demote(RBD::AioCompletion *c);
802 int aio_mirror_image_get_info(mirror_image_info_t *mirror_image_info,
803 size_t info_size, RBD::AioCompletion *c);
804 int aio_mirror_image_get_mode(mirror_image_mode_t *mode,
805 RBD::AioCompletion *c);
806 int aio_mirror_image_get_global_status(
807 mirror_image_global_status_t *mirror_image_global_status,
808 size_t status_size, RBD::AioCompletion *c);
809 int aio_mirror_image_get_status(
810 mirror_image_status_t *mirror_image_status, size_t status_size,
811 RBD::AioCompletion *c)
812 CEPH_RBD_DEPRECATED;
813 int aio_mirror_image_create_snapshot(uint32_t flags, uint64_t *snap_id,
814 RBD::AioCompletion *c);
815
816 int update_watch(UpdateWatchCtx *ctx, uint64_t *handle);
817 int update_unwatch(uint64_t handle);
818
819 int list_watchers(std::list<image_watcher_t> &watchers);
820
821 int config_list(std::vector<config_option_t> *options);
822
823 int quiesce_watch(QuiesceWatchCtx *ctx, uint64_t *handle);
824 int quiesce_unwatch(uint64_t handle);
825 void quiesce_complete(uint64_t handle, int r);
826
827 private:
828 friend class RBD;
829
830 Image(const Image& rhs);
831 const Image& operator=(const Image& rhs);
832
833 image_ctx_t ctx;
834 };
835
836 } // namespace librbd
837
838 #if __GNUC__ >= 4
839 #pragma GCC diagnostic pop
840 #endif
841
842 #endif // __LIBRBD_HPP