~ubuntu-branches/ubuntu/raring/ceph/raring

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */


#ifndef CEPH_MOSDMAP_H
#define CEPH_MOSDMAP_H

#include "msg/Message.h"
#include "osd/OSDMap.h"
#include "include/ceph_features.h"

class MOSDMap : public Message {

  static const int HEAD_VERSION = 3;

 public:
  uuid_d fsid;
  map<epoch_t, bufferlist> maps;
  map<epoch_t, bufferlist> incremental_maps;
  epoch_t oldest_map, newest_map;

  epoch_t get_first() const {
    epoch_t e = 0;
    map<epoch_t, bufferlist>::const_iterator i = maps.begin();
    if (i != maps.end())  e = i->first;
    i = incremental_maps.begin();    
    if (i != incremental_maps.end() &&
        (e == 0 || i->first < e)) e = i->first;
    return e;
  }
  epoch_t get_last() const {
    epoch_t e = 0;
    map<epoch_t, bufferlist>::const_reverse_iterator i = maps.rbegin();
    if (i != maps.rend())  e = i->first;
    i = incremental_maps.rbegin();    
    if (i != incremental_maps.rend() &&
        (e == 0 || i->first > e)) e = i->first;
    return e;
  }
  epoch_t get_oldest() {
    return oldest_map;
  }
  epoch_t get_newest() {
    return newest_map;
  }


  MOSDMap() : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION) { }
  MOSDMap(const uuid_d &f, OSDMap *oc=0)
    : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION),
      fsid(f),
      oldest_map(0), newest_map(0) {
    if (oc)
      oc->encode(maps[oc->get_epoch()]);
  }
private:
  ~MOSDMap() {}

public:
  // marshalling
  void decode_payload() {
    bufferlist::iterator p = payload.begin();
    ::decode(fsid, p);
    ::decode(incremental_maps, p);
    ::decode(maps, p);
    if (header.version >= 2) {
      ::decode(oldest_map, p);
      ::decode(newest_map, p);
    } else {
      oldest_map = 0;
      newest_map = 0;
    }
  }
  void encode_payload(uint64_t features) {
    ::encode(fsid, payload);
    if ((features & CEPH_FEATURE_PGID64) == 0 ||
	(features & CEPH_FEATURE_PGPOOL3) == 0 ||
	(features & CEPH_FEATURE_OSDENC) == 0) {
      if ((features & CEPH_FEATURE_PGID64) == 0 ||
	  (features & CEPH_FEATURE_PGPOOL3) == 0)
	header.version = 1;  // old old_client version
      else
	header.version = 2;  // old pg_pool_t

      // reencode maps using old format
      //
      // FIXME: this can probably be done more efficiently higher up
      // the stack, or maybe replaced with something that only
      // includes the pools the client cares about.
      for (map<epoch_t,bufferlist>::iterator p = incremental_maps.begin();
	   p != incremental_maps.end();
	   ++p) {
	OSDMap::Incremental inc;
	bufferlist::iterator q = p->second.begin();
	inc.decode(q);
	p->second.clear();
	if (inc.fullmap.length()) {
	  // embedded full map?
	  OSDMap m;
	  m.decode(inc.fullmap);
	  inc.fullmap.clear();
	  m.encode(inc.fullmap, features);
	}
	inc.encode(p->second, features);
      }
      for (map<epoch_t,bufferlist>::iterator p = maps.begin();
	   p != maps.end();
	   ++p) {
	OSDMap m;
	m.decode(p->second);
	p->second.clear();
	m.encode(p->second, features);
      }
    }
    ::encode(incremental_maps, payload);
    ::encode(maps, payload);
    if (header.version >= 2) {
      ::encode(oldest_map, payload);
      ::encode(newest_map, payload);
    }
  }

  const char *get_type_name() const { return "omap"; }
  void print(ostream& out) const {
    out << "osd_map(" << get_first() << ".." << get_last();
    if (oldest_map || newest_map)
      out << " src has " << oldest_map << ".." << newest_map;
    out << ")";
  }
};

#endif