]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: check for exisiting entries in cls_rgw_reshard_add
authorOrit Wasserman <owasserm@redhat.com>
Sun, 30 Apr 2017 07:16:18 +0000 (10:16 +0300)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 5 Jun 2017 20:17:38 +0000 (13:17 -0700)
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/cls/rgw/cls_rgw.cc

index c6cfd42dfeda48c74c3343d242e8e5ff34700197..9335cdd4c694c8bd0ef6d56f4e8deb732cb9a76b 100644 (file)
@@ -3502,12 +3502,21 @@ static int rgw_reshard_add(cls_method_context_t hctx, bufferlist *in, bufferlist
     return -EINVAL;
   }
 
-  bufferlist bl;
-  ::encode(op.entry, bl);
 
   string key;
   generate_reshard_key(op.entry, key);
-  int ret = cls_cxx_map_set_val(hctx, key, &bl);
+  bufferlist bl;
+  int ret = cls_cxx_map_get_val(hctx, key, &bl);
+  if (ret < 0 && ret != -ENOENT) {
+    CLS_ERR("error adding reshard job for bucket %s with key %s: %d",op.entry.bucket_name.c_str(), key.c_str()
+           , ret);
+    return ret;
+  } else if (ret != -ENOENT) {
+    return -EEXIST;
+  }
+
+  ::encode(op.entry, bl);
+  ret = cls_cxx_map_set_val(hctx, key, &bl);
   if (ret < 0) {
     CLS_ERR("error adding reshard job for bucket %s with key %s",op.entry.bucket_name.c_str(), key.c_str());
     return ret;