]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/rgw: fix remove_reshard objclass op
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 19 May 2017 22:44:06 +0000 (15:44 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 5 Jun 2017 20:17:53 +0000 (13:17 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/cls/rgw/cls_rgw.cc
src/cls/rgw/cls_rgw_client.cc
src/cls/rgw/cls_rgw_ops.h

index dda7726c9d303f2f73b509d7a2a638fa5cdbc6ce..8964081ceed911f63019b976a5ea46b991d15d67 100644 (file)
@@ -3567,6 +3567,22 @@ static int rgw_reshard_list(cls_method_context_t hctx, bufferlist *in, bufferlis
   return 0;
 }
 
+static int get_reshard_entry(cls_method_context_t hctx, const string& key, cls_rgw_reshard_entry *entry)
+{
+  bufferlist bl;
+  int ret = cls_cxx_map_get_val(hctx, key, &bl);
+  if (ret < 0)
+    return ret;
+  bufferlist::iterator iter = bl.begin();
+  try {
+    ::decode(*entry, iter);
+  } catch (buffer::error& err) {
+    CLS_LOG(0, "ERROR: %s : failed to decode entry %s\n", __func__, err.what());
+    return -EIO;
+  }
+  return 0;
+}
+
 static int rgw_reshard_get(cls_method_context_t hctx, bufferlist *in,  bufferlist *out)
 {
   bufferlist::iterator in_iter = in->begin();
@@ -3579,19 +3595,12 @@ static int rgw_reshard_get(cls_method_context_t hctx, bufferlist *in,  bufferlis
     return -EINVAL;
   }
 
-  bufferlist bl;
   string key;
+  cls_rgw_reshard_entry  entry;
   generate_reshard_key(op.entry, &key);
-  int ret = cls_cxx_map_get_val(hctx, key, &bl);
-  if (ret < 0)
+  int ret = get_reshard_entry(hctx, key, &entry);
+  if (ret < 0) {
     return ret;
-  cls_rgw_reshard_entry  entry;
-  bufferlist::iterator iter = bl.begin();
-  try {
-    ::decode(entry, iter);
-  } catch (buffer::error& err) {
-    CLS_LOG(0, "ERROR: rgw_cls_reshard_get : failed to decode entry %s\n",err.what());
-    return -EIO;
   }
 
   cls_rgw_reshard_get_ret op_ret;
@@ -3613,8 +3622,23 @@ static int rgw_reshard_remove(cls_method_context_t hctx, bufferlist *in, bufferl
   }
 
   string key;
-  generate_reshard_key(op.bucket_name, op.bucket_id, &key);
-  int ret = cls_cxx_map_remove_key(hctx, key);
+  cls_rgw_reshard_entry  entry;
+  generate_reshard_key(op.tenant, op.bucket_name, &key);
+  int ret = get_reshard_entry(hctx, key, &entry);
+  if (ret < 0) {
+    return ret;
+  }
+
+  if (!op.bucket_id.empty() &&
+      entry.bucket_id != op.bucket_id) {
+    return 0;
+  }
+
+  ret = cls_cxx_map_remove_key(hctx, key);
+  if (ret < 0) {
+    CLS_LOG(0, "ERROR: failed to remove key: key=%s ret=%d", key.c_str(), ret);
+    return 0;
+  }
   return ret;
 }
 
index edc6136e38af89f3465c125d2e02e6cddd30b6e9..d3a0df776b3011374b99a174e4fbf179309b70e3 100644 (file)
@@ -844,6 +844,9 @@ void cls_rgw_reshard_remove(librados::ObjectWriteOperation& op, const cls_rgw_re
 {
   bufferlist in;
   struct cls_rgw_reshard_remove_op call;
+  call.tenant = entry.tenant;
+  call.bucket_name = entry.bucket_name;
+  call.bucket_id = entry.bucket_id;
   ::encode(call, in);
   op.exec("rgw", "reshard_remove", in);
 }
index 6f8107516bed84e871f5a6b614bedefa87da9d0b..fd1a12e4cbc5557b7f5cd20c931525595f4afeee 100644 (file)
@@ -1258,6 +1258,7 @@ struct cls_rgw_reshard_get_ret {
 WRITE_CLASS_ENCODER(cls_rgw_reshard_get_ret)
 
 struct cls_rgw_reshard_remove_op {
+  string tenant;
   string bucket_name;
   string bucket_id;
 
@@ -1265,6 +1266,7 @@ struct cls_rgw_reshard_remove_op {
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);
+    ::encode(tenant, bl);
     ::encode(bucket_name, bl);
     ::encode(bucket_id, bl);
     ENCODE_FINISH(bl);
@@ -1272,6 +1274,7 @@ struct cls_rgw_reshard_remove_op {
 
   void decode(bufferlist::iterator& bl) {
     DECODE_START(1, bl);
+    ::decode(tenant, bl);
     ::decode(bucket_name, bl);
     ::decode(bucket_id, bl);
     DECODE_FINISH(bl);