]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/mClockOpClassQueue.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / osd / mClockOpClassQueue.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 Red Hat Inc.
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15
16 #pragma once
17
18 #include <ostream>
19
20 #include "boost/variant.hpp"
21 #include "boost/container/flat_set.hpp"
22
23 #include "common/config.h"
24 #include "common/ceph_context.h"
25 #include "common/mClockPriorityQueue.h"
26 #include "osd/OpQueueItem.h"
27 #include "osd/mClockOpClassSupport.h"
28
29
30 namespace ceph {
31
32 using Request = OpQueueItem;
33 using Client = uint64_t;
34
35 // This class exists to bridge the ceph code, which treats the class
36 // as the client, and the queue, where the class is
37 // osd_op_type_t. So this adapter class will transform calls
38 // appropriately.
39 class mClockOpClassQueue : public OpQueue<Request, Client> {
40
41 using osd_op_type_t = ceph::mclock::osd_op_type_t;
42
43 using queue_t = mClockQueue<Request, osd_op_type_t>;
44 queue_t queue;
45
46 ceph::mclock::OpClassClientInfoMgr client_info_mgr;
47
48 public:
49
50 mClockOpClassQueue(CephContext *cct);
51
52 const crimson::dmclock::ClientInfo*
53 op_class_client_info_f(const osd_op_type_t& op_type);
54
55 inline unsigned get_size_slow() const {
56 return queue.get_size_slow();
57 }
58
59 // Ops of this priority should be deleted immediately
60 inline void remove_by_class(Client cl,
61 std::list<Request> *out) override final {
62 queue.remove_by_filter(
63 [&cl, out] (Request&& r) -> bool {
64 if (cl == r.get_owner()) {
65 out->push_front(std::move(r));
66 return true;
67 } else {
68 return false;
69 }
70 });
71 }
72
73 inline void enqueue_strict(Client cl,
74 unsigned priority,
75 Request&& item) override final {
76 queue.enqueue_strict(client_info_mgr.osd_op_type(item),
77 priority,
78 std::move(item));
79 }
80
81 // Enqueue op in the front of the strict queue
82 inline void enqueue_strict_front(Client cl,
83 unsigned priority,
84 Request&& item) override final {
85 queue.enqueue_strict_front(client_info_mgr.osd_op_type(item),
86 priority,
87 std::move(item));
88 }
89
90 // Enqueue op in the back of the regular queue
91 inline void enqueue(Client cl,
92 unsigned priority,
93 unsigned cost,
94 Request&& item) override final {
95 queue.enqueue(client_info_mgr.osd_op_type(item),
96 priority,
97 1u,
98 std::move(item));
99 }
100
101 // Enqueue the op in the front of the regular queue
102 inline void enqueue_front(Client cl,
103 unsigned priority,
104 unsigned cost,
105 Request&& item) override final {
106 queue.enqueue_front(client_info_mgr.osd_op_type(item),
107 priority,
108 1u,
109 std::move(item));
110 }
111
112 // Returns if the queue is empty
113 inline bool empty() const override final {
114 return queue.empty();
115 }
116
117 // Return an op to be dispatch
118 inline Request dequeue() override final {
119 return queue.dequeue();
120 }
121
122 // Formatted output of the queue
123 void dump(ceph::Formatter *f) const override final;
124 }; // class mClockOpClassAdapter
125 } // namespace ceph