]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add cls _bucket_resharding_set and cls_bucket_resharding_clear
authorOrit Wasserman <owasserm@redhat.com>
Thu, 6 Apr 2017 18:58:37 +0000 (21:58 +0300)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 2 Jun 2017 21:46:44 +0000 (14:46 -0700)
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/cls/rgw/cls_rgw.cc
src/cls/rgw/cls_rgw_client.cc
src/cls/rgw/cls_rgw_client.h
src/cls/rgw/cls_rgw_ops.cc
src/cls/rgw/cls_rgw_ops.h
src/cls/rgw/cls_rgw_types.cc
src/cls/rgw/cls_rgw_types.h
src/test/encoding/types.h

index 0f2fcd1da5a087d66b7def233e4f5073c981045b..846a0ac494f85060f79dc6d1418ba4bf0d0424ae 100644 (file)
@@ -3614,6 +3614,66 @@ static int rgw_reshard_remove(cls_method_context_t hctx, bufferlist *in, bufferl
   return ret;
 }
 
+const string resharding_attr = "resharding";
+
+static int cls_rgw_set_bucket_resharding(cls_method_context_t hctx, bufferlist *in,  bufferlist *out)
+{
+  cls_rgw_set_bucket_resharding_op op;
+
+  bufferlist::iterator in_iter = in->begin();
+  try {
+    ::decode(op, in_iter);
+  } catch (buffer::error& err) {
+    CLS_LOG(1, "ERROR: cls_rgw_set_bucket_resharding: failed to decode entry\n");
+    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;
+  }
+
+  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;
+  }
+
+  return 0;
+}
+
+static int cls_rgw_clear_bucket_resharding(cls_method_context_t hctx, bufferlist *in,  bufferlist *out)
+{
+  cls_rgw_set_bucket_resharding_op op;
+
+  bufferlist::iterator in_iter = in->begin();
+  try {
+    ::decode(op, in_iter);
+  } catch (buffer::error& err) {
+    CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
+    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;
+  }
+
+  return 0;
+}
+
 
 CLS_INIT(rgw)
 {
@@ -3659,6 +3719,8 @@ CLS_INIT(rgw)
   cls_method_handle_t h_rgw_reshard_get;
   cls_method_handle_t h_rgw_reshard_get_head;
   cls_method_handle_t h_rgw_reshard_remove;
+  cls_method_handle_t h_rgw_set_bucket_resharding;
+  cls_method_handle_t h_rgw_clear_bucket_resharding;
 
 
   cls_register(RGW_CLASS, &h_class);
index 3173cacdd7c32e02aab3d18b57f435c6a9d57fc9..81165b5aa9174e41c3bcce91eaace833986d885f 100644 (file)
@@ -866,3 +866,24 @@ void cls_rgw_reshard_remove(librados::ObjectWriteOperation& op, const cls_rgw_re
   ::encode(call, in);
   op.exec("rgw", "reshard_remove", in);
 }
+
+int cls_rgw_set_bucket_resharding(librados::IoCtx& io_ctx, const string& oid,
+                                 const cls_rgw_bucket_instance_entry& entry)
+{
+  bufferlist in, out;
+  struct cls_rgw_set_bucket_resharding_op call;
+  call.entry = entry;
+  ::encode(call, in);
+  return io_ctx.exec(oid, "rgw", "set_bucket_resharding", in, out);
+}
+
+int cls_rgw_clear_bucket_resharding(librados::IoCtx& io_ctx, const string& oid,
+                                   const cls_rgw_bucket_instance_entry& entry)
+{
+  bufferlist in, out;
+  struct cls_rgw_clear_bucket_resharding_op call;
+  call.entry = entry;
+  ::encode(call, in);
+  return io_ctx.exec(oid, "rgw", "clear_bucket_resharding", in, out);
+}
+
index 497f5df91951a37fa41f34230c1e02478e271d37..63097a4f2c4d4aa7a978a51e8a68316f1940ad28 100644 (file)
@@ -501,4 +501,10 @@ int cls_rgw_reshard_get(librados::IoCtx& io_ctx, const string& oid, cls_rgw_resh
 int cls_rgw_reshard_get_head(librados::IoCtx& io_ctx, const string& oid, cls_rgw_reshard_entry& entry);
 void cls_rgw_reshard_remove(librados::ObjectWriteOperation& op, const cls_rgw_reshard_entry& entry);
 
+/* resharding attribute  */
+int cls_rgw_set_bucket_resharding(librados::IoCtx& io_ctx, const string& oid,
+                                  const cls_rgw_bucket_instance_entry& entry);
+int cls_rgw_clear_bucket_resharding(librados::IoCtx& io_ctx, const string& oid,
+                                    const cls_rgw_bucket_instance_entry& entry);
+
 #endif
index 1c547e04a503f13e5f607026a45da6f98a014337..81c9af9c05b1afec9e524d5077e97c681012b201 100644 (file)
@@ -514,5 +514,30 @@ void cls_rgw_reshard_remove_op::dump(Formatter *f) const
 }
 
 
+void cls_rgw_set_bucket_resharding_op::generate_test_instances(
+  list<cls_rgw_set_bucket_resharding_op*>& ls)
+{
+  ls.push_back(new cls_rgw_set_bucket_resharding_op);
+  ls.push_back(new cls_rgw_set_bucket_resharding_op);
+}
+
+void cls_rgw_set_bucket_resharding_op::dump(Formatter *f) const
+{
+  ::encode_json("entry", entry, f);
+}
+
+void cls_rgw_clear_bucket_resharding_op::generate_test_instances(
+  list<cls_rgw_clear_bucket_resharding_op*>& ls)
+{
+  ls.push_back(new cls_rgw_clear_bucket_resharding_op);
+  ls.push_back(new cls_rgw_clear_bucket_resharding_op);
+}
+
+void cls_rgw_clear_bucket_resharding_op::dump(Formatter *f) const
+{
+  ::encode_json("entry", entry, f);
+}
+
+
 
 
index 7a034a1ae3e3c7d3dea1812d588e1f67baad74bd..178dc9d86df802dd21cfbbb2eff6167a23c5b61f 100644 (file)
@@ -1320,4 +1320,42 @@ struct cls_rgw_reshard_remove_op {
 };
 WRITE_CLASS_ENCODER(cls_rgw_reshard_remove_op)
 
+struct cls_rgw_set_bucket_resharding_op  {
+  cls_rgw_bucket_instance_entry entry;
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    ::encode(entry, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::iterator& bl) {
+    DECODE_START(1, bl);
+    ::decode(entry, bl);
+    DECODE_FINISH(bl);
+  }
+  static void generate_test_instances(list<cls_rgw_set_bucket_resharding_op*>& o);
+  void dump(Formatter *f) const;
+};
+WRITE_CLASS_ENCODER(cls_rgw_set_bucket_resharding_op)
+
+struct cls_rgw_clear_bucket_resharding_op {
+  cls_rgw_bucket_instance_entry entry;
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    ::encode(entry, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::iterator& bl) {
+    DECODE_START(1, bl);
+    ::decode(entry, bl);
+    DECODE_FINISH(bl);
+  }
+  static void generate_test_instances(list<cls_rgw_clear_bucket_resharding_op*>& o);
+  void dump(Formatter *f) const;
+};
+WRITE_CLASS_ENCODER(cls_rgw_clear_bucket_resharding_op)
+
 #endif /* CEPH_CLS_RGW_OPS_H */
index 5be8b1e326e18574f32315378a69252672973ee8..a1c3524406b9d0fc533334f73e6e40514eaa9e12 100644 (file)
@@ -592,3 +592,19 @@ void cls_rgw_reshard_entry::generate_test_instances(list<cls_rgw_reshard_entry*>
   ls.back()->old_num_shards = 8;
   ls.back()->new_num_shards = 64;
 }
+
+void cls_rgw_bucket_instance_entry::dump(Formatter *f) const
+{
+  encode_json("data", data, f);
+  encode_json("resharding", resharding, f);
+  encode_json("new_bucket_instance_id", new_bucket_instance_id, f);
+
+}
+
+void cls_rgw_bucket_instance_entry::generate_test_instances(list<cls_rgw_bucket_instance_entry*>& ls)
+{
+  ls.push_back(new cls_rgw_bucket_instance_entry);
+  ls.push_back(new cls_rgw_bucket_instance_entry);
+  ls.back()->resharding = true;
+  ls.back()->new_bucket_instance_id = "new_instance_id";
+}
index 3df336ec99d433ffb243e48c96d65dbe972bd114..090b5ec6228e553f319b858dee9ced6d3fec388a 100644 (file)
@@ -1044,4 +1044,30 @@ struct cls_rgw_reshard_entry
 };
 WRITE_CLASS_ENCODER(cls_rgw_reshard_entry)
 
