From 4087a1289056fbdc57196ab07040ba3a584b9f76 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 13 Jun 2019 22:44:16 +0800 Subject: [PATCH] crimson/os: use buffer::write_file() helper instead of using the blocking calls so we can write to file without blocking the reactor Signed-off-by: Kefu Chai --- src/crimson/common/buffer_io.cc | 9 ++++--- src/crimson/os/cyan_store.cc | 47 +++++++++++++++------------------ 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/crimson/common/buffer_io.cc b/src/crimson/common/buffer_io.cc index 8e33cab44a87a..9a08228077f5b 100644 --- a/src/crimson/common/buffer_io.cc +++ b/src/crimson/common/buffer_io.cc @@ -19,9 +19,12 @@ seastar::future<> write_file(ceph::buffer::list&& bl, foo.create_permissions = permissions; return seastar::open_file_dma(fn, flags, foo).then( [bl=std::move(bl)](seastar::file f) { - return seastar::do_with(seastar::make_file_output_stream(f), std::move(f), - [&bl](seastar::output_stream& out, - seastar::file& f) { + return seastar::do_with(seastar::make_file_output_stream(f), + std::move(f), + std::move(bl), + [](seastar::output_stream& out, + seastar::file& f, + ceph::buffer::list& bl) { return seastar::do_for_each(bl.buffers(), [&out](auto& buf) { return out.write(buf.c_str(), buf.length()); }).then([&out] { diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc index 79102f0f6f5a3..016a63e5f644d 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -4,7 +4,7 @@ #include #include "common/safe_io.h" - +#include "crimson/common/buffer_io.h" #include "crimson/os/cyan_collection.h" #include "crimson/os/cyan_object.h" #include "os/Transaction.h" @@ -55,25 +55,22 @@ seastar::future<> CyanStore::mount() seastar::future<> CyanStore::umount() { - std::set collections; - for (auto& [col, ch] : coll_map) { - collections.insert(col); - ceph::bufferlist bl; - ceph_assert(ch); - ch->encode(bl); - std::string fn = fmt::format("{}/{}", path, col); - if (int r = bl.write_file(fn.c_str()); r < 0) { - throw std::runtime_error("write_file"); - } - } - - std::string fn = path + "/collections"; - ceph::bufferlist bl; - ceph::encode(collections, bl); - if (int r = bl.write_file(fn.c_str()); r < 0) { - throw std::runtime_error("write_file"); - } - return seastar::now(); + return seastar::do_with(std::set{}, [this](auto& collections) { + return seastar::do_for_each(coll_map, [&collections, this](auto& coll) { + auto& [col, ch] = coll; + collections.insert(col); + ceph::bufferlist bl; + ceph_assert(ch); + ch->encode(bl); + std::string fn = fmt::format("{}/{}", path, col); + return ceph::buffer::write_file(std::move(bl), fn); + }).then([&collections, this] { + ceph::bufferlist bl; + ceph::encode(collections, bl); + std::string fn = fmt::format("{}/collections", path); + return ceph::buffer::write_file(std::move(bl), fn); + }); + }); } seastar::future<> CyanStore::mkfs() @@ -96,12 +93,10 @@ seastar::future<> CyanStore::mkfs() ceph::bufferlist bl; std::set collections; ceph::encode(collections, bl); - r = bl.write_file(fn.c_str()); - if (r < 0) - throw std::runtime_error("write_file"); - - write_meta("type", "memstore"); - return seastar::now(); + return ceph::buffer::write_file(std::move(bl), fn).then([this] { + write_meta("type", "memstore"); + return seastar::now(); + }); } seastar::future, ghobject_t> -- 2.39.5