]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: clean up some locator use
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 7 Aug 2014 23:10:12 +0000 (16:10 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 16 Jan 2015 22:26:03 +0000 (14:26 -0800)
We don't use locators anymore. New objects are always created having the
locator equals to the object name. Don't allow this to happen through
magic, just get rid of code that is setting the locator. Legacy objects
should continue to work as we'll still decode the locator, and set it on
the ioctx where needed.

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

index e1b2d3afb94230c34bbab45e8066ece3f9db02da..dde83cb2859a51a40b315cd0577db15a68cdadc8 100644 (file)
@@ -1066,12 +1066,12 @@ WRITE_CLASS_ENCODER(RGWBucketEnt)
 
 class rgw_obj {
   std::string orig_obj;
-  std::string orig_loc;
   std::string loc;
   std::string object;
   std::string instance;
 public:
   const std::string& get_object() const { return object; }
+  const std::string& get_orig_obj() const { return orig_obj; }
   const std::string& get_loc() const { return loc; }
   const std::string& get_instance() const { return instance; }
   rgw_bucket bucket;
@@ -1083,31 +1083,14 @@ public:
   rgw_obj(rgw_bucket& b, const std::string& o) : in_extra_data(false) {
     init(b, o);
   }
-  rgw_obj(rgw_bucket& b, const std::string& o, const std::string& k) : in_extra_data(false) {
-    init(b, o, k);
-  }
-  rgw_obj(rgw_bucket& b, const std::string& o, const std::string& k, const std::string& n) : in_extra_data(false) {
-    init(b, o, k, n);
-  }
   rgw_obj(rgw_bucket& b, const rgw_obj_key& k) {
     init(b, k.name);
     set_instance(k.instance);
   }
-  void init(rgw_bucket& b, const std::string& o, const std::string& k, const std::string& n) {
-    bucket = b;
-    set_ns(n);
-    set_obj(o);
-    set_loc(k);
-  }
-  void init(rgw_bucket& b, const std::string& o, const std::string& k) {
-    bucket = b;
-    set_obj(o);
-    set_loc(k);
-  }
   void init(rgw_bucket& b, const std::string& o) {
     bucket = b;
     set_obj(o);
-    orig_loc = loc = o;
+    reset_loc();
   }
   void init_ns(rgw_bucket& b, const std::string& o, const std::string& n) {
     bucket = b;
@@ -1137,12 +1120,10 @@ public:
   }
 
   void set_loc(const string& k) {
-    orig_loc = k;
     loc = k;
   }
 
   void reset_loc() {
-    orig_loc.clear();
     loc.clear();
   }
 
@@ -1150,7 +1131,7 @@ public:
     object.reserve(128);
 
     orig_obj = o;
-    if (ns.empty()) {
+    if (ns.empty() && instance.empty()) {
       if (o.empty()) {
         return;
       }
@@ -1169,10 +1150,6 @@ public:
       object.append("_");
       object.append(o);
     }
-    if (orig_loc.size())
-      set_loc(orig_loc);
-    else
-      set_loc(orig_obj);
   }
 
   /*
index ed024c9c90f5e7a136cb01efb02a8188e2b7c0fd..192f9ef115c2574184edc84a2f6b1a891bea6d95 100644 (file)
@@ -1216,8 +1216,8 @@ int RGWPutObjProcessor_Atomic::do_complete(string& etag, time_t *mtime, time_t s
   extra_params.owner = bucket_owner;
 
   if (versioned_object) {
-    rgw_obj ver_head_obj = head_obj;
-
+    rgw_obj ver_head_obj(head_obj.bucket, head_obj.get_orig_obj());
+    ver_head_obj.set_ns(head_obj.ns);
     ver_head_obj.set_instance("instance");
 
     r = store->put_obj_meta(NULL, ver_head_obj, obj_len, attrs,
@@ -2783,7 +2783,7 @@ int RGWRados::get_obj_ioctx(const rgw_obj& obj, librados::IoCtx *ioctx)
 {
   rgw_bucket bucket;
   string oid, key;
-  get_obj_bucket_and_oid_key(obj, bucket, oid, key);
+  get_obj_bucket_and_oid_loc(obj, bucket, oid, key);
 
   int r;
 
@@ -2802,7 +2802,7 @@ int RGWRados::get_obj_ioctx(const rgw_obj& obj, librados::IoCtx *ioctx)
 
 int RGWRados::get_obj_ref(const rgw_obj& obj, rgw_rados_ref *ref, rgw_bucket *bucket, bool ref_system_obj)
 {
-  get_obj_bucket_and_oid_key(obj, *bucket, ref->oid, ref->key);
+  get_obj_bucket_and_oid_loc(obj, *bucket, ref->oid, ref->key);
 
   int r;
 
@@ -3488,7 +3488,7 @@ set_err_state:
       ObjectWriteOperation op;
       cls_refcount_get(op, tag, true);
       const rgw_obj& loc = miter.get_location();
-      get_obj_bucket_and_oid_key(loc, bucket, oid, key);
+      get_obj_bucket_and_oid_loc(loc, bucket, oid, key);
       ref.ioctx.locator_set_key(key);
 
       ret = ref.ioctx.operate(oid, &op);
@@ -3545,7 +3545,7 @@ done_ret:
       ObjectWriteOperation op;
       cls_refcount_put(op, tag, true);
 
-      get_obj_bucket_and_oid_key(*riter, bucket, oid, key);
+      get_obj_bucket_and_oid_loc(*riter, bucket, oid, key);
       ref.ioctx.locator_set_key(key);
 
       int r = ref.ioctx.operate(oid, &op);
@@ -3754,7 +3754,7 @@ int RGWRados::complete_atomic_overwrite(RGWRadosCtx *rctx, RGWObjState *state, r
       continue;
     string oid, loc;
     rgw_bucket bucket;
-    get_obj_bucket_and_oid_key(mobj, bucket, oid, loc);
+    get_obj_bucket_and_oid_loc(mobj, bucket, oid, loc);
     cls_rgw_obj_key key(obj.get_index_key_name(), obj.get_instance());
     chain.push_obj(bucket.data_pool, key, loc);
   }
@@ -3841,7 +3841,7 @@ int RGWRados::defer_gc(void *ctx, rgw_obj& obj)
   RGWRadosCtx *rctx = static_cast<RGWRadosCtx *>(ctx);
   rgw_bucket bucket;
   std::string oid, key;
-  get_obj_bucket_and_oid_key(obj, bucket, oid, key);
+  get_obj_bucket_and_oid_loc(obj, bucket, oid, key);
   if (!rctx)
     return 0;
 
@@ -3968,7 +3968,7 @@ int RGWRados::delete_obj_index(rgw_obj& obj)
 {
   rgw_bucket bucket;
   std::string oid, key;
-  get_obj_bucket_and_oid_key(obj, bucket, oid, key);
+  get_obj_bucket_and_oid_loc(obj, bucket, oid, key);
 
   string tag;
   int r = complete_update_index_del(bucket, obj, tag, -1 /* pool */, 0);
@@ -4592,7 +4592,7 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj,
 {
   rgw_bucket bucket;
   std::string dst_oid, dst_key;
-  get_obj_bucket_and_oid_key(dst_obj, bucket, dst_oid, dst_key);
+  get_obj_bucket_and_oid_loc(dst_obj, bucket, dst_oid, dst_key);
   librados::IoCtx io_ctx;
   RGWRadosCtx *rctx = static_cast<RGWRadosCtx *>(ctx);
   uint64_t size = 0;
@@ -4653,12 +4653,12 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj,
         << " range.src_ofs=" << range.src_ofs << " range.len=" << range.len << dendl;
       if (xattr_cond) {
         string src_cmp_obj, src_cmp_key;
-        get_obj_bucket_and_oid_key(range.src, bucket, src_cmp_obj, src_cmp_key);
+        get_obj_bucket_and_oid_loc(range.src, bucket, src_cmp_obj, src_cmp_key);
         op.src_cmpxattr(src_cmp_obj, xattr_cond->first.c_str(),
                         LIBRADOS_CMPXATTR_OP_EQ, xattr_cond->second);
       }
       string src_oid, src_key;
-      get_obj_bucket_and_oid_key(range.src, bucket, src_oid, src_key);
+      get_obj_bucket_and_oid_loc(range.src, bucket, src_oid, src_key);
       if (range.dst_ofs + range.len > size)
         size = range.dst_ofs + range.len;
       op.clone_range(range.dst_ofs, src_oid, range.src_ofs, range.len);
@@ -4749,7 +4749,7 @@ int RGWRados::get_obj(void *ctx, RGWObjVersionTracker *objv_tracker, void **hand
   uint64_t max_chunk_size;
 
 
-  get_obj_bucket_and_oid_key(obj, bucket, oid, key);
+  get_obj_bucket_and_oid_loc(obj, bucket, oid, key);
 
   if (!rctx) {
     new_ctx = new RGWRadosCtx(this);
@@ -4776,7 +4776,7 @@ int RGWRados::get_obj(void *ctx, RGWObjVersionTracker *objv_tracker, void **hand
     reading_from_head = (read_obj == obj);
 
     if (!reading_from_head) {
-      get_obj_bucket_and_oid_key(read_obj, bucket, oid, key);
+      get_obj_bucket_and_oid_loc(read_obj, bucket, oid, key);
     }
   }
 
@@ -5163,7 +5163,7 @@ int RGWRados::get_obj_iterate_cb(void *ctx, RGWObjState *astate,
   if (r < 0)
     return r;
 
-  get_obj_bucket_and_oid_key(obj, bucket, oid, key);
+  get_obj_bucket_and_oid_loc(obj, bucket, oid, key);
 
   d->throttle.get(len);
   if (d->is_cancelled()) {
@@ -6353,9 +6353,11 @@ int RGWRados::check_disk_state(librados::IoCtx io_ctx,
     // well crap
     assert(0 == "got bad object name off disk");
   }
-  obj.init(bucket, oid, list_state.locator, ns);
+  obj.init(bucket, oid);
+  obj.set_loc(list_state.locator);
+  obj.set_ns(ns);
   obj.set_instance(key.instance);
-  get_obj_bucket_and_oid_key(obj, bucket, oid, loc);
+  get_obj_bucket_and_oid_loc(obj, bucket, oid, loc);
   io_ctx.locator_set_key(loc);
 
   RGWObjState *astate = NULL;
index e86b88756d95c6477a2bffc029767863f86a61b1..e6c12d21ff8301741e6dd06a55ff86db8dbfe537 100644 (file)
@@ -43,11 +43,16 @@ static inline void prepend_bucket_marker(rgw_bucket& bucket, const string& orig_
   }
 }
 
-static inline void get_obj_bucket_and_oid_key(const rgw_obj& obj, rgw_bucket& bucket, string& oid, string& key)
+static inline void get_obj_bucket_and_oid_loc(const rgw_obj& obj, rgw_bucket& bucket, string& oid, string& locator)
 {
   bucket = obj.bucket;
   prepend_bucket_marker(bucket, obj.get_object(), oid);
-  prepend_bucket_marker(bucket, obj.get_loc(), key);
+  const string& loc = obj.get_loc();
+  if (!loc.empty()) {
+    prepend_bucket_marker(bucket, obj.get_loc(), locator);
+  } else {
+    locator.clear();
+  }
 }
 
 int rgw_policy_from_attrset(CephContext *cct, map<string, bufferlist>& attrset, RGWAccessControlPolicy *policy);