summaryrefslogtreecommitdiffstats
path: root/src/common/snap_types.cc
blob: 521404ca2b5b028b22128c224e3d65f5428026f6 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "snap_types.h"
#include "common/Formatter.h"

void SnapRealmInfo::encode(ceph::buffer::list& bl) const
{
  h.num_snaps = my_snaps.size();
  h.num_prior_parent_snaps = prior_parent_snaps.size();
  using ceph::encode;
  encode(h, bl);
  ceph::encode_nohead(my_snaps, bl);
  ceph::encode_nohead(prior_parent_snaps, bl);
}

void SnapRealmInfo::decode(ceph::buffer::list::const_iterator& bl)
{
  using ceph::decode;
  decode(h, bl);
  ceph::decode_nohead(h.num_snaps, my_snaps, bl);
  ceph::decode_nohead(h.num_prior_parent_snaps, prior_parent_snaps, bl);
}

void SnapRealmInfo::dump(ceph::Formatter *f) const
{
  f->dump_unsigned("ino", ino());
  f->dump_unsigned("parent", parent());
  f->dump_unsigned("seq", seq());
  f->dump_unsigned("parent_since", parent_since());
  f->dump_unsigned("created", created());

  f->open_array_section("snaps");
  for (auto p = my_snaps.begin(); p != my_snaps.end(); ++p)
    f->dump_unsigned("snap", *p);
  f->close_section();

  f->open_array_section("prior_parent_snaps");
  for (auto p = prior_parent_snaps.begin(); p != prior_parent_snaps.end(); ++p)
    f->dump_unsigned("snap", *p);
  f->close_section();
}

void SnapRealmInfo::generate_test_instances(std::list<SnapRealmInfo*>& o)
{
  o.push_back(new SnapRealmInfo);
  o.push_back(new SnapRealmInfo(1, 10, 10, 0));
  o.push_back(new SnapRealmInfo(1, 10, 10, 0));
  o.back()->my_snaps.push_back(10);
  o.push_back(new SnapRealmInfo(1, 10, 10, 5));
  o.back()->my_snaps.push_back(10);
  o.back()->prior_parent_snaps.push_back(3);
  o.back()->prior_parent_snaps.push_back(5);
}


// -----

bool SnapContext::is_valid() const
{
  // seq is a valid snapid
  if (seq > CEPH_MAXSNAP)
    return false;
  if (!snaps.empty()) {
    // seq >= snaps[0]
    if (snaps[0] > seq)
      return false;
    // snaps[] is descending
    snapid_t t = snaps[0];
    for (unsigned i=1; i<snaps.size(); i++) {
      if (snaps[i] >= t || t == 0)
	return false;
      t = snaps[i];
    }
  }
  return true;
}

void SnapContext::dump(ceph::Formatter *f) const
{
  f->dump_unsigned("seq", seq);
  f->open_array_section("snaps");
  for (auto p = snaps.cbegin(); p != snaps.cend(); ++p)
    f->dump_unsigned("snap", *p);
  f->close_section();
}

void SnapContext::generate_test_instances(std::list<SnapContext*>& o)
{
  o.push_back(new SnapContext);
  std::vector<snapid_t> v;
  o.push_back(new SnapContext(10, v));
  v.push_back(18);
  v.push_back(3);
  v.push_back(1);
  o.push_back(new SnapContext(20, v));
}