]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
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 "include/rados/librados_fwd.hpp" | |
19 | #include <boost/intrusive/list.hpp> | |
20 | #include "rgw_common.h" | |
21 | #include "services/svc_rados.h" // cant forward declare RGWSI_RADOS::Obj | |
22 | ||
23 | namespace rgw { | |
24 | ||
25 | struct AioResult { | |
26 | RGWSI_RADOS::Obj obj; | |
27 | uint64_t id = 0; // id allows caller to associate a result with its request | |
28 | bufferlist data; // result buffer for reads | |
29 | int result = 0; | |
30 | }; | |
31 | struct AioResultEntry : AioResult, boost::intrusive::list_base_hook<> { | |
32 | virtual ~AioResultEntry() {} | |
33 | }; | |
34 | // a list of polymorphic entries that frees them on destruction | |
35 | template <typename T, typename ...Args> | |
36 | struct OwningList : boost::intrusive::list<T, Args...> { | |
37 | OwningList() = default; | |
38 | ~OwningList() { this->clear_and_dispose(std::default_delete<T>{}); } | |
39 | OwningList(OwningList&&) = default; | |
40 | OwningList& operator=(OwningList&&) = default; | |
41 | OwningList(const OwningList&) = delete; | |
42 | OwningList& operator=(const OwningList&) = delete; | |
43 | }; | |
44 | using AioResultList = OwningList<AioResultEntry>; | |
45 | ||
46 | // returns the first error code or 0 if all succeeded | |
47 | inline int check_for_errors(const AioResultList& results) { | |
48 | for (auto& e : results) { | |
49 | if (e.result < 0) { | |
50 | return e.result; | |
51 | } | |
52 | } | |
53 | return 0; | |
54 | } | |
55 | ||
56 | // interface to submit async librados operations and wait on their completions. | |
57 | // each call returns a list of results from prior completions | |
58 | class Aio { | |
59 | public: | |
60 | virtual ~Aio() {} | |
61 | ||
62 | virtual AioResultList submit(RGWSI_RADOS::Obj& obj, | |
63 | librados::ObjectReadOperation *op, | |
64 | uint64_t cost, uint64_t id) = 0; | |
65 | ||
66 | virtual AioResultList submit(RGWSI_RADOS::Obj& obj, | |
67 | librados::ObjectWriteOperation *op, | |
68 | uint64_t cost, uint64_t id) = 0; | |
69 | ||
70 | // poll for any ready completions without waiting | |
71 | virtual AioResultList poll() = 0; | |
72 | ||
73 | // return any ready completions. if there are none, wait for the next | |
74 | virtual AioResultList wait() = 0; | |
75 | ||
76 | // wait for all outstanding completions and return their results | |
77 | virtual AioResultList drain() = 0; | |
78 | }; | |
79 | ||
80 | } // namespace rgw |