From: Jason Dillaman Date: Fri, 31 Aug 2018 21:17:25 +0000 (-0400) Subject: librbd: cls_rbd_snap on-disk struct supports parent overlap X-Git-Tag: v14.0.1~241^2~13 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9163112989dd3846306f1313c5d68d8d8e00c832;p=ceph-ci.git librbd: cls_rbd_snap on-disk struct supports parent overlap This is the first step to fix the denormalization of the parent image spec references between the HEAD revision and the snapshot revisions. Signed-off-by: Jason Dillaman --- diff --git a/src/cls/rbd/cls_rbd.cc b/src/cls/rbd/cls_rbd.cc index 0d747db59b4..9751e699bf2 100644 --- a/src/cls/rbd/cls_rbd.cc +++ b/src/cls/rbd/cls_rbd.cc @@ -965,11 +965,8 @@ int set_protection_status(cls_method_context_t hctx, bufferlist *in, } snap.protection_status = status; - bufferlist snapshot_bl; - encode(snap, snapshot_bl); - r = cls_cxx_map_set_val(hctx, snapshot_key, &snapshot_bl); + r = write_key(hctx, snapshot_key, snap, get_encode_features(hctx)); if (r < 0) { - CLS_ERR("error writing snapshot metadata: %s", cpp_strerror(r).c_str()); return r; } @@ -1298,19 +1295,13 @@ int set_flags(cls_method_context_t hctx, bufferlist *in, bufferlist *out) flags, mask); if (snap_id == CEPH_NOSNAP) { - bufferlist bl; - encode(flags, bl); - r = cls_cxx_map_set_val(hctx, "flags", &bl); + r = write_key(hctx, "flags", flags); } else { snap_meta.flags = flags; - - bufferlist bl; - encode(snap_meta, bl); - r = cls_cxx_map_set_val(hctx, snap_meta_key, &bl); + r = write_key(hctx, snap_meta_key, snap_meta, get_encode_features(hctx)); } if (r < 0) { - CLS_ERR("error updating flags: %s", cpp_strerror(r).c_str()); return r; } return 0; @@ -1541,7 +1532,8 @@ int remove_parent(cls_method_context_t hctx, bufferlist *in, bufferlist *out) std::string snap_key; key_from_snap_id(snap_meta_copy.id, &snap_key); - int r = write_key(hctx, snap_key, snap_meta_copy); + int r = write_key(hctx, snap_key, snap_meta_copy, + get_encode_features(hctx)); if (r < 0) { return r; } @@ -2116,7 +2108,7 @@ int snapshot_add(cls_method_context_t hctx, bufferlist *in, bufferlist *out) } bufferlist snap_metabl, snap_seqbl; - encode(snap_meta, snap_metabl); + encode(snap_meta, snap_metabl, get_encode_features(hctx)); encode(snap_meta.id, snap_seqbl); string snapshot_key; @@ -2203,12 +2195,8 @@ int snapshot_rename(cls_method_context_t hctx, bufferlist *in, bufferlist *out) } snap_meta.name = dst_snap_name; - bufferlist snap_metabl; - encode(snap_meta, snap_metabl); - - r = cls_cxx_map_set_val(hctx, src_snap_key, &snap_metabl); + r = write_key(hctx, src_snap_key, snap_meta, get_encode_features(hctx)); if (r < 0) { - CLS_ERR("error writing snapshot metadata: %s", cpp_strerror(r).c_str()); return r; } @@ -2364,7 +2352,7 @@ int snapshot_trash_add(cls_method_context_t hctx, bufferlist *in, uuid_gen.generate_random(); snap.name = uuid_gen.to_string(); - r = write_key(hctx, snapshot_key, snap); + r = write_key(hctx, snapshot_key, snap, get_encode_features(hctx)); if (r < 0) { return r; } @@ -3628,7 +3616,7 @@ int child_attach(cls_method_context_t hctx, bufferlist *in, bufferlist *out) } ++snap.child_count; - r = write_key(hctx, snapshot_key, snap); + r = write_key(hctx, snapshot_key, snap, get_encode_features(hctx)); if (r < 0) { CLS_ERR("error writing snapshot: %s", cpp_strerror(r).c_str()); return r; @@ -3705,7 +3693,7 @@ int child_detach(cls_method_context_t hctx, bufferlist *in, bufferlist *out) } --snap.child_count; - r = write_key(hctx, snapshot_key, snap); + r = write_key(hctx, snapshot_key, snap, get_encode_features(hctx)); if (r < 0) { CLS_ERR("error writing snapshot: %s", cpp_strerror(r).c_str()); return r; diff --git a/src/cls/rbd/cls_rbd.h b/src/cls/rbd/cls_rbd.h index 202ff97b721..ed6443ffbff 100644 --- a/src/cls/rbd/cls_rbd.h +++ b/src/cls/rbd/cls_rbd.h @@ -113,25 +113,27 @@ struct cls_rbd_snap { cls::rbd::SnapshotNamespace snapshot_namespace = { cls::rbd::UserSnapshotNamespace{}}; uint32_t child_count = 0; + std::optional parent_overlap = std::nullopt; /// true if we have a parent bool has_parent() const { return parent.exists(); } - void encode(bufferlist& bl) const { - ENCODE_START(7, 1, bl); + void encode(bufferlist& bl, uint64_t features) const { + ENCODE_START(8, 1, bl); encode(id, bl); encode(name, bl); encode(image_size, bl); uint64_t features = 0; encode(features, bl); // unused -- preserve ABI - encode(parent, bl, 0); + encode(parent, bl, features); encode(protection_status, bl); encode(flags, bl); encode(snapshot_namespace, bl); encode(timestamp, bl); encode(child_count, bl); + encode(parent_overlap, bl); ENCODE_FINISH(bl); } void decode(bufferlist::const_iterator& p) { @@ -159,6 +161,9 @@ struct cls_rbd_snap { if (struct_v >= 7) { decode(child_count, p); } + if (struct_v >= 8) { + decode(parent_overlap, p); + } DECODE_FINISH(p); } void dump(Formatter *f) const { @@ -184,6 +189,9 @@ struct cls_rbd_snap { ceph_abort(); } f->dump_unsigned("child_count", child_count); + if (parent_overlap) { + f->dump_unsigned("parent_overlap", *parent_overlap); + } } static void generate_test_instances(list& o) { o.push_back(new cls_rbd_snap); @@ -205,6 +213,6 @@ struct cls_rbd_snap { o.push_back(t); } }; -WRITE_CLASS_ENCODER(cls_rbd_snap) +WRITE_CLASS_ENCODER_FEATURES(cls_rbd_snap) #endif // __CEPH_CLS_RBD_H diff --git a/src/tools/ceph-dencoder/types.h b/src/tools/ceph-dencoder/types.h index b56110df2a2..b782e221a1b 100644 --- a/src/tools/ceph-dencoder/types.h +++ b/src/tools/ceph-dencoder/types.h @@ -462,7 +462,7 @@ TYPE(rgw_data_sync_status) #ifdef WITH_RBD #include "cls/rbd/cls_rbd.h" TYPE_FEATUREFUL(cls_rbd_parent) -TYPE(cls_rbd_snap) +TYPE_FEATUREFUL(cls_rbd_snap) #include "cls/rbd/cls_rbd_types.h" TYPE(cls::rbd::ParentImageSpec)