Skip to content

Commit 32b14ed

Browse files
author
Jason Dillaman
committed
librbd: break cls_rbd_snap on-disk struct backwards compatability
The cls methods are now storing normalized parent overlaps within the snapshot if the OSDs are required to be Nautilus or later. Therefore, we can safely break the on-disk format compatibility for those newer OSDs. Signed-off-by: Jason Dillaman <dillaman@redhat.com>
1 parent 95b02b9 commit 32b14ed

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

src/cls/rbd/cls_rbd.h

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ WRITE_CLASS_ENCODER_FEATURES(cls_rbd_parent)
104104

105105
struct cls_rbd_snap {
106106
snapid_t id = CEPH_NOSNAP;
107-
string name;
107+
std::string name;
108108
uint64_t image_size = 0;
109109
uint8_t protection_status = RBD_PROTECTION_STATUS_UNPROTECTED;
110110
cls_rbd_parent parent;
@@ -115,9 +115,18 @@ struct cls_rbd_snap {
115115
uint32_t child_count = 0;
116116
std::optional<uint64_t> parent_overlap = std::nullopt;
117117

118-
/// true if we have a parent
119-
bool has_parent() const {
120-
return parent.exists();
118+
cls_rbd_snap() {
119+
}
120+
cls_rbd_snap(snapid_t id, const std::string& name, uint64_t image_size,
121+
uint8_t protection_status, const cls_rbd_parent& parent,
122+
uint64_t flags, utime_t timestamp,
123+
const cls::rbd::SnapshotNamespace& snapshot_namespace,
124+
uint32_t child_count,
125+
const std::optional<uint64_t>& parent_overlap)
126+
: id(id), name(name), image_size(image_size),
127+
protection_status(protection_status), parent(parent), flags(flags),
128+
timestamp(timestamp), snapshot_namespace(snapshot_namespace),
129+
child_count(child_count), parent_overlap(parent_overlap) {
121130
}
122131

123132
bool migrate_parent_format(uint64_t features) const {
@@ -126,13 +135,22 @@ struct cls_rbd_snap {
126135
}
127136

128137
void encode(bufferlist& bl, uint64_t features) const {
129-
ENCODE_START(8, 1, bl);
138+
// NOTE: remove support for versions < 8 after Nautilus EOLed
139+
uint8_t min_version = 1;
140+
if ((features & CEPH_FEATURE_SERVER_NAUTILUS) != 0ULL) {
141+
// break backwards compatability when using nautilus or later OSDs
142+
min_version = 8;
143+
}
144+
145+
ENCODE_START(8, min_version, bl);
130146
encode(id, bl);
131147
encode(name, bl);
132148
encode(image_size, bl);
133-
uint64_t features = 0;
134-
encode(features, bl); // unused -- preserve ABI
135-
encode(parent, bl, features);
149+
if (min_version < 8) {
150+
uint64_t image_features = 0;
151+
encode(image_features, bl); // unused -- preserve ABI
152+
encode(parent, bl, features);
153+
}
136154
encode(protection_status, bl);
137155
encode(flags, bl);
138156
encode(snapshot_namespace, bl);
@@ -141,14 +159,17 @@ struct cls_rbd_snap {
141159
encode(parent_overlap, bl);
142160
ENCODE_FINISH(bl);
143161
}
162+
144163
void decode(bufferlist::const_iterator& p) {
145-
DECODE_START(7, p);
164+
DECODE_START(8, p);
146165
decode(id, p);
147166
decode(name, p);
148167
decode(image_size, p);
149-
uint64_t features;
150-
decode(features, p); // unused -- preserve ABI
151-
if (struct_v >= 2) {
168+
if (struct_compat < 8) {
169+
uint64_t features;
170+
decode(features, p); // unused -- preserve ABI
171+
}
172+
if (struct_v >= 2 && struct_compat < 8) {
152173
decode(parent, p);
153174
}
154175
if (struct_v >= 3) {
@@ -171,11 +192,12 @@ struct cls_rbd_snap {
171192
}
172193
DECODE_FINISH(p);
173194
}
195+
174196
void dump(Formatter *f) const {
175197
f->dump_unsigned("id", id);
176198
f->dump_string("name", name);
177199
f->dump_unsigned("image_size", image_size);
178-
if (has_parent()) {
200+
if (parent.exists()) {
179201
f->open_object_section("parent");
180202
parent.dump(f);
181203
f->close_section();
@@ -198,24 +220,22 @@ struct cls_rbd_snap {
198220
f->dump_unsigned("parent_overlap", *parent_overlap);
199221
}
200222
}
223+
201224
static void generate_test_instances(list<cls_rbd_snap*>& o) {
202-
o.push_back(new cls_rbd_snap);
203-
cls_rbd_snap *t = new cls_rbd_snap;
204-
t->id = 1;
205-
t->name = "snap";
206-
t->image_size = 123456;
207-
t->flags = 31;
208-
t->child_count = 543;
209-
o.push_back(t);
210-
t = new cls_rbd_snap;
211-
t->id = 2;
212-
t->name = "snap2";
213-
t->image_size = 12345678;
214-
t->parent = {{1, "", "parent", 456}, 12345};
215-
t->protection_status = RBD_PROTECTION_STATUS_PROTECTED;
216-
t->flags = 14;
217-
t->timestamp = utime_t();
218-
o.push_back(t);
225+
o.push_back(new cls_rbd_snap{});
226+
o.push_back(new cls_rbd_snap{1, "snap", 123456,
227+
RBD_PROTECTION_STATUS_PROTECTED,
228+
{{1, "", "image", 123}, 234}, 31, {},
229+
cls::rbd::UserSnapshotNamespace{}, 543, {}});
230+
o.push_back(new cls_rbd_snap{1, "snap", 123456,
231+
RBD_PROTECTION_STATUS_PROTECTED,
232+
{{1, "", "image", 123}, 234}, 31, {},
233+
cls::rbd::UserSnapshotNamespace{}, 543, {0}});
234+
o.push_back(new cls_rbd_snap{1, "snap", 123456,
235+
RBD_PROTECTION_STATUS_PROTECTED,
236+
{{1, "ns", "image", 123}, 234}, 31, {},
237+
cls::rbd::UserSnapshotNamespace{}, 543,
238+
{123}});
219239
}
220240
};
221241
WRITE_CLASS_ENCODER_FEATURES(cls_rbd_snap)

0 commit comments

Comments
 (0)