Merge pull request #12842 from trociny/wip-break_lock_test

test/librbd: add break_lock test

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2017-01-11 19:30:36 -05:00 committed by GitHub
commit 2e86a67b1b

View File

@ -183,6 +183,12 @@ public:
ASSERT_NE("", m_pool_name = create_pool());
}
bool is_librados_test_stub() {
std::string fsid;
EXPECT_EQ(0, _rados.cluster_fsid(&fsid));
return fsid == "00000000-1111-2222-3333-444444444444";
}
void validate_object_map(rbd_image_t image, bool *passed) {
uint64_t flags;
ASSERT_EQ(0, rbd_get_flags(image, &flags));
@ -5030,6 +5036,59 @@ TEST_F(TestLibRBD, ExclusiveLock)
rados_ioctx_destroy(ioctx);
}
TEST_F(TestLibRBD, BreakLock)
{
REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
REQUIRE(!is_librados_test_stub());
static char buf[10];
rados_t blacklist_cluster;
ASSERT_EQ("", connect_cluster(&blacklist_cluster));
rados_ioctx_t ioctx, blacklist_ioctx;
ASSERT_EQ(0, rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx));
ASSERT_EQ(0, rados_ioctx_create(blacklist_cluster, m_pool_name.c_str(),
&blacklist_ioctx));
std::string name = get_temp_image_name();
uint64_t size = 2 << 20;
int order = 0;
ASSERT_EQ(0, create_image(ioctx, name.c_str(), size, &order));
rbd_image_t image, blacklist_image;
ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL));
ASSERT_EQ(0, rbd_open(blacklist_ioctx, name.c_str(), &blacklist_image, NULL));
ASSERT_EQ(0, rbd_metadata_set(image, "rbd_blacklist_on_break_lock", "true"));
ASSERT_EQ(0, rbd_lock_acquire(blacklist_image, RBD_LOCK_MODE_EXCLUSIVE));
rbd_lock_mode_t lock_mode;
char *lock_owners[1];
size_t max_lock_owners = 1;
ASSERT_EQ(0, rbd_lock_get_owners(image, &lock_mode, lock_owners,
&max_lock_owners));
ASSERT_EQ(RBD_LOCK_MODE_EXCLUSIVE, lock_mode);
ASSERT_STRNE("", lock_owners[0]);
ASSERT_EQ(1U, max_lock_owners);
ASSERT_EQ(0, rbd_lock_break(image, RBD_LOCK_MODE_EXCLUSIVE, lock_owners[0]));
ASSERT_EQ(0, rbd_lock_acquire(image, RBD_LOCK_MODE_EXCLUSIVE));
EXPECT_EQ(0, rados_wait_for_latest_osdmap(blacklist_cluster));
ASSERT_EQ((ssize_t)sizeof(buf), rbd_write(image, 0, sizeof(buf), buf));
ASSERT_EQ(-EBLACKLISTED, rbd_write(blacklist_image, 0, sizeof(buf), buf));
ASSERT_EQ(0, rbd_close(image));
ASSERT_EQ(0, rbd_close(blacklist_image));
rbd_lock_get_owners_cleanup(lock_owners, max_lock_owners);
rados_ioctx_destroy(ioctx);
rados_ioctx_destroy(blacklist_ioctx);
rados_shutdown(blacklist_cluster);
}
TEST_F(TestLibRBD, DiscardAfterWrite)
{
CephContext* cct = reinterpret_cast<CephContext*>(_rados.cct());