]>
git.proxmox.com Git - ceph.git/blob - 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
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2018 Red Hat, Inc.
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.
20 #include <type_traits>
22 #include <boost/intrusive/list.hpp>
23 #include "include/rados/librados_fwd.hpp"
24 #include "common/async/yield_context.h"
26 #include "services/svc_rados.h" // cant forward declare RGWSI_RADOS::Obj
28 #include "rgw_common.h"
30 #include "include/function2.hpp"
38 uint64_t id
= 0; // id allows caller to associate a result with its request
39 bufferlist data
; // result buffer for reads
41 std::aligned_storage_t
<3 * sizeof(void*)> user_data
;
43 AioResult() = default;
44 AioResult(const AioResult
&) = delete;
45 AioResult
& operator =(const AioResult
&) = delete;
46 AioResult(AioResult
&&) = delete;
47 AioResult
& operator =(AioResult
&&) = delete;
49 struct AioResultEntry
: AioResult
, boost::intrusive::list_base_hook
<> {
50 virtual ~AioResultEntry() {}
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;
62 using AioResultList
= OwningList
<AioResultEntry
>;
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
) {
74 // interface to submit async librados operations and wait on their completions.
75 // each call returns a list of results from prior completions
78 using OpFunc
= fu2::unique_function
<void(Aio
*, AioResult
&) &&>;
82 virtual AioResultList
get(const RGWSI_RADOS::Obj
& obj
,
84 uint64_t cost
, uint64_t id
) = 0;
85 virtual void put(AioResult
& r
) = 0;
87 // poll for any ready completions without waiting
88 virtual AioResultList
poll() = 0;
90 // return any ready completions. if there are none, wait for the next
91 virtual AioResultList
wait() = 0;
93 // wait for all outstanding completions and return their results
94 virtual AioResultList
drain() = 0;
96 static OpFunc
librados_op(librados::ObjectReadOperation
&& op
,
98 static OpFunc
librados_op(librados::ObjectWriteOperation
&& op
,
100 static OpFunc
d3n_cache_op(const DoutPrefixProvider
*dpp
, optional_yield y
,
101 off_t read_ofs
, off_t read_len
, std::string
& location
);