#include "test/librbd/test_support.h"
#include "common/Cond.h"
#include "common/Mutex.h"
+#include "common/config.h"
+#include "common/ceph_context.h"
#include "common/errno.h"
#include "include/interval_set.h"
#include "include/stringify.h"
rados_ioctx_t ioctx;
rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx);
+ CephContext* cct = reinterpret_cast<CephContext*>(_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
rbd_image_t image;
int order = 0;
std::string name = get_temp_image_name();
uint64_t size = 2 << 20;
-
+
ASSERT_EQ(0, create_image(ioctx, name.c_str(), size, &order));
ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL));
ASSERT_PASSED(aio_discard_test_data, image, TEST_IO_SIZE*3, TEST_IO_SIZE);
ASSERT_PASSED(read_test_data, image, test_data, 0, TEST_IO_SIZE, 0);
- ASSERT_PASSED(read_test_data, image, zero_data, TEST_IO_SIZE, TEST_IO_SIZE, 0);
+ ASSERT_PASSED(read_test_data, image, skip_discard ? test_data : zero_data,
+ TEST_IO_SIZE, TEST_IO_SIZE, 0);
ASSERT_PASSED(read_test_data, image, test_data, TEST_IO_SIZE*2, TEST_IO_SIZE, 0);
- ASSERT_PASSED(read_test_data, image, zero_data, TEST_IO_SIZE*3, TEST_IO_SIZE, 0);
+ ASSERT_PASSED(read_test_data, image, skip_discard ? test_data : zero_data,
+ TEST_IO_SIZE*3, TEST_IO_SIZE, 0);
ASSERT_PASSED(read_test_data, image, test_data, TEST_IO_SIZE*4, TEST_IO_SIZE, 0);
-
+
rbd_image_info_t info;
rbd_completion_t comp;
ASSERT_EQ(0, rbd_stat(image, &info, sizeof(info)));
rados_ioctx_t ioctx;
rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx);
+ CephContext* cct = reinterpret_cast<CephContext*>(_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
rbd_image_t image;
int order = 0;
std::string name = get_temp_image_name();
ASSERT_PASSED(read_test_data, image, test_data, 0, TEST_IO_SIZE,
LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL);
- ASSERT_PASSED(read_test_data, image, zero_data, TEST_IO_SIZE, TEST_IO_SIZE,
+ ASSERT_PASSED(read_test_data, image, skip_discard ? test_data : zero_data,
+ TEST_IO_SIZE, TEST_IO_SIZE,
LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL);
ASSERT_PASSED(read_test_data, image, test_data, TEST_IO_SIZE*2, TEST_IO_SIZE,
LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL);
- ASSERT_PASSED(read_test_data, image, zero_data, TEST_IO_SIZE*3, TEST_IO_SIZE,
+ ASSERT_PASSED(read_test_data, image, skip_discard ? test_data : zero_data,
+ TEST_IO_SIZE*3, TEST_IO_SIZE,
LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL);
ASSERT_PASSED(read_test_data, image, test_data, TEST_IO_SIZE*4, TEST_IO_SIZE, 0);
*passed = true;
}
-TEST_F(TestLibRBD, TestIOPP)
+TEST_F(TestLibRBD, TestIOPP)
{
librados::IoCtx ioctx;
ASSERT_EQ(0, _rados.ioctx_create(m_pool_name.c_str(), ioctx));
+ CephContext* cct = reinterpret_cast<CephContext*>(_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
{
librbd::RBD rbd;
librbd::Image image;
int order = 0;
std::string name = get_temp_image_name();
uint64_t size = 2 << 20;
-
+
ASSERT_EQ(0, create_image_pp(rbd, ioctx, name.c_str(), size, &order));
ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), NULL));
char test_data[TEST_IO_SIZE + 1];
char zero_data[TEST_IO_SIZE + 1];
int i;
-
+
for (i = 0; i < TEST_IO_SIZE; ++i) {
test_data[i] = (char) (rand() % (126 - 33) + 33);
}
for (i = 0; i < 5; ++i)
ASSERT_PASSED(write_test_data, image, test_data, strlen(test_data) * i, 0);
-
+
for (i = 5; i < 10; ++i)
ASSERT_PASSED(aio_write_test_data, image, test_data, strlen(test_data) * i, 0);
-
+
for (i = 0; i < 5; ++i)
ASSERT_PASSED(read_test_data, image, test_data, strlen(test_data) * i, TEST_IO_SIZE, 0);
-
+
for (i = 5; i < 10; ++i)
ASSERT_PASSED(aio_read_test_data, image, test_data, strlen(test_data) * i, TEST_IO_SIZE, 0);
// discard 2nd, 4th sections.
ASSERT_PASSED(discard_test_data, image, TEST_IO_SIZE, TEST_IO_SIZE);
ASSERT_PASSED(aio_discard_test_data, image, TEST_IO_SIZE*3, TEST_IO_SIZE);
-
+
ASSERT_PASSED(read_test_data, image, test_data, 0, TEST_IO_SIZE, 0);
- ASSERT_PASSED(read_test_data, image, zero_data, TEST_IO_SIZE, TEST_IO_SIZE, 0);
+ ASSERT_PASSED(read_test_data, image, skip_discard ? test_data : zero_data,
+ TEST_IO_SIZE, TEST_IO_SIZE, 0);
ASSERT_PASSED(read_test_data, image, test_data, TEST_IO_SIZE*2, TEST_IO_SIZE, 0);
- ASSERT_PASSED(read_test_data, image, zero_data, TEST_IO_SIZE*3, TEST_IO_SIZE, 0);
+ ASSERT_PASSED(read_test_data, image, skip_discard ? test_data : zero_data,
+ TEST_IO_SIZE*3, TEST_IO_SIZE, 0);
ASSERT_PASSED(read_test_data, image, test_data, TEST_IO_SIZE*4, TEST_IO_SIZE, 0);
ASSERT_PASSED(validate_object_map, image);
return -EINVAL;
}
-void scribble(librbd::Image& image, int n, int max,
+void scribble(librbd::Image& image, int n, int max, bool skip_discard,
interval_set<uint64_t> *exists,
interval_set<uint64_t> *what)
{
for (int i=0; i<n; i++) {
uint64_t off = rand() % (size - max + 1);
uint64_t len = 1 + rand() % max;
- if (rand() % 4 == 0) {
+ if (!skip_discard && rand() % 4 == 0) {
ASSERT_EQ((int)len, image.discard(off, len));
interval_set<uint64_t> w;
w.insert(off, len);
librados::IoCtx ioctx;
ASSERT_EQ(0, this->_rados.ioctx_create(this->m_pool_name.c_str(), ioctx));
+ CephContext* cct = reinterpret_cast<CephContext*>(this->_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
{
librbd::RBD rbd;
librbd::Image image;
interval_set<uint64_t> exists;
interval_set<uint64_t> one, two;
- scribble(image, 10, 102400, &exists, &one);
+ scribble(image, 10, 102400, skip_discard, &exists, &one);
cout << " wrote " << one << std::endl;
ASSERT_EQ(0, image.snap_create("one"));
- scribble(image, 10, 102400, &exists, &two);
+ scribble(image, 10, 102400, skip_discard, &exists, &two);
two = round_diff_interval(two, object_size);
cout << " wrote " << two << std::endl;
librados::IoCtx ioctx;
ASSERT_EQ(0, this->_rados.ioctx_create(this->m_pool_name.c_str(), ioctx));
+ CephContext* cct = reinterpret_cast<CephContext*>(this->_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
librbd::RBD rbd;
librbd::Image image;
int order = 0;
int n = 20;
for (int i=0; i<n; i++) {
interval_set<uint64_t> w;
- scribble(image, 10, 8192000, &curexists, &w);
+ scribble(image, 10, 8192000, skip_discard, &curexists, &w);
cout << " i=" << i << " exists " << curexists << " wrote " << w << std::endl;
string s = "snap" + stringify(i);
ASSERT_EQ(0, image.snap_create(s.c_str()));
librados::IoCtx ioctx;
ASSERT_EQ(0, this->_rados.ioctx_create(this->m_pool_name.c_str(), ioctx));
+ CephContext* cct = reinterpret_cast<CephContext*>(this->_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
librbd::RBD rbd;
librbd::Image image;
std::string name = this->get_temp_image_name();
interval_set<uint64_t> exists;
interval_set<uint64_t> two;
- scribble(image, 10, 102400, &exists, &two);
+ scribble(image, 10, 102400, skip_discard, &exists, &two);
two = round_diff_interval(two, object_size);
cout << " wrote " << two << " to clone" << std::endl;
librados::IoCtx ioctx;
ASSERT_EQ(0, this->_rados.ioctx_create(this->m_pool_name.c_str(), ioctx));
+ CephContext* cct = reinterpret_cast<CephContext*>(this->_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
{
librbd::RBD rbd;
librbd::Image image;
interval_set<uint64_t> exists;
interval_set<uint64_t> one;
- scribble(image, 10, 102400, &exists, &one);
+ scribble(image, 10, 102400, skip_discard, &exists, &one);
cout << " wrote " << one << std::endl;
interval_set<uint64_t> diff;
librados::IoCtx ioctx;
ASSERT_EQ(0, this->_rados.ioctx_create(this->m_pool_name.c_str(), ioctx));
+ CephContext* cct = reinterpret_cast<CephContext*>(this->_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
librbd::RBD rbd;
librbd::Image image;
std::string name = this->get_temp_image_name();
interval_set<uint64_t> exists;
interval_set<uint64_t> one;
- scribble(image, 10, 102400, &exists, &one);
+ scribble(image, 10, 102400, skip_discard, &exists, &one);
ASSERT_EQ(0, image.snap_create("one"));
ASSERT_EQ(1 << order, image.discard(0, 1 << order));
ASSERT_EQ(0, rbd.open(ioctx, image, clone_name.c_str(), NULL));
interval_set<uint64_t> two;
- scribble(image, 10, 102400, &exists, &two);
+ scribble(image, 10, 102400, skip_discard, &exists, &two);
two = round_diff_interval(two, object_size);
interval_set<uint64_t> diff;
librados::IoCtx ioctx;
ASSERT_EQ(0, _rados.ioctx_create(m_pool_name.c_str(), ioctx));
+ CephContext* cct = reinterpret_cast<CephContext*>(_rados.cct());
+ bool skip_discard = cct->_conf->rbd_skip_partial_discard;
+
librbd::RBD rbd;
std::string name = get_temp_image_name();
uint64_t size = 1 << 20;
bufferlist expected_bl;
expected_bl.append(std::string(128, '1'));
- expected_bl.append(std::string(128, '\0'));
+ expected_bl.append(std::string(128, skip_discard ? '1' : '\0'));
ASSERT_TRUE(expected_bl.contents_equal(read_bl));
}