summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-02-28 16:48:57 -0800
committerYehuda Sadeh <yehuda@inktank.com>2013-03-22 11:25:06 -0700
commit590b4d2e8ca12df07969e26dd43cd9dd188367db (patch)
tree0af33ade29ee50b19663fe7ef6846ba33e9696ec
parente40b76b49d64ab8ceb799760689f4375b5405fd7 (diff)
downloadceph-590b4d2e8ca12df07969e26dd43cd9dd188367db.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.cc2
-rw-r--r--src/rgw/rgw_cache.h16
-rw-r--r--src/rgw/rgw_op.cc8
-rw-r--r--src/rgw/rgw_rados.cc56
-rw-r--r--src/rgw/rgw_rados.h6
-rw-r--r--src/rgw/rgw_tools.cc6
-rw-r--r--src/rgw/rgw_tools.h4
-rw-r--r--src/rgw/rgw_user.cc4
8 files changed, 52 insertions, 50 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index e2c713dd39e..2d2f072582f 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -692,7 +692,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 33ef24f93a5..5e37ffab9b5 100644
--- a/src/rgw/rgw_op.cc
+++ b/src/rgw/rgw_op.cc
@@ -229,7 +229,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;
}
@@ -358,7 +358,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;
@@ -381,7 +381,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;
@@ -579,7 +579,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 d3281439d5f..455e37065ff 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;
@@ -1226,7 +1226,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;
}
@@ -1651,7 +1651,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;
@@ -1669,7 +1669,7 @@ int RGWRados::copy_obj(void *ctx,
RGWObjManifest manifest;
RGWObjState *astate = NULL;
RGWRadosCtx *rctx = static_cast<RGWRadosCtx *>(ctx);
- ret = get_obj_state(rctx, src_obj, &astate);
+ ret = get_obj_state(rctx, src_obj, &astate, NULL);
if (ret < 0)
return ret;
@@ -1746,7 +1746,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;
@@ -1814,7 +1814,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;
@@ -2075,7 +2075,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;
@@ -2216,7 +2216,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;
@@ -2224,13 +2224,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;
@@ -2315,7 +2308,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)
@@ -2338,7 +2331,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;
@@ -2361,7 +2354,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;
@@ -2626,6 +2619,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)
{
@@ -2662,7 +2656,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;
@@ -2966,7 +2960,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;
@@ -2993,7 +2987,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;
@@ -3036,6 +3030,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) {
@@ -3068,7 +3066,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;
}
@@ -3444,7 +3442,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;
@@ -3558,7 +3556,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);
@@ -3602,7 +3600,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;
@@ -4156,7 +4154,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 83486ae56bc..203031de27b 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 3798c19fb3a..79adde7dfab 100644
--- a/src/rgw/rgw_user.cc
+++ b/src/rgw/rgw_user.cc
@@ -125,7 +125,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;
@@ -150,7 +150,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;