]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/osd/state.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / osd / state.h
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#pragma once
5
6#include <string_view>
7#include <ostream>
8
9class OSDMap;
10
11class OSDState {
12
13 enum class State {
14 INITIALIZING,
15 PREBOOT,
16 BOOTING,
17 ACTIVE,
f67539c2 18 PRESTOP,
11fdf7f2
TL
19 STOPPING,
20 WAITING_FOR_HEALTHY,
21 };
22
23 State state = State::INITIALIZING;
24
25public:
26 bool is_initializing() const {
27 return state == State::INITIALIZING;
28 }
29 bool is_preboot() const {
30 return state == State::PREBOOT;
31 }
32 bool is_booting() const {
33 return state == State::BOOTING;
34 }
35 bool is_active() const {
36 return state == State::ACTIVE;
37 }
f67539c2
TL
38 bool is_prestop() const {
39 return state == State::PRESTOP;
40 }
11fdf7f2
TL
41 bool is_stopping() const {
42 return state == State::STOPPING;
43 }
44 bool is_waiting_for_healthy() const {
45 return state == State::WAITING_FOR_HEALTHY;
46 }
47 void set_preboot() {
48 state = State::PREBOOT;
49 }
50 void set_booting() {
51 state = State::BOOTING;
52 }
53 void set_active() {
54 state = State::ACTIVE;
55 }
f67539c2
TL
56 void set_prestop() {
57 state = State::PRESTOP;
58 }
11fdf7f2
TL
59 void set_stopping() {
60 state = State::STOPPING;
61 }
62 std::string_view to_string() const {
63 switch (state) {
64 case State::INITIALIZING: return "initializing";
65 case State::PREBOOT: return "preboot";
66 case State::BOOTING: return "booting";
67 case State::ACTIVE: return "active";
f67539c2 68 case State::PRESTOP: return "prestop";
11fdf7f2
TL
69 case State::STOPPING: return "stopping";
70 case State::WAITING_FOR_HEALTHY: return "waiting_for_healthy";
71 default: return "???";
72 }
73 }
74};
75
76inline std::ostream&
77operator<<(std::ostream& os, const OSDState& s) {
78 return os << s.to_string();
79}