Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgw:add a s3 API of make torrent for a object #9589

Merged
merged 1 commit into from Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/common/config_opts.h
Expand Up @@ -1457,6 +1457,14 @@ OPTION(rgw_list_bucket_min_readahead, OPT_INT, 1000) // minimum number of entrie
OPTION(mutex_perf_counter, OPT_BOOL, false) // enable/disable mutex perf counter
OPTION(throttler_perf_counter, OPT_BOOL, true) // enable/disable throttler perf counter

/* The following are tunables for torrent data */
OPTION(rgw_torrent_tracker, OPT_STR, "") // torrent field annouce and annouce list
OPTION(rgw_torrent_createby, OPT_STR, "") // torrent field created by
OPTION(rgw_torrent_comment, OPT_STR, "") // torrent field comment
OPTION(rgw_torrent_encoding, OPT_STR, "") // torrent field encoding
OPTION(rgw_torrent_origin, OPT_STR, "") // torrent origin
OPTION(rgw_torrent_sha_unit, OPT_INT, 512*1024) //torrent field piece length 521K

// This will be set to true when it is safe to start threads.
// Once it is true, it will never change.
OPTION(internal_safe_to_start_threads, OPT_BOOL, false)
Expand Down
4 changes: 3 additions & 1 deletion src/rgw/Makefile.am
Expand Up @@ -89,7 +89,8 @@ librgw_la_SOURCES = \
rgw/librgw.cc \
rgw/rgw_xml.cc \
rgw/rgw_xml_enc.cc \
rgw/rgw_website.cc
rgw/rgw_website.cc \
rgw/rgw_torrent.cc

if WITH_OPENLDAP
librgw_la_SOURCES += rgw/rgw_ldap.cc
Expand Down Expand Up @@ -269,6 +270,7 @@ noinst_HEADERS += \
rgw/rgw_civetweb_log.h \
rgw/rgw_website.h \
rgw/rgw_rest_s3website.h \
rgw/rgw_torrent.h \
civetweb/civetweb.h \
civetweb/include/civetweb.h \
civetweb/include/civetweb_conf.h \
Expand Down
38 changes: 38 additions & 0 deletions src/rgw/rgw_op.cc
Expand Up @@ -1234,6 +1234,7 @@ int RGWGetObj::get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len)
gc_invalidate_time = start_time;
gc_invalidate_time += (s->cct->_conf->rgw_gc_obj_min_wait / 2);
}

return send_response_data(bl, bl_ofs, bl_len);
}

Expand Down Expand Up @@ -1333,6 +1334,28 @@ void RGWGetObj::execute()
if (op_ret < 0)
goto done_err;

/* start gettorrent */
if (torrent.get_flag())
{
torrent.init(s, store);
torrent.get_torrent_file(op_ret, read_op, total_len, bl, obj);
if (op_ret < 0)
{
ldout(s->cct, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
<< dendl;
goto done_err;
}
op_ret = send_response_data(bl, 0, total_len);
if (op_ret < 0)
{
ldout(s->cct, 0) << "ERROR: failed to send_response_data ret= " << op_ret
<< dendl;
goto done_err;
}
return;
}
/* end gettorrent */

attr_iter = attrs.find(RGW_ATTR_USER_MANIFEST);
if (attr_iter != attrs.end() && !skip_manifest) {
op_ret = handle_user_manifest(attr_iter->second.c_str());
Expand Down Expand Up @@ -2676,6 +2699,9 @@ void RGWPutObj::execute()
len = data.length();
}

/* save data for producing torrent data */
torrent.save_data(data_in);

/* do we need this operation to be synchronous? if we're dealing with an object with immutable
* head, e.g., multipart object we need to make sure we're the first one writing to this object
*/
Expand Down Expand Up @@ -2828,6 +2854,18 @@ void RGWPutObj::execute()

op_ret = processor->complete(etag, &mtime, real_time(), attrs, delete_at,
if_match, if_nomatch);
/* produce torrent */
if (ofs == torrent.get_data_len())
{
torrent.init(s, store);
torrent.set_create_date(mtime);
op_ret = torrent.handle_data();
if (0 != op_ret)
{
ldout(s->cct, 0) << "ERROR: torrent.handle_data() returned " << op_ret << dendl;
goto done;
}
}

done:
dispose_processor(processor);
Expand Down
4 changes: 4 additions & 0 deletions src/rgw/rgw_op.h
Expand Up @@ -34,10 +34,12 @@
#include "rgw_acl.h"
#include "rgw_cors.h"
#include "rgw_quota.h"
#include "rgw_torrent.h"

#include "include/assert.h"

using namespace std;
using ceph::crypto::SHA1;

struct req_state;
class RGWHandler;
Expand Down Expand Up @@ -103,6 +105,7 @@ RGWOp() : s(nullptr), dialect_handler(nullptr), store(nullptr),

class RGWGetObj : public RGWOp {
protected:
seed torrent; // get torrent
const char *range_str;
const char *if_mod;
const char *if_unmod;
Expand Down Expand Up @@ -642,6 +645,7 @@ class RGWPutObj : public RGWOp {
friend class RGWPutObjProcessor;

protected:
seed torrent;
off_t ofs;
const char *supplied_md5_b64;
const char *supplied_etag;
Expand Down
22 changes: 22 additions & 0 deletions src/rgw/rgw_rest.cc
Expand Up @@ -790,6 +790,19 @@ int RGWGetObj_ObjStore::get_params()
mod_pg_ver = s->info.env->get_int("HTTP_DEST_PG_VER", 0);
}

/* start gettorrent */
const char *query_str = s->info.env->get("QUERY_STRING");
if (0 == strcmp(query_str, GET_TORRENT))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there may be other params in the query string, right? i think you want to use s->info.args.exists(GET_TORRENT) here instead

{
int ret = 0;
ret = torrent.get_params();
if (ret < 0)
{
return ret;
}
}
/* end gettorrent */

return 0;
}

Expand Down Expand Up @@ -1000,6 +1013,15 @@ int RGWPutObj_ObjStore::verify_params()

int RGWPutObj_ObjStore::get_params()
{
/* start gettorrent */
int ret = 0;
ret = torrent.get_params();
if (ret < 0)
{
return ret;
}
torrent.set_info_name((s->object).name);
/* end gettorrent */
supplied_md5_b64 = s->info.env->get("HTTP_CONTENT_MD5");

return 0;
Expand Down