]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MOSDFailure.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / messages / MOSDFailure.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) 2004-2006 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
15
16#ifndef CEPH_MOSDFAILURE_H
17#define CEPH_MOSDFAILURE_H
18
19#include "messages/PaxosServiceMessage.h"
20
21
11fdf7f2
TL
22class MOSDFailure : public MessageInstance<MOSDFailure, PaxosServiceMessage> {
23public:
24 friend factory;
25private:
26 static constexpr int HEAD_VERSION = 4;
27 static constexpr int COMPAT_VERSION = 4;
7c673cae
FG
28
29 public:
30 enum {
31 FLAG_ALIVE = 0, // use this on its own to mark as "I'm still alive"
32 FLAG_FAILED = 1, // if set, failure; if not, recovery
33 FLAG_IMMEDIATE = 2, // known failure, not a timeout
34 };
35
36 uuid_d fsid;
11fdf7f2
TL
37 int32_t target_osd;
38 entity_addrvec_t target_addrs;
d2e6a577 39 __u8 flags = 0;
11fdf7f2 40 epoch_t epoch = 0;
d2e6a577 41 int32_t failed_for = 0; // known to be failed since at least this long
7c673cae 42
11fdf7f2
TL
43 MOSDFailure() : MessageInstance(MSG_OSD_FAILURE, 0, HEAD_VERSION) { }
44 MOSDFailure(const uuid_d &fs, int osd, const entity_addrvec_t& av,
45 int duration, epoch_t e)
46 : MessageInstance(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION),
47 fsid(fs),
48 target_osd(osd),
49 target_addrs(av),
7c673cae
FG
50 flags(FLAG_FAILED),
51 epoch(e), failed_for(duration) { }
11fdf7f2
TL
52 MOSDFailure(const uuid_d &fs, int osd, const entity_addrvec_t& av,
53 int duration,
7c673cae 54 epoch_t e, __u8 extra_flags)
11fdf7f2
TL
55 : MessageInstance(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION),
56 fsid(fs),
57 target_osd(osd),
58 target_addrs(av),
7c673cae
FG
59 flags(extra_flags),
60 epoch(e), failed_for(duration) { }
61private:
62 ~MOSDFailure() override {}
63
11fdf7f2
TL
64public:
65 int get_target_osd() { return target_osd; }
66 const entity_addrvec_t& get_target_addrs() { return target_addrs; }
7c673cae
FG
67 bool if_osd_failed() const {
68 return flags & FLAG_FAILED;
69 }
70 bool is_immediate() const {
71 return flags & FLAG_IMMEDIATE;
72 }
73 epoch_t get_epoch() const { return epoch; }
74
75 void decode_payload() override {
11fdf7f2 76 auto p = payload.cbegin();
7c673cae 77 paxos_decode(p);
11fdf7f2
TL
78 decode(fsid, p);
79 if (header.version < 4) {
80 entity_inst_t i;
81 decode(i, p);
82 target_osd = i.name.num();
83 target_addrs.v.push_back(i.addr);
84 } else {
85 decode(target_osd, p);
86 decode(target_addrs, p);
87 }
88 decode(epoch, p);
89 decode(flags, p);
90 decode(failed_for, p);
7c673cae
FG
91 }
92
93 void encode_payload(uint64_t features) override {
11fdf7f2 94 using ceph::encode;
7c673cae 95 paxos_encode();
11fdf7f2
TL
96 if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) {
97 header.version = 3;
98 header.compat_version = 3;
99 encode(fsid, payload);
100 encode(entity_inst_t(entity_name_t::OSD(target_osd),
101 target_addrs.legacy_addr()), payload, features);
102 encode(epoch, payload);
103 encode(flags, payload);
104 encode(failed_for, payload);
105 return;
106 }
107 header.version = HEAD_VERSION;
108 header.compat_version = COMPAT_VERSION;
109 encode(fsid, payload);
110 encode(target_osd, payload, features);
111 encode(target_addrs, payload, features);
112 encode(epoch, payload);
113 encode(flags, payload);
114 encode(failed_for, payload);
7c673cae
FG
115 }
116
11fdf7f2 117 std::string_view get_type_name() const override { return "osd_failure"; }
7c673cae
FG
118 void print(ostream& out) const override {
119 out << "osd_failure("
120 << (if_osd_failed() ? "failed " : "recovered ")
121 << (is_immediate() ? "immediate " : "timeout ")
11fdf7f2
TL
122 << "osd." << target_osd << " " << target_addrs
123 << " for " << failed_for << "sec e" << epoch
7c673cae
FG
124 << " v" << version << ")";
125 }
126};
127
128#endif