summaryrefslogtreecommitdiffstats
path: root/src/mds/FSMapUser.cc
blob: 1b58fdbb2f8f62b33f8f14509323cd626323f522 (plain)
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
#include "FSMapUser.h"

void FSMapUser::encode(ceph::buffer::list& bl, uint64_t features) const
{
  ENCODE_START(1, 1, bl);
  encode(epoch, bl);
  encode(legacy_client_fscid, bl);
  std::vector<fs_info_t> fs_list;
  for (auto p = filesystems.begin(); p != filesystems.end(); ++p)
    fs_list.push_back(p->second);
  encode(fs_list, bl, features);
  ENCODE_FINISH(bl);
}

void FSMapUser::decode(ceph::buffer::list::const_iterator& p)
{
  DECODE_START(1, p);
  decode(epoch, p);
  decode(legacy_client_fscid, p);
  std::vector<fs_info_t> fs_list;
  decode(fs_list, p);
  filesystems.clear();
  for (auto p = fs_list.begin(); p != fs_list.end(); ++p)
    filesystems[p->cid] = *p;
  DECODE_FINISH(p);
}

void FSMapUser::fs_info_t::encode(ceph::buffer::list& bl, uint64_t features) const
{
  ENCODE_START(1, 1, bl);
  encode(cid, bl);
  encode(name, bl);
  ENCODE_FINISH(bl);
}

void FSMapUser::fs_info_t::decode(ceph::buffer::list::const_iterator& p)
{
  DECODE_START(1, p);
  decode(cid, p);
  decode(name, p);
  DECODE_FINISH(p);
}

void FSMapUser::generate_test_instances(std::list<FSMapUser*>& ls)
{
  FSMapUser *m = new FSMapUser();
  m->epoch = 2;
  m->legacy_client_fscid = 1;
  m->filesystems[1].cid = 1;
  m->filesystems[2].name = "cephfs2";
  m->filesystems[2].cid = 2;
  m->filesystems[1].name = "cephfs1";
  ls.push_back(m);
}


void FSMapUser::print(std::ostream& out) const
{
  out << "e" << epoch << std::endl;
  out << "legacy_client_fscid: " << legacy_client_fscid << std::endl;
  for (auto &p : filesystems)
    out << " id " <<  p.second.cid << " name " << p.second.name << std::endl;
}

void FSMapUser::print_summary(ceph::Formatter *f, std::ostream *out) const
{
  std::map<mds_role_t,std::string> by_rank;
  std::map<std::string,int> by_state;

  if (f) {
    f->dump_unsigned("epoch", get_epoch());
    for (auto &p : filesystems) {
      f->dump_unsigned("id", p.second.cid);
      f->dump_string("name", p.second.name);
    }
  } else {
    *out << "e" << get_epoch() << ":";
    for (auto &p : filesystems)
      *out << " " << p.second.name << "(" << p.second.cid << ")";
  }
}