]>
Commit | Line | Data |
---|---|---|
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_MOSDMAP_H | |
17 | #define CEPH_MOSDMAP_H | |
18 | ||
19 | #include "msg/Message.h" | |
20 | #include "osd/OSDMap.h" | |
21 | #include "include/ceph_features.h" | |
22 | ||
23 | class MOSDMap : public Message { | |
24 | ||
25 | static const int HEAD_VERSION = 3; | |
26 | ||
27 | public: | |
28 | uuid_d fsid; | |
28e407b8 | 29 | uint64_t encode_features = 0; |
7c673cae FG |
30 | map<epoch_t, bufferlist> maps; |
31 | map<epoch_t, bufferlist> incremental_maps; | |
d2e6a577 | 32 | epoch_t oldest_map =0, newest_map = 0; |
7c673cae FG |
33 | |
34 | epoch_t get_first() const { | |
35 | epoch_t e = 0; | |
36 | map<epoch_t, bufferlist>::const_iterator i = maps.begin(); | |
37 | if (i != maps.end()) e = i->first; | |
38 | i = incremental_maps.begin(); | |
39 | if (i != incremental_maps.end() && | |
40 | (e == 0 || i->first < e)) e = i->first; | |
41 | return e; | |
42 | } | |
43 | epoch_t get_last() const { | |
44 | epoch_t e = 0; | |
45 | map<epoch_t, bufferlist>::const_reverse_iterator i = maps.rbegin(); | |
46 | if (i != maps.rend()) e = i->first; | |
47 | i = incremental_maps.rbegin(); | |
48 | if (i != incremental_maps.rend() && | |
49 | (e == 0 || i->first > e)) e = i->first; | |
50 | return e; | |
51 | } | |
52 | epoch_t get_oldest() { | |
53 | return oldest_map; | |
54 | } | |
55 | epoch_t get_newest() { | |
56 | return newest_map; | |
57 | } | |
58 | ||
59 | ||
60 | MOSDMap() : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION) { } | |
28e407b8 | 61 | MOSDMap(const uuid_d &f, const uint64_t features) |
7c673cae | 62 | : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION), |
28e407b8 | 63 | fsid(f), encode_features(features), |
7c673cae FG |
64 | oldest_map(0), newest_map(0) { } |
65 | private: | |
66 | ~MOSDMap() override {} | |
7c673cae FG |
67 | public: |
68 | // marshalling | |
69 | void decode_payload() override { | |
70 | bufferlist::iterator p = payload.begin(); | |
71 | ::decode(fsid, p); | |
72 | ::decode(incremental_maps, p); | |
73 | ::decode(maps, p); | |
74 | if (header.version >= 2) { | |
75 | ::decode(oldest_map, p); | |
76 | ::decode(newest_map, p); | |
77 | } else { | |
78 | oldest_map = 0; | |
79 | newest_map = 0; | |
80 | } | |
81 | } | |
82 | void encode_payload(uint64_t features) override { | |
83 | header.version = HEAD_VERSION; | |
84 | ::encode(fsid, payload); | |
28e407b8 AA |
85 | if (OSDMap::get_significant_features(encode_features) != |
86 | OSDMap::get_significant_features(features)) { | |
7c673cae FG |
87 | if ((features & CEPH_FEATURE_PGID64) == 0 || |
88 | (features & CEPH_FEATURE_PGPOOL3) == 0) | |
89 | header.version = 1; // old old_client version | |
90 | else if ((features & CEPH_FEATURE_OSDENC) == 0) | |
91 | header.version = 2; // old pg_pool_t | |
92 | ||
93 | // reencode maps using old format | |
94 | // | |
95 | // FIXME: this can probably be done more efficiently higher up | |
96 | // the stack, or maybe replaced with something that only | |
97 | // includes the pools the client cares about. | |
98 | for (map<epoch_t,bufferlist>::iterator p = incremental_maps.begin(); | |
99 | p != incremental_maps.end(); | |
100 | ++p) { | |
101 | OSDMap::Incremental inc; | |
102 | bufferlist::iterator q = p->second.begin(); | |
103 | inc.decode(q); | |
28e407b8 AA |
104 | // always encode with subset of osdmaps canonical features |
105 | uint64_t f = inc.encode_features & features; | |
7c673cae FG |
106 | p->second.clear(); |
107 | if (inc.fullmap.length()) { | |
108 | // embedded full map? | |
109 | OSDMap m; | |
110 | m.decode(inc.fullmap); | |
111 | inc.fullmap.clear(); | |
28e407b8 | 112 | m.encode(inc.fullmap, f | CEPH_FEATURE_RESERVED); |
7c673cae | 113 | } |
3efd9988 FG |
114 | if (inc.crush.length()) { |
115 | // embedded crush map | |
116 | CrushWrapper c; | |
117 | auto p = inc.crush.begin(); | |
118 | c.decode(p); | |
119 | inc.crush.clear(); | |
28e407b8 | 120 | c.encode(inc.crush, f); |
3efd9988 | 121 | } |
28e407b8 | 122 | inc.encode(p->second, f | CEPH_FEATURE_RESERVED); |
7c673cae FG |
123 | } |
124 | for (map<epoch_t,bufferlist>::iterator p = maps.begin(); | |
125 | p != maps.end(); | |
126 | ++p) { | |
127 | OSDMap m; | |
128 | m.decode(p->second); | |
28e407b8 AA |
129 | // always encode with subset of osdmaps canonical features |
130 | uint64_t f = m.get_encoding_features() & features; | |
7c673cae | 131 | p->second.clear(); |
28e407b8 | 132 | m.encode(p->second, f | CEPH_FEATURE_RESERVED); |
7c673cae FG |
133 | } |
134 | } | |
135 | ::encode(incremental_maps, payload); | |
136 | ::encode(maps, payload); | |
137 | if (header.version >= 2) { | |
138 | ::encode(oldest_map, payload); | |
139 | ::encode(newest_map, payload); | |
140 | } | |
141 | } | |
142 | ||
143 | const char *get_type_name() const override { return "osdmap"; } | |
144 | void print(ostream& out) const override { | |
145 | out << "osd_map(" << get_first() << ".." << get_last(); | |
146 | if (oldest_map || newest_map) | |
147 | out << " src has " << oldest_map << ".." << newest_map; | |
148 | out << ")"; | |
149 | } | |
150 | }; | |
151 | ||
152 | #endif |