]>
git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MOSDMap.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 #ifndef CEPH_MOSDMAP_H
17 #define CEPH_MOSDMAP_H
19 #include "msg/Message.h"
20 #include "osd/OSDMap.h"
21 #include "include/ceph_features.h"
23 class MOSDMap
: public Message
{
25 static const int HEAD_VERSION
= 3;
29 uint64_t encode_features
= 0;
30 map
<epoch_t
, bufferlist
> maps
;
31 map
<epoch_t
, bufferlist
> incremental_maps
;
32 epoch_t oldest_map
=0, newest_map
= 0;
34 epoch_t
get_first() const {
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
;
43 epoch_t
get_last() const {
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
;
52 epoch_t
get_oldest() {
55 epoch_t
get_newest() {
60 MOSDMap() : Message(CEPH_MSG_OSD_MAP
, HEAD_VERSION
) { }
61 MOSDMap(const uuid_d
&f
, const uint64_t features
)
62 : Message(CEPH_MSG_OSD_MAP
, HEAD_VERSION
),
63 fsid(f
), encode_features(features
),
64 oldest_map(0), newest_map(0) { }
66 ~MOSDMap() override
{}
69 void decode_payload() override
{
70 bufferlist::iterator p
= payload
.begin();
72 ::decode(incremental_maps
, p
);
74 if (header
.version
>= 2) {
75 ::decode(oldest_map
, p
);
76 ::decode(newest_map
, p
);
82 void encode_payload(uint64_t features
) override
{
83 header
.version
= HEAD_VERSION
;
84 ::encode(fsid
, payload
);
85 if (OSDMap::get_significant_features(encode_features
) !=
86 OSDMap::get_significant_features(features
)) {
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
93 // reencode maps using old format
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();
101 OSDMap::Incremental inc
;
102 bufferlist::iterator q
= p
->second
.begin();
104 // always encode with subset of osdmaps canonical features
105 uint64_t f
= inc
.encode_features
& features
;
107 if (inc
.fullmap
.length()) {
108 // embedded full map?
110 m
.decode(inc
.fullmap
);
112 m
.encode(inc
.fullmap
, f
| CEPH_FEATURE_RESERVED
);
114 if (inc
.crush
.length()) {
115 // embedded crush map
117 auto p
= inc
.crush
.begin();
120 c
.encode(inc
.crush
, f
);
122 inc
.encode(p
->second
, f
| CEPH_FEATURE_RESERVED
);
124 for (map
<epoch_t
,bufferlist
>::iterator p
= maps
.begin();
129 // always encode with subset of osdmaps canonical features
130 uint64_t f
= m
.get_encoding_features() & features
;
132 m
.encode(p
->second
, f
| CEPH_FEATURE_RESERVED
);
135 ::encode(incremental_maps
, payload
);
136 ::encode(maps
, payload
);
137 if (header
.version
>= 2) {
138 ::encode(oldest_map
, payload
);
139 ::encode(newest_map
, payload
);
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
;