]>
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; | |
29 | map<epoch_t, bufferlist> maps; | |
30 | map<epoch_t, bufferlist> incremental_maps; | |
d2e6a577 | 31 | epoch_t oldest_map =0, newest_map = 0; |
7c673cae FG |
32 | |
33 | epoch_t get_first() const { | |
34 | epoch_t e = 0; | |
35 | map<epoch_t, bufferlist>::const_iterator i = maps.begin(); | |
36 | if (i != maps.end()) e = i->first; | |
37 | i = incremental_maps.begin(); | |
38 | if (i != incremental_maps.end() && | |
39 | (e == 0 || i->first < e)) e = i->first; | |
40 | return e; | |
41 | } | |
42 | epoch_t get_last() const { | |
43 | epoch_t e = 0; | |
44 | map<epoch_t, bufferlist>::const_reverse_iterator i = maps.rbegin(); | |
45 | if (i != maps.rend()) e = i->first; | |
46 | i = incremental_maps.rbegin(); | |
47 | if (i != incremental_maps.rend() && | |
48 | (e == 0 || i->first > e)) e = i->first; | |
49 | return e; | |
50 | } | |
51 | epoch_t get_oldest() { | |
52 | return oldest_map; | |
53 | } | |
54 | epoch_t get_newest() { | |
55 | return newest_map; | |
56 | } | |
57 | ||
58 | ||
59 | MOSDMap() : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION) { } | |
60 | MOSDMap(const uuid_d &f) | |
61 | : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION), | |
62 | fsid(f), | |
63 | oldest_map(0), newest_map(0) { } | |
64 | private: | |
65 | ~MOSDMap() override {} | |
66 | ||
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); | |
85 | if ((features & CEPH_FEATURE_PGID64) == 0 || | |
86 | (features & CEPH_FEATURE_PGPOOL3) == 0 || | |
87 | (features & CEPH_FEATURE_OSDENC) == 0 || | |
88 | (features & CEPH_FEATURE_OSDMAP_ENC) == 0 || | |
89 | (features & CEPH_FEATURE_MSG_ADDR2) == 0) { | |
90 | if ((features & CEPH_FEATURE_PGID64) == 0 || | |
91 | (features & CEPH_FEATURE_PGPOOL3) == 0) | |
92 | header.version = 1; // old old_client version | |
93 | else if ((features & CEPH_FEATURE_OSDENC) == 0) | |
94 | header.version = 2; // old pg_pool_t | |
95 | ||
96 | // reencode maps using old format | |
97 | // | |
98 | // FIXME: this can probably be done more efficiently higher up | |
99 | // the stack, or maybe replaced with something that only | |
100 | // includes the pools the client cares about. | |
101 | for (map<epoch_t,bufferlist>::iterator p = incremental_maps.begin(); | |
102 | p != incremental_maps.end(); | |
103 | ++p) { | |
104 | OSDMap::Incremental inc; | |
105 | bufferlist::iterator q = p->second.begin(); | |
106 | inc.decode(q); | |
107 | p->second.clear(); | |
108 | if (inc.fullmap.length()) { | |
109 | // embedded full map? | |
110 | OSDMap m; | |
111 | m.decode(inc.fullmap); | |
112 | inc.fullmap.clear(); | |
113 | m.encode(inc.fullmap, features | CEPH_FEATURE_RESERVED); | |
114 | } | |
115 | inc.encode(p->second, features | CEPH_FEATURE_RESERVED); | |
116 | } | |
117 | for (map<epoch_t,bufferlist>::iterator p = maps.begin(); | |
118 | p != maps.end(); | |
119 | ++p) { | |
120 | OSDMap m; | |
121 | m.decode(p->second); | |
122 | p->second.clear(); | |
123 | m.encode(p->second, features | CEPH_FEATURE_RESERVED); | |
124 | } | |
125 | } | |
126 | ::encode(incremental_maps, payload); | |
127 | ::encode(maps, payload); | |
128 | if (header.version >= 2) { | |
129 | ::encode(oldest_map, payload); | |
130 | ::encode(newest_map, payload); | |
131 | } | |
132 | } | |
133 | ||
134 | const char *get_type_name() const override { return "osdmap"; } | |
135 | void print(ostream& out) const override { | |
136 | out << "osd_map(" << get_first() << ".." << get_last(); | |
137 | if (oldest_map || newest_map) | |
138 | out << " src has " << oldest_map << ".." << newest_map; | |
139 | out << ")"; | |
140 | } | |
141 | }; | |
142 | ||
143 | #endif |