store(_store), op(_op), num_shards(_num_shards) {
shards.reserve(num_shards);
for (int i = 0; i < num_shards; ++i) {
- char buf[oid_prefix.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%d", oid_prefix.c_str(), i);
- RGWOmapAppend *shard = new RGWOmapAppend(async_rados, store, rgw_raw_obj(pool, buf));
+ RGWOmapAppend *shard = new RGWOmapAppend(
+ async_rados, store, rgw_raw_obj(pool,
+ fmt::format("{}.{}", oid_prefix, i)));
shard->get();
shards.push_back(shard);
op->spawn(shard, false);
static string full_data_sync_index_shard_oid(const rgw_zone_id& source_zone, int shard_id)
{
- char buf[datalog_sync_full_sync_index_prefix.size() + 1 + source_zone.id.size() + 1 + 16];
- snprintf(buf, sizeof(buf), "%s.%s.%d", datalog_sync_full_sync_index_prefix.c_str(), source_zone.id.c_str(), shard_id);
- return string(buf);
+ return fmt::format("{}.{}.{}", datalog_sync_full_sync_index_prefix,
+ source_zone.id, shard_id);
}
struct read_metadata_list {
{
// construct and start bid manager for data sync fairness
const auto& control_pool = sc.env->driver->svc()->zone->get_zone_params().control_pool;
- char buf[data_sync_bids_oid.size() + sc.source_zone.id.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%s", data_sync_bids_oid.c_str(), sc.source_zone.id.c_str());
- auto control_obj = rgw_raw_obj{control_pool, string(buf)};
+ auto control_obj = rgw_raw_obj{
+ control_pool,
+ fmt::format("{}.{}", data_sync_bids_oid, sc.source_zone.id)
+ };
auto bid_manager = rgw::sync_fairness::create_rados_bid_manager(
driver, control_obj, num_shards);
string RGWDataSyncStatusManager::sync_status_oid(const rgw_zone_id& source_zone)
{
- char buf[datalog_sync_status_oid_prefix.size() + source_zone.id.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%s", datalog_sync_status_oid_prefix.c_str(), source_zone.id.c_str());
-
- return string(buf);
+ return fmt::format("{}.{}", datalog_sync_status_oid_prefix, source_zone.id);
}
-string RGWDataSyncStatusManager::shard_obj_name(const rgw_zone_id& source_zone, int shard_id)
+string RGWDataSyncStatusManager::shard_obj_name(const rgw_zone_id& source_zone,
+ int shard_id)
{
- char buf[datalog_sync_status_shard_prefix.size() + source_zone.id.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%s.%d", datalog_sync_status_shard_prefix.c_str(), source_zone.id.c_str(), shard_id);
-
- return string(buf);
+ return fmt::format("{}.{}.{}", datalog_sync_status_shard_prefix,
+ source_zone.id, shard_id);
}
class RGWInitBucketShardSyncStatusCoroutine : public RGWCoroutine {
} else if (strncmp(name, RGW_ATTR_META_PREFIX,
sizeof(RGW_ATTR_META_PREFIX)-1) == 0) {
name += sizeof(RGW_ATTR_META_PREFIX) - 1;
- string sname(name);
- string name_prefix = RGW_ATTR_META_PREFIX;
- char full_name_buf[name_prefix.size() + sname.size() + 1];
- snprintf(full_name_buf, sizeof(full_name_buf), "%.*s%.*s",
- static_cast<int>(name_prefix.length()),
- name_prefix.data(),
- static_cast<int>(sname.length()),
- sname.data());
- headers[full_name_buf] = rgw_bl_str(kv.second);
+ headers[fmt::format("{}{}", RGW_ATTR_META_PREFIX, name)] = rgw_bl_str(kv.second);
} else if (strcmp(name,RGW_ATTR_CONTENT_TYPE) == 0) {
headers["CONTENT_TYPE"] = rgw_bl_str(kv.second);
}
void RGWRados::create_bucket_id(string *bucket_id)
{
- uint64_t iid = instance_id();
- uint64_t bid = next_bucket_id();
- char buf[svc.zone->get_zone_params().get_id().size() + 48];
- snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%" PRIu64,
- svc.zone->get_zone_params().get_id().c_str(), iid, bid);
- *bucket_id = buf;
+ *bucket_id = fmt::format("{}.{}.{}", svc.zone->get_zone_params().get_id(),
+ instance_id(), next_bucket_id());
}
int RGWRados::create_bucket(const DoutPrefixProvider* dpp,
}
const string& src_name = obj.get_oid();
- char buf[src_name.size() + 32];
struct timespec ts = ceph::real_clock::to_timespec(state->mtime);
- snprintf(buf, sizeof(buf), "%03x%s/%lld.%06ld", (int)src_name.size(),
- src_name.c_str(), (long long)ts.tv_sec, ts.tv_nsec / 1000);
+ auto buf = fmt::format("{:03x}{}/{}.{:06}", int(src_name.size()),
+ src_name, static_cast<long long>(ts.tv_sec),
+ ts.tv_nsec / 1000);
RGWBucketInfo dest_bucket_info;
}
}
string RGWSyncErrorLogger::get_shard_oid(const string& oid_prefix, int shard_id) {
- char buf[oid_prefix.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%d", oid_prefix.c_str(), shard_id);
- return string(buf);
+ return fmt::format("{}.{}", oid_prefix, shard_id);
}
RGWCoroutine *RGWSyncErrorLogger::log_error_cr(const DoutPrefixProvider *dpp, const string& source_zone, const string& section, const string& name, uint32_t error_code, const string& message) {
string RGWMetaSyncEnv::shard_obj_name(int shard_id)
{
- char buf[mdlog_sync_status_shard_prefix.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%d", mdlog_sync_status_shard_prefix.c_str(), shard_id);
-
- return string(buf);
+ return fmt::format("{}.{}", mdlog_sync_status_shard_prefix, shard_id);
}
class RGWAsyncReadMDLogEntries : public RGWAsyncRadosRequest {
static string full_sync_index_shard_oid(int shard_id)
{
- char buf[mdlog_sync_full_sync_index_prefix.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%d", mdlog_sync_full_sync_index_prefix.c_str(), shard_id);
- return string(buf);
+ return fmt::format("{}.{}", mdlog_sync_full_sync_index_prefix, shard_id);
}
class RGWReadRemoteMetadataCR : public RGWCoroutine {
return std::string("_") + name;
};
- char buf[ns.size() + 16];
- snprintf(buf, sizeof(buf), "_%s_", ns.c_str());
- return std::string(buf) + name;
+ return fmt::format("_{}_{}", ns, name);
};
void get_index_key(rgw_obj_index_key* key) const {
const std::string_view& name_prefix,
const std::string_view& name,
Args&&... args) {
- char full_name_buf[name_prefix.size() + name.size() + 1];
- const auto len = snprintf(full_name_buf, sizeof(full_name_buf), "%.*s%.*s",
- static_cast<int>(name_prefix.length()),
- name_prefix.data(),
- static_cast<int>(name.length()),
- name.data());
- std::string_view full_name(full_name_buf, len);
+ const auto full_name = fmt::format("{}{}", name_prefix, name);
return dump_header(s, std::move(full_name), std::forward<Args>(args)...);
}
const std::string_view& infix,
const std::string_view& sufix,
Args&&... args) {
- char full_name_buf[prefix.size() + infix.size() + sufix.size() + 1];
- const auto len = snprintf(full_name_buf, sizeof(full_name_buf), "%.*s%.*s%.*s",
- static_cast<int>(prefix.length()),
- prefix.data(),
- static_cast<int>(infix.length()),
- infix.data(),
- static_cast<int>(sufix.length()),
- sufix.data());
- std::string_view full_name(full_name_buf, len);
+ auto full_name = fmt::format("{}{}{}", prefix, infix, sufix);
return dump_header(s, std::move(full_name), std::forward<Args>(args)...);
}
const std::string_view& name,
const std::string_view& val) {
/* We need two extra bytes for quotes. */
- char qvalbuf[val.size() + 2 + 1];
- const auto len = snprintf(qvalbuf, sizeof(qvalbuf), "\"%.*s\"",
- static_cast<int>(val.length()), val.data());
- return dump_header(s, name, std::string_view(qvalbuf, len));
+ auto qval = fmt::format("\"{}\"", val);
+ return dump_header(s, name, std::move(qval));
}
template <class ValueT>
s->prot_flags |= RGW_REST_SWIFT;
- char reqbuf[frontend_prefix.length() + s->decoded_uri.length() + 1];
- sprintf(reqbuf, "%s%s", frontend_prefix.c_str(), s->decoded_uri.c_str());
- const char *req_name = reqbuf;
+ auto reqbuf = fmt::format("{}{}", frontend_prefix, s->decoded_uri);
+ std::string_view req_name = reqbuf;
- const char *p;
+ // args.set requires a `const std::string&`
+ std::string p;
- if (*req_name == '?') {
+ if (req_name.starts_with('?')) {
p = req_name;
} else {
- p = s->info.request_params.c_str();
+ p = s->info.request_params;
}
s->info.args.set(p);
s->info.args.parse(s);
/* Skip the leading slash of URL hierarchy. */
- if (req_name[0] != '/') {
+ if (!req_name.starts_with('/')) {
return 0;
} else {
- req_name++;
+ req_name.remove_prefix(1);
}
- if ('\0' == req_name[0]) {
+ if (req_name.empty()) {
return g_conf()->rgw_swift_url_prefix == "/" ? -ERR_BAD_URL : 0;
}
}
/* verify that the request_uri conforms with what's expected */
- char buf[g_conf()->rgw_swift_url_prefix.length() + 16 + tenant_path.length()];
- int blen;
- if (g_conf()->rgw_swift_url_prefix == "/") {
- blen = sprintf(buf, "/v1%s", tenant_path.c_str());
- } else {
- blen = sprintf(buf, "/%s/v1%s",
- g_conf()->rgw_swift_url_prefix.c_str(), tenant_path.c_str());
- }
+ const std::string swift_url_prefix =
+ (g_conf()->rgw_swift_url_prefix == "/")
+ ? fmt::format("/v1{}", tenant_path)
+ : fmt::format("/{}/v1{}", g_conf()->rgw_swift_url_prefix, tenant_path);
- if (strncmp(reqbuf, buf, blen) != 0) {
+ if (!reqbuf.starts_with(swift_url_prefix)) {
return -ENOENT;
}
}
auth_url.append("token");
- char url_buf[auth_url.size() + 1 + token.length() + 1];
- sprintf(url_buf, "%s/%s", auth_url.c_str(), token.c_str());
+ auto url_buf = fmt::format("{}/{}", auth_url, token);
RGWHTTPHeadersCollector validator(cct, "GET", url_buf, { "X-Auth-Groups", "X-Auth-Ttl" });
#include <algorithm>
#include <iterator>
+#include <fmt/format.h>
+
#include "svc_bi_rados.h"
#include "svc_bilog_rados.h"
#include "svc_zone.h"
#include "rgw_asio_thread.h"
-#include "rgw_bucket.h"
#include "rgw_zone.h"
#include "driver/rados/rgw_datalog.h"
return 0;
}
-static char bucket_obj_with_generation(char *buf, size_t len, const string& bucket_oid_base, uint64_t gen_id,
- uint32_t shard_id)
+namespace {
+inline std::string
+bucket_obj_with_generation(
+ std::string_view bucket_oid_base,
+ uint64_t gen_id,
+ uint32_t shard_id)
{
- return snprintf(buf, len, "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
+ return fmt::format("{}.{}.{}", bucket_oid_base, gen_id, shard_id);
}
-static char bucket_obj_without_generation(char *buf, size_t len, const string& bucket_oid_base, uint32_t shard_id)
+inline std::string
+bucket_obj_without_generation(std::string_view bucket_oid_base, uint32_t shard_id)
{
- return snprintf(buf, len, "%s.%d", bucket_oid_base.c_str(), shard_id);
+ return fmt::format("{}.{}", bucket_oid_base, shard_id);
}
+} // namespace
static void get_bucket_index_objects(const string& bucket_oid_base,
uint32_t num_shards, uint64_t gen_id,
if (!num_shards) {
bucket_objects[0] = bucket_oid_base;
} else {
- char buf[bucket_oid_base.size() + 64];
if (shard_id < 0) {
for (uint32_t i = 0; i < num_shards; ++i) {
if (gen_id) {
- bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, i);
+ bucket_objects[i] = bucket_obj_with_generation(bucket_oid_base, gen_id, i);
} else {
- bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, i);
+ bucket_objects[i] = bucket_obj_without_generation(bucket_oid_base, i);
}
- bucket_objects[i] = buf;
}
} else {
if (std::cmp_greater(shard_id, num_shards)) {
return;
} else {
if (gen_id) {
- bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, shard_id);
+ bucket_objects[shard_id] =
+ bucket_obj_with_generation(bucket_oid_base, gen_id, shard_id);
} else {
// for backward compatibility, gen_id(0) will not be added in the object name
- bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, shard_id);
+ bucket_objects[shard_id] =
+ bucket_obj_without_generation(bucket_oid_base, shard_id);
}
- bucket_objects[shard_id] = buf;
}
}
}
// By default with no sharding, we use the bucket oid as itself
(*bucket_obj) = bucket_oid_base;
} else {
- char buf[bucket_oid_base.size() + 64];
if (gen_id) {
- bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, shard_id);
- (*bucket_obj) = buf;
- ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl;
+ (*bucket_obj) =
+ bucket_obj_with_generation(bucket_oid_base, gen_id, shard_id);
+ ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl;
} else {
// for backward compatibility, gen_id(0) will not be added in the object name
- bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, shard_id);
- (*bucket_obj) = buf;
+ (*bucket_obj) = bucket_obj_without_generation(bucket_oid_base, shard_id);
}
}
}
}
} else {
uint32_t sid = bucket_shard_index(obj_key, normal.num_shards);
- char buf[bucket_oid_base.size() + 64];
if (gen_id) {
- bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, sid);
+ (*bucket_obj) =
+ bucket_obj_with_generation(bucket_oid_base, gen_id, sid);
} else {
- bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, sid);
+ (*bucket_obj) = bucket_obj_without_generation(bucket_oid_base, sid);
}
- (*bucket_obj) = buf;
if (shard_id) {
*shard_id = (int)sid;
}
string RGWSI_Notify::get_control_oid(int i)
{
- char buf[notify_oid_prefix.size() + 16];
- snprintf(buf, sizeof(buf), "%s.%d", notify_oid_prefix.c_str(), i);
-
- return string(buf);
+ return fmt::format("{}.{}", notify_oid_prefix, i);
}
// do not call pick_obj_control before init_watch
return std::string("_") + orig_obj;
};
- char buf[ns.size() + 16];
- snprintf(buf, sizeof(buf), "_%s_", ns.c_str());
- return std::string(buf) + orig_obj;
+ return fmt::format("_{}_{}", ns, orig_obj);
};
void from_index_key(old_rgw_bucket& b, const rgw_obj_key& key) {