]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os: use buffer::write_file() helper
authorKefu Chai <kchai@redhat.com>
Thu, 13 Jun 2019 14:44:16 +0000 (22:44 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 14 Jun 2019 08:31:22 +0000 (16:31 +0800)
instead of using the blocking calls

so we can write to file without blocking the reactor

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/common/buffer_io.cc
src/crimson/os/cyan_store.cc

index 8e33cab44a87a14b123c46202c75722834282581..9a08228077f5bda999ba17feb7b57c6e09d1ca3a 100644 (file)
@@ -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<char>& out,
-                                  seastar::file& f) {
+    return seastar::do_with(seastar::make_file_output_stream(f),
+                            std::move(f),
+                            std::move(bl),
+                            [](seastar::output_stream<char>& 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] {
index 79102f0f6f5a3eed3979bde9909a1a58e6c5bb54..016a63e5f644dc9c8e0ca4bb8c69ff36dd09d1fb 100644 (file)
@@ -4,7 +4,7 @@
 #include <fmt/ostream.h>
 
 #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<coll_t> 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<coll_t>{}, [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<coll_t> 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<std::vector<ghobject_t>, ghobject_t>