]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: store resharding information in bucket header
authorOrit Wasserman <owasserm@redhat.com>
Thu, 27 Apr 2017 20:13:52 +0000 (23:13 +0300)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 5 Jun 2017 20:17:35 +0000 (13:17 -0700)
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/cls/rgw/cls_rgw.cc
src/cls/rgw/cls_rgw_types.cc
src/cls/rgw/cls_rgw_types.h

index 6149f688cf7e82da6bd5c0808150f49e1745909f..ddca884f125214900b43d971ed3f645b76a2f0c0 100644 (file)
@@ -3628,21 +3628,17 @@ static int rgw_set_bucket_resharding(cls_method_context_t hctx, bufferlist *in,
     return -EINVAL;
   }
 
-  bufferlist bl;
-  ::encode(true, bl);
-  int ret = cls_cxx_setxattr(hctx, resharding_attr.c_str(), &bl);
-  if (ret < 0) {
-    CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__, resharding_attr.c_str(), ret);
-    return ret;
+  struct rgw_bucket_dir_header header;
+  int rc = read_bucket_header(hctx, &header);
+  if (rc < 0) {
+    CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__);
+    return rc;
   }
 
-  ret = cls_cxx_write(hctx, 0, op.entry.data.length(), &op.entry.data);
-  if (ret < 0) {
-    CLS_LOG(0, "ERROR: %s(): cls_cxx_write returned %d", __func__, ret);
-    return ret;
-  }
+  header.is_resharding = true;
+  header.new_bucket_instance_id = op.entry.new_bucket_instance_id;
 
-  return 0;
+  return write_bucket_header(hctx, &header);
 }
 
 static int rgw_clear_bucket_resharding(cls_method_context_t hctx, bufferlist *in,  bufferlist *out)
@@ -3657,21 +3653,16 @@ static int rgw_clear_bucket_resharding(cls_method_context_t hctx, bufferlist *in
     return -EINVAL;
   }
 
-  bufferlist bl;
-  ::encode(false, bl);
-  int ret = cls_cxx_setxattr(hctx, resharding_attr.c_str(), &bl);
-  if (ret < 0) {
-    CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__, resharding_attr.c_str(), ret);
-    return ret;
-  }
-
-  ret = cls_cxx_write(hctx, 0, op.entry.data.length(), &op.entry.data);
-  if (ret < 0) {
-    CLS_LOG(0, "ERROR: %s(): cls_cxx_write returned %d", __func__, ret);
-    return ret;
+  struct rgw_bucket_dir_header header;
+  int rc = read_bucket_header(hctx, &header);
+  if (rc < 0) {
+    CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__);
+    return rc;
   }
+  header.is_resharding = false;
+  header.new_bucket_instance_id.clear();
 
-  return 0;
+  return write_bucket_header(hctx, &header);
 }
 
 static int rgw_get_bucket_resharding(cls_method_context_t hctx, bufferlist *in,  bufferlist *out)
@@ -3686,20 +3677,15 @@ static int rgw_get_bucket_resharding(cls_method_context_t hctx, bufferlist *in,
     return -EINVAL;
   }
 
-  bufferlist bl;
-  int ret = cls_cxx_getxattr(hctx, resharding_attr.c_str(), &bl);
-  if (ret < 0) {
-    CLS_LOG(0, "ERROR: %s(): cls_cxx_getxattr (attr=%s) returned %d", __func__, resharding_attr.c_str(), ret);
-    return ret;
+  struct rgw_bucket_dir_header header;
+  int rc = read_bucket_header(hctx, &header);
+  if (rc < 0) {
+    CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__);
+    return rc;
   }
 
   cls_rgw_get_bucket_resharding_ret op_ret;
-  try {
-    ::decode(op_ret.resharding, bl);
-  } catch (buffer::error& err) {
-    CLS_LOG(1, "ERROR: cls_rgw_get_bucket_resharding: failed to decode entry\n");
-    return -EINVAL;
-  }
+  op_ret.resharding = header.is_resharding;
 
   ::encode(op_ret, *out);
 
index a1c3524406b9d0fc533334f73e6e40514eaa9e12..c0af4c06a7759b280f1ecfa7ad381349e0a0e355 100644 (file)
@@ -517,6 +517,8 @@ void rgw_bucket_dir_header::dump(Formatter *f) const
     iter->second.dump(f);
     f->close_section();
   }
+  f->dump_bool("is_resharding", is_resharding);
+  f->dump_string("new_bucket_instance_id",new_bucket_instance_id);
   f->close_section();
 }
 
index 090b5ec6228e553f319b858dee9ced6d3fec388a..a6eb2ef8e8c12202f50d4395d5e4856f5f16e91a 100644 (file)
@@ -610,20 +610,24 @@ struct rgw_bucket_dir_header {
   uint64_t ver;
   uint64_t master_ver;
   string max_marker;
+  bool is_resharding;
+  string new_bucket_instance_id;
 
   rgw_bucket_dir_header() : tag_timeout(0), ver(0), master_ver(0) {}
 
   void encode(bufferlist &bl) const {
-    ENCODE_START(5, 2, bl);
+    ENCODE_START(6, 2, bl);
     ::encode(stats, bl);
     ::encode(tag_timeout, bl);
     ::encode(ver, bl);
     ::encode(master_ver, bl);
     ::encode(max_marker, bl);
+    ::encode(is_resharding, bl);
+    ::encode(new_bucket_instance_id, bl);
     ENCODE_FINISH(bl);
   }
   void decode(bufferlist::iterator &bl) {
-    DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
+    DECODE_START_LEGACY_COMPAT_LEN(6, 2, 2, bl);
     ::decode(stats, bl);
     if (struct_v > 2) {
       ::decode(tag_timeout, bl);
@@ -639,6 +643,12 @@ struct rgw_bucket_dir_header {
     if (struct_v >= 5) {
       ::decode(max_marker, bl);
     }
+    if (struct_v >= 6) {
+      ::decode(is_resharding, bl);
+      ::decode(new_bucket_instance_id, bl);
+    } else {
+        is_resharding = false;
+    }
     DECODE_FINISH(bl);
   }
   void dump(Formatter *f) const;