summaryrefslogtreecommitdiffstats
path: root/src/test/cls_lock
diff options
context:
space:
mode:
authorJason Dillaman <dillaman@redhat.com>2014-11-18 09:56:41 +0100
committerJosh Durgin <jdurgin@redhat.com>2015-01-25 00:05:49 +0100
commit71e84e048f73034cb126b9fe25e4571806c351c3 (patch)
tree8d1e3c66fd71d77a7d95971c3dac87973f05f555 /src/test/cls_lock
parentlibrbd: Coordinate maintenance through exclusive lock leader (diff)
downloadceph-71e84e048f73034cb126b9fe25e4571806c351c3.tar.xz
ceph-71e84e048f73034cb126b9fe25e4571806c351c3.zip
cls_lock: New assert_locked operation
The assert_locked operation can be combined with other RADOS ops to prevent an update to a locked object when the client doesn't own the lock. It will not attempt to acquire the lock if the object is not currently locked. Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Diffstat (limited to 'src/test/cls_lock')
-rw-r--r--src/test/cls_lock/test_cls_lock.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/cls_lock/test_cls_lock.cc b/src/test/cls_lock/test_cls_lock.cc
index ead03bb2183..72dbb8ecad0 100644
--- a/src/test/cls_lock/test_cls_lock.cc
+++ b/src/test/cls_lock/test_cls_lock.cc
@@ -298,3 +298,43 @@ TEST(ClsLock, TestLockDuration) {
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
+
+TEST(ClsLock, TestAssertLocked) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ string oid = "foo";
+ Lock l("lock1");
+ ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid));
+
+ librados::ObjectWriteOperation op1;
+ l.assert_locked_exclusive(&op1);
+ ASSERT_EQ(0, ioctx.operate(oid, &op1));
+
+ librados::ObjectWriteOperation op2;
+ l.assert_locked_shared(&op2);
+ ASSERT_EQ(-EBUSY, ioctx.operate(oid, &op2));
+
+ l.set_tag("tag");
+ librados::ObjectWriteOperation op3;
+ l.assert_locked_exclusive(&op3);
+ ASSERT_EQ(-EBUSY, ioctx.operate(oid, &op3));
+ l.set_tag("");
+
+ l.set_cookie("cookie");
+ librados::ObjectWriteOperation op4;
+ l.assert_locked_exclusive(&op4);
+ ASSERT_EQ(-EBUSY, ioctx.operate(oid, &op4));
+ l.set_cookie("");
+
+ ASSERT_EQ(0, l.unlock(&ioctx, oid));
+
+ librados::ObjectWriteOperation op5;
+ l.assert_locked_exclusive(&op5);
+ ASSERT_EQ(-EBUSY, ioctx.operate(oid, &op5));
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}