/** Create a new bucket*/
virtual int create_bucket(std::string& id, rgw_bucket& bucket, map<std::string, bufferlist>& attrs, bool create_pool, bool assign_marker, bool exclusive = true, uint64_t auid = 0) = 0;
+ virtual int select_bucket_placement(string& bucket_name, rgw_bucket& bucket) { return 0; }
virtual int create_pools(std::string& id, vector<string>& names, vector<int>& retcodes, int auid = 0) { return -ENOTSUP; }
/** write an object to the storage device in the appropriate pool
with the given stats */
#include "rgw_bucket.h"
#include "rgw_tools.h"
-#include "auth/Crypto.h" // get_random_bytes()
-
-
static rgw_bucket pi_buckets(BUCKETS_POOL_NAME);
-static string default_storage_pool(DEFAULT_BUCKET_STORE_POOL);
-static string avail_pools = ".pools.avail";
static string pool_name_prefix = "p";
return rgw_get_bucket_info(bucket_string, info);
}
-int rgw_bucket_select_host_pool(string& bucket_name, rgw_bucket& bucket)
-{
- bufferlist header;
- map<string, bufferlist> m;
- string pool_name;
-
- rgw_obj obj(pi_buckets, avail_pools);
- int ret = rgwstore->tmap_get(obj, header, m);
- if (ret < 0 || !m.size()) {
- string id;
- vector<string> names;
- names.push_back(default_storage_pool);
- vector<int> retcodes;
- bufferlist bl;
- ret = rgwstore->create_pools(id, names, retcodes);
- if (ret < 0)
- return ret;
- ret = rgwstore->tmap_set(obj, default_storage_pool, bl);
- if (ret < 0)
- return ret;
- m[default_storage_pool] = bl;
- }
-
- vector<string> v;
- map<string, bufferlist>::iterator miter;
- for (miter = m.begin(); miter != m.end(); ++miter) {
- v.push_back(miter->first);
- }
-
- uint32_t r;
- ret = get_random_bytes((char *)&r, sizeof(r));
- if (ret < 0)
- return ret;
-
- int i = r % v.size();
- pool_name = v[i];
- bucket.pool = pool_name;
- bucket.name = bucket_name;
-
- return 0;
-}
-
-
-
int rgw_create_bucket(std::string& id, string& bucket_name, rgw_bucket& bucket,
map<std::string, bufferlist>& attrs, bool exclusive, uint64_t auid)
{
return rgwstore->create_bucket(id, bucket, attrs, true, false, exclusive, auid);
}
- int ret = rgw_bucket_select_host_pool(bucket_name, bucket);
+ int ret = rgwstore->select_bucket_placement(bucket_name, bucket);
if (ret < 0)
return ret;
#include "rgw_common.h"
#define BUCKETS_POOL_NAME ".rgw"
-#define DEFAULT_BUCKET_STORE_POOL ".rgw.buckets"
extern int rgw_get_bucket_info_id(uint64_t bucket_id, RGWBucketInfo& info);
extern int rgw_get_bucket_info(string& bucket_name, RGWBucketInfo& info);
extern int rgw_store_bucket_info(RGWBucketInfo& info);
-extern int rgw_bucket_select_host_pool(string& bucket_name, rgw_bucket& bucket);
extern int rgw_create_bucket(std::string& id, string& bucket_name, rgw_bucket& bucket,
map<std::string, bufferlist>& attrs, bool exclusive = true, uint64_t auid = 0);
attrs[RGW_ATTR_ACL] = aclbl;
- ret = rgw_bucket_select_host_pool(s->bucket_name_str, s->bucket);
+ ret = rgwstore->select_bucket_placement(s->bucket_name_str, s->bucket);
if (ret < 0)
goto done;
#include <vector>
#include <list>
#include <map>
+#include "auth/Crypto.h" // get_random_bytes()
using namespace std;
static string shadow_ns = "shadow";
static string bucket_marker_ver_oid = ".rgw.bucket-marker-ver";
static string dir_oid_prefix = ".dir.";
+static string default_storage_pool(DEFAULT_BUCKET_STORE_POOL);
+static string avail_pools = ".pools.avail";
+
+#include "rgw/rgw_bucket.h"
+static rgw_bucket pi_buckets_rados(BUCKETS_POOL_NAME);
+
static RGWObjCategory shadow_category = RGW_OBJ_CATEGORY_SHADOW;
static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN;
return ret;
}
+int RGWRados::select_bucket_placement(string& bucket_name, rgw_bucket& bucket)
+{
+ bufferlist header;
+ map<string, bufferlist> m;
+ string pool_name;
+
+ rgw_obj obj(pi_buckets_rados, avail_pools);
+ int ret = tmap_get(obj, header, m);
+ if (ret < 0 || !m.size()) {
+ string id;
+ vector<string> names;
+ names.push_back(default_storage_pool);
+ vector<int> retcodes;
+ bufferlist bl;
+ ret = create_pools(id, names, retcodes);
+ if (ret < 0)
+ return ret;
+ ret = tmap_set(obj, default_storage_pool, bl);
+ if (ret < 0)
+ return ret;
+ m[default_storage_pool] = bl;
+ }
+
+ vector<string> v;
+ map<string, bufferlist>::iterator miter;
+ for (miter = m.begin(); miter != m.end(); ++miter) {
+ v.push_back(miter->first);
+ }
+
+ uint32_t r;
+ ret = get_random_bytes((char *)&r, sizeof(r));
+ if (ret < 0)
+ return ret;
+
+ int i = r % v.size();
+ pool_name = v[i];
+ bucket.pool = pool_name;
+ bucket.name = bucket_name;
+
+ return 0;
+
+}
+
int RGWRados::create_pools(std::string& id, vector<string>& names, vector<int>& retcodes, int auid)
{
vector<string>::iterator iter;
class SafeTimer;
class ACLOwner;
+#define DEFAULT_BUCKET_STORE_POOL ".rgw.buckets"
+
struct RGWObjState {
bool is_atomic;
bool has_attrs;
* returns 0 on success, -ERR# otherwise.
*/
virtual int create_bucket(std::string& id, rgw_bucket& bucket, map<std::string,bufferlist>& attrs, bool create_pool, bool assign_marker, bool exclusive = true, uint64_t auid = 0);
+ virtual int select_bucket_placement(std::string& bucket_name, rgw_bucket& bucket);
virtual int create_pools(std::string& id, vector<string>& names, vector<int>& retcodes, int auid = 0);
/** Write/overwrite an object to the bucket storage. */