]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: user quota interface
authorYehuda Sadeh <yehuda@inktank.com>
Fri, 10 Jan 2014 23:11:08 +0000 (15:11 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 24 Jan 2014 18:28:50 +0000 (10:28 -0800)
also add needed functionality in RGWUser

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_common.h
src/rgw/rgw_json_enc.cc
src/rgw/rgw_user.cc
src/rgw/rgw_user.h

index 986b2ea0ad105dd0876f5b31beea124445bb6e5b..0bef8864fc06a600c950a5cef35da3980ccd4e79 100644 (file)
@@ -722,6 +722,24 @@ int set_user_bucket_quota(int opt_cmd, RGWUser& user, RGWUserAdminOpState& op_st
   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;
@@ -2412,11 +2430,14 @@ next:
       }
       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);
     }
   }
 
index d6a1286429c588c1a4b4ac64814c1bd8be376975..3e4f0f4823f356ee2ded6687b24cda5b6739cf45 100644 (file)
@@ -432,11 +432,12 @@ struct RGWUserInfo
   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;
@@ -472,6 +473,7 @@ struct RGWUserInfo
      ::encode(default_placement, bl);
      ::encode(placement_tags, bl);
      ::encode(bucket_quota, bl);
+     ::encode(user_quota, bl);
      ENCODE_FINISH(bl);
   }
   void decode(bufferlist::iterator& bl) {
@@ -531,6 +533,9 @@ struct RGWUserInfo
     if (struct_v >= 14) {
       ::decode(bucket_quota, bl);
     }
+    if (struct_v >= 15) {
+      ::decode(user_quota, bl);
+    }
     DECODE_FINISH(bl);
   }
   void dump(Formatter *f) const;
index 4d6b25374b9a002e0f4526aa5ef6fd5ea0a62418..89c0238605db3e63d7c57c83da82a5e3e94a37c0 100644 (file)
@@ -397,6 +397,7 @@ void RGWUserInfo::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);
 }
 
 
@@ -448,6 +449,7 @@ void RGWUserInfo::decode_json(JSONObj *obj)
   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
index d8bbafabfb55b0ae65bf1fccbeb8fa7492ffc3a5..7e769332cc3f7132f4b69daa5ce441b3bb2326d0 100644 (file)
@@ -1685,6 +1685,9 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg)
   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();
@@ -1890,6 +1893,9 @@ int RGWUser::execute_modify(RGWUserAdminOpState& op_state, std::string *err_msg)
   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;
index 2749e6c2d51d35d68a57bebc157b0217a6ef8d47..9d4315bdd6650ec2d704326505840b116c8cfed3 100644 (file)
@@ -173,8 +173,10 @@ struct RGWUserAdminOpState {
   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())
@@ -289,12 +291,16 @@ struct RGWUserAdminOpState {
     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; };
@@ -314,6 +320,7 @@ struct RGWUserAdminOpState {
   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; };
@@ -329,6 +336,7 @@ struct RGWUserAdminOpState {
   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; };
@@ -417,6 +425,7 @@ struct RGWUserAdminOpState {
     subuser_params_checked = false;
     user_params_checked = false;
     bucket_quota_specified = false;
+    user_quota_specified = false;
   }
 };