]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson/seastore: add TestBlockPhysical
authorSamuel Just <sjust@redhat.com>
Wed, 15 Jul 2020 23:47:14 +0000 (16:47 -0700)
committerSamuel Just <sjust@redhat.com>
Thu, 16 Jul 2020 23:16:38 +0000 (16:16 -0700)
TestBlock doesn't work without the rest of the TransactionManager
machinery.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/os/seastore/cache.cc
src/crimson/os/seastore/seastore_types.cc
src/crimson/os/seastore/seastore_types.h
src/test/crimson/seastore/test_block.h
src/test/crimson/seastore/test_btree_lba_manager.cc
src/test/crimson/seastore/test_seastore_cache.cc

index 25a337633c7813364318c441fff3f8b528cd9807..f03ead74ab0abde9f1bfaeb4cf16e9b39172ece3 100644 (file)
@@ -295,6 +295,11 @@ Cache::get_extent_ertr::future<CachedExtentRef> Cache::get_extent_by_type(
     ).safe_then([](auto extent) {
       return CachedExtentRef(extent.detach(), false /* add_ref */);
     });
+  case extent_types_t::TEST_BLOCK_PHYSICAL:
+    return get_extent<TestBlockPhysical>(offset, length
+    ).safe_then([](auto extent) {
+      return CachedExtentRef(extent.detach(), false /* add_ref */);
+    });
   case extent_types_t::NONE: {
     ceph_assert(0 == "NONE is an invalid extent type");
     return get_extent_ertr::make_ready_future<CachedExtentRef>();
index 85914241caa2a2f83b5d5e0881d25732b715fa92..becd0469200bc8c6a7e2b6be21f91296fec57598 100644 (file)
@@ -45,6 +45,8 @@ std::ostream &operator<<(std::ostream &out, extent_types_t t)
     return out << "LADDR_LEAF";
   case extent_types_t::TEST_BLOCK:
     return out << "TEST_BLOCK";
+  case extent_types_t::TEST_BLOCK_PHYSICAL:
+    return out << "TEST_BLOCK_PHYSICAL";
   case extent_types_t::NONE:
     return out << "NONE";
   default:
index a0e61b16ab94cea497dc49de54a6806218dc3364..b735b37792c6fb3452f631a96829e1bc4213fb88 100644 (file)
@@ -215,6 +215,7 @@ enum class extent_types_t : uint8_t {
 
   // Test Block Types
   TEST_BLOCK = 0xF0,
+  TEST_BLOCK_PHYSICAL = 0xF1,
 
   // None
   NONE = 0xFF
index 446e7ec031428d43c7431b4514ff9033fb06ee49..81ac32f365d694ceac16ab1c476c4ad031115f3e 100644 (file)
@@ -89,6 +89,42 @@ struct TestBlock : crimson::os::seastore::LogicalCachedExtent {
 };
 using TestBlockRef = TCachedExtentRef<TestBlock>;
 
+struct TestBlockPhysical : crimson::os::seastore::CachedExtent{
+  constexpr static segment_off_t SIZE = 4<<10;
+  using Ref = TCachedExtentRef<TestBlockPhysical>;
+
+  std::vector<test_block_delta_t> delta = {};
+
+  TestBlockPhysical(ceph::bufferptr &&ptr)
+    : CachedExtent(std::move(ptr)) {}
+  TestBlockPhysical(const TestBlock &other)
+    : CachedExtent(other) {}
+
+  CachedExtentRef duplicate_for_write() final {
+    return CachedExtentRef(new TestBlockPhysical(*this));
+  };
+
+  static constexpr extent_types_t TYPE = extent_types_t::TEST_BLOCK_PHYSICAL;
+  extent_types_t get_type() const final {
+    return TYPE;
+  }
+
+  void set_contents(char c, uint16_t offset, uint16_t len) {
+    ::memset(get_bptr().c_str() + offset, c, len);
+  }
+
+  void set_contents(char c) {
+    set_contents(c, 0, get_length());
+  }
+
+  ceph::bufferlist get_delta() final { return ceph::bufferlist(); }
+
+  int checksum() { return 0; }
+
+  void apply_delta_and_adjust_crc(paddr_t, const ceph::bufferlist &bl) final {}
+};
+using TestBlockPhysicalRef = TCachedExtentRef<TestBlockPhysical>;
+
 struct test_block_mutator_t {
   std::uniform_int_distribution<int8_t>
   contents_distribution = std::uniform_int_distribution<int8_t>(
index 91846919987ba1cdb60a4420f06313f0488533f2..be5408ebacd304a92762ba89f25a2fe9f5148e37 100644 (file)
@@ -122,7 +122,7 @@ struct btree_lba_manager_test :
       lba_manager->create_transaction(),
       test_lba_mappings
     };
-    cache.alloc_new_extent<TestBlock>(*t.t, TestBlock::SIZE);
+    cache.alloc_new_extent<TestBlockPhysical>(*t.t, TestBlockPhysical::SIZE);
     return t;
   }
 
index 6091fd67edc7ac9da450ac9454aa88ead61add1c..96fd87aa46b16972319422eba32bfbc78d7e16a0 100644 (file)
@@ -103,9 +103,9 @@ TEST_F(cache_test_t, test_addr_fixup)
     int csum = 0;
     {
       auto t = get_transaction();
-      auto extent = cache.alloc_new_extent<TestBlock>(
+      auto extent = cache.alloc_new_extent<TestBlockPhysical>(
        *t,
-       TestBlock::SIZE);
+       TestBlockPhysical::SIZE);
       extent->set_contents('c');
       csum = extent->checksum();
       auto ret = submit_transaction(std::move(t)).get0();
@@ -114,10 +114,10 @@ TEST_F(cache_test_t, test_addr_fixup)
     }
     {
       auto t = get_transaction();
-      auto extent = cache.get_extent<TestBlock>(
+      auto extent = cache.get_extent<TestBlockPhysical>(
        *t,
        addr,
-       TestBlock::SIZE).unsafe_get0();
+       TestBlockPhysical::SIZE).unsafe_get0();
       ASSERT_EQ(extent->get_paddr(), addr);
       ASSERT_EQ(extent->checksum(), csum);
     }
@@ -133,9 +133,9 @@ TEST_F(cache_test_t, test_dirty_extent)
     {
       // write out initial test block
       auto t = get_transaction();
-      auto extent = cache.alloc_new_extent<TestBlock>(
+      auto extent = cache.alloc_new_extent<TestBlockPhysical>(
        *t,
-       TestBlock::SIZE);
+       TestBlockPhysical::SIZE);
       extent->set_contents('c');
       csum = extent->checksum();
       auto reladdr = extent->get_paddr();
@@ -143,10 +143,10 @@ TEST_F(cache_test_t, test_dirty_extent)
       {
        // test that read with same transaction sees new block though
        // uncommitted
-       auto extent = cache.get_extent<TestBlock>(
+       auto extent = cache.get_extent<TestBlockPhysical>(
          *t,
          reladdr,
-         TestBlock::SIZE).unsafe_get0();
+         TestBlockPhysical::SIZE).unsafe_get0();
        ASSERT_TRUE(extent->is_clean());
        ASSERT_TRUE(extent->is_pending());
        ASSERT_TRUE(extent->get_paddr().is_relative());
@@ -160,26 +160,26 @@ TEST_F(cache_test_t, test_dirty_extent)
     {
       // test that consecutive reads on the same extent get the same ref
       auto t = get_transaction();
-      auto extent = cache.get_extent<TestBlock>(
+      auto extent = cache.get_extent<TestBlockPhysical>(
        *t,
        addr,
-       TestBlock::SIZE).unsafe_get0();
+       TestBlockPhysical::SIZE).unsafe_get0();
       auto t2 = get_transaction();
-      auto extent2 = cache.get_extent<TestBlock>(
+      auto extent2 = cache.get_extent<TestBlockPhysical>(
        *t2,
        addr,
-       TestBlock::SIZE).unsafe_get0();
+       TestBlockPhysical::SIZE).unsafe_get0();
       ASSERT_EQ(&*extent, &*extent2);
     }
     {
       // read back test block
       auto t = get_transaction();
-      auto extent = cache.get_extent<TestBlock>(
+      auto extent = cache.get_extent<TestBlockPhysical>(
        *t,
        addr,
-       TestBlock::SIZE).unsafe_get0();
+       TestBlockPhysical::SIZE).unsafe_get0();
       // duplicate and reset contents
-      extent = cache.duplicate_for_write(*t, extent)->cast<TestBlock>();
+      extent = cache.duplicate_for_write(*t, extent)->cast<TestBlockPhysical>();
       extent->set_contents('c');
       csum2 = extent->checksum();
       ASSERT_EQ(extent->get_paddr(), addr);
@@ -187,10 +187,10 @@ TEST_F(cache_test_t, test_dirty_extent)
        // test that concurrent read with fresh transaction sees old
         // block
        auto t2 = get_transaction();
-       auto extent = cache.get_extent<TestBlock>(
+       auto extent = cache.get_extent<TestBlockPhysical>(
          *t2,
          addr,
-         TestBlock::SIZE).unsafe_get0();
+         TestBlockPhysical::SIZE).unsafe_get0();
        ASSERT_TRUE(extent->is_clean());
        ASSERT_FALSE(extent->is_pending());
        ASSERT_EQ(addr, extent->get_paddr());
@@ -199,10 +199,10 @@ TEST_F(cache_test_t, test_dirty_extent)
       }
       {
        // test that read with same transaction sees new block
-       auto extent = cache.get_extent<TestBlock>(
+       auto extent = cache.get_extent<TestBlockPhysical>(
          *t,
          addr,
-         TestBlock::SIZE).unsafe_get0();
+         TestBlockPhysical::SIZE).unsafe_get0();
        ASSERT_TRUE(extent->is_dirty());
        ASSERT_TRUE(extent->is_pending());
        ASSERT_EQ(addr, extent->get_paddr());
@@ -220,10 +220,10 @@ TEST_F(cache_test_t, test_dirty_extent)
     {
       // test that fresh transaction now sees newly dirty block
       auto t = get_transaction();
-      auto extent = cache.get_extent<TestBlock>(
+      auto extent = cache.get_extent<TestBlockPhysical>(
        *t,
        addr,
-       TestBlock::SIZE).unsafe_get0();
+       TestBlockPhysical::SIZE).unsafe_get0();
       ASSERT_TRUE(extent->is_dirty());
       ASSERT_EQ(addr, extent->get_paddr());
       ASSERT_EQ(extent->get_version(), 1);