diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-02-28 16:48:57 -0800 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-02-28 16:48:57 -0800 |
commit | 8ae5c32715e0edced604010dab3b6179961cf3ba (patch) | |
tree | 530e721ee16f9bf849d34ea2fd0a50bf6b4b7d56 | |
parent | 62cca78e40858fb32653b448d2c482a3a28d0736 (diff) | |
download | ceph-8ae5c32715e0edced604010dab3b6179961cf3ba.tar.gz |
rgw: rgw_get_system_obj() can return obj_version
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_admin.cc | 2 | ||||
-rw-r--r-- | src/rgw/rgw_cache.h | 16 | ||||
-rw-r--r-- | src/rgw/rgw_op.cc | 8 | ||||
-rw-r--r-- | src/rgw/rgw_rados.cc | 56 | ||||
-rw-r--r-- | src/rgw/rgw_rados.h | 6 | ||||
-rw-r--r-- | src/rgw/rgw_tools.cc | 6 | ||||
-rw-r--r-- | src/rgw/rgw_tools.h | 4 | ||||
-rw-r--r-- | src/rgw/rgw_user.cc | 4 |
8 files changed, 52 insertions, 50 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 9c1fa16d74b..81acbdf5c31 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -691,7 +691,7 @@ static int remove_bucket(RGWRados *store, rgw_bucket& bucket, bool delete_childr obj.bucket = bucket; int max = 1000; - ret = rgw_get_obj(store, NULL, store->zone.domain_root, bucket.name, bl, NULL); + ret = rgw_get_system_obj(store, NULL, store->zone.domain_root, bucket.name, bl, NULL); bufferlist::iterator iter = bl.begin(); try { diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index e51be9fd5e0..2364aab3e4f 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -197,9 +197,9 @@ public: int put_obj_data(void *ctx, rgw_obj& obj, const char *data, off_t ofs, size_t len, bool exclusive); - int get_obj(void *ctx, void **handle, rgw_obj& obj, bufferlist& bl, off_t ofs, off_t end); + int get_obj(void *ctx, obj_version *objv, void **handle, rgw_obj& obj, bufferlist& bl, off_t ofs, off_t end); - int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, uint64_t *epoch, map<string, bufferlist> *attrs, bufferlist *first_chunk); + int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, uint64_t *epoch, map<string, bufferlist> *attrs, bufferlist *first_chunk, obj_version *objv); int delete_obj(void *ctx, rgw_obj& obj); }; @@ -235,13 +235,13 @@ int RGWCache<T>::delete_obj(void *ctx, rgw_obj& obj) } template <class T> -int RGWCache<T>::get_obj(void *ctx, void **handle, rgw_obj& obj, bufferlist& obl, off_t ofs, off_t end) +int RGWCache<T>::get_obj(void *ctx, obj_version *objv, void **handle, rgw_obj& obj, bufferlist& obl, off_t ofs, off_t end) { rgw_bucket bucket; string oid; normalize_bucket_and_obj(obj.bucket, obj.object, bucket, oid); if (bucket.name[0] != '.' || ofs != 0) - return T::get_obj(ctx, handle, obj, obl, ofs, end); + return T::get_obj(ctx, objv, handle, obj, obl, ofs, end); string name = normal_name(obj.bucket, oid); @@ -259,7 +259,7 @@ int RGWCache<T>::get_obj(void *ctx, void **handle, rgw_obj& obj, bufferlist& obl i.copy_all(obl); return bl.length(); } - int r = T::get_obj(ctx, handle, obj, obl, ofs, end); + int r = T::get_obj(ctx, objv, handle, obj, obl, ofs, end); if (r < 0) { if (r == -ENOENT) { // only update ENOENT, we'd rather retry other errors info.status = r; @@ -425,13 +425,13 @@ int RGWCache<T>::put_obj_data(void *ctx, rgw_obj& obj, const char *data, template <class T> int RGWCache<T>::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, uint64_t *pepoch, map<string, bufferlist> *attrs, - bufferlist *first_chunk) + bufferlist *first_chunk, obj_version *objv) { rgw_bucket bucket; string oid; normalize_bucket_and_obj(obj.bucket, obj.object, bucket, oid); if (bucket.name[0] != '.') - return T::obj_stat(ctx, obj, psize, pmtime, pepoch, attrs, first_chunk); + return T::obj_stat(ctx, obj, psize, pmtime, pepoch, attrs, first_chunk, objv); string name = normal_name(bucket, oid); @@ -450,7 +450,7 @@ int RGWCache<T>::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmti epoch = info.epoch; goto done; } - r = T::obj_stat(ctx, obj, &size, &mtime, &epoch, &info.xattrs, first_chunk); + r = T::obj_stat(ctx, obj, &size, &mtime, &epoch, &info.xattrs, first_chunk, objv); if (r < 0) { if (r == -ENOENT) { info.status = r; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 405fac8738b..5099415d173 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -230,7 +230,7 @@ static int get_obj_attrs(RGWRados *store, struct req_state *s, rgw_obj& obj, map { void *handle; int ret = store->prepare_get_obj(s->obj_ctx, obj, NULL, NULL, &attrs, NULL, - NULL, NULL, NULL, NULL, NULL, obj_size, &handle, &s->err); + NULL, NULL, NULL, NULL, NULL, obj_size, NULL, &handle, &s->err); store->finish_get_obj(&handle); return ret; } @@ -359,7 +359,7 @@ int RGWGetObj::read_user_manifest_part(rgw_bucket& bucket, RGWObjEnt& ent, RGWAc store->set_atomic(obj_ctx, part); store->set_prefetch_data(obj_ctx, part); ret = store->prepare_get_obj(obj_ctx, part, &cur_ofs, &cur_end, &attrs, NULL, - NULL, NULL, NULL, NULL, NULL, &obj_size, &handle, &s->err); + NULL, NULL, NULL, NULL, NULL, &obj_size, NULL, &handle, &s->err); if (ret < 0) goto done_err; @@ -382,7 +382,7 @@ int RGWGetObj::read_user_manifest_part(rgw_bucket& bucket, RGWObjEnt& ent, RGWAc perfcounter->inc(l_rgw_get_b, cur_end - cur_ofs); while (cur_ofs <= cur_end) { bufferlist bl; - ret = store->get_obj(obj_ctx, &handle, part, bl, cur_ofs, cur_end); + ret = store->get_obj(obj_ctx, NULL, &handle, part, bl, cur_ofs, cur_end); if (ret < 0) goto done_err; @@ -580,7 +580,7 @@ void RGWGetObj::execute() new_end = end; ret = store->prepare_get_obj(s->obj_ctx, obj, &new_ofs, &new_end, &attrs, mod_ptr, - unmod_ptr, &lastmod, if_match, if_nomatch, &total_len, &s->obj_size, &handle, &s->err); + unmod_ptr, &lastmod, if_match, if_nomatch, &total_len, &s->obj_size, NULL, &handle, &s->err); if (ret < 0) goto done_err; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index e3b6daa6720..f09315970b2 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -95,7 +95,7 @@ int RGWRegion::read_default(RGWDefaultRegionInfo& default_info) rgw_bucket pool(pool_name.c_str()); bufferlist bl; - int ret = rgw_get_obj(store, NULL, pool, oid, bl); + int ret = rgw_get_system_obj(store, NULL, pool, oid, bl, NULL); if (ret < 0) return ret; @@ -176,7 +176,7 @@ int RGWRegion::read_info(const string& region_name) string oid = region_info_oid_prefix + name; - int ret = rgw_get_obj(store, NULL, pool, oid, bl); + int ret = rgw_get_system_obj(store, NULL, pool, oid, bl, NULL); if (ret < 0) { lderr(cct) << "failed reading region info from " << pool << ":" << oid << ": " << cpp_strerror(-ret) << dendl; return ret; @@ -282,7 +282,7 @@ int RGWZoneParams::init(CephContext *cct, RGWRados *store, RGWRegion& region) bufferlist bl; string oid = zone_info_oid_prefix + name; - int ret = rgw_get_obj(store, NULL, pool, oid, bl); + int ret = rgw_get_system_obj(store, NULL, pool, oid, bl, NULL); if (ret < 0) return ret; @@ -355,7 +355,7 @@ int RGWRegionMap::read(CephContext *cct, RGWRados *store) rgw_bucket pool(pool_name.c_str()); bufferlist bl; - int ret = rgw_get_obj(store, NULL, pool, oid, bl); + int ret = rgw_get_system_obj(store, NULL, pool, oid, bl, NULL); if (ret < 0) return ret; @@ -1206,7 +1206,7 @@ int RGWRados::select_bucket_placement(string& bucket_name, rgw_bucket& bucket) rgw_obj obj(zone.domain_root, avail_pools); - int ret = rgw_get_obj(this, NULL, zone.domain_root, avail_pools, map_bl); + int ret = rgw_get_system_obj(this, NULL, zone.domain_root, avail_pools, map_bl, NULL); if (ret < 0) { goto read_omap; } @@ -1634,7 +1634,7 @@ int RGWRados::copy_obj(void *ctx, off_t ofs = 0; off_t end = -1; ret = prepare_get_obj(ctx, src_obj, &ofs, &end, &attrset, - mod_ptr, unmod_ptr, &lastmod, if_match, if_nomatch, &total_len, &obj_size, &handle, err); + mod_ptr, unmod_ptr, &lastmod, if_match, if_nomatch, &total_len, &obj_size, NULL, &handle, err); if (ret < 0) return ret; @@ -1652,7 +1652,7 @@ int RGWRados::copy_obj(void *ctx, RGWObjManifest manifest; RGWObjState *astate = NULL; RGWRadosCtx *rctx = (RGWRadosCtx *)ctx; - ret = get_obj_state(rctx, src_obj, &astate); + ret = get_obj_state(rctx, src_obj, &astate, NULL); if (ret < 0) return ret; @@ -1729,7 +1729,7 @@ int RGWRados::copy_obj(void *ctx, } if (copy_first) { - ret = get_obj(ctx, &handle, src_obj, first_chunk, 0, RGW_MAX_CHUNK_SIZE); + ret = get_obj(ctx, NULL, &handle, src_obj, first_chunk, 0, RGW_MAX_CHUNK_SIZE); if (ret < 0) goto done_ret; @@ -1797,7 +1797,7 @@ int RGWRados::copy_obj_data(void *ctx, do { bufferlist bl; - ret = get_obj(ctx, &handle, src_obj, bl, ofs, end); + ret = get_obj(ctx, NULL, &handle, src_obj, bl, ofs, end); if (ret < 0) return ret; @@ -2058,7 +2058,7 @@ int RGWRados::defer_gc(void *ctx, rgw_obj& obj) RGWObjState *state = NULL; - int r = get_obj_state(rctx, obj, &state); + int r = get_obj_state(rctx, obj, &state, NULL); if (r < 0) return r; @@ -2199,7 +2199,7 @@ static void generate_fake_tag(CephContext *cct, map<string, bufferlist>& attrset tag_bl.append(tag.c_str(), tag.size() + 1); } -int RGWRados::get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, RGWObjState **state) +int RGWRados::get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, RGWObjState **state, obj_version *objv) { RGWObjState *s = rctx->get_state(obj); ldout(cct, 20) << "get_obj_state: rctx=" << (void *)rctx << " obj=" << obj << " state=" << (void *)s << " s->prefetch_data=" << s->prefetch_data << dendl; @@ -2207,13 +2207,6 @@ int RGWRados::get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, RGWObjState **state if (s->has_attrs) return 0; - obj_version *objv = NULL; - - if (bucket_is_system(obj.bucket)) { -// objv = &s->objv; -#warning FIXME - } - int r = obj_stat(rctx, obj, &s->size, &s->mtime, &s->epoch, &s->attrset, (s->prefetch_data ? &s->data : NULL), objv); if (r == -ENOENT) { s->exists = false; @@ -2298,7 +2291,7 @@ int RGWRados::get_attr(void *ctx, rgw_obj& obj, const char *name, bufferlist& de if (rctx) { RGWObjState *state; - r = get_obj_state(rctx, obj, &state); + r = get_obj_state(rctx, obj, &state, NULL); if (r < 0) return r; if (!state->exists) @@ -2321,7 +2314,7 @@ int RGWRados::append_atomic_test(RGWRadosCtx *rctx, rgw_obj& obj, if (!rctx) return 0; - int r = get_obj_state(rctx, obj, pstate); + int r = get_obj_state(rctx, obj, pstate, NULL); if (r < 0) return r; @@ -2344,7 +2337,7 @@ int RGWRados::prepare_atomic_for_write_impl(RGWRadosCtx *rctx, rgw_obj& obj, ObjectWriteOperation& op, RGWObjState **pstate, bool reset_obj, const string *ptag) { - int r = get_obj_state(rctx, obj, pstate); + int r = get_obj_state(rctx, obj, pstate, NULL); if (r < 0) return r; @@ -2609,6 +2602,7 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj, const char *if_nomatch, uint64_t *total_size, uint64_t *obj_size, + obj_version *objv, void **handle, struct rgw_err *err) { @@ -2645,7 +2639,7 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj, rctx = new_ctx; } - r = get_obj_state(rctx, obj, &astate); + r = get_obj_state(rctx, obj, &astate, objv); if (r < 0) goto done_err; @@ -2949,7 +2943,7 @@ int RGWRados::clone_objs(void *ctx, rgw_obj& dst_obj, } -int RGWRados::get_obj(void *ctx, void **handle, rgw_obj& obj, +int RGWRados::get_obj(void *ctx, obj_version *objv, void **handle, rgw_obj& obj, bufferlist& bl, off_t ofs, off_t end) { rgw_bucket bucket; @@ -2976,7 +2970,7 @@ int RGWRados::get_obj(void *ctx, void **handle, rgw_obj& obj, rctx = new_ctx; } - int r = get_obj_state(rctx, obj, &astate); + int r = get_obj_state(rctx, obj, &astate, NULL); if (r < 0) goto done_ret; @@ -3019,6 +3013,10 @@ int RGWRados::get_obj(void *ctx, void **handle, rgw_obj& obj, goto done_ret; } + if (objv) { + cls_version_check(op, *objv, VER_COND_EQ); + } + read_len = len; if (astate) { @@ -3051,7 +3049,7 @@ int RGWRados::get_obj(void *ctx, void **handle, rgw_obj& obj, ldout(cct, 0) << "NOTICE: RGWRados::get_obj: raced with another process, going to the shadow obj instead" << dendl; string loc = obj.loc(); rgw_obj shadow(bucket, astate->shadow_obj, loc, shadow_ns); - r = get_obj(NULL, handle, shadow, bl, ofs, end); + r = get_obj(NULL, NULL, handle, shadow, bl, ofs, end); goto done_ret; } @@ -3427,7 +3425,7 @@ int RGWRados::iterate_obj(void *ctx, rgw_obj& obj, rctx = new_ctx; } - int r = get_obj_state(rctx, obj, &astate); + int r = get_obj_state(rctx, obj, &astate, NULL); if (r < 0) goto done_err; @@ -3541,7 +3539,7 @@ int RGWRados::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, ObjectReadOperation op; if (objv) { -#warning FIXME + cls_version_read(op, objv); } op.getxattrs(&attrset, NULL); op.stat(&size, &mtime, NULL); @@ -3585,7 +3583,7 @@ int RGWRados::get_bucket_info(void *ctx, string& bucket_name, RGWBucketInfo& inf { bufferlist bl; - int ret = rgw_get_obj(this, ctx, zone.domain_root, bucket_name, bl, pattrs); + int ret = rgw_get_system_obj(this, ctx, zone.domain_root, bucket_name, bl, NULL, pattrs); if (ret < 0) { if (ret != -ENOENT) return ret; @@ -4139,7 +4137,7 @@ int RGWRados::check_disk_state(librados::IoCtx io_ctx, RGWObjState *astate = NULL; RGWRadosCtx rctx(this); - int r = get_obj_state(&rctx, obj, &astate); + int r = get_obj_state(&rctx, obj, &astate, NULL); if (r < 0) return r; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index d45aaa93b6a..300509a9503 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -181,6 +181,7 @@ struct RGWObjState { bool has_data; bufferlist data; bool prefetch_data; + obj_version objv; map<string, bufferlist> attrset; RGWObjState() : is_atomic(false), has_attrs(0), exists(false), @@ -464,7 +465,7 @@ class RGWRados Mutex bucket_id_lock; uint64_t max_bucket_id; - int get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, RGWObjState **state); + int get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, RGWObjState **state, obj_version *objv); int append_atomic_test(RGWRadosCtx *rctx, rgw_obj& obj, librados::ObjectOperation& op, RGWObjState **state); int prepare_atomic_for_write_impl(RGWRadosCtx *rctx, rgw_obj& obj, @@ -820,10 +821,11 @@ public: const char *if_nomatch, uint64_t *total_size, uint64_t *obj_size, + obj_version *objv, void **handle, struct rgw_err *err); - virtual int get_obj(void *ctx, void **handle, rgw_obj& obj, + virtual int get_obj(void *ctx, obj_version *objv, void **handle, rgw_obj& obj, bufferlist& bl, off_t ofs, off_t end); virtual void finish_get_obj(void **handle); diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index da7413c0848..a8c4fed225b 100644 --- a/src/rgw/rgw_tools.cc +++ b/src/rgw/rgw_tools.cc @@ -33,7 +33,7 @@ int rgw_put_system_obj(RGWRados *rgwstore, rgw_bucket& bucket, string& oid, cons return ret; } -int rgw_get_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, map<string, bufferlist> *pattrs) +int rgw_get_system_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, obj_version *objv, map<string, bufferlist> *pattrs) { int ret; struct rgw_err err; @@ -43,11 +43,11 @@ int rgw_get_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, rgw_obj obj(bucket, key); do { ret = rgwstore->prepare_get_obj(ctx, obj, NULL, NULL, pattrs, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, &handle, &err); + NULL, NULL, NULL, NULL, NULL, NULL, objv, &handle, &err); if (ret < 0) return ret; - ret = rgwstore->get_obj(ctx, &handle, obj, bl, 0, request_len - 1); + ret = rgwstore->get_obj(ctx, objv, &handle, obj, bl, 0, request_len - 1); rgwstore->finish_get_obj(&handle); if (ret < 0) return ret; diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h index 6553d9d1465..442c2cc8788 100644 --- a/src/rgw/rgw_tools.h +++ b/src/rgw/rgw_tools.h @@ -8,8 +8,10 @@ class RGWRados; +struct obj_version; + int rgw_put_system_obj(RGWRados *rgwstore, rgw_bucket& bucket, string& oid, const char *data, size_t size, bool exclusive, map<string, bufferlist> *pattrs = NULL); -int rgw_get_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, map<string, bufferlist> *pattrs = NULL); +int rgw_get_system_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, obj_version *objv, map<string, bufferlist> *pattrs = NULL); int rgw_tools_init(CephContext *cct); void rgw_tools_cleanup(); diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index df5c514ad6a..aef5030d972 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -127,7 +127,7 @@ int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucke bufferlist bl; RGWUID uid; - int ret = rgw_get_obj(store, NULL, bucket, key, bl); + int ret = rgw_get_system_obj(store, NULL, bucket, key, bl, NULL); if (ret < 0) return ret; @@ -152,7 +152,7 @@ int rgw_get_user_info_by_uid(RGWRados *store, string& uid, RGWUserInfo& info) bufferlist bl; RGWUID user_id; - int ret = rgw_get_obj(store, NULL, store->zone.user_uid_pool, uid, bl); + int ret = rgw_get_system_obj(store, NULL, store->zone.user_uid_pool, uid, bl, NULL); if (ret < 0) return ret; |