]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw, cls_user: fix bucket creation
authorYehuda Sadeh <yehuda@inktank.com>
Mon, 13 Jan 2014 22:19:27 +0000 (14:19 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 24 Jan 2014 18:28:53 +0000 (10:28 -0800)
There's a single op to create and update the user bucket info, however,
the cases differ a bit, as we only need to guard against ENOENT if we're
updating the info.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/cls/user/cls_user.cc
src/cls/user/cls_user_client.cc
src/cls/user/cls_user_client.h
src/cls/user/cls_user_ops.h
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 3b82eab4fb7cb6929989634a3fb374bb95f435f0..a72ba33604e7a0bd0b27b196affb5fb1401ac73f 100644 (file)
@@ -144,9 +144,13 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in,
     cls_user_bucket_entry old_entry;
     ret = get_existing_bucket_entry(hctx, key, old_entry);
 
-    if (ret == -ENOENT)
+    if (ret == -ENOENT) {
+     if (!op.add)
       continue; /* racing bucket removal */
 
+     ret = 0;
+    }
+
     if (ret < 0) {
       CLS_LOG(0, "ERROR: get_existing_bucket_entry() key=%s returned %d", key.c_str(), ret);
       return ret;
index a21616007e275a7105d6a22dc4a55cfe572eb914..d2f4b366fd74cce5f89df42eb1083b6583437c2e 100644 (file)
 using namespace librados;
 
 
-void cls_user_set_buckets(librados::ObjectWriteOperation& op, list<cls_user_bucket_entry>& entries)
+void cls_user_set_buckets(librados::ObjectWriteOperation& op, list<cls_user_bucket_entry>& entries, bool add)
 {
   bufferlist in;
   cls_user_set_buckets_op call;
   call.entries = entries;
+  call.add = add;
   call.time = ceph_clock_now(NULL);
   ::encode(call, in);
   op.exec("user", "set_buckets_info", in);
index 34f8278a41c2a4c60a45bc18bf5f076678237d3f..62e96294997cd67ba6d523ad984303d77de13eb8 100644 (file)
@@ -19,7 +19,7 @@ public:
  * user objclass
  */
 
-void cls_user_set_buckets(librados::ObjectWriteOperation& op, list<cls_user_bucket_entry>& entries);
+void cls_user_set_buckets(librados::ObjectWriteOperation& op, list<cls_user_bucket_entry>& entries, bool add);
 void cls_user_complete_stats_sync(librados::ObjectWriteOperation& op);
 void cls_user_remove_bucket(librados::ObjectWriteOperation& op,  const cls_user_bucket& bucket);
 void cls_user_bucket_list(librados::ObjectReadOperation& op,
index 5beb2f17c4e7428e46c5d5f7f51c080d6f497bac..16cfe81fef341d4288db09f30ebb8084b4d75b86 100644 (file)
@@ -9,13 +9,15 @@
 
 struct cls_user_set_buckets_op {
   list<cls_user_bucket_entry> entries;
+  bool add;
   utime_t time; /* op time */
 
-  cls_user_set_buckets_op() {}
+  cls_user_set_buckets_op() : add(false) {}
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);
     ::encode(entries, bl);
+    ::encode(add, bl);
     ::encode(time, bl);
     ENCODE_FINISH(bl);
   }
@@ -23,6 +25,7 @@ struct cls_user_set_buckets_op {
   void decode(bufferlist::iterator& bl) {
     DECODE_START(1, bl);
     ::decode(entries, bl);
+    ::decode(add, bl);
     ::decode(time, bl);
     DECODE_FINISH(bl);
   }
index 5a0738e1d6914e9994c996058504a1a0222dccc3..9852558b8a455a94074058b6e86187a239ca1764 100644 (file)
@@ -1951,7 +1951,6 @@ next:
             cerr << "failed to read user buckets: " << cpp_strerror(-ret) << std::endl;
             return -ret;
           }
-
           map<string, RGWBucketEnt>& buckets = user_buckets.get_buckets();
           for (map<string, RGWBucketEnt>::iterator i = buckets.begin();
                i != buckets.end();
index 6952eb6d6957fe22ef8c93bee1f545b6b03b3a83..5a10e42741655c815d0259b944eb96759c2b4885 100644 (file)
@@ -5729,7 +5729,7 @@ int RGWRados::cls_user_sync_bucket_stats(rgw_obj& user_obj, rgw_bucket& bucket)
   list<cls_user_bucket_entry> entries;
   entries.push_back(entry);
 
-  r = cls_user_update_buckets(user_obj, entries);
+  r = cls_user_update_buckets(user_obj, entries, false);
   if (r < 0) {
     ldout(cct, 20) << "cls_user_update_buckets() returned " << r << dendl;
     return r;
@@ -5753,7 +5753,7 @@ int RGWRados::update_user_bucket_stats(const string& user_id, rgw_bucket& bucket
   rgw_get_buckets_obj(user_id, buckets_obj_id);
   rgw_obj obj(zone.user_uid_pool, buckets_obj_id);
 
-  int r = cls_user_update_buckets(obj, entries);
+  int r = cls_user_update_buckets(obj, entries, false);
   if (r < 0) {
     ldout(cct, 20) << "cls_user_update_buckets() returned " << r << dendl;
     return r;
@@ -5785,7 +5785,7 @@ int RGWRados::cls_user_list_buckets(rgw_obj& obj,
   return 0;
 }
 
-int RGWRados::cls_user_update_buckets(rgw_obj& obj, list<cls_user_bucket_entry>& entries)
+int RGWRados::cls_user_update_buckets(rgw_obj& obj, list<cls_user_bucket_entry>& entries, bool add)
 {
   bufferlist bl;
   librados::IoCtx io_ctx;
@@ -5797,7 +5797,7 @@ int RGWRados::cls_user_update_buckets(rgw_obj& obj, list<cls_user_bucket_entry>&
     return r;
 
   librados::ObjectWriteOperation op;
-  cls_user_set_buckets(op, entries);
+  cls_user_set_buckets(op, entries, add);
   r = io_ctx.operate(oid, &op);
   if (r < 0)
     return r;
@@ -5838,7 +5838,7 @@ int RGWRados::cls_user_add_bucket(rgw_obj& obj, const cls_user_bucket_entry& ent
   list<cls_user_bucket_entry> l;
   l.push_back(entry);
 
-  return cls_user_update_buckets(obj, l);
+  return cls_user_update_buckets(obj, l, true);
 }
 
 int RGWRados::cls_user_remove_bucket(rgw_obj& obj, const cls_user_bucket& bucket)
index d33cd31c6149570e9dcdadbe04733792076f077c..34005392526bbabd00639cb175455a7cc827a71e 100644 (file)
@@ -1445,7 +1445,7 @@ public:
                             list<cls_user_bucket_entry>& entries,
                             string *out_marker, bool *truncated);
   int cls_user_add_bucket(rgw_obj& obj, const cls_user_bucket_entry& entry);
-  int cls_user_update_buckets(rgw_obj& obj, list<cls_user_bucket_entry>& entries);
+  int cls_user_update_buckets(rgw_obj& obj, list<cls_user_bucket_entry>& entries, bool add);
   int cls_user_complete_stats_sync(rgw_obj& obj);
   int complete_sync_user_stats(const string& user_id);
   int cls_user_add_bucket(rgw_obj& obj, list<cls_user_bucket_entry>& entries);