Skip to content

Commit

Permalink
librbd: expand API to include namespaces and image ids
Browse files Browse the repository at this point in the history
The get parent and list children methods now return a common
struct that includes the full pool details (including the
optional namespace). Additionally, a new image list method has
been added which includes both the name and id (of v2 images).

Fixes: http://tracker.ceph.com/issues/36650
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed Nov 25, 2018
1 parent ef634fd commit 3d5f055
Show file tree
Hide file tree
Showing 12 changed files with 1,044 additions and 505 deletions.
85 changes: 68 additions & 17 deletions src/include/rbd/librbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ typedef int (*librbd_progress_fn_t)(uint64_t offset, uint64_t total, void *ptr);

typedef void (*rbd_update_callback_t)(void *arg);

typedef enum {
RBD_SNAP_NAMESPACE_TYPE_USER = 0,
RBD_SNAP_NAMESPACE_TYPE_GROUP = 1,
RBD_SNAP_NAMESPACE_TYPE_TRASH = 2
} rbd_snap_namespace_type_t;

typedef struct {
char *id;
char *name;
} rbd_image_spec_t;

typedef struct {
int64_t pool_id;
char *pool_name;
char *pool_namespace;
char *image_id;
char *image_name;
bool trash;
} rbd_linked_image_spec_t;

typedef struct {
uint64_t id;
rbd_snap_namespace_type_t namespace_type;
char *name;
} rbd_snap_spec_t;

