]> git.proxmox.com Git - ceph.git/blame - ceph/src/osd/OpRequest.h
bump version to 19.2.0-pve1
[ceph.git] / ceph / src / osd / OpRequest.h
CommitLineData
7c673cae
FG
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) 2012 New Dream Network/Sage Weil <sage@newdream.net>
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#ifndef OPREQUEST_H_
15#define OPREQUEST_H_
11fdf7f2 16
9f95a23c 17#include "osd/osd_op_util.h"
7c673cae
FG
18#include "osd/osd_types.h"
19#include "common/TrackedOp.h"
f67539c2 20#include "common/tracer.h"
7c673cae
FG
21/**
22 * The OpRequest takes in a Message* and takes over a single reference
23 * to it, which it puts() when destroyed.
24 */
25struct OpRequest : public TrackedOp {
26 friend class OpTracker;
27
9f95a23c
TL
28private:
29 OpInfo op_info;
7c673cae 30
9f95a23c
TL
31public:
32 int maybe_init_op_info(const OSDMap &osdmap);
33
34 auto get_flags() const { return op_info.get_flags(); }
35 bool op_info_needs_init() const { return op_info.get_flags() == 0; }
36 bool check_rmw(int flag) const { return op_info.check_rmw(flag); }
37 bool may_read() const { return op_info.may_read(); }
f38dd50b 38 bool may_read_data() const { return op_info.may_read_data(); }
9f95a23c
TL
39 bool may_write() const { return op_info.may_write(); }
40 bool may_cache() const { return op_info.may_cache(); }
41 bool rwordered_forced() const { return op_info.rwordered_forced(); }
42 bool rwordered() const { return op_info.rwordered(); }
43 bool includes_pg_op() const { return op_info.includes_pg_op(); }
44 bool need_read_cap() const { return op_info.need_read_cap(); }
45 bool need_write_cap() const { return op_info.need_write_cap(); }
46 bool need_promote() const { return op_info.need_promote(); }
47 bool need_skip_handle_cache() const { return op_info.need_skip_handle_cache(); }
48 bool need_skip_promote() const { return op_info.need_skip_promote(); }
49 bool allows_returnvec() const { return op_info.allows_returnvec(); }
50
51 std::vector<OpInfo::ClassInfo> classes() const {
52 return op_info.get_classes();
7c673cae
FG
53 }
54
9f95a23c 55 void _dump(ceph::Formatter *f) const override;
7c673cae
FG
56
57 bool has_feature(uint64_t f) const {
f51cf556
TL
58#ifdef WITH_SEASTAR
59 ceph_abort("In crimson, conn is independently maintained outside Message");
60#else
7c673cae 61 return request->get_connection()->has_feature(f);
f51cf556 62#endif
7c673cae
FG
63 }
64
65private:
66 Message *request; /// the logical request we are tracking
67 osd_reqid_t reqid;
c07f9fc5 68 entity_inst_t req_src_inst;
7c673cae
FG
69 uint8_t hit_flag_points;
70 uint8_t latest_flag_point;
aee94f69 71 const char* last_event_detail = nullptr;
7c673cae
FG
72 utime_t dequeued_time;
73 static const uint8_t flag_queued_for_pg=1 << 0;
74 static const uint8_t flag_reached_pg = 1 << 1;
75 static const uint8_t flag_delayed = 1 << 2;
76 static const uint8_t flag_started = 1 << 3;
77 static const uint8_t flag_sub_op_sent = 1 << 4;
78 static const uint8_t flag_commit_sent = 1 << 5;
79
7c673cae
FG
80 OpRequest(Message *req, OpTracker *tracker);
81
82protected:
aee94f69 83 void _dump_op_descriptor(std::ostream& stream) const override;
7c673cae 84 void _unregistered() override;
9f95a23c 85 bool filter_out(const std::set<std::string>& filters) override;
7c673cae
FG
86
87public:
88 ~OpRequest() override {
89 request->put();
90 }
91
92 bool check_send_map = true; ///< true until we check if sender needs a map
93 epoch_t sent_epoch = 0; ///< client's map epoch
94 epoch_t min_epoch = 0; ///< min epoch needed to handle this msg
95
96 bool hitset_inserted;
f51cf556 97 jspan_ptr osd_parent_span;
20effc67 98
9f95a23c
TL
99 template<class T>
100 const T* get_req() const { return static_cast<const T*>(request); }
101
7c673cae
FG
102 const Message *get_req() const { return request; }
103 Message *get_nonconst_req() { return request; }
104
105 entity_name_t get_source() {
106 if (request) {
107 return request->get_source();
108 } else {
109 return entity_name_t();
110 }
111 }
20effc67
TL
112 uint8_t state_flag() const {
113 return latest_flag_point;
114 }
7c673cae 115
aee94f69 116 std::string _get_state_string() const override {
7c673cae
FG
117 switch(latest_flag_point) {
118 case flag_queued_for_pg: return "queued for pg";
119 case flag_reached_pg: return "reached pg";
aee94f69 120 case flag_delayed: return last_event_detail;
7c673cae
FG
121 case flag_started: return "started";
122 case flag_sub_op_sent: return "waiting for sub ops";
123 case flag_commit_sent: return "commit sent; apply or cleanup";
124 default: break;
125 }
126 return "no flag points reached";
127 }
128
20effc67
TL
129 static std::string get_state_string(uint8_t flag) {
130 std::string flag_point;
131
132 switch(flag) {
133 case flag_queued_for_pg:
134 flag_point = "queued for pg";
135 break;
136 case flag_reached_pg:
137 flag_point = "reached pg";
138 break;
139 case flag_delayed:
140 flag_point = "delayed";
141 break;
142 case flag_started:
143 flag_point = "started";
144 break;
145 case flag_sub_op_sent:
146 flag_point = "waiting for sub ops";
147 break;
148 case flag_commit_sent:
149 flag_point = "commit sent; apply or cleanup";
150 break;
151 }
152 return flag_point;
153 }
154
7c673cae
FG
155 void mark_queued_for_pg() {
156 mark_flag_point(flag_queued_for_pg, "queued_for_pg");
157 }
158 void mark_reached_pg() {
159 mark_flag_point(flag_reached_pg, "reached_pg");
160 }
aee94f69
TL
161 void mark_delayed(const char* s) {
162 mark_flag_point(flag_delayed, s);
7c673cae
FG
163 }
164 void mark_started() {
165 mark_flag_point(flag_started, "started");
166 }
9f95a23c 167 void mark_sub_op_sent(const std::string& s) {
7c673cae
FG
168 mark_flag_point_string(flag_sub_op_sent, s);
169 }
170 void mark_commit_sent() {
171 mark_flag_point(flag_commit_sent, "commit_sent");
172 }
173
174 utime_t get_dequeued_time() const {
175 return dequeued_time;
176 }
177 void set_dequeued_time(utime_t deq_time) {
178 dequeued_time = deq_time;
179 }
180
181 osd_reqid_t get_reqid() const {
182 return reqid;
183 }
184
185 typedef boost::intrusive_ptr<OpRequest> Ref;
186
187private:
7c673cae 188 void mark_flag_point(uint8_t flag, const char *s);
9f95a23c 189 void mark_flag_point_string(uint8_t flag, const std::string& s);
7c673cae
FG
190};
191
192typedef OpRequest::Ref OpRequestRef;
193
7c673cae 194#endif /* OPREQUEST_H_ */