+struct cls_rgw_bucket_instance_entry {
+  bool resharding;
+  string new_bucket_instance_id;
+  bufferlist data;
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    ::encode(resharding, bl);
+    ::encode(new_bucket_instance_id, bl);
+    ::encode(data, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::iterator& bl) {
+    DECODE_START(1, bl);
+    ::decode(resharding, bl);
+    ::decode(new_bucket_instance_id, bl);
+    ::decode(data, bl);
+    DECODE_FINISH(bl);
+  }
+
+  void dump(Formatter *f) const;
+  static void generate_test_instances(list<cls_rgw_bucket_instance_entry*>& o);
+};
+WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry)
+
 #endif
index c39deff889d4495302c6b0a362d81e97ea32e78f..773a07c2ccebaa0bbcb4865464d7c4091560e7dc 100644 (file)
@@ -344,10 +344,13 @@ TYPE(cls_rgw_reshard_get_ret)
 TYPE(cls_rgw_reshard_get_head_op)
 TYPE(cls_rgw_reshard_get_head_ret)
 TYPE(cls_rgw_reshard_remove_op)
+TYPE(cls_rgw_set_bucket_resharding_op)
+TYPE(cls_rgw_clear_bucket_resharding_op)
 
 #include "cls/rgw/cls_rgw_client.h"
 TYPE(rgw_bi_log_entry)
 TYPE(cls_rgw_reshard_entry)
+TYPE(cls_rgw_bucket_instance_entry)
 
 #include "cls/user/cls_user_types.h"
 TYPE(cls_user_bucket)