typedef struct {
uint64_t id;
uint64_t size;
Expand Down Expand Up @@ -179,12 +205,6 @@ typedef struct {
rbd_group_snap_state_t state;
} rbd_group_snap_info_t;

typedef enum {
RBD_SNAP_NAMESPACE_TYPE_USER = 0,
RBD_SNAP_NAMESPACE_TYPE_GROUP = 1,
RBD_SNAP_NAMESPACE_TYPE_TRASH = 2
} rbd_snap_namespace_type_t;

typedef struct {
int64_t group_pool;
char *group_name;
Expand Down Expand Up @@ -296,8 +316,21 @@ CEPH_RBD_API int rbd_image_options_unset(rbd_image_options_t opts, int optname);
CEPH_RBD_API void rbd_image_options_clear(rbd_image_options_t opts);
CEPH_RBD_API int rbd_image_options_is_empty(rbd_image_options_t opts);

/* helpers */
CEPH_RBD_API void rbd_image_spec_cleanup(rbd_image_spec_t *image);
CEPH_RBD_API void rbd_image_spec_list_cleanup(rbd_image_spec_t *images,
size_t num_images);
CEPH_RBD_API void rbd_linked_image_spec_cleanup(rbd_linked_image_spec_t *image);
CEPH_RBD_API void rbd_linked_image_spec_list_cleanup(
rbd_linked_image_spec_t *images, size_t num_images);
CEPH_RBD_API void rbd_snap_spec_cleanup(rbd_snap_spec_t *snap);

/* images */
CEPH_RBD_API int rbd_list(rados_ioctx_t io, char *names, size_t *size);
CEPH_RBD_API int rbd_list(rados_ioctx_t io, char *names, size_t *size)
__attribute__((deprecated));
CEPH_RBD_API int rbd_list2(rados_ioctx_t io, rbd_image_spec_t* images,
size_t *max_images);

CEPH_RBD_API int rbd_create(rados_ioctx_t io, const char *name, uint64_t size,
int *order);
CEPH_RBD_API int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size,
Expand Down Expand Up @@ -352,8 +385,10 @@ CEPH_RBD_API int rbd_trash_list(rados_ioctx_t io,
CEPH_RBD_API void rbd_trash_list_cleanup(rbd_trash_image_info_t *trash_entries,
size_t num_entries);
CEPH_RBD_API int rbd_trash_remove(rados_ioctx_t io, const char *id, bool force);
CEPH_RBD_API int rbd_trash_remove_with_progress(rados_ioctx_t io, const char *id,
bool force, librbd_progress_fn_t cb,
CEPH_RBD_API int rbd_trash_remove_with_progress(rados_ioctx_t io,
const char *id,
bool force,
librbd_progress_fn_t cb,
void *cbdata);
CEPH_RBD_API int rbd_trash_restore(rados_ioctx_t io, const char *id,
const char *name);
Expand Down Expand Up @@ -527,18 +562,25 @@ CEPH_RBD_API int rbd_get_id(rbd_image_t image, char *id, size_t id_len);
CEPH_RBD_API int rbd_get_block_name_prefix(rbd_image_t image,
char *prefix, size_t prefix_len);
CEPH_RBD_API int64_t rbd_get_data_pool_id(rbd_image_t image);

CEPH_RBD_API int rbd_get_parent_info(rbd_image_t image,
char *parent_poolname, size_t ppoolnamelen,
char *parent_name, size_t pnamelen,
char *parent_snapname,
size_t psnapnamelen);
size_t psnapnamelen)
__attribute__((deprecated));
CEPH_RBD_API int rbd_get_parent_info2(rbd_image_t image,
char *parent_poolname,
size_t ppoolnamelen,
char *parent_name, size_t pnamelen,
char *parent_id, size_t pidlen,
char *parent_snapname,
size_t psnapnamelen);
size_t psnapnamelen)
__attribute__((deprecated));
CEPH_RBD_API int rbd_get_parent(rbd_image_t image,
rbd_linked_image_spec_t *parent_image,
rbd_snap_spec_t *parent_snap);

CEPH_RBD_API int rbd_get_flags(rbd_image_t image, uint64_t *flags);
CEPH_RBD_API int rbd_get_group(rbd_image_t image, rbd_group_info_t *group_info,
size_t group_info_size);
Expand Down Expand Up @@ -603,8 +645,9 @@ CEPH_RBD_API int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps,
CEPH_RBD_API void rbd_snap_list_end(rbd_snap_info_t *snaps);
CEPH_RBD_API int rbd_snap_create(rbd_image_t image, const char *snapname);
CEPH_RBD_API int rbd_snap_remove(rbd_image_t image, const char *snapname);
CEPH_RBD_API int rbd_snap_remove2(rbd_image_t image, const char *snap_name, uint32_t flags,
librbd_progress_fn_t cb, void *cbdata);
CEPH_RBD_API int rbd_snap_remove2(rbd_image_t image, const char *snap_name,
uint32_t flags, librbd_progress_fn_t cb,
void *cbdata);
CEPH_RBD_API int rbd_snap_remove_by_id(rbd_image_t image, uint64_t snap_id);
CEPH_RBD_API int rbd_snap_rollback(rbd_image_t image, const char *snapname);
CEPH_RBD_API int rbd_snap_rollback_with_progress(rbd_image_t image,
Expand Down Expand Up @@ -710,13 +753,21 @@ CEPH_RBD_API int rbd_flatten_with_progress(rbd_image_t image,
*/
CEPH_RBD_API ssize_t rbd_list_children(rbd_image_t image, char *pools,
size_t *pools_len, char *images,
size_t *images_len);
size_t *images_len)
__attribute__((deprecated));
CEPH_RBD_API int rbd_list_children2(rbd_image_t image,
rbd_child_info_t *children,
int *max_children);
CEPH_RBD_API void rbd_list_child_cleanup(rbd_child_info_t *child);
int *max_children)
__attribute__((deprecated));
CEPH_RBD_API void rbd_list_child_cleanup(rbd_child_info_t *child)
__attribute__((deprecated));
CEPH_RBD_API void rbd_list_children_cleanup(rbd_child_info_t *children,
size_t num_children);
size_t num_children)
__attribute__((deprecated));

CEPH_RBD_API int rbd_list_children3(rbd_image_t image,
rbd_linked_image_spec_t *images,
size_t *max_images);

/**
* @defgroup librbd_h_locking Advisory Locking
Expand Down
45 changes: 38 additions & 7 deletions src/include/rbd/librbd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,34 @@ namespace librbd {
typedef void *completion_t;
typedef void (*callback_t)(completion_t cb, void *arg);

typedef struct {
std::string id;
std::string name;
} image_spec_t;

typedef struct {
int64_t pool_id;
std::string pool_name;
std::string pool_namespace;
std::string image_id;
std::string image_name;
bool trash;
} linked_image_spec_t;

typedef rbd_snap_namespace_type_t snap_namespace_type_t;

typedef struct {
uint64_t id;
snap_namespace_type_t namespace_type;
std::string name;
} snap_spec_t;

typedef struct {
uint64_t id;
uint64_t size;
std::string name;
} snap_info_t;

typedef rbd_snap_namespace_type_t snap_namespace_type_t;

typedef struct {
int64_t group_pool;
std::string group_name;
Expand Down Expand Up @@ -190,7 +210,11 @@ class CEPH_RBD_API RBD
const char *snapname, RBD::AioCompletion *c);
int aio_open_by_id_read_only(IoCtx& io_ctx, Image& image, const char *id,
const char *snapname, RBD::AioCompletion *c);
int list(IoCtx& io_ctx, std::vector<std::string>& names);

int list(IoCtx& io_ctx, std::vector<std::string>& names)
__attribute__((deprecated));
int list2(IoCtx& io_ctx, std::vector<image_spec_t>* images);

int create(IoCtx& io_ctx, const char *name, uint64_t size, int *order);
int create2(IoCtx& io_ctx, const char *name, uint64_t size,
uint64_t features, int *order);
Expand Down Expand Up @@ -383,9 +407,13 @@ class CEPH_RBD_API Image
std::string get_block_name_prefix();
int64_t get_data_pool_id();
int parent_info(std::string *parent_poolname, std::string *parent_name,
std::string *parent_snapname);
std::string *parent_snapname)
__attribute__((deprecated));
int parent_info2(std::string *parent_poolname, std::string *parent_name,
std::string *parent_id, std::string *parent_snapname);
std::string *parent_id, std::string *parent_snapname)
__attribute__((deprecated));
int get_parent(linked_image_spec_t *parent_image, snap_spec_t *parent_snap);

int old_format(uint8_t *old);
int size(uint64_t *size);
int get_group(group_info_t *group_info, size_t group_info_size);
Expand Down Expand Up @@ -442,12 +470,15 @@ class CEPH_RBD_API Image
* Returns a pair of poolname, imagename for each clone
* of this image at the currently set snapshot.
*/
int list_children(std::set<std::pair<std::string, std::string> > *children);
int list_children(std::set<std::pair<std::string, std::string> > *children)
__attribute__((deprecated));
/**
* Returns a structure of poolname, imagename, imageid and trash flag
* for each clone of this image at the currently set snapshot.
*/
int list_children2(std::vector<librbd::child_info_t> *children);
int list_children2(std::vector<librbd::child_info_t> *children)
__attribute__((deprecated));
int list_children3(std::vector<linked_image_spec_t> *images);

/* advisory locking (see librbd.h for details) */
int list_lockers(std::list<locker_t> *lockers,
Expand Down

0 comments on commit 3d5f055

Please sign in to comment.