Skip to content

Commit

Permalink
rgw: allow protocol bucket listing default max to override config max
Browse files Browse the repository at this point in the history
The config option "rgw_max_listing_results" sets a maximum listing
count across a number of operations. Some protocols define a default
listing count for some operations. For example, Swift defines a
default container listing count of 10,000 items. When this protocol
default exceeds the number defined in the config option, the default
value should be considered the actual maximum allowed.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
  • Loading branch information
ivancich committed May 8, 2020
1 parent 2cf01c4 commit dc36295
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/common/options.cc
Expand Up @@ -6935,8 +6935,9 @@ std::vector<Option> get_rgw_options() {
.set_default(1000)
.set_min_max(1, 100000)
.add_service("rgw")
.set_description("Upper bound on results in listing operations, ListBucket max-keys")
.set_description("Upper-bound on results in listing operations, ListBucket max-keys")
.set_long_description("This caps the maximum permitted value for listing-like operations in RGW S3. "
"Swift overrides this to 10000 for bucket listing. "
"Affects ListBucket(max-keys), "
"ListBucketVersions(max-keys), "
"ListBucketMultipartUploads(max-uploads), "
Expand Down
9 changes: 6 additions & 3 deletions src/rgw/rgw_op.cc
Expand Up @@ -2888,9 +2888,12 @@ int RGWListBucket::parse_max_keys()
// Bound min value of max-keys to '0'
// Some S3 clients explicitly send max-keys=0 to detect if the bucket is
// empty without listing any items.
return parse_value_and_bound(max_keys, max, 0,
g_conf().get_val<uint64_t>("rgw_max_listing_results"),
default_max);
return parse_value_and_bound(max_keys, // input string
max, // output int
0, // lower-bound
g_conf().get_val<uint64_t>("rgw_max_listing_results"), // upper-bound
default_max // default value
);
}

void RGWListBucket::pre_exec()
Expand Down
23 changes: 18 additions & 5 deletions src/rgw/rgw_op.h
Expand Up @@ -2458,17 +2458,30 @@ static inline int parse_value_and_bound(
char *endptr;
output = strtol(input.c_str(), &endptr, 10);
if (endptr) {
if (endptr == input.c_str()) return -EINVAL;
while (*endptr && isspace(*endptr)) // ignore white space
if (endptr == input.c_str()) {
// if no numeric characters, invalid input
return -EINVAL;
}
while (*endptr && isspace(*endptr)) { // ignore white space
endptr++;
}
if (*endptr) {
// if after skipping white-space we're not at the null
// terminating character, then there are one/more illegal
// characters
return -EINVAL;
}
}
if(output > upper_bound) {
output = upper_bound;

// if the default values is greater than the upper-bound, it
// becomes the upper-bound; for example, Swift's default value for
// bucket listing is 10,000
const long true_upper_bound = std::max(upper_bound, default_val);

if (output > true_upper_bound) {
output = true_upper_bound;
}
if(output < lower_bound) {
if (output < lower_bound) {
output = lower_bound;
}
} else {
Expand Down

0 comments on commit dc36295

Please sign in to comment.