return 0;
}
+int set_user_quota(int opt_cmd, RGWUser& user, RGWUserAdminOpState& op_state, int64_t max_size, int64_t max_objects,
+ bool have_max_size, bool have_max_objects)
+{
+ RGWUserInfo& user_info = op_state.get_user_info();
+
+ set_quota_info(user_info.user_quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects);
+
+ op_state.set_user_quota(user_info.user_quota);
+
+ string err;
+ int r = user.modify(op_state, &err);
+ if (r < 0) {
+ cerr << "ERROR: failed updating user info: " << cpp_strerror(-r) << ": " << err << std::endl;
+ return -r;
+ }
+ return 0;
+}
+
static int sync_bucket_stats(RGWRados *store, string& bucket_name)
{
RGWBucketInfo bucket_info;
}
set_bucket_quota(store, opt_cmd, bucket_name, max_size, max_objects, have_max_size, have_max_objects);
} else if (!user_id.empty()) {
- if (quota_scope != "bucket") {
- cerr << "ERROR: only bucket-level user quota can be handled. Please specify --quota-scope=bucket" << std::endl;
+ if (quota_scope == "bucket") {
+ set_user_bucket_quota(opt_cmd, user, user_op, max_size, max_objects, have_max_size, have_max_objects);
+ } else if (quota_scope == "user") {
+ set_user_quota(opt_cmd, user, user_op, max_size, max_objects, have_max_size, have_max_objects);
+ } else {
+ cerr << "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl;
return EINVAL;
}
- set_user_bucket_quota(opt_cmd, user, user_op, max_size, max_objects, have_max_size, have_max_objects);
}
}
string default_placement;
list<string> placement_tags;
RGWQuotaInfo bucket_quota;
+ RGWQuotaInfo user_quota;
RGWUserInfo() : auid(0), suspended(0), max_buckets(RGW_DEFAULT_MAX_BUCKETS), op_mask(RGW_OP_TYPE_ALL), system(0) {}
void encode(bufferlist& bl) const {
- ENCODE_START(14, 9, bl);
+ ENCODE_START(15, 9, bl);
::encode(auid, bl);
string access_key;
string secret_key;
::encode(default_placement, bl);
::encode(placement_tags, bl);
::encode(bucket_quota, bl);
+ ::encode(user_quota, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
if (struct_v >= 14) {
::decode(bucket_quota, bl);
}
+ if (struct_v >= 15) {
+ ::decode(user_quota, bl);
+ }
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
encode_json("default_placement", default_placement, f);
encode_json("placement_tags", placement_tags, f);
encode_json("bucket_quota", bucket_quota, f);
+ encode_json("user_quota", user_quota, f);
}
JSONDecoder::decode_json("default_placement", default_placement, obj);
JSONDecoder::decode_json("placement_tags", placement_tags, obj);
JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
+ JSONDecoder::decode_json("user_quota", user_quota, obj);
}
void RGWQuotaInfo::dump(Formatter *f) const
if (op_state.has_bucket_quota())
user_info.bucket_quota = op_state.get_bucket_quota();
+ if (op_state.has_user_quota())
+ user_info.user_quota = op_state.get_user_quota();
+
// update the request
op_state.set_user_info(user_info);
op_state.set_populated();
if (op_state.has_bucket_quota())
user_info.bucket_quota = op_state.get_bucket_quota();
+ if (op_state.has_user_quota())
+ user_info.user_quota = op_state.get_user_quota();
+
if (op_state.has_suspension_op()) {
__u8 suspended = op_state.get_suspension_status();
user_info.suspended = suspended;
bool user_params_checked;
bool bucket_quota_specified;
+ bool user_quota_specified;
RGWQuotaInfo bucket_quota;
+ RGWQuotaInfo user_quota;
void set_access_key(std::string& access_key) {
if (access_key.empty())
key_op = true;
}
- void set_bucket_quota(RGWQuotaInfo& quota)
- {
+ void set_bucket_quota(RGWQuotaInfo& quota) {
bucket_quota = quota;
bucket_quota_specified = true;
}
+ void set_user_quota(RGWQuotaInfo& quota) {
+ user_quota = quota;
+ user_quota_specified = true;
+ }
+
bool is_populated() { return populated; };
bool is_initialized() { return initialized; };
bool has_existing_user() { return existing_user; };
bool will_purge_data() { return purge_data; };
bool will_generate_subuser() { return gen_subuser; };
bool has_bucket_quota() { return bucket_quota_specified; }
+ bool has_user_quota() { return user_quota_specified; }
void set_populated() { populated = true; };
void clear_populated() { populated = false; };
void set_initialized() { initialized = true; };
uint32_t get_max_buckets() { return max_buckets; };
uint32_t get_op_mask() { return op_mask; };
RGWQuotaInfo& get_bucket_quota() { return bucket_quota; }
+ RGWQuotaInfo& get_user_quota() { return user_quota; }
std::string get_user_id() { return user_id; };
std::string get_subuser() { return subuser; };
subuser_params_checked = false;
user_params_checked = false;
bucket_quota_specified = false;
+ user_quota_specified = false;
}
};