]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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" | |
11fdf7f2 | 5 | #include "gtest/gtest.h" |
f67539c2 | 6 | #include "common/ceph_context.h" |
7c673cae FG |
7 | #include <sstream> |
8 | ||
9 | bool get_features(uint64_t *features) { | |
10 | const char *c = getenv("RBD_FEATURES"); | |
11 | if (c == NULL) { | |
12 | return false; | |
13 | } | |
14 | ||
15 | std::stringstream ss(c); | |
16 | if (!(ss >> *features)) { | |
17 | return false; | |
18 | } | |
19 | return true; | |
20 | } | |
21 | ||
22 | bool is_feature_enabled(uint64_t feature) { | |
23 | uint64_t features; | |
24 | return (get_features(&features) && (features & feature) == feature); | |
25 | } | |
26 | ||
27 | int create_image_full_pp(librbd::RBD &rbd, librados::IoCtx &ioctx, | |
28 | const std::string &name, uint64_t size, | |
29 | uint64_t features, bool old_format, int *order) | |
30 | { | |
31 | if (old_format) { | |
32 | librados::Rados rados(ioctx); | |
33 | int r = rados.conf_set("rbd_default_format", "1"); | |
34 | if (r < 0) { | |
35 | return r; | |
36 | } | |
37 | return rbd.create(ioctx, name.c_str(), size, order); | |
38 | } else if ((features & RBD_FEATURE_STRIPINGV2) != 0) { | |
39 | uint64_t stripe_unit = IMAGE_STRIPE_UNIT; | |
40 | if (*order) { | |
41 | // use a conservative stripe_unit for non default order | |
42 | stripe_unit = (1ull << (*order-1)); | |
43 | } | |
44 | ||
45 | printf("creating image with stripe unit: %" PRIu64 ", stripe count: %" PRIu64 "\n", | |
46 | stripe_unit, IMAGE_STRIPE_COUNT); | |
47 | return rbd.create3(ioctx, name.c_str(), size, features, order, stripe_unit, | |
48 | IMAGE_STRIPE_COUNT); | |
49 | } else { | |
50 | return rbd.create2(ioctx, name.c_str(), size, features, order); | |
51 | } | |
52 | } | |
53 | ||
54 | int create_image_pp(librbd::RBD &rbd, librados::IoCtx &ioctx, | |
55 | const std::string &name, uint64_t size) { | |
56 | int order = 0; | |
57 | uint64_t features = 0; | |
58 | if (!get_features(&features)) { | |
59 | // ensure old-format tests actually use the old format | |
60 | librados::Rados rados(ioctx); | |
61 | int r = rados.conf_set("rbd_default_format", "1"); | |
62 | if (r < 0) { | |
63 | return r; | |
64 | } | |
65 | return rbd.create(ioctx, name.c_str(), size, &order); | |
66 | } else { | |
67 | return rbd.create2(ioctx, name.c_str(), size, features, &order); | |
68 | } | |
69 | } | |
70 | ||
71 | int clone_image_pp(librbd::RBD &rbd, librbd::Image &p_image, librados::IoCtx &p_ioctx, | |
72 | const char *p_name, const char *p_snap_name, librados::IoCtx &c_ioctx, | |
73 | const char *c_name, uint64_t features) | |
74 | { | |
75 | uint64_t stripe_unit = p_image.get_stripe_unit(); | |
76 | uint64_t stripe_count = p_image.get_stripe_count(); | |
77 | ||
78 | librbd::image_info_t p_info; | |
79 | int r = p_image.stat(p_info, sizeof(p_info)); | |
80 | if (r < 0) { | |
81 | return r; | |
82 | } | |
83 | ||
84 | int c_order = p_info.order; | |
85 | return rbd.clone2(p_ioctx, p_name, p_snap_name, c_ioctx, c_name, | |
86 | features, &c_order, stripe_unit, stripe_count); | |
87 | } | |
88 | ||
89 | int get_image_id(librbd::Image &image, std::string *image_id) | |
90 | { | |
91 | int r = image.get_id(image_id); | |
92 | if (r < 0) { | |
93 | return r; | |
94 | } | |
95 | return 0; | |
96 | } | |
97 | ||
98 | int create_image_data_pool(librados::Rados &rados, std::string &data_pool, bool *created) { | |
99 | std::string pool; | |
100 | int r = rados.conf_get("rbd_default_data_pool", pool); | |
101 | if (r != 0) { | |
102 | return r; | |
103 | } else if (pool.empty()) { | |
104 | return 0; | |
105 | } | |
106 | ||
107 | r = rados.pool_create(pool.c_str()); | |
108 | if ((r == 0) || (r == -EEXIST)) { | |
109 | data_pool = pool; | |
110 | *created = (r == 0); | |
111 | return 0; | |
112 | } | |
113 | ||
c07f9fc5 FG |
114 | librados::IoCtx ioctx; |
115 | r = rados.ioctx_create(pool.c_str(), ioctx); | |
116 | if (r < 0) { | |
117 | return r; | |
118 | } | |
c07f9fc5 | 119 | |
11fdf7f2 TL |
120 | librbd::RBD rbd; |
121 | return rbd.pool_init(ioctx, true); | |
7c673cae | 122 | } |
11fdf7f2 TL |
123 | |
124 | bool is_librados_test_stub(librados::Rados &rados) { | |
125 | std::string fsid; | |
126 | EXPECT_EQ(0, rados.cluster_fsid(&fsid)); | |
127 | return fsid == "00000000-1111-2222-3333-444444444444"; | |
128 | } | |
129 | ||
f67539c2 TL |
130 | bool is_rbd_pwl_enabled(ceph::common::CephContext *cct) { |
131 | #if defined(WITH_RBD_RWL) || defined(WITH_RBD_SSD_CACHE) | |
132 | auto value = cct->_conf.get_val<std::string>("rbd_persistent_cache_mode"); | |
133 | return value == "disabled" ? false : true; | |
134 | #else | |
135 | return false; | |
136 | #endif | |
137 | } |