1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 Red Hat Inc.
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.
20 #include "boost/variant.hpp"
22 #include "common/config.h"
23 #include "common/ceph_context.h"
24 #include "osd/PGQueueable.h"
26 #include "common/mClockPriorityQueue.h"
31 using Request
= std::pair
<spg_t
, PGQueueable
>;
32 using Client
= entity_inst_t
;
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 adpater class will transform calls
39 class mClockClientQueue
: public OpQueue
<Request
, Client
> {
41 enum class osd_op_type_t
{
42 client_op
, osd_subop
, bg_snaptrim
, bg_recovery
, bg_scrub
};
44 using InnerClient
= std::pair
<entity_inst_t
,osd_op_type_t
>;
46 using queue_t
= mClockQueue
<Request
, InnerClient
>;
50 struct mclock_op_tags_t
{
51 crimson::dmclock::ClientInfo client_op
;
52 crimson::dmclock::ClientInfo osd_subop
;
53 crimson::dmclock::ClientInfo snaptrim
;
54 crimson::dmclock::ClientInfo recov
;
55 crimson::dmclock::ClientInfo scrub
;
57 mclock_op_tags_t(CephContext
*cct
);
60 static std::unique_ptr
<mclock_op_tags_t
> mclock_op_tags
;
64 mClockClientQueue(CephContext
*cct
);
66 static crimson::dmclock::ClientInfo
67 op_class_client_info_f(const InnerClient
& client
);
69 inline unsigned length() const override final
{
70 return queue
.length();
73 // Ops of this priority should be deleted immediately
74 inline void remove_by_class(Client cl
,
75 std::list
<Request
> *out
) override final
{
76 queue
.remove_by_filter(
77 [&cl
, out
] (const Request
& r
) -> bool {
78 if (cl
== r
.second
.get_owner()) {
87 void enqueue_strict(Client cl
,
89 Request item
) override final
;
91 // Enqueue op in the front of the strict queue
92 void enqueue_strict_front(Client cl
,
94 Request item
) override final
;
96 // Enqueue op in the back of the regular queue
97 void enqueue(Client cl
,
100 Request item
) override final
;
102 // Enqueue the op in the front of the regular queue
103 void enqueue_front(Client cl
,
106 Request item
) override final
;
108 // Return an op to be dispatch
109 Request
dequeue() override final
;
111 // Returns if the queue is empty
112 inline bool empty() const override final
{
113 return queue
.empty();
116 // Formatted output of the queue
117 void dump(ceph::Formatter
*f
) const override final
;
121 struct pg_queueable_visitor_t
: public boost::static_visitor
<osd_op_type_t
> {
122 osd_op_type_t
operator()(const OpRequestRef
& o
) const {
123 // don't know if it's a client_op or a
124 return osd_op_type_t::client_op
;
127 osd_op_type_t
operator()(const PGSnapTrim
& o
) const {
128 return osd_op_type_t::bg_snaptrim
;
131 osd_op_type_t
operator()(const PGScrub
& o
) const {
132 return osd_op_type_t::bg_scrub
;
135 osd_op_type_t
operator()(const PGRecovery
& o
) const {
136 return osd_op_type_t::bg_recovery
;
138 }; // class pg_queueable_visitor_t
140 static pg_queueable_visitor_t pg_queueable_visitor
;
142 osd_op_type_t
get_osd_op_type(const Request
& request
);
143 InnerClient
get_inner_client(const Client
& cl
, const Request
& request
);
144 }; // class mClockClientAdapter