virtual int create_bucket(std::string& id, std::string& bucket, map<std::string, bufferlist>& attrs, uint64_t auid=0) = 0;
/** write an object to the storage device in the appropriate pool
with the given stats */
- virtual int put_obj_meta(std::string& id, rgw_obj& obj, std::string& loc, time_t *mtime,
+ virtual int put_obj_meta(std::string& id, rgw_obj& obj, time_t *mtime,
map<std::string, bufferlist>& attrs, bool exclusive) = 0;
- virtual int put_obj_data(std::string& id, rgw_obj& obj, std::string& loc, const char *data,
+ virtual int put_obj_data(std::string& id, rgw_obj& obj, const char *data,
off_t ofs, size_t len, time_t *mtime) = 0;
- int put_obj(std::string& id, rgw_obj& obj, std::string& loc, const char *data, size_t len,
+ int put_obj(std::string& id, rgw_obj& obj, const char *data, size_t len,
time_t *mtime, map<std::string, bufferlist>& attrs) {
- int ret = put_obj_meta(id, obj, loc, NULL, attrs, false);
+ int ret = put_obj_meta(id, obj, NULL, attrs, false);
if (ret >= 0) {
- ret = put_obj_data(id, obj, loc, data, -1, len, mtime);
+ ret = put_obj_data(id, obj, data, -1, len, mtime);
}
return ret;
}
* (if get_data==true) length of read data,
* (if get_data==false) length of the object
*/
- virtual int prepare_get_obj(rgw_obj& obj, std::string& loc,
+ virtual int prepare_get_obj(rgw_obj& obj,
off_t ofs, off_t *end,
map<string, bufferlist> *attrs,
const time_t *mod_ptr,
void **handle,
struct rgw_err *err) = 0;
- virtual int get_obj(void **handle, rgw_obj& obj, std::string& loc,
+ virtual int get_obj(void **handle, rgw_obj& obj,
char **data, off_t ofs, off_t end) = 0;
virtual void finish_get_obj(void **handle) = 0;
virtual int clone_range(rgw_obj& dst_obj, off_t dst_ofs,
rgw_obj& src_obj, off_t src_ofs,
- size_t size, std::string& loc) = 0;
+ size_t size) = 0;
/**
* a simple object read without keeping state
*/
* dest: bufferlist to store the result in
* Returns: 0 on success, -ERR# otherwise.
*/
- virtual int get_attr(rgw_obj& obj, std::string& loc, const char *name, bufferlist& dest) = 0;
+ virtual int get_attr(rgw_obj& obj, const char *name, bufferlist& dest) = 0;
/**
* Set an attr on an object.
string bucket_str(bucket);
string object_str(object);
rgw_obj obj(bucket_str, object_str);
- int ret = store->get_attr(obj, object_str, RGW_ATTR_ACL, bl);
+ int ret = store->get_attr(obj, RGW_ATTR_ACL, bl);
RGWAccessControlPolicy policy;
if (ret >= 0) {
public:
std::string bucket;
std::string object;
+ std::string key;
rgw_obj() {}
- rgw_obj(std::string& b, std::string& o) : bucket(b), object(o) {}
+ rgw_obj(std::string& b, std::string& o) {
+ init(b, o);
+ }
+ rgw_obj(std::string& b, std::string& o, std::string& k) {
+ init(b, o, k);
+ }
+ void init(std::string& b, std::string& o, std::string& k) {
+ bucket = b;
+ object = o;
+ }
void init(std::string& b, std::string& o) {
bucket = b;
object = o;
+ key = o;
}
};
return 0;
}
-int RGWFS::put_obj_meta(std::string& id, rgw_obj& obj, std::string& loc,
+int RGWFS::put_obj_meta(std::string& id, rgw_obj& obj,
time_t *mtime, map<string, bufferlist>& attrs, bool exclusive)
{
std::string& bucket = obj.bucket;
return -errno;
}
-int RGWFS::put_obj_data(std::string& id, rgw_obj& obj, std::string& loc, const char *data,
+int RGWFS::put_obj_data(std::string& id, rgw_obj& obj, const char *data,
off_t ofs, size_t size, time_t *mtime)
{
std::string& bucket = obj.bucket;
map<string, bufferlist>& attrs,
struct rgw_err *err)
{
- std::string& dest_bucket = dest_obj.bucket;
- std::string& dest_oid = dest_obj.object;
- std::string& src_bucket = src_obj.bucket;
- std::string& src_oid = src_obj.object;
int ret;
char *data;
void *handle;
time_t lastmod;
map<string, bufferlist> attrset;
- ret = prepare_get_obj(src_obj, src_oid, 0, &end, &attrset, mod_ptr, unmod_ptr, &lastmod,
+ ret = prepare_get_obj(src_obj, 0, &end, &attrset, mod_ptr, unmod_ptr, &lastmod,
if_match, if_nomatch, &total_len, &handle, err);
if (ret < 0)
return ret;
do {
- ret = get_obj(&handle, src_obj, src_oid, &data, ofs, end);
+ ret = get_obj(&handle, src_obj, &data, ofs, end);
if (ret < 0)
return ret;
ofs += ret;
}
attrs = attrset;
- ret = put_obj(id, dest_obj, dest_oid, data, ret, mtime, attrs);
+ ret = put_obj(id, dest_obj, data, ret, mtime, attrs);
return ret;
}
return attr_len;
}
-int RGWFS::get_attr(rgw_obj& obj, std::string& loc,
- const char *name, bufferlist& dest)
+int RGWFS::get_attr(rgw_obj& obj, const char *name, bufferlist& dest)
{
std::string& bucket = obj.bucket;
std::string& oid = obj.object;
return ret;
}
-int RGWFS::prepare_get_obj(rgw_obj& obj, std::string& loc,
+int RGWFS::prepare_get_obj(rgw_obj& obj,
off_t ofs, off_t *end,
map<string, bufferlist> *attrs,
const time_t *mod_ptr,
return r;
}
-int RGWFS::get_obj(void **handle, rgw_obj& obj, std::string& loc,
- char **data, off_t ofs, off_t end)
+int RGWFS::get_obj(void **handle, rgw_obj& obj, char **data, off_t ofs, off_t end)
{
uint64_t len;
bufferlist bl;
bool get_content_type);
int create_bucket(std::string& id, std::string& bucket, map<std::string, bufferlist>& attrs, uint64_t auid=0);
- int put_obj_meta(std::string& id, rgw_obj& obj, std::string& loc, time_t *mtime,
+ int put_obj_meta(std::string& id, rgw_obj& obj, time_t *mtime,
map<std::string, bufferlist>& attrs, bool exclusive);
- int put_obj_data(std::string& id, rgw_obj& obj, std::string& loc, const char *data,
+ int put_obj_data(std::string& id, rgw_obj& obj, const char *data,
off_t ofs, size_t size, time_t *mtime);
int clone_range(rgw_obj& dst_obj, off_t dst_ofs,
- rgw_obj& src_obj, off_t src_ofs, size_t size, std::string& loc) { return -ENOTSUP; }
+ rgw_obj& src_obj, off_t src_ofs, size_t size) { return -ENOTSUP; }
int copy_obj(std::string& id, rgw_obj& dest_obj,
rgw_obj& src_obj,
time_t *mtime,
int get_attr(const char *name, int fd, char **attr);
int get_attr(const char *name, const char *path, char **attr);
- int get_attr(rgw_obj& obj, std::string& loc, const char *name, bufferlist& dest);
+ int get_attr(rgw_obj& obj, const char *name, bufferlist& dest);
int set_attr(rgw_obj& obj, const char *name, bufferlist& bl);
- int prepare_get_obj(rgw_obj& obj, std::string& loc,
+ int prepare_get_obj(rgw_obj& obj,
off_t ofs, off_t *end,
map<std::string, bufferlist> *attrs,
const time_t *mod_ptr,
void **handle,
struct rgw_err *err);
- int get_obj(void **handle, rgw_obj& obj, std::string& loc,
- char **data, off_t ofs, off_t end);
+ int get_obj(void **handle, rgw_obj& obj, char **data, off_t ofs, off_t end);
void finish_get_obj(void **handle);
int read(rgw_obj& obj, off_t ofs, size_t size, bufferlist& bl);
char buf[entry.bucket.size() + 16];
sprintf(buf, "%.4d-%.2d-%.2d-%s", (bdt.tm_year+1900), (bdt.tm_mon+1), bdt.tm_mday, entry.bucket.c_str());
- rgw_obj obj;
- obj.bucket = log_bucket;
- obj.object = buf;
+ string oid(buf);
+ rgw_obj obj(log_bucket, oid);
int ret = rgwstore->append_async(obj, bl.length(), bl);
* object: name of the object to get the ACL for.
* Returns: 0 on success, -ERR# otherwise.
*/
-static int get_policy_from_attr(RGWAccessControlPolicy *policy, string& bucket, string& object, string& loc)
+static int get_policy_from_attr(RGWAccessControlPolicy *policy, rgw_obj& obj)
{
bufferlist bl;
int ret = 0;
- if (bucket.size()) {
- rgw_obj obj(bucket, object);
- ret = rgwstore->get_attr(obj, loc, RGW_ATTR_ACL, bl);
+ if (obj.bucket.size()) {
+ ret = rgwstore->get_attr(obj, RGW_ATTR_ACL, bl);
if (ret >= 0) {
bufferlist::iterator iter = bl.begin();
int read_acls(struct req_state *s, RGWAccessControlPolicy *policy, string& bucket, string& object)
{
string upload_id = s->args.get("uploadId");
- string obj = object;
- string loc = object;
+ string oid = object;
- if (!obj.empty() && !upload_id.empty()) {
- obj.append(".");
- obj.append(upload_id);
+ if (!oid.empty() && !upload_id.empty()) {
+ oid.append(".");
+ oid.append(upload_id);
}
+ rgw_obj obj(bucket, oid, object);
- int ret = get_policy_from_attr(policy, bucket, obj, loc);
+ int ret = get_policy_from_attr(policy, obj);
if (ret == -ENOENT && object.size()) {
/* object does not exist checking the bucket's ACL to make sure
that we send a proper error code */
RGWAccessControlPolicy bucket_policy;
string no_object;
- ret = get_policy_from_attr(&bucket_policy, bucket, no_object, no_object);
+ rgw_obj no_obj(bucket, no_object);
+ ret = get_policy_from_attr(&bucket_policy, no_obj);
if (ret < 0)
return ret;
init_common();
obj.init(s->bucket_str, s->object_str);
- ret = rgwstore->prepare_get_obj(obj, s->object_str, ofs, &end, &attrs, mod_ptr,
+ ret = rgwstore->prepare_get_obj(obj, ofs, &end, &attrs, mod_ptr,
unmod_ptr, &lastmod, if_match, if_nomatch, &total_len, &handle, &s->err);
if (ret < 0)
goto done;
goto done;
while (ofs <= end) {
- ret = rgwstore->get_obj(&handle, obj, s->object_str, &data, ofs, end);
+ ret = rgwstore->get_obj(&handle, obj, &data, ofs, end);
if (ret < 0) {
goto done;
}
bool existed;
bool pol_ret;
- int r = get_policy_from_attr(&old_policy, rgw_root_bucket, s->bucket_str, s->bucket_str);
+ rgw_obj obj(rgw_root_bucket, s->bucket_str);
+
+ int r = get_policy_from_attr(&old_policy, obj);
if (r >= 0) {
if (old_policy.get_owner().get_id().compare(s->user.user_id) != 0) {
ret = -EEXIST;
oid.append(".");
oid.append(part_num);
}
- rgw_obj obj(s->bucket_str, oid);
+ rgw_obj obj(s->bucket_str, oid, s->object_str);
do {
get_data();
if (len > 0) {
// For the first call to put_obj_data, pass -1 as the offset to
// do a write_full.
ret = rgwstore->put_obj_data(s->user.user_id, obj,
- s->object_str, data,
+ data,
((ofs == 0) ? -1 : ofs), len, NULL);
free(data);
if (ret < 0)
get_request_metadata(s, attrs);
- ret = rgwstore->put_obj_meta(s->user.user_id, obj, s->object_str, NULL, attrs, false);
+ ret = rgwstore->put_obj_meta(s->user.user_id, obj, NULL, attrs, false);
if (ret < 0)
goto done;
RGW_LOG(0) << "JJJ name=" << p << "bl.length()=" << bl.length() << dendl;
meta_attrs[p] = bl;
- rgw_obj meta_obj(s->bucket_str, multipart_meta_obj);
+ rgw_obj meta_obj(s->bucket_str, multipart_meta_obj, s->object_str);
- ret = rgwstore->put_obj_meta(s->user.user_id, meta_obj, s->object_str, NULL, meta_attrs, false);
+ ret = rgwstore->put_obj_meta(s->user.user_id, meta_obj, NULL, meta_attrs, false);
}
}
done:
tmp_obj_name.append(".");
tmp_obj_name.append(upload_id);
- obj.init(s->bucket_str, tmp_obj_name);
- ret = rgwstore->put_obj_meta(s->user.user_id, obj, s->object_str, NULL, attrs, true);
+ obj.init(s->bucket_str, tmp_obj_name, s->object_str);
+ ret = rgwstore->put_obj_meta(s->user.user_id, obj, NULL, attrs, true);
} while (ret == -EEXIST);
done:
send_response();
map<string, bufferlist> attrs;
map<string, bufferlist>::iterator iter;
- rgw_obj obj(s->bucket_str, oid);
+ rgw_obj obj(s->bucket_str, oid, s->object_str);
- int ret = rgwstore->prepare_get_obj(obj, s->object_str, 0, NULL, &attrs, NULL,
+ int ret = rgwstore->prepare_get_obj(obj, 0, NULL, &attrs, NULL,
NULL, NULL, NULL, NULL, NULL, &handle, &s->err);
rgwstore->finish_get_obj(&handle);
attrs[RGW_ATTR_ETAG] = etag_bl;
target_obj.init(s->bucket_str, s->object_str);
- ret = rgwstore->put_obj_meta(s->user.user_id, target_obj, s->object_str, NULL, attrs, false);
+ ret = rgwstore->put_obj_meta(s->user.user_id, target_obj, NULL, attrs, false);
if (ret < 0)
goto done;
char buf[16];
snprintf(buf, sizeof(buf), "%d", obj_iter->second.num);
oid.append(buf);
- rgw_obj src_obj(s->bucket_str, oid);
+ rgw_obj src_obj(s->bucket_str, oid, s->object_str);
rgw_obj dst_obj(s->bucket_str, s->object_str);
- rgwstore->clone_range(dst_obj, ofs, src_obj, 0, obj_iter->second.size, s->object_str);
+ rgwstore->clone_range(dst_obj, ofs, src_obj, 0, obj_iter->second.size);
ofs += obj_iter->second.size;
}
char buf[16];
snprintf(buf, sizeof(buf), "%d", obj_iter->second.num);
oid.append(buf);
- rgw_obj obj(s->bucket_str, oid);
+ rgw_obj obj(s->bucket_str, oid, s->object_str);
rgwstore->delete_obj(s->user.user_id, obj);
}
// and also remove the metadata obj
- meta_obj.init(s->bucket_str, meta_oid);
+ meta_obj.init(s->bucket_str, meta_oid, s->object_str);
rgwstore->delete_obj(s->user.user_id, meta_obj);
* exclusive: create object exclusively
* Returns: 0 on success, -ERR# otherwise.
*/
-int RGWRados::put_obj_meta(std::string& id, rgw_obj& obj, std::string& loc,
+int RGWRados::put_obj_meta(std::string& id, rgw_obj& obj,
time_t *mtime, map<string, bufferlist>& attrs, bool exclusive)
{
std::string& bucket = obj.bucket;
if (r < 0)
return r;
- io_ctx.locator_set_key(loc);
+ io_ctx.locator_set_key(obj.key);
if (exclusive) {
r = io_ctx.create(oid, true);
* attrs: all the given attrs are written to bucket storage for the given object
* Returns: 0 on success, -ERR# otherwise.
*/
-int RGWRados::put_obj_data(std::string& id, rgw_obj& obj, std::string& loc,
+int RGWRados::put_obj_data(std::string& id, rgw_obj& obj,
const char *data, off_t ofs, size_t len, time_t *mtime)
{
std::string& bucket = obj.bucket;
if (r < 0)
return r;
- io_ctx.locator_set_key(loc);
+ io_ctx.locator_set_key(obj.key);
bufferlist bl;
bl.append(data, len);
map<string, bufferlist>& attrs, /* in/out */
struct rgw_err *err)
{
- string& dest_bucket = dest_obj.bucket;
- string& dest_oid = dest_obj.object;
- string& src_bucket = src_obj.bucket;
- string& src_oid = src_obj.object;
int ret, r;
char *data;
off_t end = -1;
time_t lastmod;
map<string, bufferlist>::iterator iter;
- RGW_LOG(5) << "Copy object " << src_bucket << ":" << src_oid << " => " << dest_bucket << ":" << dest_oid << dendl;
+ RGW_LOG(5) << "Copy object " << src_obj.bucket << ":" << src_obj.object << " => " << dest_obj.bucket << ":" << dest_obj.object << dendl;
void *handle = NULL;
map<string, bufferlist> attrset;
- ret = prepare_get_obj(src_obj, src_oid, 0, &end, &attrset,
+ ret = prepare_get_obj(src_obj, 0, &end, &attrset,
mod_ptr, unmod_ptr, &lastmod, if_match, if_nomatch, &total_len, &handle, err);
if (ret < 0)
off_t ofs = 0;
do {
- ret = get_obj(&handle, src_obj, src_oid, &data, ofs, end);
+ ret = get_obj(&handle, src_obj, &data, ofs, end);
if (ret < 0)
return ret;
// In the first call to put_obj_data, we pass ofs == -1 so that it will do
// a write_full, wiping out whatever was in the object before this
- r = put_obj_data(id, dest_obj, dest_oid, data,
+ r = put_obj_data(id, dest_obj, data,
((ofs == 0) ? -1 : ofs), ret, NULL);
free(data);
if (r < 0)
}
attrs = attrset;
- ret = put_obj_meta(id, dest_obj, dest_oid, mtime, attrs, false);
+ ret = put_obj_meta(id, dest_obj, mtime, attrs, false);
finish_get_obj(&handle);
* dest: bufferlist to store the result in
* Returns: 0 on success, -ERR# otherwise.
*/
-int RGWRados::get_attr(rgw_obj& obj, std::string& loc,
- const char *name, bufferlist& dest)
+int RGWRados::get_attr(rgw_obj& obj, const char *name, bufferlist& dest)
{
std::string& bucket = obj.bucket;
std::string& oid = obj.object;
if (r < 0)
return r;
- io_ctx.locator_set_key(loc);
+ io_ctx.locator_set_key(obj.key);
r = io_ctx.getxattr(actual_obj, name, dest);
if (r < 0)
* (if get_data==true) length of read data,
* (if get_data==false) length of the object
*/
-int RGWRados::prepare_get_obj(rgw_obj& obj, std::string& loc,
+int RGWRados::prepare_get_obj(rgw_obj& obj,
off_t ofs, off_t *end,
map<string, bufferlist> *attrs,
const time_t *mod_ptr,
if (r < 0)
goto done_err;
- state->io_ctx.locator_set_key(loc);
+ state->io_ctx.locator_set_key(obj.key);
if (total_size || end) {
r = state->io_ctx.stat(oid, &size, &mtime);
}
}
if (if_match || if_nomatch) {
- r = get_attr(obj, loc, RGW_ATTR_ETAG, etag);
+ r = get_attr(obj, RGW_ATTR_ETAG, etag);
if (r < 0)
goto done_err;
}
int RGWRados::clone_range(rgw_obj& dst_obj, off_t dst_ofs,
- rgw_obj& src_obj, off_t src_ofs, size_t size, std::string& loc)
+ rgw_obj& src_obj, off_t src_ofs, size_t size)
{
std::string& bucket = dst_obj.bucket;
std::string& dst_oid = dst_obj.object;
if (r < 0)
return r;
- io_ctx.locator_set_key(loc);
+ io_ctx.locator_set_key(dst_obj.key);
return io_ctx.clone_range(dst_oid, dst_ofs, src_oid, src_ofs, size);
}
-int RGWRados::get_obj(void **handle,
- rgw_obj& obj, string& loc,
+int RGWRados::get_obj(void **handle, rgw_obj& obj,
char **data, off_t ofs, off_t end)
{
- std::string& bucket = obj.bucket;
std::string& oid = obj.object;
uint64_t len;
bufferlist bl;
if (len > RGW_MAX_CHUNK_SIZE)
len = RGW_MAX_CHUNK_SIZE;
- state->io_ctx.locator_set_key(loc);
+ state->io_ctx.locator_set_key(obj.key);
RGW_LOG(20) << "rados->read ofs=" << ofs << " len=" << len << dendl;
int r = state->io_ctx.read(oid, bl, len, ofs);
virtual int create_bucket(std::string& id, std::string& bucket, map<std::string,bufferlist>& attrs, uint64_t auid=0);
/** Write/overwrite an object to the bucket storage. */
- virtual int put_obj_meta(std::string& id, rgw_obj& obj, std::string& loc, time_t *mtime,
+ virtual int put_obj_meta(std::string& id, rgw_obj& obj, time_t *mtime,
map<std::string, bufferlist>& attrs, bool exclusive);
- virtual int put_obj_data(std::string& id, rgw_obj& obj, std::string& loc, const char *data,
+ virtual int put_obj_data(std::string& id, rgw_obj& obj, const char *data,
off_t ofs, size_t len, time_t *mtime);
virtual int clone_range(rgw_obj& dst_obj, off_t dst_ofs,
- rgw_obj& src_obj, off_t src_ofs, size_t size, std::string& loc);
+ rgw_obj& src_obj, off_t src_ofs, size_t size);
/** Copy an object, with many extra options */
virtual int copy_obj(std::string& id, rgw_obj& dest_obj,
rgw_obj& src_obj,
virtual int delete_obj(std::string& id, rgw_obj& src_obj);
/** Get the attributes for an object.*/
- virtual int get_attr(rgw_obj& obj, std::string& loc,
- const char *name, bufferlist& dest);
+ virtual int get_attr(rgw_obj& obj, const char *name, bufferlist& dest);
/** Set an attr on an object. */
virtual int set_attr(rgw_obj& obj, const char *name, bufferlist& bl);
/** Get data about an object out of RADOS and into memory. */
- virtual int prepare_get_obj(rgw_obj& obj, std::string& loc,
+ virtual int prepare_get_obj(rgw_obj& obj,
off_t ofs, off_t *end,
map<string, bufferlist> *attrs,
const time_t *mod_ptr,
void **handle,
struct rgw_err *err);
- virtual int get_obj(void **handle, rgw_obj& obj, std::string& loc,
+ virtual int get_obj(void **handle, rgw_obj& obj,
char **data, off_t ofs, off_t end);
virtual void finish_get_obj(void **handle);
{
map<string,bufferlist> attrs;
- rgw_obj obj;
- obj.bucket = bucket;
- obj.object = oid;
+ rgw_obj obj(bucket, oid);
- int ret = rgwstore->put_obj(uid, obj, oid, data, size, NULL, attrs);
+ int ret = rgwstore->put_obj(uid, obj, data, size, NULL, attrs);
if (ret == -ENOENT) {
ret = rgwstore->create_bucket(uid, bucket, attrs);
if (ret >= 0)
- ret = rgwstore->put_obj(uid, obj, oid, data, size, NULL, attrs);
+ ret = rgwstore->put_obj(uid, obj, data, size, NULL, attrs);
}
return ret;
bufferlist::iterator iter;
int request_len = READ_CHUNK_LEN;
rgw_obj obj(bucket, key);
- ret = rgwstore->prepare_get_obj(obj, key, 0, NULL, NULL, NULL,
+ ret = rgwstore->prepare_get_obj(obj, 0, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, &handle, &err);
if (ret < 0)
return ret;
do {
- ret = rgwstore->get_obj(&handle, obj, key, &data, 0, request_len - 1);
+ ret = rgwstore->get_obj(&handle, obj, &data, 0, request_len - 1);
if (ret < 0)
goto done;
if (ret < request_len)
{
bufferlist bl;
rgw_obj obj(ui_uid_bucket, user_id);
- int ret = rgwstore->get_attr(obj, user_id, RGW_ATTR_BUCKETS, bl);
+ int ret = rgwstore->get_attr(obj, RGW_ATTR_BUCKETS, bl);
if (ret)
return ret;