Skip to content

Commit

Permalink
Merge pull request #9743: jewel : rgw: support size suffixes for --ma…
Browse files Browse the repository at this point in the history
…x-size in radosgw-admin command

Reviewed-by: Loic Dachary <ldachary@redhat.com>
  • Loading branch information
Loic Dachary committed Jul 1, 2016
2 parents 7cba72e + 762db30 commit 4f36f5a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions doc/radosgw/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ storage size in megabytes.
the maximum number of objects. A negative value disables this setting.

- **Maximum Size:** The ``--max-size`` option allows you to specify a quota
for the maximum number of bytes. A negative value disables this setting.
size in B/K/M/G/T. A negative value disables this setting.

- **Quota Scope:** The ``--quota-scope`` option sets the scope for the quota.
The options are ``bucket`` and ``user``. Bucket quotas apply to buckets a
Expand All @@ -327,7 +327,7 @@ For example::

For example::

radosgw-admin quota set --quota-scope=user --uid=johndoe --max-objects=1024 --max-size=1024
radosgw-admin quota set --quota-scope=user --uid=johndoe --max-objects=1024 --max-size=1024B


A negative value for num objects and / or max size means that the
Expand Down
2 changes: 2 additions & 0 deletions src/common/strtol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ template int strict_si_cast<int>(const char *str, std::string *err);

template long long strict_si_cast<long long>(const char *str, std::string *err);

template int64_t strict_si_cast<int64_t>(const char *str, std::string *err);

template uint64_t strict_si_cast<uint64_t>(const char *str, std::string *err);

uint64_t strict_sistrtoll(const char *str, std::string *err)
Expand Down
10 changes: 7 additions & 3 deletions src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void _usage()
cout << "\nQuota options:\n";
cout << " --bucket specified bucket for quota command\n";
cout << " --max-objects specify max objects (negative value to disable)\n";
cout << " --max-size specify max size (in bytes, negative value to disable)\n";
cout << " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
cout << " --quota-scope scope of quota (bucket, user)\n";
cout << "\nOrphans search options:\n";
cout << " --pool data pool to scan for leaked rados objects in\n";
Expand Down Expand Up @@ -1021,7 +1021,11 @@ void set_quota_info(RGWQuotaInfo& quota, int opt_cmd, int64_t max_size, int64_t

case OPT_QUOTA_SET:
if (have_max_objects) {
quota.max_objects = max_objects;
if (max_objects < 0) {
quota.max_objects = -1;
} else {
quota.max_objects = max_objects;
}
}
if (have_max_size) {
if (max_size < 0) {
Expand Down Expand Up @@ -2142,7 +2146,7 @@ int main(int argc, char **argv)
return EINVAL;
}
} else if (ceph_argparse_witharg(args, i, &val, "--max-size", (char*)NULL)) {
max_size = (int64_t)strict_strtoll(val.c_str(), 10, &err);
max_size = strict_si_cast<int64_t>(val.c_str(), &err);
if (!err.empty()) {
cerr << "ERROR: failed to parse max size: " << err << std::endl;
return EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion src/test/cli/radosgw-admin/help.t
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
Quota options:
--bucket specified bucket for quota command
--max-objects specify max objects (negative value to disable)
--max-size specify max size (in bytes, negative value to disable)
--max-size specify max size (in B/K/M/G/T, negative value to disable)
--quota-scope scope of quota (bucket, user)
Orphans search options:
Expand Down
15 changes: 15 additions & 0 deletions src/test/strtol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ TEST(StrictSICast, Error) {
(void)strict_si_cast<int>("1T", &err);
ASSERT_NE(err, "");
}
{
std::string err;
(void)strict_si_cast<int64_t>("2E", &err);
ASSERT_EQ(err, "");
}
{
std::string err;
(void)strict_si_cast<int64_t>("-2E", &err);
ASSERT_EQ(err, "");
}
{
std::string err;
(void)strict_si_cast<int64_t>("1T", &err);
ASSERT_EQ(err, "");
}
}

/*
Expand Down

0 comments on commit 4f36f5a

Please sign in to comment.