From: Samuel Just Date: Wed, 15 Jul 2020 23:47:14 +0000 (-0700) Subject: test/crimson/seastore: add TestBlockPhysical X-Git-Tag: v16.1.0~1513^2~22 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fe636f712198abee0e2e6653ffafa67861224a3a;p=ceph.git test/crimson/seastore: add TestBlockPhysical TestBlock doesn't work without the rest of the TransactionManager machinery. Signed-off-by: Samuel Just --- diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index 25a337633c7..f03ead74ab0 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -295,6 +295,11 @@ Cache::get_extent_ertr::future 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(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(); diff --git a/src/crimson/os/seastore/seastore_types.cc b/src/crimson/os/seastore/seastore_types.cc index 85914241caa..becd0469200 100644 --- a/src/crimson/os/seastore/seastore_types.cc +++ b/src/crimson/os/seastore/seastore_types.cc @@ -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: diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index a0e61b16ab9..b735b37792c 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -215,6 +215,7 @@ enum class extent_types_t : uint8_t { // Test Block Types TEST_BLOCK = 0xF0, + TEST_BLOCK_PHYSICAL = 0xF1, // None NONE = 0xFF diff --git a/src/test/crimson/seastore/test_block.h b/src/test/crimson/seastore/test_block.h index 446e7ec0314..81ac32f365d 100644 --- a/src/test/crimson/seastore/test_block.h +++ b/src/test/crimson/seastore/test_block.h @@ -89,6 +89,42 @@ struct TestBlock : crimson::os::seastore::LogicalCachedExtent { }; using TestBlockRef = TCachedExtentRef; +struct TestBlockPhysical : crimson::os::seastore::CachedExtent{ + constexpr static segment_off_t SIZE = 4<<10; + using Ref = TCachedExtentRef; + + std::vector 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; + struct test_block_mutator_t { std::uniform_int_distribution contents_distribution = std::uniform_int_distribution( diff --git a/src/test/crimson/seastore/test_btree_lba_manager.cc b/src/test/crimson/seastore/test_btree_lba_manager.cc index 91846919987..be5408ebacd 100644 --- a/src/test/crimson/seastore/test_btree_lba_manager.cc +++ b/src/test/crimson/seastore/test_btree_lba_manager.cc @@ -122,7 +122,7 @@ struct btree_lba_manager_test : lba_manager->create_transaction(), test_lba_mappings }; - cache.alloc_new_extent(*t.t, TestBlock::SIZE); + cache.alloc_new_extent(*t.t, TestBlockPhysical::SIZE); return t; } diff --git a/src/test/crimson/seastore/test_seastore_cache.cc b/src/test/crimson/seastore/test_seastore_cache.cc index 6091fd67edc..96fd87aa46b 100644 --- a/src/test/crimson/seastore/test_seastore_cache.cc +++ b/src/test/crimson/seastore/test_seastore_cache.cc @@ -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( + auto extent = cache.alloc_new_extent( *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( + auto extent = cache.get_extent( *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( + auto extent = cache.alloc_new_extent( *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( + auto extent = cache.get_extent( *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( + auto extent = cache.get_extent( *t, addr, - TestBlock::SIZE).unsafe_get0(); + TestBlockPhysical::SIZE).unsafe_get0(); auto t2 = get_transaction(); - auto extent2 = cache.get_extent( + auto extent2 = cache.get_extent( *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( + auto extent = cache.get_extent( *t, addr, - TestBlock::SIZE).unsafe_get0(); + TestBlockPhysical::SIZE).unsafe_get0(); // duplicate and reset contents - extent = cache.duplicate_for_write(*t, extent)->cast(); + extent = cache.duplicate_for_write(*t, extent)->cast(); 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( + auto extent = cache.get_extent( *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( + auto extent = cache.get_extent( *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( + auto extent = cache.get_extent( *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);