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.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * Copyright 2021 ScyllaDB
24 #include <boost/container/small_vector.hpp>
25 #include <seastar/core/internal/io_intent.hh>
26 #include <seastar/core/io_priority_class.hh>
30 /// \example file_demo.cc
31 /// A handle confirming the caller's intent to do the IO
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.
38 /// If no intent is provided, then the request is processed till its
39 /// completion be it success or error
41 struct intents_for_queue {
43 io_priority_class_id qid;
44 internal::cancellable_queue cq;
46 intents_for_queue(dev_t dev_, io_priority_class_id qid_) noexcept
47 : dev(dev_), qid(qid_), cq() {}
49 intents_for_queue(intents_for_queue&&) noexcept = default;
50 intents_for_queue& operator=(intents_for_queue&&) noexcept = default;
54 internal::intent_reference::container_type list;
56 references(references&& o) noexcept : list(std::move(o.list)) {}
57 references() noexcept : list() {}
58 ~references() { clear(); }
61 list.clear_and_dispose([] (internal::intent_reference* r) { r->on_cancel(); });
64 void bind(internal::intent_reference& iref) noexcept {
69 boost::container::small_vector<intents_for_queue, 1> _intents;
71 friend internal::intent_reference::intent_reference(io_intent*) noexcept;
74 io_intent() = default;
75 ~io_intent() = default;
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) {
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 {
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) {
102 _intents.emplace_back(dev, qid);
103 return _intents.back().cq;
107 } // namespace seastar