]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: get rid of put_obj_meta(), replace with put_system_obj()
authorYehuda Sadeh <yehuda@redhat.com>
Sat, 4 Oct 2014 04:49:45 +0000 (21:49 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 19 Jan 2015 23:57:39 +0000 (15:57 -0800)
Last use of put_obj_meta() was for system object, simplify it for that
specific use case and rename.

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

index fe007704c9e1cb23f033905f5a3319c51dc71a84..b1eceede1b3f0c6f26ecb11a3d841d9e2ba95db5 100644 (file)
@@ -210,13 +210,11 @@ public:
                 map<string, bufferlist>& attrs,
                 map<string, bufferlist>* rmattrs,
                 RGWObjVersionTracker *objv_tracker);
-  int put_obj_meta_impl(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
-                   map<std::string, bufferlist>& attrs, RGWObjCategory category, int flags,
-                   map<std::string, bufferlist>* rmattrs, const bufferlist *data,
-                   RGWObjManifest *manifest, const string *ptag, list<rgw_obj_key> *remove_objs,
-                   bool modify_version, RGWObjVersionTracker *objv_tracker, time_t set_mtime,
-                   const string& owner,
-                   const char *if_match = NULL, const char *if_nomatch = NULL);
+  int put_system_obj_impl(rgw_obj& obj, uint64_t size, time_t *mtime,
+              map<std::string, bufferlist>& attrs, int flags,
+              bufferlist& data,
+              RGWObjVersionTracker *objv_tracker,
+              time_t set_mtime);
   int put_obj_data(void *ctx, rgw_obj& obj, const char *data,
               off_t ofs, size_t len, bool exclusive);
 
@@ -398,13 +396,11 @@ int RGWCache<T>::set_attrs(void *ctx, rgw_obj& obj,
 }
 
 template <class T>
