From: Matan Breizman Date: Thu, 1 Sep 2022 08:16:03 +0000 (+0000) Subject: test/librados/aio_cxx: add multithreaded aio_read test X-Git-Tag: v16.2.11~226^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f35e3964b78be27c5615c6b603566162bb6950bd;p=ceph.git test/librados/aio_cxx: add multithreaded aio_read test Signed-off-by: Matan Breizman (cherry picked from commit c4a2c380ea319ddc1e9997be4130a365f483cf0e) --- diff --git a/src/test/librados/aio_cxx.cc b/src/test/librados/aio_cxx.cc index 84ea454e85c..5df248869f5 100644 --- a/src/test/librados/aio_cxx.cc +++ b/src/test/librados/aio_cxx.cc @@ -2231,3 +2231,47 @@ TEST(LibRadosAio, RoundTripCmpExtPP2) ioctx.remove("test_obj"); destroy_one_pool_pp(pool_name, cluster); } + +// This test case reproduces https://tracker.ceph.com/issues/57152 +TEST(LibRadosAio, MultiReads) { + + // here we test multithreaded aio reads + + AioTestDataPP test_data; + ASSERT_EQ("", test_data.init()); + auto my_completion = std::unique_ptr{Rados::aio_create_completion()}; + ASSERT_TRUE(my_completion); + char buf[128]; + memset(buf, 0xcc, sizeof(buf)); + bufferlist bl1; + bl1.append(buf, sizeof(buf)); + ASSERT_EQ(0, test_data.m_ioctx.aio_write("foo", my_completion.get(), + bl1, sizeof(buf), 0)); + { + TestAlarm alarm; + ASSERT_EQ(0, my_completion->wait_for_complete()); + } + ASSERT_EQ(0, my_completion->get_return_value()); + + // Don't use std::vector to store bufferlists (e.g for parallelizing aio_reads), + // as they are being moved whenever the vector resizes + // and will cause invalidated references. + std::deque>> reads; + for (int i = 0; i < 100; i++) { + // std::deque is appropriate here as emplace_back() is obliged to + // preserve the referenced inserted element. (Unlike insert() or erase()) + auto& [bl, aiocp] = reads.emplace_back(); + aiocp = std::unique_ptr{Rados::aio_create_completion()}; + ASSERT_TRUE(aiocp); + ASSERT_EQ(0, test_data.m_ioctx.aio_read("foo", aiocp.get(), + &bl, sizeof(buf), 0)); + } + for (auto& [bl, aiocp] : reads) { + { + TestAlarm alarm; + ASSERT_EQ(0, aiocp->wait_for_complete()); + } + ASSERT_EQ((int)sizeof(buf), aiocp->get_return_value()); + ASSERT_EQ(0, memcmp(buf, bl.c_str(), sizeof(buf))); + } +}