]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_aio.h
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / rgw / rgw_aio.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2018 Red Hat, Inc.
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 *
14 */
15
16 #pragma once
17
18 #include <cstdint>
19 #include <memory>
20 #include <type_traits>
21
22 #include <boost/intrusive/list.hpp>
23 #include "include/rados/librados_fwd.hpp"
24 #include "common/async/yield_context.h"
25
26 #include "services/svc_rados.h" // cant forward declare RGWSI_RADOS::Obj
27
28 #include "rgw_common.h"
29
30 #include "include/function2.hpp"
31
32 struct D3nGetObjData;
33
34 namespace rgw {
35
36 struct AioResult {
37 RGWSI_RADOS::Obj obj;
38 uint64_t id = 0; // id allows caller to associate a result with its request
39 bufferlist data; // result buffer for reads
40 int result = 0;
41 std::aligned_storage_t<3 * sizeof(void*)> user_data;
42
43 AioResult() = default;
44 AioResult(const AioResult&) = delete;
45 AioResult& operator =(const AioResult&) = delete;
46 AioResult(AioResult&&) = delete;
47 AioResult& operator =(AioResult&&) = delete;
48 };
49 struct AioResultEntry : AioResult, boost::intrusive::list_base_hook<> {
50 virtual ~AioResultEntry() {}
51 };
52 // a list of polymorphic entries that frees them on destruction
53 template <typename T, typename ...Args>
54 struct OwningList : boost::intrusive::list<T, Args...> {
55 OwningList() = default;
56 ~OwningList() { this->clear_and_dispose(std::default_delete<T>{}); }
57 OwningList(OwningList&&) = default;
58 OwningList& operator=(OwningList&&) = default;
59 OwningList(const OwningList&) = delete;
60 OwningList& operator=(const OwningList&) = delete;
61 };
62 using AioResultList = OwningList<AioResultEntry>;
63
64 // returns the first error code or 0 if all succeeded
65 inline int check_for_errors(const AioResultList& results) {
66 for (auto& e : results) {
67 if (e.result < 0) {
68 return e.result;
69 }
70 }
71 return 0;
72 }
73
74 // interface to submit async librados operations and wait on their completions.
75 // each call returns a list of results from prior completions
76 class Aio {
77 public:
78 using OpFunc = fu2::unique_function<void(Aio*, AioResult&) &&>;
79
80 virtual ~Aio() {}
81
82 virtual AioResultList get(const RGWSI_RADOS::Obj& obj,
83 OpFunc&& f,
84 uint64_t cost, uint64_t id) = 0;
85 virtual void put(AioResult& r) = 0;
86
87 // poll for any ready completions without waiting
88 virtual AioResultList poll() = 0;
89
90 // return any ready completions. if there are none, wait for the next
91 virtual AioResultList wait() = 0;
92
93 // wait for all outstanding completions and return their results
94 virtual AioResultList drain() = 0;
95
96 static OpFunc librados_op(librados::ObjectReadOperation&& op,
97 optional_yield y);
98 static OpFunc librados_op(librados::ObjectWriteOperation&& op,
99 optional_yield y);
100 static OpFunc d3n_cache_op(const DoutPrefixProvider *dpp, optional_yield y,
101 off_t read_ofs, off_t read_len, std::string& location);
102 };
103
104 } // namespace rgw