From 5ec878d7360d7272c8cc89f2ade8e890fc595f5e Mon Sep 17 00:00:00 2001 From: Xiaoxi Chen Date: Mon, 30 Sep 2024 00:43:57 +0800 Subject: [PATCH] Fsync pdev in vdev cp. This is to ensure data written to the vdev(and fiannly to the pdev), is actually written to disk, even pdev uses buffer io. Signed-off-by: Xiaoxi Chen --- src/lib/device/virtual_dev.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/device/virtual_dev.cpp b/src/lib/device/virtual_dev.cpp index 3665f13b9..ef8fa2542 100644 --- a/src/lib/device/virtual_dev.cpp +++ b/src/lib/device/virtual_dev.cpp @@ -574,13 +574,13 @@ folly::Future< std::error_code > VirtualDev::queue_fsync_pdevs() { assert(m_pdevs.size() > 0); if (m_pdevs.size() == 1) { auto* pdev = *(m_pdevs.begin()); - HS_LOG(TRACE, device, "Flushing pdev {}", pdev->get_devname()); + HS_LOG(DEBUG, device, "Flushing pdev {}", pdev->get_devname()); return pdev->queue_fsync(); } else { static thread_local std::vector< folly::Future< std::error_code > > s_futs; s_futs.clear(); for (auto* pdev : m_pdevs) { - HS_LOG(TRACE, device, "Flushing pdev {}", pdev->get_devname()); + HS_LOG(DEBUG, device, "Flushing pdev {}", pdev->get_devname()); s_futs.emplace_back(pdev->queue_fsync()); } return folly::collectAllUnsafe(s_futs).thenTry([](auto&& t) { @@ -683,6 +683,13 @@ void VirtualDev::cp_flush(VDevCPContext* v_cp_ctx) { m_chunk_selector->foreach_chunks( [this, cp](cshared< Chunk >& chunk) { chunk->blk_allocator_mutable()->cp_flush(cp); }); + // fsync the pdev to ensure even pdev open with buffer io, all data we have written prior to this point + // has been persisted to disk. + HS_LOG(DEBUG, device, "in CP flush, fsync-ing pdevs"); + auto fut = queue_fsync_pdevs(); + std::move(fut).wait(); + HS_LOG(DEBUG, device, "in CP flush, pdevs fsync done"); + // All of the blkids which were captured in the current vdev cp context will now be freed and hence available for // allocation on the new CP dirty collection session which is ongoing for (auto const& b : v_cp_ctx->m_free_blkid_list) {