]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: don't reset multipart parts when updating their metadata
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 24 Oct 2012 19:56:59 +0000 (12:56 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 6 Nov 2012 18:16:59 +0000 (10:16 -0800)
Fixes: #3401
The problem was that put_obj_meta() was assuming object is going
to be reset, so it was resetting the object anyway. This is not
true when dealing with the immutable multipart upload parts.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_op.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index f227aa3208c05234e5a24b26ecdaa220feba0b18..05038bfa9899c0c0c39df1cb35cb5afd3cc9b22d 100644 (file)
@@ -912,7 +912,7 @@ int RGWPutObjProcessor_Plain::handle_data(bufferlist& bl, off_t _ofs, void **pha
 int RGWPutObjProcessor_Plain::complete(string& etag, map<string, bufferlist>& attrs)
 {
   int r = store->put_obj_meta(s->obj_ctx, obj, data.length(), NULL, attrs,
-                              RGW_OBJ_CATEGORY_MAIN, false, NULL, &data, NULL, NULL);
+                              RGW_OBJ_CATEGORY_MAIN, PUT_OBJ_CREATE, NULL, &data, NULL, NULL);
   return r;
 }
 
@@ -1075,7 +1075,7 @@ int RGWPutObjProcessor_Atomic::complete(string& etag, map<string, bufferlist>& a
   store->set_atomic(s->obj_ctx, head_obj);
 
   int r = store->put_obj_meta(s->obj_ctx, head_obj, obj_len, NULL, attrs,
-                              RGW_OBJ_CATEGORY_MAIN, false, NULL, &first_chunk, &manifest, NULL);
+                              RGW_OBJ_CATEGORY_MAIN, PUT_OBJ_CREATE, NULL, &first_chunk, &manifest, NULL);
 
   return r;
 }
@@ -1113,7 +1113,7 @@ int RGWPutObjProcessor_Multipart::prepare(RGWRados *store, struct req_state *s)
 
 int RGWPutObjProcessor_Multipart::complete(string& etag, map<string, bufferlist>& attrs)
 {
-  int r = store->put_obj_meta(s->obj_ctx, obj, s->obj_size, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, NULL, NULL, NULL, NULL);
+  int r = store->put_obj_meta(s->obj_ctx, obj, s->obj_size, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, 0, NULL, NULL, NULL, NULL);
   if (r < 0)
     return r;
 
@@ -1656,7 +1656,7 @@ void RGWInitMultipart::execute()
 
     obj.init_ns(s->bucket, tmp_obj_name, mp_ns);
     // the meta object will be indexed with 0 size, we c
-    ret = store->put_obj_meta(s->obj_ctx, obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MULTIMETA, true, NULL, NULL, NULL, NULL);
+    ret = store->put_obj_meta(s->obj_ctx, obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MULTIMETA, PUT_OBJ_CREATE_EXCL, NULL, NULL, NULL, NULL);
   } while (ret == -EEXIST);
 }
 
@@ -1821,7 +1821,7 @@ void RGWCompleteMultipart::execute()
 
   target_obj.init(s->bucket, s->object_str);
   store->set_atomic(s->obj_ctx, target_obj);
-  ret = store->put_obj_meta(s->obj_ctx, target_obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, false, NULL, NULL, NULL, NULL);
+  ret = store->put_obj_meta(s->obj_ctx, target_obj, 0, NULL, attrs, RGW_OBJ_CATEGORY_MAIN, PUT_OBJ_CREATE, NULL, NULL, NULL, NULL);
   if (ret < 0)
     return;
   
@@ -1844,7 +1844,7 @@ void RGWCompleteMultipart::execute()
   store->set_atomic(s->obj_ctx, target_obj);
 
   ret = store->put_obj_meta(s->obj_ctx, target_obj, ofs, NULL, attrs,
-                            RGW_OBJ_CATEGORY_MAIN, false, NULL, NULL, &manifest, NULL);
+                            RGW_OBJ_CATEGORY_MAIN, PUT_OBJ_CREATE, NULL, NULL, &manifest, NULL);
   if (ret < 0)
     return;
 
