From: Yehuda Sadeh Date: Fri, 1 Mar 2013 00:48:57 +0000 (-0800) Subject: rgw: rgw_get_system_obj() can return obj_version X-Git-Tag: v0.67-rc1~128^2~193 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fe96600e1b655f7c5a8610d71f9e04fe52d01658;p=ceph.git rgw: rgw_get_system_obj() can return obj_version Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 2f05264778e..9845eef8f37 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -277,8 +277,7 @@ int rgw_remove_bucket(RGWRados *store, rgw_bucket& bucket, bool delete_children) 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 { @@ -289,8 +288,8 @@ int rgw_remove_bucket(RGWRados *store, rgw_bucket& bucket, bool delete_children) } if (delete_children) { - ret = store->list_objects(bucket, max, prefix, delim, marker,\ - objs, common_prefixes,\ + ret = store->list_objects(bucket, max, prefix, delim, marker, + objs, common_prefixes, false, ns, (bool *)false, NULL); if (ret < 0) 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 *attrs, bufferlist *first_chunk); + int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, uint64_t *epoch, map *attrs, bufferlist *first_chunk, obj_version *objv); int delete_obj(void *ctx, rgw_obj& obj); }; @@ -235,13 +235,13 @@ int RGWCache::delete_obj(void *ctx, rgw_obj& obj) } template -int RGWCache::get_obj(void *ctx, void **handle, rgw_obj& obj, bufferlist& obl, off_t ofs, off_t end) +int RGWCache::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::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::put_obj_data(void *ctx, rgw_obj& obj, const char *data, template int RGWCache::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, uint64_t *pepoch, map *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::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 a7f89fa6202..02d2dc4fb97 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -232,7 +232,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; } @@ -361,7 +361,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; @@ -384,7 +384,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; @@ -582,7 +582,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 30a16597e1a..e83bc18c82f 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; @@ -1219,7 +1219,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; } @@ -1644,7 +1644,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; @@ -1662,7 +1662,7 @@ int RGWRados::copy_obj(void *ctx, RGWObjManifest manifest; RGWObjState *astate = NULL; RGWRadosCtx *rctx = static_cast(ctx); - ret = get_obj_state(rctx, src_obj, &astate); + ret = get_obj_state(rctx, src_obj, &astate, NULL); if (ret < 0) return ret; @@ -1742,7 +1742,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; @@ -1810,7 +1810,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; @@ -2094,7 +2094,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; @@ -2235,7 +2235,7 @@ static void generate_fake_tag(CephContext *cct, map& 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; @@ -2243,13 +2243,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; @@ -2334,7 +2327,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) @@ -2357,7 +2350,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; @@ -2380,7 +2373,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; @@ -2645,6 +2638,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) { @@ -2681,7 +2675,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; @@ -2985,7 +2979,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; @@ -3012,7 +3006,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; @@ -3055,6 +3049,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) { @@ -3087,7 +3085,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; } @@ -3463,7 +3461,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; @@ -3577,7 +3575,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); @@ -3621,7 +3619,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; @@ -4181,7 +4179,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 74162f9be9f..7798d97505d 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -182,6 +182,7 @@ struct RGWObjState { bufferlist data; bool prefetch_data; bool keep_tail; + obj_version objv; map attrset; RGWObjState() : is_atomic(false), has_attrs(0), exists(false), @@ -465,7 +466,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, @@ -822,10 +823,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 *pattrs) +int rgw_get_system_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, obj_version *objv, map *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 *pattrs = NULL); -int rgw_get_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, map *pattrs = NULL); +int rgw_get_system_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, obj_version *objv, map *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 9a75ba69b9e..fa19351882a 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -131,7 +131,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; @@ -156,7 +156,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;