]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/rbd/librbd.hpp
1bb74ce72f2e9e13f3800306143fc47285de78db
[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 class CEPH_RBD_API RBD
218 {
219 public:
220 RBD();
221 ~RBD();
222
223 // This must be dynamically allocated with new, and
224 // must be released with release().
225 // Do not use delete.
226 struct AioCompletion {
227 void *pc;
228 AioCompletion(void *cb_arg, callback_t complete_cb);
229 bool is_complete();
230 int wait_for_complete();
231 ssize_t get_return_value();
232 void *get_arg();
233 void release();
234 };
235
236 void version(int *major, int *minor, int *extra);
237
238 int open(IoCtx& io_ctx, Image& image, const char *name);
239 int open(IoCtx& io_ctx, Image& image, const char *name, const char *snapname);
240 int open_by_id(IoCtx& io_ctx, Image& image, const char *id);
241 int open_by_id(IoCtx& io_ctx, Image& image, const char *id, const char *snapname);
242 int aio_open(IoCtx& io_ctx, Image& image, const char *name,
243 const char *snapname, RBD::AioCompletion *c);
244 int aio_open_by_id(IoCtx& io_ctx, Image& image, const char *id,
245 const char *snapname, RBD::AioCompletion *c);
246 // see librbd.h
247 int open_read_only(IoCtx& io_ctx, Image& image, const char *name,
248 const char *snapname);
249 int open_by_id_read_only(IoCtx& io_ctx, Image& image, const char *id,
250 const char *snapname);
251 int aio_open_read_only(IoCtx& io_ctx, Image& image, const char *name,
252 const char *snapname, RBD::AioCompletion *c);
253 int aio_open_by_id_read_only(IoCtx& io_ctx, Image& image, const char *id,
254 const char *snapname, RBD::AioCompletion *c);
255 int features_to_string(uint64_t features, std::string *str_features);
256 int features_from_string(const std::string str_features, uint64_t *features);
257
258 int list(IoCtx& io_ctx, std::vector<std::string>& names)
259 CEPH_RBD_DEPRECATED;
260 int list2(IoCtx& io_ctx, std::vector<image_spec_t>* images);
261
262 int create(IoCtx& io_ctx, const char *name, uint64_t size, int *order);
263 int create2(IoCtx& io_ctx, const char *name, uint64_t size,
264 uint64_t features, int *order);
265 int create3(IoCtx& io_ctx, const char *name, uint64_t size,
266 uint64_t features, int *order,
267 uint64_t stripe_unit, uint64_t stripe_count);
268 int create4(IoCtx& io_ctx, const char *name, uint64_t size,
269 ImageOptions& opts);
270 int clone(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
271 IoCtx& c_ioctx, const char *c_name, uint64_t features,
272 int *c_order);
273 int clone2(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
274 IoCtx& c_ioctx, const char *c_name, uint64_t features,
275 int *c_order, uint64_t stripe_unit, int stripe_count);
276 int clone3(IoCtx& p_ioctx, const char *p_name, const char *p_snapname,
277 IoCtx& c_ioctx, const char *c_name, ImageOptions& opts);
278 int remove(IoCtx& io_ctx, const char *name);
279 int remove_with_progress(IoCtx& io_ctx, const char *name, ProgressContext& pctx);
280 int rename(IoCtx& src_io_ctx, const char *srcname, const char *destname);
281
282 int trash_move(IoCtx &io_ctx, const char *name, uint64_t delay);
283 int trash_get(IoCtx &io_ctx, const char *id, trash_image_info_t *info);
284 int trash_list(IoCtx &io_ctx, std::vector<trash_image_info_t> &entries);
285 int trash_purge(IoCtx &io_ctx, time_t expire_ts, float threshold);
286 int trash_purge_with_progress(IoCtx &io_ctx, time_t expire_ts, float threshold,
287 ProgressContext &pctx);
288 int trash_remove(IoCtx &io_ctx, const char *image_id, bool force);
289 int trash_remove_with_progress(IoCtx &io_ctx, const char *image_id,
290 bool force, ProgressContext &pctx);
291 int trash_restore(IoCtx &io_ctx, const char *id, const char *name);
292
293 // Migration
294 int migration_prepare(IoCtx& io_ctx, const char *image_name,
295 IoCtx& dest_io_ctx, const char *dest_image_name,
296 ImageOptions& opts);
297 int migration_execute(IoCtx& io_ctx, const char *image_name);
298 int migration_execute_with_progress(IoCtx& io_ctx, const char *image_name,
299 ProgressContext &prog_ctx);
300 int migration_abort(IoCtx& io_ctx, const char *image_name);
301 int migration_abort_with_progress(IoCtx& io_ctx, const char *image_name,
302 ProgressContext &prog_ctx);
303 int migration_commit(IoCtx& io_ctx, const char *image_name);
304 int migration_commit_with_progress(IoCtx& io_ctx, const char *image_name,
305 ProgressContext &prog_ctx);
306 int migration_status(IoCtx& io_ctx, const char *image_name,
307 image_migration_status_t *status, size_t status_size);
308
309 // RBD pool mirroring support functions
310 int mirror_site_name_get(librados::Rados& rados, std::string* site_name);
311 int mirror_site_name_set(librados::Rados& rados,
312 const std::string& site_name);
313
314 int mirror_mode_get(IoCtx& io_ctx, rbd_mirror_mode_t *mirror_mode);
315 int mirror_mode_set(IoCtx& io_ctx, rbd_mirror_mode_t mirror_mode);
316
317 int mirror_uuid_get(IoCtx& io_ctx, std::string* mirror_uuid);
318
319 int mirror_peer_bootstrap_create(IoCtx& io_ctx, std::string* token);
320 int mirror_peer_bootstrap_import(IoCtx& io_ctx,
321 mirror_peer_direction_t direction,
322 const std::string &token);
323
324 int mirror_peer_site_add(IoCtx& io_ctx, std::string *uuid,
325 mirror_peer_direction_t direction,
326 const std::string &site_name,
327 const std::string &client_name);
328 int mirror_peer_site_set_name(IoCtx& io_ctx, const std::string& uuid,
329 const std::string &site_name);
330 int mirror_peer_site_set_client_name(IoCtx& io_ctx, const std::string& uuid,
331 const std::string &client_name);
332 int mirror_peer_site_set_direction(IoCtx& io_ctx, const std::string& uuid,
333 mirror_peer_direction_t direction);
334 int mirror_peer_site_remove(IoCtx& io_ctx, const std::string& uuid);
335 int mirror_peer_site_list(IoCtx& io_ctx,
336 std::vector<mirror_peer_site_t> *peers);
337 int mirror_peer_site_get_attributes(
338 IoCtx& io_ctx, const std::string &uuid,
339 std::map<std::string, std::string> *key_vals);
340 int mirror_peer_site_set_attributes(
341 IoCtx& io_ctx, const std::string &uuid,
342 const std::map<std::string, std::string>& key_vals);
343
344 int mirror_image_global_status_list(
345 IoCtx& io_ctx, const std::string &start_id, size_t max,
346 std::map<std::string, mirror_image_global_status_t> *images);
347 int mirror_image_status_summary(IoCtx& io_ctx,
348 std::map<mirror_image_status_state_t, int> *states);
349 int mirror_image_instance_id_list(IoCtx& io_ctx, const std::string &start_id,
350 size_t max, std::map<std::string, std::string> *sevice_ids);
351 int mirror_image_info_list(IoCtx& io_ctx, mirror_image_mode_t *mode_filter,
352 const std::string &start_id, size_t max,
353 std::map<std::string, std::pair<mirror_image_mode_t,
354 mirror_image_info_t>> *entries);
355
356 /// mirror_peer_ commands are deprecated to mirror_peer_site_ equivalents
357 int mirror_peer_add(IoCtx& io_ctx, std::string *uuid,
358 const std::string &cluster_name,
359 const std::string &client_name)
360 CEPH_RBD_DEPRECATED;
361 int mirror_peer_remove(IoCtx& io_ctx, const std::string &uuid)
362 CEPH_RBD_DEPRECATED;
363 int mirror_peer_list(IoCtx& io_ctx, std::vector<mirror_peer_t> *peers)
364 CEPH_RBD_DEPRECATED;
365 int mirror_peer_set_client(IoCtx& io_ctx, const std::string &uuid,
366 const std::string &client_name)
367 CEPH_RBD_DEPRECATED;
368 int mirror_peer_set_cluster(IoCtx& io_ctx, const std::string &uuid,
369 const std::string &cluster_name)
370 CEPH_RBD_DEPRECATED;
371 int mirror_peer_get_attributes(
372 IoCtx& io_ctx, const std::string &uuid,
373 std::map<std::string, std::string> *key_vals)
374 CEPH_RBD_DEPRECATED;
375 int mirror_peer_set_attributes(
376 IoCtx& io_ctx, const std::string &uuid,
377 const std::map<std::string, std::string>& key_vals)
378 CEPH_RBD_DEPRECATED;
379
380 /// mirror_image_status_list command is deprecated to
381 /// mirror_image_global_status_list
382
383 int mirror_image_status_list(
384 IoCtx& io_ctx, const std::string &start_id, size_t max,
385 std::map<std::string, mirror_image_status_t> *images)
386 CEPH_RBD_DEPRECATED;
387
388 // RBD groups support functions
389 int group_create(IoCtx& io_ctx, const char *group_name);
390 int group_remove(IoCtx& io_ctx, const char *group_name);
391 int group_list(IoCtx& io_ctx, std::vector<std::string> *names);
392 int group_rename(IoCtx& io_ctx, const char *src_group_name,
393 const char *dest_group_name);
394
395 int group_image_add(IoCtx& io_ctx, const char *group_name,
396 IoCtx& image_io_ctx, const char *image_name);
397 int group_image_remove(IoCtx& io_ctx, const char *group_name,
398 IoCtx& image_io_ctx, const char *image_name);
399 int group_image_remove_by_id(IoCtx& io_ctx, const char *group_name,
400 IoCtx& image_io_ctx, const char *image_id);
401 int group_image_list(IoCtx& io_ctx, const char *group_name,
402 std::vector<group_image_info_t> *images,
403 size_t group_image_info_size);
404
405 int group_snap_create(IoCtx& io_ctx, const char *group_name,
406 const char *snap_name);
407 int group_snap_remove(IoCtx& io_ctx, const char *group_name,
408 const char *snap_name);
409 int group_snap_rename(IoCtx& group_ioctx, const char *group_name,
410 const char *old_snap_name, const char *new_snap_name);
411 int group_snap_list(IoCtx& group_ioctx, const char *group_name,
412 std::vector<group_snap_info_t> *snaps,
413 size_t group_snap_info_size);
414 int group_snap_rollback(IoCtx& io_ctx, const char *group_name,
415 const char *snap_name);
416 int group_snap_rollback_with_progress(IoCtx& io_ctx, const char *group_name,
417 const char *snap_name,
418 ProgressContext& pctx);
419
420 int namespace_create(IoCtx& ioctx, const char *namespace_name);
421 int namespace_remove(IoCtx& ioctx, const char *namespace_name);
422 int namespace_list(IoCtx& io_ctx, std::vector<std::string>* namespace_names);
423 int namespace_exists(IoCtx& io_ctx, const char *namespace_name, bool *exists);
424
425 int pool_init(IoCtx& io_ctx, bool force);
426 int pool_stats_get(IoCtx& io_ctx, PoolStats *pool_stats);
427
428 int pool_metadata_get(IoCtx &io_ctx, const std::string &key,
429 std::string *value);
430 int pool_metadata_set(IoCtx &io_ctx, const std::string &key,
431 const std::string &value);
432 int pool_metadata_remove(IoCtx &io_ctx, const std::string &key);
433 int pool_metadata_list(IoCtx &io_ctx, const std::string &start, uint64_t max,
434 std::map<std::string, ceph::bufferlist> *pairs);
435
436 int config_list(IoCtx& io_ctx, std::vector<config_option_t> *options);
437
438 private:
439 /* We don't allow assignment or copying */
440 RBD(const RBD& rhs);
441 const RBD& operator=(const RBD& rhs);
442 };
443
444 class CEPH_RBD_API ImageOptions {
445 public:
446 ImageOptions();
447 ImageOptions(rbd_image_options_t opts);
448 ImageOptions(const ImageOptions &imgopts);
449 ~ImageOptions();
450
451 int set(int optname, const std::string& optval);
452 int set(int optname, uint64_t optval);
453 int get(int optname, std::string* optval) const;
454 int get(int optname, uint64_t* optval) const;
455 int is_set(int optname, bool* is_set);
456 int unset(int optname);
457 void clear();
458 bool empty() const;
459
460 private:
461 friend class RBD;
462 friend class Image;
463
464 rbd_image_options_t opts;
465 };
466
467 class CEPH_RBD_API PoolStats {
468 public:
469 PoolStats();
470 ~PoolStats();
471
472 PoolStats(const PoolStats&) = delete;
473 PoolStats& operator=(const PoolStats&) = delete;
474
475 int add(rbd_pool_stat_option_t option, uint64_t* opt_val);
476
477 private:
478 friend class RBD;
479
480 rbd_pool_stats_t pool_stats;
481 };
482
483 class CEPH_RBD_API UpdateWatchCtx {
484 public:
485 virtual ~UpdateWatchCtx() {}
486 /**
487 * Callback activated when we receive a notify event.
488 */
489 virtual void handle_notify() = 0;
490 };
491
492 class CEPH_RBD_API Image
493 {
494 public:
495 Image();
496 ~Image();
497
498 int close();
499 int aio_close(RBD::AioCompletion *c);
500
501 int resize(uint64_t size);
502 int resize2(uint64_t size, bool allow_shrink, ProgressContext& pctx);
503 int resize_with_progress(uint64_t size, ProgressContext& pctx);
504 int stat(image_info_t &info, size_t infosize);
505 int get_name(std::string *name);
506 int get_id(std::string *id);
507 std::string get_block_name_prefix();
508 int64_t get_data_pool_id();
509 int parent_info(std::string *parent_poolname, std::string *parent_name,
510 std::string *parent_snapname)
511 CEPH_RBD_DEPRECATED;
512 int parent_info2(std::string *parent_poolname, std::string *parent_name,
513 std::string *parent_id, std::string *parent_snapname)
514 CEPH_RBD_DEPRECATED;
515 int get_parent(linked_image_spec_t *parent_image, snap_spec_t *parent_snap);
516
517 int old_format(uint8_t *old);
518 int size(uint64_t *size);
519 int get_group(group_info_t *group_info, size_t group_info_size);
520 int features(uint64_t *features);
521 int update_features(uint64_t features, bool enabled);
522 int get_op_features(uint64_t *op_features);
523 int overlap(uint64_t *overlap);
524 int get_flags(uint64_t *flags);
525 int set_image_notification(int fd, int type);
526
527 /* exclusive lock feature */
528 int is_exclusive_lock_owner(bool *is_owner);
529 int lock_acquire(rbd_lock_mode_t lock_mode);
530 int lock_release();
531 int lock_get_owners(rbd_lock_mode_t *lock_mode,
532 std::list<std::string> *lock_owners);
533 int lock_break(rbd_lock_mode_t lock_mode, const std::string &lock_owner);
534
535 /* object map feature */
536 int rebuild_object_map(ProgressContext &prog_ctx);
537
538 int check_object_map(ProgressContext &prog_ctx);
539
540 int copy(IoCtx& dest_io_ctx, const char *destname);
541 int copy2(Image& dest);
542 int copy3(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts);
543 int copy4(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts,
544 size_t sparse_size);
545 int copy_with_progress(IoCtx& dest_io_ctx, const char *destname,
546 ProgressContext &prog_ctx);
547 int copy_with_progress2(Image& dest, ProgressContext &prog_ctx);
548 int copy_with_progress3(IoCtx& dest_io_ctx, const char *destname,
549 ImageOptions& opts, ProgressContext &prog_ctx);
550 int copy_with_progress4(IoCtx& dest_io_ctx, const char *destname,
551 ImageOptions& opts, ProgressContext &prog_ctx,
552 size_t sparse_size);
553
554 /* deep copy */
555 int deep_copy(IoCtx& dest_io_ctx, const char *destname, ImageOptions& opts);
556 int deep_copy_with_progress(IoCtx& dest_io_ctx, const char *destname,
557 ImageOptions& opts, ProgressContext &prog_ctx);
558
559 /* striping */
560 uint64_t get_stripe_unit() const;
561 uint64_t get_stripe_count() const;
562
563 int get_create_timestamp(struct timespec *timestamp);
564 int get_access_timestamp(struct timespec *timestamp);
565 int get_modify_timestamp(struct timespec *timestamp);
566
567 int flatten();
568 int flatten_with_progress(ProgressContext &prog_ctx);
569
570 int sparsify(size_t sparse_size);
571 int sparsify_with_progress(size_t sparse_size, ProgressContext &prog_ctx);
572 /**
573 * Returns a pair of poolname, imagename for each clone
574 * of this image at the currently set snapshot.
575 */
576 int list_children(std::set<std::pair<std::string, std::string> > *children)
577 CEPH_RBD_DEPRECATED;
578 /**
579 * Returns a structure of poolname, imagename, imageid and trash flag
580 * for each clone of this image at the currently set snapshot.
581 */
582 int list_children2(std::vector<librbd::child_info_t> *children)
583 CEPH_RBD_DEPRECATED;
584 int list_children3(std::vector<linked_image_spec_t> *images);
585 int list_descendants(std::vector<linked_image_spec_t> *images);
586
587 /* advisory locking (see librbd.h for details) */
588 int list_lockers(std::list<locker_t> *lockers,
589 bool *exclusive, std::string *tag);
590 int lock_exclusive(const std::string& cookie);
591 int lock_shared(const std::string& cookie, const std::string& tag);
592 int unlock(const std::string& cookie);
593 int break_lock(const std::string& client, const std::string& cookie);
594
595 /* snapshots */
596 int snap_list(std::vector<snap_info_t>& snaps);
597 /* DEPRECATED; use snap_exists2 */
598 bool snap_exists(const char *snapname) CEPH_RBD_DEPRECATED;
599 int snap_exists2(const char *snapname, bool *exists);
600 int snap_create(const char *snapname);
601 int snap_remove(const char *snapname);
602 int snap_remove2(const char *snapname, uint32_t flags, ProgressContext& pctx);
603 int snap_remove_by_id(uint64_t snap_id);
604 int snap_rollback(const char *snap_name);
605 int snap_rollback_with_progress(const char *snap_name, ProgressContext& pctx);
606 int snap_protect(const char *snap_name);
607 int snap_unprotect(const char *snap_name);
608 int snap_is_protected(const char *snap_name, bool *is_protected);
609 int snap_set(const char *snap_name);
610 int snap_set_by_id(uint64_t snap_id);
611 int snap_get_name(uint64_t snap_id, std::string *snap_name);
612 int snap_get_id(const std::string snap_name, uint64_t *snap_id);
613 int snap_rename(const char *srcname, const char *dstname);
614 int snap_get_limit(uint64_t *limit);
615 int snap_set_limit(uint64_t limit);
616 int snap_get_timestamp(uint64_t snap_id, struct timespec *timestamp);
617 int snap_get_namespace_type(uint64_t snap_id,
618 snap_namespace_type_t *namespace_type);
619 int snap_get_group_namespace(uint64_t snap_id,
620 snap_group_namespace_t *group_namespace,
621 size_t snap_group_namespace_size);
622 int snap_get_trash_namespace(uint64_t snap_id, std::string* original_name);
623 int snap_get_mirror_namespace(
624 uint64_t snap_id, snap_mirror_namespace_t *mirror_namespace,
625 size_t snap_mirror_namespace_size);
626
627 /* I/O */
628 ssize_t read(uint64_t ofs, size_t len, ceph::bufferlist& bl);
629 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
630 ssize_t read2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags);
631 int64_t read_iterate(uint64_t ofs, size_t len,
632 int (*cb)(uint64_t, size_t, const char *, void *), void *arg);
633 int read_iterate2(uint64_t ofs, uint64_t len,
634 int (*cb)(uint64_t, size_t, const char *, void *), void *arg);
635 /**
636 * get difference between two versions of an image
637 *
638 * This will return the differences between two versions of an image
639 * via a callback, which gets the offset and length and a flag
640 * indicating whether the extent exists (1), or is known/defined to
641 * be zeros (a hole, 0). If the source snapshot name is NULL, we
642 * interpret that as the beginning of time and return all allocated
643 * regions of the image. The end version is whatever is currently
644 * selected for the image handle (either a snapshot or the writeable
645 * head).
646 *
647 * @param fromsnapname start snapshot name, or NULL
648 * @param ofs start offset
649 * @param len len in bytes of region to report on
650 * @param include_parent true if full history diff should include parent
651 * @param whole_object 1 if diff extents should cover whole object
652 * @param cb callback to call for each allocated region
653 * @param arg argument to pass to the callback
654 * @returns 0 on success, or negative error code on error
655 */
656 int diff_iterate(const char *fromsnapname,
657 uint64_t ofs, uint64_t len,
658 int (*cb)(uint64_t, size_t, int, void *), void *arg);
659 int diff_iterate2(const char *fromsnapname,
660 uint64_t ofs, uint64_t len,
661 bool include_parent, bool whole_object,
662 int (*cb)(uint64_t, size_t, int, void *), void *arg);
663
664 ssize_t write(uint64_t ofs, size_t len, ceph::bufferlist& bl);
665 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
666 ssize_t write2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags);
667
668 int discard(uint64_t ofs, uint64_t len);
669 ssize_t writesame(uint64_t ofs, size_t len, ceph::bufferlist &bl, int op_flags);
670 ssize_t write_zeroes(uint64_t ofs, size_t len, int zero_flags, int op_flags);
671
672 ssize_t compare_and_write(uint64_t ofs, size_t len, ceph::bufferlist &cmp_bl,
673 ceph::bufferlist& bl, uint64_t *mismatch_off, int op_flags);
674
675 int aio_write(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
676 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
677 int aio_write2(uint64_t off, size_t len, ceph::bufferlist& bl,
678 RBD::AioCompletion *c, int op_flags);
679
680 int aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c);
681 int aio_writesame(uint64_t off, size_t len, ceph::bufferlist& bl,
682 RBD::AioCompletion *c, int op_flags);
683 int aio_write_zeroes(uint64_t ofs, size_t len, RBD::AioCompletion *c,
684 int zero_flags, int op_flags);
685
686 int aio_compare_and_write(uint64_t off, size_t len, ceph::bufferlist& cmp_bl,
687 ceph::bufferlist& bl, RBD::AioCompletion *c,
688 uint64_t *mismatch_off, int op_flags);
689
690 /**
691 * read async from image
692 *
693 * The target bufferlist is populated with references to buffers
694 * that contain the data for the given extent of the image.
695 *
696 * NOTE: If caching is enabled, the bufferlist will directly
697 * reference buffers in the cache to avoid an unnecessary data copy.
698 * As a result, if the user intends to modify the buffer contents
699 * directly, they should make a copy first (unconditionally, or when
700 * the reference count on ther underlying buffer is more than 1).
701 *
702 * @param off offset in image
703 * @param len length of read
704 * @param bl bufferlist to read into
705 * @param c aio completion to notify when read is complete
706 */
707 int aio_read(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
708 /* @param op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */
709 int aio_read2(uint64_t off, size_t len, ceph::bufferlist& bl,
710 RBD::AioCompletion *c, int op_flags);
711
712 int flush();
713 /**
714 * Start a flush if caching is enabled. Get a callback when
715 * the currently pending writes are on disk.
716 *
717 * @param image the image to flush writes to
718 * @param c what to call when flushing is complete
719 * @returns 0 on success, negative error code on failure
720 */
721 int aio_flush(RBD::AioCompletion *c);
722
723 /**
724 * Drop any cached data for this image
725 *
726 * @returns 0 on success, negative error code on failure
727 */
728 int invalidate_cache();
729
730 int poll_io_events(RBD::AioCompletion **comps, int numcomp);
731
732 int metadata_get(const std::string &key, std::string *value);
733 int metadata_set(const std::string &key, const std::string &value);
734 int metadata_remove(const std::string &key);
735 /**
736 * Returns a pair of key/value for this image
737 */
738 int metadata_list(const std::string &start, uint64_t max, std::map<std::string, ceph::bufferlist> *pairs);
739
740 // RBD image mirroring support functions
741 int mirror_image_enable() CEPH_RBD_DEPRECATED;
742 int mirror_image_enable2(mirror_image_mode_t mode);
743 int mirror_image_disable(bool force);
744 int mirror_image_promote(bool force);
745 int mirror_image_demote();
746 int mirror_image_resync();
747 int mirror_image_create_snapshot(uint64_t *snap_id);
748 int mirror_image_get_info(mirror_image_info_t *mirror_image_info,
749 size_t info_size);
750 int mirror_image_get_mode(mirror_image_mode_t *mode);
751 int mirror_image_get_global_status(
752 mirror_image_global_status_t *mirror_image_global_status,
753 size_t status_size);
754 int mirror_image_get_status(
755 mirror_image_status_t *mirror_image_status, size_t status_size)
756 CEPH_RBD_DEPRECATED;
757 int mirror_image_get_instance_id(std::string *instance_id);
758 int aio_mirror_image_promote(bool force, RBD::AioCompletion *c);
759 int aio_mirror_image_demote(RBD::AioCompletion *c);
760 int aio_mirror_image_get_info(mirror_image_info_t *mirror_image_info,
761 size_t info_size, RBD::AioCompletion *c);
762 int aio_mirror_image_get_mode(mirror_image_mode_t *mode,
763 RBD::AioCompletion *c);
764 int aio_mirror_image_get_global_status(
765 mirror_image_global_status_t *mirror_image_global_status,
766 size_t status_size, RBD::AioCompletion *c);
767 int aio_mirror_image_get_status(
768 mirror_image_status_t *mirror_image_status, size_t status_size,
769 RBD::AioCompletion *c)
770 CEPH_RBD_DEPRECATED;
771
772 int update_watch(UpdateWatchCtx *ctx, uint64_t *handle);
773 int update_unwatch(uint64_t handle);
774
775 int list_watchers(std::list<image_watcher_t> &watchers);
776
777 int config_list(std::vector<config_option_t> *options);
778
779 private:
780 friend class RBD;
781
782 Image(const Image& rhs);
783 const Image& operator=(const Image& rhs);
784
785 image_ctx_t ctx;
786 };
787
788 } // namespace librbd
789
790 #if __GNUC__ >= 4
791 #pragma GCC diagnostic pop
792 #endif
793
794 #endif // __LIBRBD_HPP