]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/common/buffer_io.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / crimson / common / buffer_io.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "buffer_io.h"
5
6 #include <seastar/core/reactor.hh>
7 #include <seastar/core/fstream.hh>
8 #include <seastar/core/do_with.hh>
9
10 #include "include/buffer.h"
11
12 namespace ceph::buffer {
13
14 seastar::future<> write_file(ceph::buffer::list&& bl,
15 seastar::sstring fn,
16 seastar::file_permissions permissions)
17 {
18 const auto flags = (seastar::open_flags::wo |
19 seastar::open_flags::create |
20 seastar::open_flags::truncate);
21 seastar::file_open_options foo;
22 foo.create_permissions = permissions;
23 return seastar::open_file_dma(fn, flags, foo).then(
24 [bl=std::move(bl)](seastar::file f) {
25 return seastar::do_with(seastar::make_file_output_stream(f),
26 std::move(f),
27 std::move(bl),
28 [](seastar::output_stream<char>& out,
29 seastar::file& f,
30 ceph::buffer::list& bl) {
31 return seastar::do_for_each(bl.buffers(), [&out](auto& buf) {
32 return out.write(buf.c_str(), buf.length());
33 }).then([&out] {
34 return out.close();
35 });
36 });
37 });
38 }
39
40 }