-int RGWCache<T>::put_obj_meta_impl(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
-                              map<std::string, bufferlist>& attrs, RGWObjCategory category, int flags,
-                              map<std::string, bufferlist>* rmattrs, const bufferlist *data,
-                              RGWObjManifest *manifest, const string *ptag, list<rgw_obj_key> *remove_objs,
-                              bool modify_version, RGWObjVersionTracker *objv_tracker, time_t set_mtime,
-                              const string& owner,
-                              const char *if_match, const char *if_nomatch)
+int RGWCache<T>::put_system_obj_impl(rgw_obj& obj, uint64_t size, time_t *mtime,
+              map<std::string, bufferlist>& attrs, int flags,
+              bufferlist& data,
+              RGWObjVersionTracker *objv_tracker,
+              time_t set_mtime)
 {
   rgw_bucket bucket;
   string oid;
@@ -416,18 +412,15 @@ int RGWCache<T>::put_obj_meta_impl(void *ctx, rgw_obj& obj, uint64_t size, time_
     info.xattrs = attrs;
     info.status = 0;
     info.flags = CACHE_FLAG_XATTRS;
-    if (data) {
-      info.data = *data;
-      info.flags |= CACHE_FLAG_DATA;
-    }
+    info.data = data;
+    info.flags |= CACHE_FLAG_DATA;
     if (objv_tracker) {
       info.version = objv_tracker->write_version;
       info.flags |= CACHE_FLAG_OBJV;
     }
   }
-  int ret = T::put_obj_meta_impl(ctx, obj, size, mtime, attrs, category, flags, rmattrs, data, manifest, ptag, remove_objs,
-                                 modify_version, objv_tracker, set_mtime, owner,
-                                 if_match, if_nomatch);
+  int ret = T::put_system_obj_impl(obj, size, mtime, attrs, flags, data,
+                                   objv_tracker, set_mtime);
   if (cacheable) {
     string name = normal_name(bucket, oid);
     if (ret >= 0) {
index 224bcdbc25ec26476b6e2a8c10ec3a7dd53c00ac..9e8dd5b4e8bb42e1e457834ffd029e4c5a74d751 100644 (file)
@@ -2945,45 +2945,51 @@ done_cancel:
   if (ret < 0) {
     ldout(store->ctx(), 0) << "ERROR: complete_update_index_cancel() returned ret=" << ret << dendl;
   }
+
   /* we lost in a race. There are a few options:
    * - existing object was rewritten (ECANCELED)
    * - non existing object was created (EEXIST)
    * - object was removed (ENOENT)
    * should treat it as a success
    */
-  if ((r == -ECANCELED || r == -ENOENT) ||
-      (!(meta.flags & PUT_OBJ_EXCL) && r == -EEXIST)) {
-    r = 0;
+  if (meta.if_match == NULL && meta.if_nomatch == NULL) {
+    if ((r == -ECANCELED || r == -ENOENT) ||
+        (!(flags & PUT_OBJ_EXCL) && r == -EEXIST)) {
+      r = 0;
+    }
+  } else {
+    if (meta.if_match != NULL) {
+      // only overwrite existing object
+      if (strcmp(meta.if_match, "*") == 0) {
+        if (r == -ENOENT) {
+          r = -ERR_PRECONDITION_FAILED;
+        } else if (r == -ECANCELED) {
+          r = 0;
+        }
+      }
+    }
+
+    if (meta.if_nomatch != NULL) {
+      // only create a new object
+      if (strcmp(meta.if_nomatch, "*") == 0) {
+        if (r == -EEXIST) {
+          r = -ERR_PRECONDITION_FAILED;
+        } else if (r == -ENOENT) {
+          r = 0;
+        }
+      }
+    }
   }
 
   return r;
 }
 
-/**
- * Write/overwrite an object to the bucket storage.
- * bucket: the bucket to store the object in
- * obj: the object name/key
- * data: the object contents/value
- * size: the amount of data to write (data must be this long)
- * mtime: if non-NULL, writes the given mtime to the bucket storage
- * attrs: all the given attrs are written to bucket storage for the given object
- * exclusive: create object exclusively
- * Returns: 0 on success, -ERR# otherwise.
- */
-int RGWRados::put_obj_meta_impl(void *ctx, rgw_obj& obj,  uint64_t size,
-#warning remove me when done
-                  time_t *mtime, map<string, bufferlist>& attrs,
-                  RGWObjCategory category, int flags,
-                  map<string, bufferlist>* rmattrs,
-                  const bufferlist *data,
-                  RGWObjManifest *manifest,
-                 const string *ptag,
-                  list<rgw_obj_key> *remove_objs,
-                  bool modify_version,
-                  RGWObjVersionTracker *objv_tracker,
-                  time_t set_mtime,
-                  const string& bucket_owner,
-                  const char *if_match, const char *if_nomatch)
+/** Write/overwrite a system object. */
+int RGWRados::put_system_obj_impl(rgw_obj& obj, uint64_t size, time_t *mtime,
+              map<std::string, bufferlist>& attrs, int flags,
+              bufferlist& data,
+              RGWObjVersionTracker *objv_tracker,
+              time_t set_mtime /* 0 for don't set */)
 {
   rgw_bucket bucket;
   rgw_rados_ref ref;
@@ -2991,22 +2997,12 @@ int RGWRados::put_obj_meta_impl(void *ctx, rgw_obj& obj,  uint64_t size,
   if (r < 0)
     return r;
 
-  ObjectCtx *rctx = static_cast<ObjectCtx *>(ctx);
-
   ObjectWriteOperation op;
 
-  RGWObjState *state = NULL;
-
   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_match, if_nomatch);
-    if (r < 0)
-      return r;
   }
 
   if (objv_tracker) {
@@ -3022,37 +3018,13 @@ int RGWRados::put_obj_meta_impl(void *ctx, rgw_obj& obj,  uint64_t size,
   }
 
   op.mtime(&set_mtime);
-
-  if (data) {
-    /* if we want to overwrite the data, we also want to overwrite the
-       xattrs, so just remove the object */
-    op.write_full(*data);
-  }
+  op.write_full(data);
 
   string etag;
   string content_type;
   bufferlist acl_bl;
 
-  map<string, bufferlist>::iterator iter;
-  if (rmattrs) {
-    for (iter = rmattrs->begin(); iter != rmattrs->end(); ++iter) {
-      const string& name = iter->first;
-      op.rmxattr(name.c_str());
-    }
-  }
-
-  if (manifest) {
-    /* remove existing manifest attr */
-    iter = attrs.find(RGW_ATTR_MANIFEST);
-    if (iter != attrs.end())
-      attrs.erase(iter);
-
-    bufferlist bl;
-    ::encode(*manifest, bl);
-    op.setxattr(RGW_ATTR_MANIFEST, bl);
-  }
-
-  for (iter = attrs.begin(); iter != attrs.end(); ++iter) {
+  for (map<string, bufferlist>::iterator iter = attrs.begin(); iter != attrs.end(); ++iter) {
     const string& name = iter->first;
     bufferlist& bl = iter->second;
 
@@ -3060,106 +3032,22 @@ int RGWRados::put_obj_meta_impl(void *ctx, rgw_obj& obj,  uint64_t size,
       continue;
 
     op.setxattr(name.c_str(), bl);
-
-    if (name.compare(RGW_ATTR_ETAG) == 0) {
-      etag = bl.c_str();
-    } else if (name.compare(RGW_ATTR_CONTENT_TYPE) == 0) {
-      content_type = bl.c_str();
-    } else if (name.compare(RGW_ATTR_ACL) == 0) {
-      acl_bl = bl;
-    }
-  }
-
-  if (!op.size())
-    return 0;
-
-  string index_tag;
-  uint64_t epoch;
-  int64_t poolid;
-
-  if (state) {
-    index_tag = state->write_tag;
   }
 
-  r = prepare_update_index(NULL, bucket, CLS_RGW_OP_ADD, obj, index_tag);
-  if (r < 0)
-    return r;
-
   r = ref.ioctx.operate(ref.oid, &op);
-  if (r < 0) /* we can expect to get -ECANCELED if object was replaced under,
-                or -ENOENT if was removed, or -EEXIST if it did not exist
-                before and now it does */
-    goto done_cancel;
+  if (r < 0) {
+    return r;
+  }
 
   if (objv_tracker) {
     objv_tracker->apply_write();
   }
 
-  epoch = ref.ioctx.get_last_version();
-  poolid = ref.ioctx.get_id();
-
-  r = complete_atomic_overwrite(rctx, state, obj);
-  if (r < 0) {
-    ldout(cct, 0) << "ERROR: complete_atomic_overwrite returned r=" << r << dendl;
-  }
-
-  r = complete_update_index(bucket, obj, index_tag, poolid, epoch, size,
-                            ut, etag, content_type, &acl_bl, category, remove_objs);
-  if (r < 0)
-    goto done_cancel;
-
   if (mtime) {
     *mtime = set_mtime;
   }
 
-  if (state) {
-    /* update quota cache */
-    quota_handler->update_stats(bucket_owner, bucket, (state->exists ? 0 : 1), size, state->size);
-  }
-
   return 0;
-
-done_cancel:
-  int ret = complete_update_index_cancel(bucket, obj, index_tag);
-  if (ret < 0) {
-    ldout(cct, 0) << "ERROR: complete_update_index_cancel() returned ret=" << ret << dendl;
-  }
-  /* we lost in a race. There are a few options:
-   * - existing object was rewritten (ECANCELED)
-   * - non existing object was created (EEXIST)
-   * - object was removed (ENOENT)
-   * should treat it as a success
-   */
-  if (if_match == NULL && if_nomatch == NULL) {
-    if ((r == -ECANCELED || r == -ENOENT) ||
-        (!(flags & PUT_OBJ_EXCL) && r == -EEXIST)) {
-      r = 0;
-    }
-  } else {
-    if (if_match != NULL) {
-      // only overwrite existing object
-      if (strcmp(if_match, "*") == 0) {
-        if (r == -ENOENT) {
-          r = -ERR_PRECONDITION_FAILED;
-        } else if (r == -ECANCELED) {
-          r = 0;
-        }
-      }
-    }
-
-    if (if_nomatch != NULL) {
-      // only create a new object
-      if (strcmp(if_nomatch, "*") == 0) {
-        if (r == -EEXIST) {
-          r = -ERR_PRECONDITION_FAILED;
-        } else if (r == -ENOENT) {
-          r = 0;
-        }
-      }
-    }
-  }
-
-  return r;
 }
 
 /**
index bbf0771f027926cbf1053787d0f404db8da2fc54..f2c30d2dfa0f84ea3a1b668040e487111059e450 100644 (file)
@@ -1472,36 +1472,17 @@ public:
   };
 
   /** Write/overwrite an object to the bucket storage. */
-  virtual int put_obj_meta_impl(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
-              map<std::string, bufferlist>& attrs, RGWObjCategory category, int flags,
-              map<std::string, bufferlist>* rmattrs, const bufferlist *data,
-              RGWObjManifest *manifest, const string *ptag, list<rgw_obj_key> *remove_objs,
-              bool modify_version, RGWObjVersionTracker *objv_tracker,
-              time_t set_mtime /* 0 for don't set */,
-              const string& owner,
-              const char *if_match = NULL, const char *if_nomatch = NULL);
-
-  virtual int put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size, time_t *mtime,
-              map<std::string, bufferlist>& attrs, RGWObjCategory category, int flags,
-              const string& owner, const bufferlist *data = NULL) {
-    return put_obj_meta_impl(ctx, obj, size, mtime, attrs, category, flags,
-                        NULL, data, NULL, NULL, NULL,
-                        false, NULL, 0, owner);
-  }
-
-  virtual int put_obj_meta(void *ctx, rgw_obj& obj, uint64_t size,  map<std::string, bufferlist>& attrs,
-                           RGWObjCategory category, int flags, PutObjMetaExtraParams& params) {
-    return put_obj_meta_impl(ctx, obj, size, params.mtime, attrs, category, flags,
-                        params.rmattrs, params.data, params.manifest, params.ptag, params.remove_objs,
-                        params.modify_version, params.objv_tracker, params.set_mtime, params.owner,
-                        params.if_match, params.if_nomatch);
-  }
+  virtual int put_system_obj_impl(rgw_obj& obj, uint64_t size, time_t *mtime,
+              map<std::string, bufferlist>& attrs, int flags,
+              bufferlist& data,
+              RGWObjVersionTracker *objv_tracker,
+              time_t set_mtime /* 0 for don't set */);
 
   virtual int put_obj_data(void *ctx, rgw_obj& obj, const char *data,
               off_t ofs, size_t len, bool exclusive);
   virtual int aio_put_obj_data(void *ctx, rgw_obj& obj, bufferlist& bl,
                                off_t ofs, bool exclusive, void **handle);
-  /* note that put_obj doesn't set category on an object, only use it for none user objects */
+
   int put_system_obj(void *ctx, rgw_obj& obj, const char *data, size_t len, bool exclusive,
               time_t *mtime, map<std::string, bufferlist>& attrs, RGWObjVersionTracker *objv_tracker,
               time_t set_mtime) {
@@ -1511,15 +1492,7 @@ public:
     if (exclusive)
       flags |= PUT_OBJ_EXCL;
 
-    PutObjMetaExtraParams ep;
-    ep.mtime = mtime;
-    ep.data = &bl;
-    ep.modify_version = true;
-    ep.objv_tracker = objv_tracker;
-    ep.set_mtime = set_mtime;
-
-    int ret = put_obj_meta(ctx, obj, len, attrs, RGW_OBJ_CATEGORY_NONE, flags, ep);
-    return ret;
+    return put_system_obj_impl(obj, len, mtime, attrs, flags, bl, objv_tracker, set_mtime);
   }
   virtual int aio_wait(void *handle);
   virtual bool aio_completed(void *handle);