]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/core/io_intent.hh
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / include / seastar / core / io_intent.hh
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright 2021 ScyllaDB
20 */
21
22 #pragma once
23
24 #include <boost/container/small_vector.hpp>
25 #include <seastar/core/internal/io_intent.hh>
26 #include <seastar/core/io_priority_class.hh>
27
28 namespace seastar {
29
30 /// \example file_demo.cc
31 /// A handle confirming the caller's intent to do the IO
32 ///
33 /// When a pointer to an intent is passed to the \ref io_queue
34 /// "io_queue"::queue_request() method, the issued request is pinned
35 /// to the intent and is only processed as long as the intent object
36 /// is alive and the **cancel()** method is not called.
37 ///
38 /// If no intent is provided, then the request is processed till its
39 /// completion be it success or error
40 class io_intent {
41 struct intents_for_queue {
42 dev_t dev;
43 io_priority_class_id qid;
44 internal::cancellable_queue cq;
45
46 intents_for_queue(dev_t dev_, io_priority_class_id qid_) noexcept
47 : dev(dev_), qid(qid_), cq() {}
48
49 intents_for_queue(intents_for_queue&&) noexcept = default;
50 intents_for_queue& operator=(intents_for_queue&&) noexcept = default;
51 };
52
53 struct references {
54 internal::intent_reference::container_type list;
55
56 references(references&& o) noexcept : list(std::move(o.list)) {}
57 references() noexcept : list() {}
58 ~references() { clear(); }
59
60 void clear() {
61 list.clear_and_dispose([] (internal::intent_reference* r) { r->on_cancel(); });
62 }
63
64 void bind(internal::intent_reference& iref) noexcept {
65 list.push_back(iref);
66 }
67 };
68
69 boost::container::small_vector<intents_for_queue, 1> _intents;
70 references _refs;
71 friend internal::intent_reference::intent_reference(io_intent*) noexcept;
72
73 public:
74 io_intent() = default;
75 ~io_intent() = default;
76
77 io_intent(const io_intent&) = delete;
78 io_intent& operator=(const io_intent&) = delete;
79 io_intent& operator=(io_intent&&) = delete;
80 io_intent(io_intent&& o) noexcept : _intents(std::move(o._intents)), _refs(std::move(o._refs)) {
81 for (auto&& r : _refs.list) {
82 r._intent = this;
83 }
84 }
85
86 /// Explicitly cancels all the requests attached to this intent
87 /// so far. The respective futures are resolved into the \ref
88 /// cancelled_error "cancelled_error"
89 void cancel() noexcept {
90 _refs.clear();
91 _intents.clear();
92 }
93
94 /// @private
95 internal::cancellable_queue& find_or_create_cancellable_queue(dev_t dev, io_priority_class_id qid) {
96 for (auto&& i : _intents) {
97 if (i.dev == dev && i.qid == qid) {
98 return i.cq;
99 }
100 }
101
102 _intents.emplace_back(dev, qid);
103 return _intents.back().cq;
104 }
105 };
106
107 } // namespace seastar