Skip to content

Commit 57e5aef

Browse files
authored
Merge pull request ceph#62850 from ivancich/wip-shard-report-crash
rgw: prevent crash in `radosgw-admin bucket object shard ...` Reviewed-by: Casey Bodley <[email protected]> Reviewed-by: Jesse Williamson <[email protected]>
2 parents 716d158 + a2b76b0 commit 57e5aef

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/rgw/driver/rados/rgw_tools.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ inline int rgw_shards_max()
6262
// only called by rgw_shard_id and rgw_bucket_shard_index
6363
static inline int rgw_shards_mod(unsigned hval, int max_shards)
6464
{
65-
if (max_shards <= RGW_SHARDS_PRIME_0) {
65+
if (max_shards <= 0) {
66+
return -1;
67+
} else if (max_shards <= RGW_SHARDS_PRIME_0) {
6668
return hval % RGW_SHARDS_PRIME_0 % max_shards;
69+
} else {
70+
return hval % RGW_SHARDS_PRIME_1 % max_shards;
6771
}
68-
return hval % RGW_SHARDS_PRIME_1 % max_shards;
6972
}
7073

7174
// used for logging and tagging

src/rgw/radosgw-admin/radosgw-admin.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7695,8 +7695,13 @@ int main(int argc, const char **argv)
76957695
cerr << "ERROR: num-shards and object must be specified."
76967696
<< std::endl;
76977697
return EINVAL;
7698+
} else if (num_shards <= 0) {
7699+
cerr << "ERROR: non-positive value supplied for num-shards: " <<
7700+
num_shards << std::endl;
7701+
return EINVAL;
76987702
}
7699-
auto shard = RGWSI_BucketIndex_RADOS::bucket_shard_index(object, num_shards);
7703+
auto shard =
7704+
RGWSI_BucketIndex_RADOS::bucket_shard_index(object, num_shards);
77007705
formatter->open_object_section("obj_shard");
77017706
encode_json("shard", shard, formatter.get());
77027707
formatter->close_section();

src/rgw/services/svc_bi_rados.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex
100100
return rgw_shard_id(key, max_shards);
101101
}
102102

103-
static uint32_t bucket_shard_index(const std::string& key,
104-
int num_shards) {
103+
static int32_t bucket_shard_index(const std::string& key,
104+
int num_shards) {
105105
uint32_t sid = ceph_str_hash_linux(key.c_str(), key.size());
106106
uint32_t sid2 = sid ^ ((sid & 0xFF) << 24);
107107
return rgw_shards_mod(sid2, num_shards);
108108
}
109109

110-
static uint32_t bucket_shard_index(const rgw_obj_key& obj_key,
111-
int num_shards)
110+
static int32_t bucket_shard_index(const rgw_obj_key& obj_key,
111+
int num_shards)
112112
{
113113
std::string sharding_key;
114114
if (obj_key.ns == RGW_OBJ_NS_MULTIPART) {

0 commit comments

Comments
 (0)