-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonMap.cc
48 lines (40 loc) · 920 Bytes
/
MonMap.cc
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
#include "MonMap.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
// read from/write to a file
int MonMap::write(const char *fn)
{
// encode
bufferlist bl;
encode(bl);
return bl.write_file(fn);
}
int MonMap::read(const char *fn)
{
// read
bufferlist bl;
int r = bl.read_file(fn);
if (r < 0)
return r;
decode(bl);
return 0;
}
void MonMap::print_summary(ostream& out) const
{
out << "e" << epoch << ": "
<< mon_addr.size() << " mons at "
<< mon_addr;
}
void MonMap::print(ostream& out) const
{
out << "epoch " << epoch << "\n";
out << "fsid " << fsid << "\n";
out << "last_changed " << last_changed << "\n";
out << "created " << created << "\n";
unsigned i = 0;
for (map<string,entity_addr_t>::const_iterator p = mon_addr.begin();
p != mon_addr.end();
p++)
out << i++ << ": " << p->second << " mon." << p->first << "\n";
}