1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_LIBRBD_INTERNAL_H
4 #define CEPH_LIBRBD_INTERNAL_H
6 #include "include/int_types.h"
13 #include "include/buffer_fwd.h"
14 #include "include/rbd/librbd.hpp"
15 #include "include/rbd_types.h"
16 #include "cls/rbd/cls_rbd_types.h"
17 #include "common/ceph_time.h"
18 #include "librbd/Types.h"
23 namespace io
{ struct AioCompletion
; }
25 class NoOpProgressContext
: public ProgressContext
31 int update_progress(uint64_t offset
, uint64_t src_size
) override
37 int detect_format(librados::IoCtx
&io_ctx
, const std::string
&name
,
38 bool *old_format
, uint64_t *size
);
40 bool has_parent(int64_t parent_pool_id
, uint64_t off
, uint64_t overlap
);
42 std::string
image_option_name(int optname
);
43 void image_options_create(rbd_image_options_t
* opts
);
44 void image_options_create_ref(rbd_image_options_t
* opts
,
45 rbd_image_options_t orig
);
46 void image_options_copy(rbd_image_options_t
*opts
,
47 const ImageOptions
&orig
);
48 void image_options_destroy(rbd_image_options_t opts
);
49 int image_options_set(rbd_image_options_t opts
, int optname
,
50 const std::string
& optval
);
51 int image_options_set(rbd_image_options_t opts
, int optname
, uint64_t optval
);
52 int image_options_get(rbd_image_options_t opts
, int optname
,
54 int image_options_get(rbd_image_options_t opts
, int optname
,
56 int image_options_is_set(rbd_image_options_t opts
, int optname
,
58 int image_options_unset(rbd_image_options_t opts
, int optname
);
59 void image_options_clear(rbd_image_options_t opts
);
60 bool image_options_is_empty(rbd_image_options_t opts
);
62 int create(librados::IoCtx
& io_ctx
, const char *imgname
, uint64_t size
,
64 int create(librados::IoCtx
& io_ctx
, const char *imgname
, uint64_t size
,
65 bool old_format
, uint64_t features
, int *order
,
66 uint64_t stripe_unit
, uint64_t stripe_count
);
67 int create(IoCtx
& io_ctx
, const std::string
&image_name
,
68 const std::string
&image_id
, uint64_t size
, ImageOptions
& opts
,
69 const std::string
&non_primary_global_image_id
,
70 const std::string
&primary_mirror_uuid
,
71 bool skip_mirror_enable
);
72 int clone(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
73 IoCtx
& c_ioctx
, const char *c_name
,
74 uint64_t features
, int *c_order
,
75 uint64_t stripe_unit
, int stripe_count
);
76 int clone(IoCtx
& p_ioctx
, const char *p_id
, const char *p_name
,
77 const char *p_snap_name
, IoCtx
& c_ioctx
, const char *c_id
,
78 const char *c_name
, ImageOptions
& c_opts
,
79 const std::string
&non_primary_global_image_id
,
80 const std::string
&primary_mirror_uuid
);
81 int rename(librados::IoCtx
& io_ctx
, const char *srcname
, const char *dstname
);
82 int info(ImageCtx
*ictx
, image_info_t
& info
, size_t image_size
);
83 int get_old_format(ImageCtx
*ictx
, uint8_t *old
);
84 int get_size(ImageCtx
*ictx
, uint64_t *size
);
85 int get_features(ImageCtx
*ictx
, uint64_t *features
);
86 int get_overlap(ImageCtx
*ictx
, uint64_t *overlap
);
87 int get_flags(ImageCtx
*ictx
, uint64_t *flags
);
88 int set_image_notification(ImageCtx
*ictx
, int fd
, int type
);
89 int is_exclusive_lock_owner(ImageCtx
*ictx
, bool *is_owner
);
90 int lock_acquire(ImageCtx
*ictx
, rbd_lock_mode_t lock_mode
);
91 int lock_release(ImageCtx
*ictx
);
92 int lock_get_owners(ImageCtx
*ictx
, rbd_lock_mode_t
*lock_mode
,
93 std::list
<std::string
> *lock_owners
);
94 int lock_break(ImageCtx
*ictx
, rbd_lock_mode_t lock_mode
,
95 const std::string
&lock_owner
);
97 int copy(ImageCtx
*ictx
, IoCtx
& dest_md_ctx
, const char *destname
,
98 ImageOptions
& opts
, ProgressContext
&prog_ctx
, size_t sparse_size
);
99 int copy(ImageCtx
*src
, ImageCtx
*dest
, ProgressContext
&prog_ctx
, size_t sparse_size
);
101 /* cooperative locking */
102 int list_lockers(ImageCtx
*ictx
,
103 std::list
<locker_t
> *locks
,
106 int lock(ImageCtx
*ictx
, bool exclusive
, const std::string
& cookie
,
107 const std::string
& tag
);
108 int lock_shared(ImageCtx
*ictx
, const std::string
& cookie
,
109 const std::string
& tag
);
110 int unlock(ImageCtx
*ictx
, const std::string
& cookie
);
111 int break_lock(ImageCtx
*ictx
, const std::string
& client
,
112 const std::string
& cookie
);
114 void trim_image(ImageCtx
*ictx
, uint64_t newsize
, ProgressContext
& prog_ctx
);
116 int read_header_bl(librados::IoCtx
& io_ctx
, const std::string
& md_oid
,
117 ceph::bufferlist
& header
, uint64_t *ver
);
118 int read_header(librados::IoCtx
& io_ctx
, const std::string
& md_oid
,
119 struct rbd_obj_header_ondisk
*header
, uint64_t *ver
);
120 int tmap_set(librados::IoCtx
& io_ctx
, const std::string
& imgname
);
121 int tmap_rm(librados::IoCtx
& io_ctx
, const std::string
& imgname
);
122 void image_info(const ImageCtx
*ictx
, image_info_t
& info
, size_t info_size
);
123 uint64_t oid_to_object_no(const std::string
& oid
,
124 const std::string
& object_prefix
);
125 int clip_io(ImageCtx
*ictx
, uint64_t off
, uint64_t *len
);
126 void init_rbd_header(struct rbd_obj_header_ondisk
& ondisk
,
127 uint64_t size
, int order
, uint64_t bid
);
129 int64_t read_iterate(ImageCtx
*ictx
, uint64_t off
, uint64_t len
,
130 int (*cb
)(uint64_t, size_t, const char *, void *),
133 int invalidate_cache(ImageCtx
*ictx
);
134 int poll_io_events(ImageCtx
*ictx
, io::AioCompletion
**comps
, int numcomp
);
135 int metadata_list(ImageCtx
*ictx
, const std::string
&last
, uint64_t max
,
136 std::map
<std::string
, bufferlist
> *pairs
);
137 int metadata_get(ImageCtx
*ictx
, const std::string
&key
, std::string
*value
);
139 int list_watchers(ImageCtx
*ictx
, std::list
<librbd::image_watcher_t
> &watchers
);
142 std::ostream
&operator<<(std::ostream
&os
, const librbd::ImageOptions
&opts
);