]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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) 2019 Red Hat <contact@redhat.com> | |
7 | * Author: Adam C. Emerson <aemerson@redhat.com> | |
8 | * | |
9 | * This is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License version 2.1, as published by the Free Software | |
12 | * Foundation. See file COPYING. | |
13 | * | |
14 | */ | |
15 | ||
16 | #include <string> | |
17 | ||
18 | #include "common/error_code.h" | |
19 | #include "common/errno.h" | |
20 | #include "error_code.h" | |
21 | ||
22 | #pragma GCC diagnostic push | |
23 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | |
24 | #pragma clang diagnostic push | |
25 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor" | |
26 | class osd_error_category : public ceph::converting_category { | |
27 | public: | |
28 | osd_error_category(){} | |
29 | const char* name() const noexcept override; | |
30 | const char* message(int ev, char*, std::size_t) const noexcept override; | |
31 | std::string message(int ev) const override; | |
32 | boost::system::error_condition default_error_condition(int ev) const noexcept | |
33 | override; | |
34 | bool equivalent(int ev, const boost::system::error_condition& c) const | |
35 | noexcept override; | |
36 | using ceph::converting_category::equivalent; | |
37 | int from_code(int ev) const noexcept override; | |
38 | }; | |
39 | #pragma GCC diagnostic pop | |
40 | #pragma clang diagnostic pop | |
41 | ||
42 | const char* osd_error_category::name() const noexcept { | |
43 | return "osd"; | |
44 | } | |
45 | ||
46 | const char* osd_error_category::message(int ev, char* buf, | |
47 | std::size_t len) const noexcept { | |
48 | if (ev == 0) | |
49 | return "No error"; | |
50 | ||
51 | switch (static_cast<osd_errc>(ev)) { | |
52 | case osd_errc::old_snapc: | |
53 | return "ORDERSNAP flag set; writer has old snapc"; | |
54 | case osd_errc::blocklisted: | |
55 | return "Blocklisted"; | |
56 | } | |
57 | ||
58 | if (len) { | |
59 | auto s = cpp_strerror(ev); | |
60 | auto n = s.copy(buf, len - 1); | |
61 | *(buf + n) = '\0'; | |
62 | } | |
63 | return buf; | |
64 | } | |
65 | ||
66 | std::string osd_error_category::message(int ev) const { | |
67 | if (ev == 0) | |
68 | return "No error"; | |
69 | ||
70 | switch (static_cast<osd_errc>(ev)) { | |
71 | case osd_errc::old_snapc: | |
72 | return "ORDERSNAP flag set; writer has old snapc"; | |
73 | case osd_errc::blocklisted: | |
74 | return "Blocklisted"; | |
75 | } | |
76 | ||
77 | return cpp_strerror(ev); | |
78 | } | |
79 | ||
80 | boost::system::error_condition osd_error_category::default_error_condition(int ev) const noexcept { | |
81 | if (ev == static_cast<int>(osd_errc::old_snapc) || | |
82 | ev == static_cast<int>(osd_errc::blocklisted)) | |
83 | return { ev, *this }; | |
84 | else | |
85 | return { ev, boost::system::generic_category() }; | |
86 | } | |
87 | ||
88 | bool osd_error_category::equivalent(int ev, const boost::system::error_condition& c) const noexcept { | |
89 | switch (static_cast<osd_errc>(ev)) { | |
90 | case osd_errc::old_snapc: | |
91 | return c == boost::system::errc::invalid_argument; | |
92 | case osd_errc::blocklisted: | |
93 | return c == boost::system::errc::operation_not_permitted; | |
94 | } | |
95 | return default_error_condition(ev) == c; | |
96 | } | |
97 | ||
98 | int osd_error_category::from_code(int ev) const noexcept { | |
99 | return -ev; | |
100 | } | |
101 | ||
102 | const boost::system::error_category& osd_category() noexcept { | |
103 | static const osd_error_category c; | |
104 | return c; | |
105 | } |