]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: cls_rbd_snap on-disk struct supports parent overlap
authorJason Dillaman <dillaman@redhat.com>
Fri, 31 Aug 2018 21:17:25 +0000 (17:17 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 19 Sep 2018 12:04:12 +0000 (08:04 -0400)
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 <dillaman@redhat.com>
src/cls/rbd/cls_rbd.cc
src/cls/rbd/cls_rbd.h
src/tools/ceph-dencoder/types.h

index 0d747db59b45ab3ba2d2682e384cdf49c749ac35..9751e699bf2e3a6a8fd5e5ec931ed079f39b902c 100644 (file)
@@ -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;
index 202ff97b7216686d0b6bca9b63fa2160fb6ec227..ed6443ffbffe3ec7a8e122ed5d78a6990a6d70b0 100644 (file)
@@ -113,25 +113,27 @@ struct cls_rbd_snap {
   cls::rbd::SnapshotNamespace snapshot_namespace = {
     cls::rbd::UserSnapshotNamespace{}};
   uint32_t child_count = 0;
+  std::optional<uint64_t> 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<cls_rbd_snap*>& 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
index b56110df2a2c32c56708fc47ea7fb730656cfe5f..b782e221a1bb35c16e5a8d628f936215f8de7ddf 100644 (file)
@@ -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)