]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mds/snap.cc
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- 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.
17 #include "common/Formatter.h"
23 void SnapInfo::encode(bufferlist
& bl
) const
25 ENCODE_START(2, 2, bl
);
33 void SnapInfo::decode(bufferlist::iterator
& bl
)
35 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
43 void SnapInfo::dump(Formatter
*f
) const
45 f
->dump_unsigned("snapid", snapid
);
46 f
->dump_unsigned("ino", ino
);
47 f
->dump_stream("stamp") << stamp
;
48 f
->dump_string("name", name
);
51 void SnapInfo::generate_test_instances(list
<SnapInfo
*>& ls
)
53 ls
.push_back(new SnapInfo
);
54 ls
.push_back(new SnapInfo
);
55 ls
.back()->snapid
= 1;
57 ls
.back()->stamp
= utime_t(3, 4);
58 ls
.back()->name
= "foo";
61 ostream
& operator<<(ostream
& out
, const SnapInfo
&sn
)
63 return out
<< "snap(" << sn
.snapid
66 << "' " << sn
.stamp
<< ")";
69 const string
& SnapInfo::get_long_name()
71 if (long_name
.length() == 0) {
73 snprintf(nm
, sizeof(nm
), "_%s_%llu", name
.c_str(), (unsigned long long)ino
);
83 void snaplink_t::encode(bufferlist
& bl
) const
85 ENCODE_START(2, 2, bl
);
91 void snaplink_t::decode(bufferlist::iterator
& bl
)
93 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
99 void snaplink_t::dump(Formatter
*f
) const
101 f
->dump_unsigned("ino", ino
);
102 f
->dump_unsigned("first", first
);
105 void snaplink_t::generate_test_instances(list
<snaplink_t
*>& ls
)
107 ls
.push_back(new snaplink_t
);
108 ls
.push_back(new snaplink_t
);
110 ls
.back()->first
= 123;
113 ostream
& operator<<(ostream
& out
, const snaplink_t
&l
)
115 return out
<< l
.ino
<< "@" << l
.first
;
122 void sr_t::encode(bufferlist
& bl
) const
124 ENCODE_START(4, 4, bl
);
126 ::encode(created
, bl
);
127 ::encode(last_created
, bl
);
128 ::encode(last_destroyed
, bl
);
129 ::encode(current_parent_since
, bl
);
131 ::encode(past_parents
, bl
);
135 void sr_t::decode(bufferlist::iterator
& p
)
137 DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, p
);
140 ::decode(struct_v
, p
); // yes, really: extra byte for v2 encoding only, see 6ee52e7d.
143 ::decode(created
, p
);
144 ::decode(last_created
, p
);
145 ::decode(last_destroyed
, p
);
146 ::decode(current_parent_since
, p
);
148 ::decode(past_parents
, p
);
152 void sr_t::dump(Formatter
*f
) const
154 f
->dump_unsigned("seq", seq
);
155 f
->dump_unsigned("created", created
);
156 f
->dump_unsigned("last_created", last_created
);
157 f
->dump_unsigned("last_destroyed", last_destroyed
);
158 f
->dump_unsigned("current_parent_since", current_parent_since
);
160 f
->open_array_section("snaps");
161 for (map
<snapid_t
,SnapInfo
>::const_iterator p
= snaps
.begin(); p
!= snaps
.end(); ++p
) {
162 f
->open_object_section("snapinfo");
163 f
->dump_unsigned("last", p
->first
);
169 f
->open_array_section("past_parents");
170 for (map
<snapid_t
,snaplink_t
>::const_iterator p
= past_parents
.begin(); p
!= past_parents
.end(); ++p
) {
171 f
->open_object_section("past_parent");
172 f
->dump_unsigned("last", p
->first
);
179 void sr_t::generate_test_instances(list
<sr_t
*>& ls
)
181 ls
.push_back(new sr_t
);
182 ls
.push_back(new sr_t
);
184 ls
.back()->created
= 2;
185 ls
.back()->last_created
= 3;
186 ls
.back()->last_destroyed
= 4;
187 ls
.back()->current_parent_since
= 5;
188 ls
.back()->snaps
[123].snapid
= 7;
189 ls
.back()->snaps
[123].ino
= 8;
190 ls
.back()->snaps
[123].stamp
= utime_t(9, 10);
191 ls
.back()->snaps
[123].name
= "name1";
192 ls
.back()->past_parents
[12].ino
= 12;
193 ls
.back()->past_parents
[12].first
= 3;