]>
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.
15 #include <string_view>
19 #include "common/Formatter.h"
25 void SnapInfo::encode(bufferlist
& bl
) const
27 ENCODE_START(3, 2, bl
);
36 void SnapInfo::decode(bufferlist::const_iterator
& bl
)
38 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl
);
49 void SnapInfo::dump(Formatter
*f
) const
51 f
->dump_unsigned("snapid", snapid
);
52 f
->dump_unsigned("ino", ino
);
53 f
->dump_stream("stamp") << stamp
;
54 f
->dump_string("name", name
);
55 f
->open_object_section("metadata");
56 for (auto &[key
, value
] : metadata
) {
57 f
->dump_string(key
, value
);
62 void SnapInfo::generate_test_instances(std::list
<SnapInfo
*>& ls
)
64 ls
.push_back(new SnapInfo
);
65 ls
.push_back(new SnapInfo
);
66 ls
.back()->snapid
= 1;
68 ls
.back()->stamp
= utime_t(3, 4);
69 ls
.back()->name
= "foo";
70 ls
.back()->metadata
= {{"foo", "bar"}};
73 ostream
& operator<<(ostream
& out
, const SnapInfo
&sn
)
75 return out
<< "snap(" << sn
.snapid
78 << "' " << sn
.stamp
<< ")";
81 std::string_view
SnapInfo::get_long_name() const
83 if (long_name
.empty() ||
84 long_name
.compare(1, name
.size(), name
) ||
85 long_name
.find_last_of("_") != name
.size() + 1) {
87 snprintf(nm
, sizeof(nm
), "_%s_%llu", name
.c_str(), (unsigned long long)ino
);
97 void snaplink_t::encode(bufferlist
& bl
) const
99 ENCODE_START(2, 2, bl
);
105 void snaplink_t::decode(bufferlist::const_iterator
& bl
)
107 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
113 void snaplink_t::dump(Formatter
*f
) const
115 f
->dump_unsigned("ino", ino
);
116 f
->dump_unsigned("first", first
);
119 void snaplink_t::generate_test_instances(std::list
<snaplink_t
*>& ls
)
121 ls
.push_back(new snaplink_t
);
122 ls
.push_back(new snaplink_t
);
124 ls
.back()->first
= 123;
127 ostream
& operator<<(ostream
& out
, const snaplink_t
&l
)
129 return out
<< l
.ino
<< "@" << l
.first
;
136 void sr_t::encode(bufferlist
& bl
) const
138 ENCODE_START(6, 4, bl
);
141 encode(last_created
, bl
);
142 encode(last_destroyed
, bl
);
143 encode(current_parent_since
, bl
);
145 encode(past_parents
, bl
);
146 encode(past_parent_snaps
, bl
);
151 void sr_t::decode(bufferlist::const_iterator
& p
)
153 DECODE_START_LEGACY_COMPAT_LEN(6, 4, 4, p
);
156 decode(struct_v
, p
); // yes, really: extra byte for v2 encoding only, see 6ee52e7d.
160 decode(last_created
, p
);
161 decode(last_destroyed
, p
);
162 decode(current_parent_since
, p
);
164 decode(past_parents
, p
);
166 decode(past_parent_snaps
, p
);
174 void sr_t::dump(Formatter
*f
) const
176 f
->dump_unsigned("seq", seq
);
177 f
->dump_unsigned("created", created
);
178 f
->dump_unsigned("last_created", last_created
);
179 f
->dump_unsigned("last_destroyed", last_destroyed
);
180 f
->dump_unsigned("current_parent_since", current_parent_since
);
182 f
->open_array_section("snaps");
183 for (map
<snapid_t
,SnapInfo
>::const_iterator p
= snaps
.begin(); p
!= snaps
.end(); ++p
) {
184 f
->open_object_section("snapinfo");
185 f
->dump_unsigned("last", p
->first
);
191 f
->open_array_section("past_parents");
192 for (map
<snapid_t
,snaplink_t
>::const_iterator p
= past_parents
.begin(); p
!= past_parents
.end(); ++p
) {
193 f
->open_object_section("past_parent");
194 f
->dump_unsigned("last", p
->first
);
200 f
->open_array_section("past_parent_snaps");
201 for (auto p
= past_parent_snaps
.begin(); p
!= past_parent_snaps
.end(); ++p
) {
202 f
->open_object_section("snapinfo");
203 f
->dump_unsigned("snapid", *p
);
209 void sr_t::generate_test_instances(std::list
<sr_t
*>& ls
)
211 ls
.push_back(new sr_t
);
212 ls
.push_back(new sr_t
);
214 ls
.back()->created
= 2;
215 ls
.back()->last_created
= 3;
216 ls
.back()->last_destroyed
= 4;
217 ls
.back()->current_parent_since
= 5;
218 ls
.back()->snaps
[123].snapid
= 7;
219 ls
.back()->snaps
[123].ino
= 8;
220 ls
.back()->snaps
[123].stamp
= utime_t(9, 10);
221 ls
.back()->snaps
[123].name
= "name1";
222 ls
.back()->past_parents
[12].ino
= 12;
223 ls
.back()->past_parents
[12].first
= 3;
225 ls
.back()->past_parent_snaps
.insert(5);
226 ls
.back()->past_parent_snaps
.insert(6);