Skip to content

Commit

Permalink
Merge pull request #21576 from cbodley/wip-23506
Browse files Browse the repository at this point in the history
rgw: fix error handling for GET with ?torrent

Reviewed-by: Daniel Gryniewicz <dang@redhat.com>
Reviewed-by: Robin H. Johnson <robin.johnson@dreamhost.com>
  • Loading branch information
cbodley committed Apr 25, 2018
2 parents 38da3ab + 4dff36e commit ce85a73
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
4 changes: 3 additions & 1 deletion src/common/options.cc
Expand Up @@ -6058,7 +6058,9 @@ std::vector<Option> get_rgw_options() {

Option("rgw_torrent_flag", Option::TYPE_BOOL, Option::LEVEL_ADVANCED)
.set_default(false)
.set_description("Produce torrent function flag"),
.set_description("When true, uploaded objects will calculate and store "
"a SHA256 hash of object data so the object can be "
"retrieved as a torrent file"),

Option("rgw_torrent_tracker", Option::TYPE_STR, Option::LEVEL_ADVANCED)
.set_default("")
Expand Down
4 changes: 3 additions & 1 deletion src/rgw/rgw_op.cc
Expand Up @@ -1763,7 +1763,9 @@ void RGWGetObj::execute()
{
attr_iter = attrs.find(RGW_ATTR_CRYPT_MODE);
if (attr_iter != attrs.end() && attr_iter->second.to_str() == "SSE-C-AES256") {
op_ret = -ERR_INVALID_REQUEST;
ldout(s->cct, 0) << "ERROR: torrents are not supported for objects "
"encrypted with SSE-C" << dendl;
op_ret = -EINVAL;
goto done_err;
}
torrent.init(s, store);
Expand Down
15 changes: 2 additions & 13 deletions src/rgw/rgw_rest.cc
Expand Up @@ -812,20 +812,9 @@ int RGWGetObj_ObjStore::get_params()
get_data &= (!rgwx_stat);
}

/* start gettorrent */
bool is_torrent = s->info.args.exists(GET_TORRENT);
bool torrent_flag = s->cct->_conf->rgw_torrent_flag;
if (torrent_flag && is_torrent)
{
int ret = 0;
ret = torrent.get_params();
if (ret < 0)
{
return ret;
}
if (s->info.args.exists(GET_TORRENT)) {
return torrent.get_params();
}
/* end gettorrent */

return 0;
}

Expand Down
28 changes: 11 additions & 17 deletions src/rgw/rgw_torrent.cc
Expand Up @@ -58,27 +58,21 @@ int seed::get_torrent_file(RGWRados::Object::Read &read_op,
}

string oid, key;
map<string, bufferlist> m;
set<string> obj_key;
get_obj_bucket_and_oid_loc(obj, oid, key);
ldout(s->cct, 0) << "NOTICE: head obj oid= " << oid << dendl;
ldout(s->cct, 20) << "NOTICE: head obj oid= " << oid << dendl;

obj_key.insert(RGW_OBJ_TORRENT);
const int op_ret = read_op.state.io_ctx.omap_get_vals_by_keys(oid, obj_key, &m);
if (op_ret < 0)
{
ldout(s->cct, 0) << "ERROR: failed to omap_get_vals_by_keys op_ret = "
<< op_ret << dendl;
return op_ret;
const set<string> obj_key{RGW_OBJ_TORRENT};
map<string, bufferlist> m;
const int r = read_op.state.io_ctx.omap_get_vals_by_keys(oid, obj_key, &m);
if (r < 0) {
ldout(s->cct, 0) << "ERROR: omap_get_vals_by_keys failed: " << r << dendl;
return r;
}

map<string, bufferlist>::iterator iter;
for (iter = m.begin(); iter != m.end(); ++iter)
{
bufferlist bl_tmp = iter->second;
char *pbuff = bl_tmp.c_str();
bl.append(pbuff, bl_tmp.length());
if (m.size() != 1) {
ldout(s->cct, 0) << "ERROR: omap key " RGW_OBJ_TORRENT " not found" << dendl;
return -EINVAL;
}
bl.append(std::move(m.begin()->second));
dencode.bencode_end(bl);

bl_data = bl;
Expand Down

0 comments on commit ce85a73

Please sign in to comment.