]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_lock: expired lock before unlock and start check 59271/head
authorNitzanMordhai <nmordech@redhat.com>
Sun, 17 Jul 2022 08:01:30 +0000 (08:01 +0000)
committerKonstantin Shalygin <k0ste@k0ste.ru>
Sat, 17 Aug 2024 11:03:04 +0000 (18:03 +0700)
If the lock expired, the stat check shouldn't return -ENOENT,
We will change the lock duration to prevent lock expired before the
stat check.

Fixes: https://tracker.ceph.com/issues/56575
Signed-off-by: Nitzan Mordechai <nmordec@redhat.com>
(cherry picked from commit d3457c64b1bdc26a4379197ae206019a615d2ebc)

src/test/cls_lock/test_cls_lock.cc

index 862720826c42abf87728ff342f48bcb293f72b98..b915de9c2362fa95c51cef1e3c5f2c2f6497ba39 100644 (file)
@@ -63,23 +63,6 @@ void lock_info(IoCtx *ioctx, string& oid, string& name, map<locker_id_t, locker_
   lock_info(ioctx, oid, name, lockers, NULL, NULL);
 }
 
-bool lock_expired(IoCtx *ioctx, string& oid, string& name)
-{
-  ClsLockType lock_type = ClsLockType::NONE;
-  string tag;
-  map<locker_id_t, locker_info_t> lockers;
-  if (0 == get_lock_info(ioctx, oid, name, &lockers, &lock_type, &tag))
-    return false;
-  utime_t now = ceph_clock_now();
-  map<locker_id_t, locker_info_t>::iterator liter;
-  for (liter = lockers.begin(); liter != lockers.end(); ++liter) {
-    if (liter->second.expiration > now)
-      return false;
-  }
-
-  return true;
-}
-
 TEST(ClsLock, TestMultiLocking) {
   Rados cluster;
   std::string pool_name = get_temp_pool_name();
@@ -493,7 +476,7 @@ TEST(ClsLock, TestExclusiveEphemeralBasic) {
   string lock_name2 = "mylock2";
 
   Lock l1(lock_name1);
-  l1.set_duration(utime_t(5, 0));
+  l1.set_duration(utime_t(300, 0));
 
   uint64_t size;
   time_t mod_time;
@@ -502,23 +485,18 @@ TEST(ClsLock, TestExclusiveEphemeralBasic) {
   ASSERT_EQ(0, l1.lock_exclusive_ephemeral(&ioctx, oid1));
   ASSERT_EQ(0, ioctx.stat(oid1, &size, &mod_time));
   sleep(2);
-  int r1 = l1.unlock(&ioctx, oid1);
-  EXPECT_TRUE(r1 == 0 || ((r1 == -ENOENT) && (lock_expired(&ioctx, oid1, lock_name1))))
-    << "unlock should return 0 or -ENOENT return: " << r1;
+  ASSERT_EQ(0, l1.unlock(&ioctx, oid1));
   ASSERT_EQ(-ENOENT, ioctx.stat(oid1, &size, &mod_time));
 
   // ***********************************************
 
   Lock l2(lock_name2);
-  utime_t lock_duration2(5, 0);
-  l2.set_duration(utime_t(5, 0));
+  l2.set_duration(utime_t(300, 0));
 
   ASSERT_EQ(0, l2.lock_exclusive(&ioctx, oid2));
   ASSERT_EQ(0, ioctx.stat(oid2, &size, &mod_time));
   sleep(2);
-  int r2 = l2.unlock(&ioctx, oid2);
-  EXPECT_TRUE(r2 == 0 || ((r2 == -ENOENT) && (lock_expired(&ioctx, oid2, lock_name2))))
-    << "unlock should return 0 or -ENOENT return: " << r2;
+  ASSERT_EQ(0, l2.unlock(&ioctx, oid2));
   ASSERT_EQ(0, ioctx.stat(oid2, &size, &mod_time));
 
   ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));