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: fix get x-amz-storage-class info for RGWPostObj #11

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cls/rgw/cls_rgw_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void rgw_bucket_dir_entry_meta::dump(Formatter *f) const
utime_t ut(mtime);
encode_json("mtime", ut, f);
encode_json("etag", etag, f);
encode_json("storage_class", storage_class, f);
encode_json("owner", owner, f);
encode_json("owner_display_name", owner_display_name, f);
encode_json("content_type", content_type, f);
Expand All @@ -72,6 +73,7 @@ void rgw_bucket_dir_entry_meta::decode_json(JSONObj *obj) {
JSONDecoder::decode_json("mtime", ut, obj);
mtime = ut.to_real_time();
JSONDecoder::decode_json("etag", etag, obj);
JSONDecoder::decode_json("storage_class", storage_class, obj);
JSONDecoder::decode_json("owner", owner, obj);
JSONDecoder::decode_json("owner_display_name", owner_display_name, obj);
JSONDecoder::decode_json("content_type", content_type, obj);
Expand Down
8 changes: 6 additions & 2 deletions src/cls/rgw/cls_rgw_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ struct rgw_bucket_dir_entry_meta {
string content_type;
uint64_t accounted_size;
string user_data;
string storage_class;

rgw_bucket_dir_entry_meta() :
category(0), size(0), accounted_size(0) { }

void encode(bufferlist &bl) const {
ENCODE_START(5, 3, bl);
ENCODE_START(6, 3, bl);
encode(category, bl);
encode(size, bl);
encode(mtime, bl);
Expand All @@ -113,10 +114,11 @@ struct rgw_bucket_dir_entry_meta {
encode(content_type, bl);
encode(accounted_size, bl);
encode(user_data, bl);
encode(storage_class, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::const_iterator &bl) {
DECODE_START_LEGACY_COMPAT_LEN(5, 3, 3, bl);
DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl);
decode(category, bl);
decode(size, bl);
decode(mtime, bl);
Expand All @@ -131,6 +133,8 @@ struct rgw_bucket_dir_entry_meta {
accounted_size = size;
if (struct_v >= 5)
decode(user_data, bl);
if (struct_v >= 6)
decode(storage_class, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
Expand Down
40 changes: 34 additions & 6 deletions src/common/ceph_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class JSONDecoder {

template<class T>
static void decode_json(const char *name, T& val, const T& default_val, JSONObj *obj);

template<class T>
static bool decode_json(const char *name, boost::optional<T>& val, JSONObj *obj, bool mandatory = false);

};

template<class T>
Expand Down Expand Up @@ -322,6 +326,32 @@ void JSONDecoder::decode_json(const char *name, T& val, const T& default_val, JS
}
}

template<class T>
bool JSONDecoder::decode_json(const char *name, boost::optional<T>& val, JSONObj *obj, bool mandatory)
{
JSONObjIter iter = obj->find_first(name);
if (iter.end()) {
if (mandatory) {
string s = "missing mandatory field " + string(name);
throw err(s);
}
val = boost::none;
return false;
}

try {
val.reset(T());
decode_json_obj(val.get(), *iter);
} catch (err& e) {
val.reset();
string s = string(name) + ": ";
s.append(e.message);
throw err(s);
}

return true;
}

template<class T>
static void encode_json(const char *name, const T& val, ceph::Formatter *f)
{
Expand Down Expand Up @@ -522,6 +552,10 @@ struct JSONFormattable {
int val_int() const;
bool val_bool() const;

const map<std::string, JSONFormattable> object() const {
return obj;
}

const vector<JSONFormattable>& array() const {
return arr;
}
Expand Down Expand Up @@ -558,12 +592,6 @@ struct JSONFormattable {
return def(string(def_val));
}

#if 0
string operator ()(const string& def_val) const {
return def(def_val);
}
#endif

int operator()(int def_val) const {
return def(def_val);
}
Expand Down
51 changes: 27 additions & 24 deletions src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ void usage()
cout << " --read-only set zone as read-only (when adding to zonegroup)\n";
cout << " --redirect-zone specify zone id to redirect when response is 404 (not found)\n";
cout << " --placement-id placement id for zonegroup placement commands\n";
cout << " --storage-class storage class for zonegroup placement commands\n";
cout << " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
cout << " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
cout << " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
Expand Down Expand Up @@ -1210,11 +1211,8 @@ static bool decode_dump(const char *field_name, bufferlist& bl, Formatter *f)

static bool dump_string(const char *field_name, bufferlist& bl, Formatter *f)
{
string val;
if (bl.length() > 0) {
val.assign(bl.c_str());
}
f->dump_string(field_name, val);
string val = bl.to_str();
f->dump_string(field_name, val.c_str() /* hide encoded null termination chars */);

return true;
}
Expand Down Expand Up @@ -2705,6 +2703,7 @@ int main(int argc, const char **argv)
string quota_scope;
string object_version;
string placement_id;
string storage_class;
list<string> tags;
list<string> tags_add;
list<string> tags_rm;
Expand Down Expand Up @@ -3009,6 +3008,8 @@ int main(int argc, const char **argv)
zonegroup_new_name = val;
} else if (ceph_argparse_witharg(args, i, &val, "--placement-id", (char*)NULL)) {
placement_id = val;
} else if (ceph_argparse_witharg(args, i, &val, "--storage-class", (char*)NULL)) {
storage_class = val;
} else if (ceph_argparse_witharg(args, i, &val, "--tags", (char*)NULL)) {
get_str_list(val, tags);
} else if (ceph_argparse_witharg(args, i, &val, "--tags-add", (char*)NULL)) {
Expand Down Expand Up @@ -4171,21 +4172,26 @@ int main(int argc, const char **argv)
return EINVAL;
}

rgw_placement_rule rule;
rule.from_str(placement_id);

if (!rule.storage_class.empty() && !storage_class.empty() &&
rule.storage_class != storage_class) {
cerr << "ERROR: provided contradicting storage class configuration" << std::endl;
return EINVAL;
} else if (rule.storage_class.empty()) {
rule.storage_class = storage_class;
}

RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name);
int ret = zonegroup.init(g_ceph_context, store);
if (ret < 0) {
cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl;
return -ret;
}

if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_ADD) {
RGWZoneGroupPlacementTarget target;
target.name = placement_id;
for (auto& t : tags) {
target.tags.insert(t);
}
zonegroup.placement_targets[placement_id] = target;
} else if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_MODIFY) {
if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_ADD ||
opt_cmd == OPT_ZONEGROUP_PLACEMENT_MODIFY) {
RGWZoneGroupPlacementTarget& target = zonegroup.placement_targets[placement_id];
if (!tags.empty()) {
target.tags.clear();
Expand All @@ -4200,6 +4206,7 @@ int main(int argc, const char **argv)
for (auto& t : tags_add) {
target.tags.insert(t);
}
target.storage_classes.insert(rule.get_storage_class());
} else if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_RM) {
zonegroup.placement_targets.erase(placement_id);
} else if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_DEFAULT) {
Expand All @@ -4208,7 +4215,7 @@ int main(int argc, const char **argv)
<< placement_id << "'" << std::endl;
return -ENOENT;
}
zonegroup.default_placement = placement_id;
zonegroup.default_placement = rule;
}

zonegroup.post_process_params();
Expand Down Expand Up @@ -4650,16 +4657,15 @@ int main(int argc, const char **argv)
RGWZonePlacementInfo& info = zone.placement_pools[placement_id];

info.index_pool = *index_pool;
info.data_pool = *data_pool;
rgw_pool dp = data_pool.get();
info.storage_classes.set_storage_class(storage_class, &dp, compression_type.get_ptr());

if (data_extra_pool) {
info.data_extra_pool = *data_extra_pool;
}
if (index_type_specified) {
info.index_type = placement_index_type;
}
if (compression_type) {
info.compression_type = *compression_type;
}

ret = check_pool_support_omap(info.get_data_extra_pool());
if (ret < 0) {
Expand All @@ -4678,18 +4684,15 @@ int main(int argc, const char **argv)
if (index_pool && !index_pool->empty()) {
info.index_pool = *index_pool;
}
if (data_pool && !data_pool->empty()) {
info.data_pool = *data_pool;
}
rgw_pool dp = data_pool.get();
info.storage_classes.set_storage_class(storage_class, &dp, compression_type.get_ptr());

if (data_extra_pool) {
info.data_extra_pool = *data_extra_pool;
}
if (index_type_specified) {
info.index_type = placement_index_type;
}
if (compression_type) {
info.compression_type = *compression_type;
}

ret = check_pool_support_omap(info.get_data_extra_pool());
if (ret < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ static int bucket_stats(RGWRados *store, const std::string& tenant_name, std::st
formatter->open_object_section("stats");
formatter->dump_string("bucket", bucket.name);
formatter->dump_string("zonegroup", bucket_info.zonegroup);
formatter->dump_string("placement_rule", bucket_info.placement_rule);
formatter->dump_string("placement_rule", bucket_info.placement_rule.to_str());
::encode_json("explicit_placement", bucket.explicit_placement, formatter);
formatter->dump_string("id", bucket.bucket_id);
formatter->dump_string("marker", bucket.marker);
Expand Down
Loading