summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda.sadeh@dreamhost.com>2011-12-02 11:26:44 -0800
committerYehuda Sadeh <yehuda.sadeh@dreamhost.com>2011-12-02 11:26:44 -0800
commit96929b50375f9248d30935bd5595a0fc1a1868e3 (patch)
tree06b6934f3e42bb38ca8e7a50cb244a6c47d07ed5
parentcd138c108bbf13411b6cca3801fc7a93ce6b754d (diff)
downloadceph-96929b50375f9248d30935bd5595a0fc1a1868e3.tar.gz
radosgw: shuffle some things around
-rw-r--r--src/Makefile.am8
-rw-r--r--src/rgw/libradosgw.cc71
-rw-r--r--src/rgw/libradosgw.hpp2
-rw-r--r--src/rgw/rgw_common.h3
-rw-r--r--src/rgw/rgw_main.cc31
-rw-r--r--src/rgw/rgw_rados.cc8
-rw-r--r--src/rgw/rgw_tools.cc16
-rw-r--r--src/rgw/rgw_tools.h6
-rw-r--r--src/rgw/rgw_user.cc10
9 files changed, 120 insertions, 35 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2800ff13eb6..92aee97f4db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -328,9 +328,7 @@ endif
if WITH_RADOSGW
my_libradosgw_src = \
- rgw/librgw.cc \
- rgw/rgw_acl.cc \
- rgw/rgw_xml.cc
+ rgw/libradosgw.cc
my_radosgw_src = \
rgw/rgw_fs.cc \
@@ -349,7 +347,9 @@ my_radosgw_src = \
rgw/rgw_formats.cc \
rgw/rgw_log.cc \
rgw/rgw_multi.cc \
- rgw/rgw_env.cc
+ rgw/rgw_env.cc \
+ rgw/rgw_acl.cc \
+ rgw/rgw_xml.cc
my_radosgw_ldadd = \
libglobal.la librgw.la librados.la -lfcgi -lcurl -lexpat \
diff --git a/src/rgw/libradosgw.cc b/src/rgw/libradosgw.cc
new file mode 100644
index 00000000000..0a4d9d0ac53
--- /dev/null
+++ b/src/rgw/libradosgw.cc
@@ -0,0 +1,71 @@
+#include "libradosgw.hpp"
+
+#include "rgw_access.h"
+#include "rgw_rados.h"
+#include "rgw_cache.h"
+
+
+namespace libradosgw {
+
+ class StoreImpl {
+ RGWAccess *rados;
+ public:
+
+ StoreImpl() : rados(NULL) {}
+
+ int init(CephContext *cct) {
+ int use_cache = cct->_conf->rgw_cache_enabled;
+
+ if (use_cache) {
+ rados = new RGWRados;
+ } else {
+ rados = new RGWCache<RGWRados>;
+ }
+
+ int ret = rados->initialize(cct);
+
+ return ret;
+ }
+
+ void shutdown() {
+ if (!rados)
+ return;
+
+ rados->finalize();
+ rados = NULL;
+ }
+
+ int get_account(string& name, Account& account) {}
+ int user_by_name(string& name, User& user) {}
+ int user_by_email(string& email, User& user) {}
+ int user_by_access_key(string& access_key, User& user) {}
+ };
+
+
+ int Store::init(CephContext *cct) {
+ impl = new StoreImpl;
+ return impl->init(cct);
+ }
+
+ void Store::shutdown() {
+ impl->shutdown();
+ delete impl;
+ impl = NULL;
+ }
+
+ int Store::get_account(string& name, Account& account) {
+ return impl->get_account(name, account);
+ }
+
+ int Store::user_by_name(string& name, User& user) {
+ return impl->user_by_name(name, user);
+ }
+
+ int Store::user_by_email(string& email, User& user) {
+ return impl->user_by_email(email, user);
+ }
+
+ int Store::user_by_access_key(string& access_key, User& user) {
+ return impl->user_by_access_key(access_key, user);
+ }
+}
diff --git a/src/rgw/libradosgw.hpp b/src/rgw/libradosgw.hpp
index 87c2c9b72e2..5c55c2b228d 100644
--- a/src/rgw/libradosgw.hpp
+++ b/src/rgw/libradosgw.hpp
@@ -177,7 +177,7 @@ namespace libradosgw {
public:
Store() : impl(NULL) {}
- int init(librados::Rados *r);
+ int init(CephContext *cct);
void shutdown();
int get_account(string& name, Account& account);
diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h
index 7aff456bf04..a4147b8e772 100644
--- a/src/rgw/rgw_common.h
+++ b/src/rgw/rgw_common.h
@@ -33,6 +33,8 @@
#include "include/types.h"
#include "include/utime.h"
+#include "libradosgw.hpp"
+
using namespace std;
namespace ceph {
@@ -510,6 +512,7 @@ struct RGWEnv;
/** Store all the state necessary to complete and respond to an HTTP request*/
struct req_state {
FCGX_Request *fcgx;
+ libradosgw::Store *store;
http_op op;
bool content_started;
int format;
diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc
index ee6263fc425..878d27cb71f 100644
--- a/src/rgw/rgw_main.cc
+++ b/src/rgw/rgw_main.cc
@@ -69,6 +69,7 @@ static void godown_alarm(int signum)
class RGWProcess {
deque<FCGX_Request *> m_fcgx_queue;
ThreadPool m_tp;
+ libradosgw::Store *store;
struct RGWWQ : public ThreadPool::WorkQueue<FCGX_Request> {
RGWProcess *process;
@@ -120,8 +121,9 @@ class RGWProcess {
} req_wq;
public:
- RGWProcess(CephContext *cct, int num_threads)
+ RGWProcess(CephContext *cct, int num_threads, libradosgw::Store *s)
: m_tp(cct, "RGWProcess::m_tp", num_threads),
+ store(s),
req_wq(this, g_conf->rgw_op_thread_timeout,
g_conf->rgw_op_thread_suicide_timeout, &m_tp) {}
void run();
@@ -178,8 +180,12 @@ void RGWProcess::handle_request(FCGX_Request *fcgx)
rgw_env.init(fcgx->envp);
struct req_state *s = new req_state(&rgw_env);
- s->obj_ctx = rgwstore->create_context(s);
- rgwstore->set_intent_cb(s->obj_ctx, call_log_intent);
+ // s->obj_ctx = rgwstore->create_context(s);
+
+ s->store = store;
+
+#warning FIXME call_log_intent
+ // rgwstore->set_intent_cb(s->obj_ctx, call_log_intent);
RGWOp *op = NULL;
int init_error = 0;
@@ -229,7 +235,7 @@ done:
int http_ret = s->err.http_ret;
handler->put_op(op);
- rgwstore->destroy_context(s->obj_ctx);
+ // rgwstore->destroy_context(s->obj_ctx);
delete s;
FCGX_Finish_r(fcgx);
delete fcgx;
@@ -292,21 +298,24 @@ int main(int argc, const char **argv)
FCGX_Init();
- RGWStoreManager store_manager;
-
- if (!store_manager.init("rados", g_ceph_context)) {
- derr << "Couldn't init storage provider (RADOS)" << dendl;
- return EIO;
+ libradosgw::Store store;
+
+ int r = store.init(g_ceph_context);
+ if (r < 0) {
+ derr << "Couldn't init storage (r=" << r << ")" << dendl;
+ return 1;
}
- int r = rgw_perf_start(g_ceph_context);
+ r = rgw_perf_start(g_ceph_context);
if (r < 0)
return 1;
- RGWProcess process(g_ceph_context, g_conf->rgw_thread_pool_size);
+ RGWProcess process(g_ceph_context, g_conf->rgw_thread_pool_size, &store);
process.run();
+
rgw_perf_stop(g_ceph_context);
+ store.shutdown();
return 0;
}
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc
index 146050b56af..11070f8243c 100644
--- a/src/rgw/rgw_rados.cc
+++ b/src/rgw/rgw_rados.cc
@@ -491,14 +491,14 @@ int RGWRados::store_bucket_info(RGWBucketInfo& info)
bufferlist bl;
::encode(info, bl);
- int ret = rgw_put_obj(info.owner, pi_buckets_rados, info.bucket.name, bl.c_str(), bl.length());
+ int ret = rgw_put_obj(this, info.owner, pi_buckets_rados, info.bucket.name, bl.c_str(), bl.length());
if (ret < 0)
return ret;
char bucket_char[16];
snprintf(bucket_char, sizeof(bucket_char), ".%lld", (long long unsigned)info.bucket.bucket_id);
string bucket_id_string(bucket_char);
- ret = rgw_put_obj(info.owner, pi_buckets_rados, bucket_id_string, bl.c_str(), bl.length());
+ ret = rgw_put_obj(this, info.owner, pi_buckets_rados, bucket_id_string, bl.c_str(), bl.length());
dout(0) << "store_bucket_info: bucket=" << info.bucket << " owner " << info.owner << dendl;
return 0;
@@ -1791,7 +1791,7 @@ int RGWRados::get_bucket_info(void *ctx, string& bucket_name, RGWBucketInfo& inf
{
bufferlist bl;
- int ret = rgw_get_obj(ctx, pi_buckets_rados, bucket_name, bl);
+ int ret = rgw_get_obj(this, ctx, pi_buckets_rados, bucket_name, bl);
if (ret < 0) {
if (ret != -ENOENT)
return ret;
@@ -1822,7 +1822,7 @@ int RGWRados::put_bucket_info(string& bucket_name, RGWBucketInfo& info)
string unused;
- int ret = rgw_put_obj(unused, pi_buckets_rados, bucket_name, bl.c_str(), bl.length());
+ int ret = rgw_put_obj(this, unused, pi_buckets_rados, bucket_name, bl.c_str(), bl.length());
return ret;
}
diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc
index eca5ce1f699..a9d60d28fb6 100644
--- a/src/rgw/rgw_tools.cc
+++ b/src/rgw/rgw_tools.cc
@@ -14,24 +14,24 @@
static map<string, string> ext_mime_map;
-int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size)
+int rgw_put_obj(RGWAccess *access, string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size)
{
map<string,bufferlist> attrs;
rgw_obj obj(bucket, oid);
- int ret = rgwstore->put_obj(NULL, obj, data, size, NULL, attrs);
+ int ret = access->put_obj(NULL, obj, data, size, NULL, attrs);
if (ret == -ENOENT) {
- ret = rgwstore->create_bucket(uid, bucket, attrs, true); //all callers are using system buckets
+ ret = access->create_bucket(uid, bucket, attrs, true); //all callers are using system buckets
if (ret >= 0)
- ret = rgwstore->put_obj(NULL, obj, data, size, NULL, attrs);
+ ret = access->put_obj(NULL, obj, data, size, NULL, attrs);
}
return ret;
}
-int rgw_get_obj(void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl)
+int rgw_get_obj(RGWAccess *access, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl)
{
int ret;
char *data = NULL;
@@ -40,13 +40,13 @@ int rgw_get_obj(void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl)
bufferlist::iterator iter;
int request_len = READ_CHUNK_LEN;
rgw_obj obj(bucket, key);
- ret = rgwstore->prepare_get_obj(ctx, obj, NULL, NULL, NULL, NULL,
+ ret = access->prepare_get_obj(ctx, obj, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, &handle, &err);
if (ret < 0)
return ret;
do {
- ret = rgwstore->get_obj(ctx, &handle, obj, &data, 0, request_len - 1);
+ ret = access->get_obj(ctx, &handle, obj, &data, 0, request_len - 1);
if (ret < 0)
goto done;
if (ret < request_len)
@@ -60,7 +60,7 @@ int rgw_get_obj(void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl)
ret = 0;
done:
- rgwstore->finish_get_obj(&handle);
+ access->finish_get_obj(&handle);
return ret;
}
diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h
index 5174d419c7a..c1f38280925 100644
--- a/src/rgw/rgw_tools.h
+++ b/src/rgw/rgw_tools.h
@@ -6,9 +6,11 @@
#include "include/types.h"
#include "rgw_common.h"
+class RGWAccess;
-int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size);
-int rgw_get_obj(void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl);
+
+int rgw_put_obj(RGWAccess *access, string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size);
+int rgw_get_obj(RGWAccess *access, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl);
int rgw_tools_init(CephContext *cct);
const char *rgw_find_mime_by_ext(string& ext);
diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc
index 6430092b1ad..81347d41375 100644
--- a/src/rgw/rgw_user.cc
+++ b/src/rgw/rgw_user.cc
@@ -80,12 +80,12 @@ int rgw_store_user_info(RGWUserInfo& info)
::encode(ui, uid_bl);
::encode(info, uid_bl);
- ret = rgw_put_obj(info.user_id, ui_uid_bucket, info.user_id, uid_bl.c_str(), uid_bl.length());
+ ret = rgw_put_obj(rgwstore, info.user_id, ui_uid_bucket, info.user_id, uid_bl.c_str(), uid_bl.length());
if (ret < 0)
return ret;
if (info.user_email.size()) {
- ret = rgw_put_obj(info.user_id, ui_email_bucket, info.user_email, uid_bl.c_str(), uid_bl.length());
+ ret = rgw_put_obj(rgwstore, info.user_id, ui_email_bucket, info.user_email, uid_bl.c_str(), uid_bl.length());
if (ret < 0)
return ret;
}
@@ -94,7 +94,7 @@ int rgw_store_user_info(RGWUserInfo& info)
map<string, RGWAccessKey>::iterator iter = info.access_keys.begin();
for (; iter != info.access_keys.end(); ++iter) {
RGWAccessKey& k = iter->second;
- ret = rgw_put_obj(k.id, ui_key_bucket, k.id, uid_bl.c_str(), uid_bl.length());
+ ret = rgw_put_obj(rgwstore, k.id, ui_key_bucket, k.id, uid_bl.c_str(), uid_bl.length());
if (ret < 0)
return ret;
}
@@ -103,7 +103,7 @@ int rgw_store_user_info(RGWUserInfo& info)
map<string, RGWAccessKey>::iterator siter;
for (siter = info.swift_keys.begin(); siter != info.swift_keys.end(); ++siter) {
RGWAccessKey& k = siter->second;
- ret = rgw_put_obj(info.user_id, ui_swift_bucket, k.id, uid_bl.c_str(), uid_bl.length());
+ ret = rgw_put_obj(rgwstore, info.user_id, ui_swift_bucket, k.id, uid_bl.c_str(), uid_bl.length());
if (ret < 0)
return ret;
}
@@ -116,7 +116,7 @@ int rgw_get_user_info_from_index(string& key, rgw_bucket& bucket, RGWUserInfo& i
bufferlist bl;
RGWUID uid;
- int ret = rgw_get_obj(NULL, bucket, key, bl);
+ int ret = rgw_get_obj(rgwstore, NULL, bucket, key, bl);
if (ret < 0)
return ret;