]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: a few more operations are using atomic infrastructure
authorYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 4 Aug 2011 20:48:35 +0000 (13:48 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 4 Aug 2011 22:58:34 +0000 (15:58 -0700)
src/rgw/rgw_access.h
src/rgw/rgw_fs.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 33e5866819fbd197f83aa835899fa79532c8eef3..52e6398ade4631a304af8c7cf42f588f6fc63e63 100644 (file)
@@ -171,10 +171,6 @@ public:
 
   virtual void finish_get_obj(void **handle) = 0;
 
-  virtual int clone_range(void *ctx, rgw_obj& dst_obj, off_t dst_ofs,
-                          rgw_obj& src_obj, off_t src_ofs,
-                          uint64_t size) = 0;
-
   virtual int clone_obj(void *ctx, rgw_obj& dst_obj, off_t dst_ofs,
                           rgw_obj& src_obj, off_t src_ofs,
                           uint64_t size, map<string, bufferlist> attrs) {
index 27ac43310f6023ce3acbeb5acbc2614864561b07..945e263a092761ac7afd06cfc10447972656f2b9 100644 (file)
@@ -23,8 +23,6 @@ public:
              map<std::string, bufferlist>& attrs, bool exclusive);
   int put_obj_data(void *ctx, std::string& id, rgw_obj& obj, const char *data,
               off_t ofs, size_t size);
-  int clone_range(void *ctx, rgw_obj& dst_obj, off_t dst_ofs,
-                  rgw_obj& src_obj, off_t src_ofs, uint64_t size) { return -ENOTSUP; }
   int copy_obj(void *ctx, std::string& id, rgw_obj& dest_obj,
                rgw_obj& src_obj,
                time_t *mtime,
index 3c58c9cd33c9b1334eb990a5b3e05258030d1330..198ae02d045eb12252063d2c59a495ca5eb1eaec 100644 (file)
@@ -347,10 +347,10 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj,
 
   io_ctx.locator_set_key(obj.key);
 
+  ObjectOperation op;
+
   if (exclusive) {
-    r = io_ctx.create(oid, true);
-    if (r < 0)
-      return r;
+    op.create(true);
   }
 
   map<string, bufferlist>::iterator iter;
@@ -359,12 +359,14 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj,
     bufferlist& bl = iter->second;
 
     if (bl.length()) {
-      r = io_ctx.setxattr(oid, name.c_str(), bl);
-      if (r < 0)
-        return r;
+      op.setxattr(name.c_str(), bl);
     }
   }
 
+  r = io_ctx.operate(oid, &op, NULL);
+  if (r < 0)
+    return r;
+
   if (mtime) {
     r = io_ctx.stat(oid, NULL, mtime);
     if (r < 0)
@@ -673,16 +675,24 @@ int RGWRados::delete_obj(void *ctx, std::string& id, rgw_obj& obj, bool sync)
   std::string& bucket = obj.bucket;
   std::string& oid = obj.object;
   librados::IoCtx io_ctx;
+  RGWRadosCtx *rctx = (RGWRadosCtx *)ctx;
   int r = open_bucket_ctx(bucket, io_ctx);
   if (r < 0)
     return r;
 
   io_ctx.locator_set_key(obj.key);
+
+  ObjectOperation op;
+
+  RGWObjState *state;
+  r = prepare_atomic_for_write(rctx, obj, io_ctx, oid, op, &state);
+  if (r < 0)
+    return r;
+
+  op.remove();
   if (sync) {
-    r = io_ctx.remove(oid);
+    r = io_ctx.operate(oid, &op, NULL);
   } else {
-    ObjectOperation op;
-    op.remove();
     librados::AioCompletion *completion = rados->aio_create_completion(NULL, NULL, NULL);
     r = io_ctx.aio_operate(obj.object, completion, &op, NULL);
     completion->release();
@@ -716,8 +726,6 @@ int RGWRados::get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, librados::IoCtx& io
 
   s->exists = true;
 
-  RGW_LOG(0) << "outbl.length()=" << outbl.length() << dendl;
-
   bufferlist::iterator oiter = outbl.begin();
   ::decode(s->attrset, oiter);
   ::decode(s->size, oiter);
@@ -807,9 +815,11 @@ int RGWRados::prepare_atomic_for_write(RGWRadosCtx *rctx, rgw_obj& obj, librados
   if (!rctx)
     return 0;
 
+RGW_LOG(0) << __FILE__ << ":" << __LINE__ << dendl;
   int r = get_obj_state(rctx, obj, io_ctx, actual_obj, pstate);
   if (r < 0)
     return r;
+RGW_LOG(0) << __FILE__ << ":" << __LINE__ << " r=" << r << dendl;
 
   RGWObjState *state = *pstate;
 
@@ -821,7 +831,7 @@ int RGWRados::prepare_atomic_for_write(RGWRadosCtx *rctx, rgw_obj& obj, librados
     RGW_LOG(0) << "can't clone object " << obj << " to shadow object, tag/shadow_obj haven't been set" << dendl;
   } else {
     RGW_LOG(0) << "cloning object " << obj << " to name=" << state->shadow_obj << dendl;
-    rgw_obj dest_obj(state->shadow_obj, obj.bucket);
+    rgw_obj dest_obj(obj.bucket, state->shadow_obj);
     if (obj.key.size())
       dest_obj.set_key(obj.key);
     else
@@ -949,10 +959,12 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj,
   std::string& bucket = obj.bucket;
   std::string& oid = obj.object;
   int r = -EINVAL;
-  uint64_t size;
   bufferlist etag;
-  time_t mtime;
   time_t ctime;
+  RGWRadosCtx *rctx = (RGWRadosCtx *)ctx;
+  RGWRadosCtx *new_ctx = NULL;
+  RGWObjState *astate = NULL;
+
 
   map<string, bufferlist>::iterator iter;
 
@@ -970,14 +982,17 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj,
 
   state->io_ctx.locator_set_key(obj.key);
 
-  if (total_size || end) {
-    r = state->io_ctx.stat(oid, &size, &mtime);
-    if (r < 0)
-      goto done_err;
+  if (!rctx) {
+    new_ctx = new RGWRadosCtx;
+    rctx = new_ctx;
   }
 
+  r = get_obj_state(rctx, obj, state->io_ctx, oid, &astate);
+  if (r < 0)
+    goto done_err;
+
   if (attrs) {
-    r = state->io_ctx.getxattrs(oid, *attrs); /* FIXME: should be get_xattrs(), using ctx */
+    *attrs = astate->attrset;
     if (g_conf->rgw_log >= 20) {
       for (iter = attrs->begin(); iter != attrs->end(); ++iter) {
         RGW_LOG(20) << "Read xattr: " << iter->first << dendl;
@@ -988,7 +1003,7 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj,
   }
 
   /* Convert all times go GMT to make them compatible */
-  ctime = mktime(gmtime(&mtime));
+  ctime = mktime(gmtime(&astate->mtime));
 
   r = -ECANCELED;
   if (mod_ptr) {
@@ -1010,7 +1025,7 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj,
     }
   }
   if (if_match || if_nomatch) {
-    r = get_attr(ctx, obj, RGW_ATTR_ETAG, etag);
+    r = get_attr(rctx, obj, RGW_ATTR_ETAG, etag);
     if (r < 0)
       goto done_err;
 
@@ -1035,40 +1050,24 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj,
   }
 
   if (end && *end < 0)
-    *end = size - 1;
+    *end = astate->size - 1;
 
   if (total_size)
     *total_size = (ofs <= *end ? *end + 1 - ofs : 0);
   if (obj_size)
-    *obj_size = size;
+    *obj_size = astate->size;
   if (lastmod)
-    *lastmod = mtime;
+    *lastmod = astate->mtime;
 
   return 0;
 
 done_err:
+  delete new_ctx;
   delete state;
   *handle = NULL;
   return r;
 }
 
-int RGWRados::clone_range(void *ctx, rgw_obj& dst_obj, off_t dst_ofs,
-                          rgw_obj& src_obj, off_t src_ofs, uint64_t size)
-{
-  std::string& bucket = dst_obj.bucket;
-  std::string& dst_oid = dst_obj.object;
-  std::string& src_oid = src_obj.object;
-  librados::IoCtx io_ctx;
-
-  int r = open_bucket_ctx(bucket, io_ctx);
-  if (r < 0)
-    return r;
-
-  io_ctx.locator_set_key(dst_obj.key);
-
-  return io_ctx.clone_range(dst_oid, dst_ofs, src_oid, src_ofs, size);
-}
-
 int RGWRados::clone_objs(void *ctx, rgw_obj& dst_obj,
                         vector<RGWCloneRangeInfo>& ranges,
                         map<string, bufferlist> attrs,
index 2b4c56be088f27ec4653bc245e7eadbe5eaf2aac..2165e18b57b934ac4d20365f46e1ea8f2f8f231a 100644 (file)
@@ -98,8 +98,6 @@ public:
                                off_t ofs, size_t len, void **handle);
   virtual int aio_wait(void *handle);
   virtual bool aio_completed(void *handle);
-  virtual int clone_range(void *ctx, rgw_obj& dst_obj, off_t dst_ofs,
-                          rgw_obj& src_obj, off_t src_ofs, uint64_t size);
   virtual int clone_objs(void *ctx, rgw_obj& dst_obj, 
                         vector<RGWCloneRangeInfo>& ranges,
                         map<string, bufferlist> attrs, bool truncate_dest);