]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/librbd/test_support.cc
fa8e25194a7661b2856f2d920bab83e406b06550
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #include "test/librbd/test_support.h"
4 #include "include/rbd_types.h"
7 bool get_features(uint64_t *features
) {
8 const char *c
= getenv("RBD_FEATURES");
13 std::stringstream
ss(c
);
14 if (!(ss
>> *features
)) {
20 bool is_feature_enabled(uint64_t feature
) {
22 return (get_features(&features
) && (features
& feature
) == feature
);
25 int create_image_full_pp(librbd::RBD
&rbd
, librados::IoCtx
&ioctx
,
26 const std::string
&name
, uint64_t size
,
27 uint64_t features
, bool old_format
, int *order
)
30 librados::Rados
rados(ioctx
);
31 int r
= rados
.conf_set("rbd_default_format", "1");
35 return rbd
.create(ioctx
, name
.c_str(), size
, order
);
36 } else if ((features
& RBD_FEATURE_STRIPINGV2
) != 0) {
37 uint64_t stripe_unit
= IMAGE_STRIPE_UNIT
;
39 // use a conservative stripe_unit for non default order
40 stripe_unit
= (1ull << (*order
-1));
43 printf("creating image with stripe unit: %" PRIu64
", stripe count: %" PRIu64
"\n",
44 stripe_unit
, IMAGE_STRIPE_COUNT
);
45 return rbd
.create3(ioctx
, name
.c_str(), size
, features
, order
, stripe_unit
,
48 return rbd
.create2(ioctx
, name
.c_str(), size
, features
, order
);
52 int create_image_pp(librbd::RBD
&rbd
, librados::IoCtx
&ioctx
,
53 const std::string
&name
, uint64_t size
) {
55 uint64_t features
= 0;
56 if (!get_features(&features
)) {
57 // ensure old-format tests actually use the old format
58 librados::Rados
rados(ioctx
);
59 int r
= rados
.conf_set("rbd_default_format", "1");
63 return rbd
.create(ioctx
, name
.c_str(), size
, &order
);
65 return rbd
.create2(ioctx
, name
.c_str(), size
, features
, &order
);
69 int clone_image_pp(librbd::RBD
&rbd
, librbd::Image
&p_image
, librados::IoCtx
&p_ioctx
,
70 const char *p_name
, const char *p_snap_name
, librados::IoCtx
&c_ioctx
,
71 const char *c_name
, uint64_t features
)
73 uint64_t stripe_unit
= p_image
.get_stripe_unit();
74 uint64_t stripe_count
= p_image
.get_stripe_count();
76 librbd::image_info_t p_info
;
77 int r
= p_image
.stat(p_info
, sizeof(p_info
));
82 int c_order
= p_info
.order
;
83 return rbd
.clone2(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
84 features
, &c_order
, stripe_unit
, stripe_count
);
87 int get_image_id(librbd::Image
&image
, std::string
*image_id
)
89 int r
= image
.get_id(image_id
);
96 int create_image_data_pool(librados::Rados
&rados
, std::string
&data_pool
, bool *created
) {
98 int r
= rados
.conf_get("rbd_default_data_pool", pool
);
101 } else if (pool
.empty()) {
105 r
= rados
.pool_create(pool
.c_str());
106 if ((r
== 0) || (r
== -EEXIST
)) {