index 583992def6ea09ff1a98031b47685a293aa2b010..b468b6f042f59ed204b4ab877f3d4073c204d675 100644 (file)
@@ -999,7 +999,7 @@ int RGWRados::create_pools(vector<string>& names, vector<int>& retcodes)
  */
 int RGWRados::put_obj_meta(void *ctx, rgw_obj& obj,  uint64_t size,
                   time_t *mtime, map<string, bufferlist>& attrs,
-                  RGWObjCategory category, bool exclusive,
+                  RGWObjCategory category, int flags,
                   map<string, bufferlist>* rmattrs,
                   const bufferlist *data,
                   RGWObjManifest *manifest,
@@ -1022,12 +1022,15 @@ int RGWRados::put_obj_meta(void *ctx, rgw_obj& obj,  uint64_t size,
 
   RGWObjState *state = NULL;
 
-  if (!exclusive) {
-    r = prepare_atomic_for_write(rctx, obj, op, &state, true, ptag);
+  if (flags & PUT_OBJ_EXCL) {
+    if (!(flags & PUT_OBJ_CREATE))
+       return -EINVAL;
+    op.create(true); // exclusive create
+  } else {
+    bool reset_obj = (flags & PUT_OBJ_CREATE) != 0;
+    r = prepare_atomic_for_write(rctx, obj, op, &state, reset_obj, ptag);
     if (r < 0)
       return r;
-  } else {
-    op.create(true); // exclusive create
   }
 
   if (data) {
@@ -1323,7 +1326,7 @@ int RGWRados::copy_obj(void *ctx,
 
   manifest.obj_size = total_len;
 
-  ret = put_obj_meta(ctx, dest_obj, end + 1, NULL, attrset, category, false, NULL, &first_chunk, &manifest, &tag);
+  ret = put_obj_meta(ctx, dest_obj, end + 1, NULL, attrset, category, PUT_OBJ_CREATE, NULL, &first_chunk, &manifest, &tag);
   if (mtime)
     obj_stat(ctx, dest_obj, NULL, mtime, NULL, NULL, NULL);
 
@@ -1412,7 +1415,7 @@ int RGWRados::copy_obj_data(void *ctx,
   }
   manifest.obj_size = ofs;
 
-  ret = put_obj_meta(ctx, dest_obj, end + 1, NULL, attrs, category, false, NULL, &first_chunk, &manifest, NULL);
+  ret = put_obj_meta(ctx, dest_obj, end + 1, NULL, attrs, category, PUT_OBJ_CREATE, NULL, &first_chunk, &manifest, NULL);
   if (mtime)
     obj_stat(ctx, dest_obj, NULL, mtime, NULL, NULL, NULL);
 
index 4a932224a9211f3b2f71c499d3ba8489ae90fafd..101ce7db2a2e3f446ed966968f168799afa174bc 100644 (file)
@@ -12,6 +12,11 @@ class SafeTimer;
 class ACLOwner;
 class RGWGC;
 
+/* flags for put_obj_meta() */
+#define PUT_OBJ_CREATE      0x01
+#define PUT_OBJ_EXCL        0x02
+#define PUT_OBJ_CREATE_EXCL (PUT_OBJ_CREATE | PUT_OBJ_EXCL)
+
 static inline void prepend_bucket_marker(rgw_bucket& bucket, string& orig_oid, string& oid)
 {
   if (bucket.marker.empty() || orig_oid.empty()) {
@@ -413,7 +418,7 @@ public:
 
   /** Write/overwrite an object to the bucket storage. */
   virtual int put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
-              map<std::string, bufferlist>& attrs, RGWObjCategory category, bool exclusive,
+              map<std::string, bufferlist>& attrs, RGWObjCategory category, int flags,
               map<std::string, bufferlist>* rmattrs, const bufferlist *data,
               RGWObjManifest *manifest, const string *ptag);
   virtual int put_obj_data(void *ctx, rgw_obj& obj, const char *data,
@@ -425,7 +430,10 @@ public:
               time_t *mtime, map<std::string, bufferlist>& attrs) {
     bufferlist bl;
     bl.append(data, len);
-    int ret = put_obj_meta(ctx, obj, len, mtime, attrs, RGW_OBJ_CATEGORY_NONE, exclusive, NULL, &bl, NULL, NULL);
+    int flags = PUT_OBJ_CREATE;
+    if (exclusive)
+      flags |= PUT_OBJ_EXCL;
+    int ret = put_obj_meta(ctx, obj, len, mtime, attrs, RGW_OBJ_CATEGORY_NONE, flags, NULL, &bl, NULL, NULL);
     return ret;
   }
   virtual int aio_wait(void *handle);