]> git.proxmox.com Git - ceph.git/blame - ceph/src/osd/OpRequest.cc
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / osd / OpRequest.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
3#include "OpRequest.h"
4#include "common/Formatter.h"
5#include <iostream>
6#include <vector>
7#include "common/debug.h"
8#include "common/config.h"
9#include "msg/Message.h"
10#include "messages/MOSDOp.h"
7c673cae 11#include "messages/MOSDRepOp.h"
11fdf7f2
TL
12#include "messages/MOSDRepOpReply.h"
13#include "include/ceph_assert.h"
7c673cae
FG
14#include "osd/osd_types.h"
15
16#ifdef WITH_LTTNG
17#define TRACEPOINT_DEFINE
18#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
19#include "tracing/oprequest.h"
20#undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
21#undef TRACEPOINT_DEFINE
22#else
23#define tracepoint(...)
24#endif
25
9f95a23c
TL
26using std::ostream;
27using std::set;
28using std::string;
29using std::stringstream;
30
31using ceph::Formatter;
32
33OpRequest::OpRequest(Message* req, OpTracker* tracker)
34 : TrackedOp(tracker, req->get_throttle_stamp()),
35 request(req),
36 hit_flag_points(0),
37 latest_flag_point(0),
38 hitset_inserted(false) {
7c673cae
FG
39 if (req->get_priority() < tracker->cct->_conf->osd_client_op_priority) {
40 // don't warn as quickly for low priority ops
41 warn_interval_multiplier = tracker->cct->_conf->osd_recovery_op_warn_multiple;
42 }
43 if (req->get_type() == CEPH_MSG_OSD_OP) {
44 reqid = static_cast<MOSDOp*>(req)->get_reqid();
7c673cae
FG
45 } else if (req->get_type() == MSG_OSD_REPOP) {
46 reqid = static_cast<MOSDRepOp*>(req)->reqid;
11fdf7f2
TL
47 } else if (req->get_type() == MSG_OSD_REPOPREPLY) {
48 reqid = static_cast<MOSDRepOpReply*>(req)->reqid;
7c673cae 49 }
c07f9fc5 50 req_src_inst = req->get_source_inst();
7c673cae
FG
51}
52
53void OpRequest::_dump(Formatter *f) const
54{
55 Message *m = request;
56 f->dump_string("flag_point", state_string());
57 if (m->get_orig_source().is_client()) {
58 f->open_object_section("client_info");
59 stringstream client_name, client_addr;
c07f9fc5
FG
60 client_name << req_src_inst.name;
61 client_addr << req_src_inst.addr;
7c673cae
FG
62 f->dump_string("client", client_name.str());
63 f->dump_string("client_addr", client_addr.str());
64 f->dump_unsigned("tid", m->get_tid());
65 f->close_section(); // client_info
66 }
9f95a23c 67
7c673cae
FG
68 {
69 f->open_array_section("events");
11fdf7f2 70 std::lock_guard l(lock);
9f95a23c
TL
71
72 for (auto i = events.begin(); i != events.end(); ++i) {
73 f->open_object_section("event");
74 f->dump_string("event", i->str);
75 f->dump_stream("time") << i->stamp;
76
20effc67 77 double duration = 0;
9f95a23c 78
20effc67
TL
79 if (i != events.begin()) {
80 auto i_prev = i - 1;
81 duration = i->stamp - i_prev->stamp;
9f95a23c
TL
82 }
83
20effc67 84 f->dump_float("duration", duration);
9f95a23c 85 f->close_section();
7c673cae
FG
86 }
87 f->close_section();
88 }
89}
90
aee94f69 91void OpRequest::_dump_op_descriptor(ostream& stream) const
7c673cae
FG
92{
93 get_req()->print(stream);
94}
95
96void OpRequest::_unregistered() {
97 request->clear_data();
98 request->clear_payload();
99 request->release_message_throttle();
100 request->set_connection(nullptr);
101}
102
9f95a23c
TL
103int OpRequest::maybe_init_op_info(const OSDMap &osdmap) {
104 if (op_info.get_flags())
105 return 0;
7c673cae 106
9f95a23c 107 auto m = get_req<MOSDOp>();
7c673cae 108
7c673cae 109#ifdef WITH_LTTNG
9f95a23c 110 auto old_rmw_flags = op_info.get_flags();
7c673cae 111#endif
9f95a23c 112 auto ret = op_info.set_from_op(m, osdmap);
7c673cae
FG
113 tracepoint(oprequest, set_rmw_flags, reqid.name._type,
114 reqid.name._num, reqid.tid, reqid.inc,
9f95a23c
TL
115 op_info.get_flags(), old_rmw_flags, op_info.get_flags());
116 return ret;
7c673cae
FG
117}
118
7c673cae
FG
119void OpRequest::mark_flag_point(uint8_t flag, const char *s) {
120#ifdef WITH_LTTNG
121 uint8_t old_flags = hit_flag_points;
122#endif
123 mark_event(s);
aee94f69 124 last_event_detail = s;
7c673cae
FG
125 hit_flag_points |= flag;
126 latest_flag_point = flag;
127 tracepoint(oprequest, mark_flag_point, reqid.name._type,
9f95a23c 128 reqid.name._num, reqid.tid, reqid.inc, op_info.get_flags(),
7c673cae
FG
129 flag, s, old_flags, hit_flag_points);
130}
131
132void OpRequest::mark_flag_point_string(uint8_t flag, const string& s) {
133#ifdef WITH_LTTNG
134 uint8_t old_flags = hit_flag_points;
135#endif
11fdf7f2 136 mark_event(s);
7c673cae
FG
137 hit_flag_points |= flag;
138 latest_flag_point = flag;
139 tracepoint(oprequest, mark_flag_point, reqid.name._type,
9f95a23c 140 reqid.name._num, reqid.tid, reqid.inc, op_info.get_flags(),
7c673cae
FG
141 flag, s.c_str(), old_flags, hit_flag_points);
142}
143
c07f9fc5
FG
144bool OpRequest::filter_out(const set<string>& filters)
145{
146 set<entity_addr_t> addrs;
147 for (auto it = filters.begin(); it != filters.end(); it++) {
148 entity_addr_t addr;
149 if (addr.parse((*it).c_str())) {
150 addrs.insert(addr);
151 }
152 }
153 if (addrs.empty())
154 return true;
155
156 entity_addr_t cmp_addr = req_src_inst.addr;
157 if (addrs.count(cmp_addr)) {
158 return true;
159 }
160 cmp_addr.set_nonce(0);
161 if (addrs.count(cmp_addr)) {
162 return true;
163 }
164 cmp_addr.set_port(0);
165 if (addrs.count(cmp_addr)) {
166 return true;
167 }
168
169 return false;
170}
171