]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/librbd: add tests for update_features 41405/head
authorDeepika Upadhyay <dupadhya@redhat.com>
Wed, 19 May 2021 13:02:53 +0000 (18:32 +0530)
committerDeepika Upadhyay <dupadhya@redhat.com>
Thu, 12 Aug 2021 06:16:30 +0000 (11:46 +0530)
* librbd/test_ImageWatcher.cc: tests for async handling of
  update_features
* librbd/test_librbd.cc: tests for updating features when 2 clients with
  exclusive locking involved

Signed-off-by: Deepika Upadhyay <dupadhya@redhat.com>
src/test/librbd/test_ImageWatcher.cc
src/test/librbd/test_librbd.cc

index f02c7b37b814621c4113b4877bb7375220522f20..88a26db7ca31220cb27c5711e157dcb365de4837 100644 (file)
@@ -217,6 +217,13 @@ public:
         *id = payload.async_request_id;
       }
       return true;
+    case NOTIFY_OP_UPDATE_FEATURES:
+      {
+        UpdateFeaturesPayload payload;
+        payload.decode(7, iter);
+        *id = payload.async_request_id;
+      }
+      return true;
     default:
       break;
     }
@@ -431,6 +438,23 @@ struct RebuildObjectMapTask {
   }
 };
 
+struct UpdateFeaturesTask {
+  librbd::ImageCtx *ictx;
+  int result;
+
+  UpdateFeaturesTask(librbd::ImageCtx *ictx)
+    : ictx(ictx), result(0) {}
+
+  void operator()() {
+    std::shared_lock l{ictx->owner_lock};
+    C_SaferCond ctx;
+    uint64_t features = 24;
+    bool enabled = 0;
+    ictx->image_watcher->notify_update_features(0, features, enabled, &ctx);
+    result = ctx.wait();
+  }
+};
+
 TEST_F(TestImageWatcher, NotifyHeaderUpdate) {
   REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
 
@@ -552,6 +576,36 @@ TEST_F(TestImageWatcher, NotifyRebuildObjectMap) {
   ASSERT_EQ(0, rebuild_task.result);
 }
 
+TEST_F(TestImageWatcher, NotifyUpdateFeatures) {
+  REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+  librbd::ImageCtx *ictx;
+  ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+  ASSERT_EQ(0, register_image_watch(*ictx));
+  ASSERT_EQ(0, lock_image(*ictx, ClsLockType::EXCLUSIVE,
+        "auto " + stringify(m_watch_ctx->get_handle())));
+
+  m_notify_acks = {{NOTIFY_OP_UPDATE_FEATURES, create_response_message(0)}};
+
+  UpdateFeaturesTask update_features_task(ictx);
+  boost::thread thread(boost::ref(update_features_task));
+
+  ASSERT_TRUE(wait_for_notifies(*ictx));
+
+  NotifyOps expected_notify_ops;
+  expected_notify_ops += NOTIFY_OP_UPDATE_FEATURES;
+  ASSERT_EQ(expected_notify_ops, m_notifies);
+
+  AsyncRequestId async_request_id;
+  ASSERT_TRUE(extract_async_request_id(NOTIFY_OP_UPDATE_FEATURES,
+                                       &async_request_id));
+
+  ASSERT_EQ(0, notify_async_complete(ictx, async_request_id, 0));
+  ASSERT_TRUE(thread.timed_join(boost::posix_time::seconds(10)));
+  ASSERT_EQ(0, update_features_task.result);
+}
+
 TEST_F(TestImageWatcher, NotifySnapCreate) {
   REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
 
index 4dbd2e2442a8d979d0afcd21489af55e4e4fcb5c..d28d7f2217cbd498dfbb7ce9042ad085a207f6bc 100644 (file)
@@ -5199,6 +5199,43 @@ TEST_F(TestLibRBD, SnapRemoveViaLockOwner)
   ASSERT_TRUE(lock_owner);
 }
 
+TEST_F(TestLibRBD, UpdateFeaturesViaLockOwner) {
+
+  REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+  librados::IoCtx ioctx;
+  ASSERT_EQ(0, _rados.ioctx_create(m_pool_name.c_str(), ioctx));
+
+  std::string name = get_temp_image_name();
+  uint64_t size = 2 << 20;
+  librbd::RBD rbd;
+  int order = 0;
+  //creates full with rbd default features
+  ASSERT_EQ(0, create_image_pp(rbd, ioctx, name.c_str(), size, &order));
+
+  bool lock_owner;
+  librbd::Image image1;
+  ASSERT_EQ(0, rbd.open(ioctx, image1, name.c_str(), NULL));
+  bufferlist bl;
+  ASSERT_EQ(0, image1.write(0, 0, bl));
+  ASSERT_EQ(0, image1.is_exclusive_lock_owner(&lock_owner));
+  ASSERT_TRUE(lock_owner);
+
+  librbd::Image image2;
+  ASSERT_EQ(0, rbd.open(ioctx, image2, name.c_str(), NULL));
+  ASSERT_EQ(0, image2.is_exclusive_lock_owner(&lock_owner));
+  ASSERT_FALSE(lock_owner);
+
+  ASSERT_EQ(0, image2.update_features(RBD_FEATURE_OBJECT_MAP, false));
+  ASSERT_EQ(0, image2.is_exclusive_lock_owner(&lock_owner));
+  ASSERT_FALSE(lock_owner);
+
+  ASSERT_EQ(0, image2.update_features(RBD_FEATURE_OBJECT_MAP, true));
+  ASSERT_EQ(0, image2.is_exclusive_lock_owner(&lock_owner));
+  ASSERT_FALSE(lock_owner);
+
+}
+
 TEST_F(TestLibRBD, EnableJournalingViaLockOwner)
 {
   REQUIRE_FEATURE(RBD_FEATURE_JOURNALING);