From 8b80074ccb5f3ab04a4ea5128a5816be37b93d4d Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 10 Jan 2018 09:37:02 -0500 Subject: [PATCH] rgw: rgw_put_system_obj takes bufferlist all callers were converting from bufferlist to const char*, then RGWRados::put_system_obj() copied that back into a new bufferlist Signed-off-by: Casey Bodley --- src/rgw/rgw_metadata.cc | 8 +++----- src/rgw/rgw_rados.cc | 17 +++++++++-------- src/rgw/rgw_rados.h | 6 ++---- src/rgw/rgw_role.cc | 7 ++++--- src/rgw/rgw_tools.cc | 6 +++--- src/rgw/rgw_tools.h | 2 +- src/rgw/rgw_user.cc | 8 +++----- 7 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index d50782dfb3dc1..66aa0489eb0e2 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -383,7 +383,7 @@ int write_history(RGWRados *store, const RGWMetadataLogHistory& state, auto& pool = store->get_zone_params().log_pool; const auto& oid = RGWMetadataLogHistory::oid; - return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), + return rgw_put_system_obj(store, pool, oid, bl, exclusive, objv_tracker, real_time{}); } @@ -1006,8 +1006,7 @@ int RGWMetadataManager::store_in_heap(RGWMetadataHandler *handler, const string& otracker.write_version = objv_tracker->write_version; string oid = heap_oid(handler, key, objv_tracker->write_version); int ret = rgw_put_system_obj(store, heap_pool, oid, - bl.c_str(), bl.length(), false, - &otracker, mtime, pattrs); + bl, false, &otracker, mtime, pattrs); if (ret < 0) { ldout(store->ctx(), 0) << "ERROR: rgw_put_system_obj() oid=" << oid << " returned ret=" << ret << dendl; return ret; @@ -1059,8 +1058,7 @@ int RGWMetadataManager::put_entry(RGWMetadataHandler *handler, const string& key goto done; } - ret = rgw_put_system_obj(store, pool, oid, - bl.c_str(), bl.length(), exclusive, + ret = rgw_put_system_obj(store, pool, oid, bl, exclusive, objv_tracker, mtime, pattrs); if (ret < 0) { diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index cca45ea381434..0d79e58f07aa5 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -608,7 +608,7 @@ int RGWSystemMetaObj::set_as_default(bool exclusive) encode(default_info, bl); - int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), + int ret = rgw_put_system_obj(store, pool, oid, bl, exclusive, NULL, real_time(), NULL); if (ret < 0) return ret; @@ -697,7 +697,7 @@ int RGWSystemMetaObj::store_name(bool exclusive) bufferlist bl; using ceph::encode; encode(nameToId, bl); - return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), exclusive, NULL, real_time(), NULL); + return rgw_put_system_obj(store, pool, oid, bl, exclusive, NULL, real_time(), NULL); } int RGWSystemMetaObj::rename(const string& new_name) @@ -814,7 +814,7 @@ int RGWSystemMetaObj::store_info(bool exclusive) bufferlist bl; using ceph::encode; encode(*this, bl); - return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), exclusive, NULL, real_time(), NULL); + return rgw_put_system_obj(store, pool, oid, bl, exclusive, NULL, real_time(), NULL); } int RGWSystemMetaObj::write(bool exclusive) @@ -898,7 +898,8 @@ int RGWRealm::create_control(bool exclusive) { auto pool = rgw_pool{get_pool(cct)}; auto oid = get_control_oid(); - return rgw_put_system_obj(store, pool, oid, nullptr, 0, exclusive, + bufferlist bl; + return rgw_put_system_obj(store, pool, oid, bl, exclusive, nullptr, real_time(), nullptr); } @@ -1050,7 +1051,7 @@ int RGWPeriodConfig::write(RGWRados *store, const std::string& realm_id) bufferlist bl; using ceph::encode; encode(*this, bl); - return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), + return rgw_put_system_obj(store, pool, oid, bl, false, nullptr, real_time(), nullptr); } @@ -1234,7 +1235,7 @@ int RGWPeriod::set_latest_epoch(epoch_t epoch, bool exclusive, using ceph::encode; encode(info, bl); - return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), + return rgw_put_system_obj(store, pool, oid, bl, exclusive, objv, real_time(), nullptr); } @@ -1371,7 +1372,7 @@ int RGWPeriod::store_info(bool exclusive) using ceph::encode; encode(*this, bl); - return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), + return rgw_put_system_obj(store, pool, oid, bl, exclusive, NULL, real_time(), NULL); } @@ -4155,7 +4156,7 @@ int RGWRados::replace_region_with_zonegroup() } /* mark as converted */ - ret = rgw_put_system_obj(this, pool, oid, bl.c_str(), bl.length(), + ret = rgw_put_system_obj(this, pool, oid, bl, true, NULL, real_time(), NULL); if (ret < 0 ) { ldout(cct, 0) << __func__ << " failed to mark cluster as converted: ret "<< ret << " " << cpp_strerror(-ret) diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index a3682eb147d32..8f4b7d1fcf2dd 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -3050,16 +3050,14 @@ public: int aio_put_obj_data(void *ctx, rgw_raw_obj& obj, bufferlist& bl, off_t ofs, bool exclusive, void **handle); - int put_system_obj(void *ctx, rgw_raw_obj& obj, const char *data, size_t len, bool exclusive, + int put_system_obj(void *ctx, rgw_raw_obj& obj, bufferlist& data, bool exclusive, ceph::real_time *mtime, map& attrs, RGWObjVersionTracker *objv_tracker, ceph::real_time set_mtime) { - bufferlist bl; - bl.append(data, len); int flags = PUT_OBJ_CREATE; if (exclusive) flags |= PUT_OBJ_EXCL; - return put_system_obj_impl(obj, len, mtime, attrs, flags, bl, objv_tracker, set_mtime); + return put_system_obj_impl(obj, data.length(), mtime, attrs, flags, data, objv_tracker, set_mtime); } int aio_wait(void *handle); bool aio_completed(void *handle); diff --git a/src/rgw/rgw_role.cc b/src/rgw/rgw_role.cc index 5c67e0980a525..8fe173d9cffe4 100644 --- a/src/rgw/rgw_role.cc +++ b/src/rgw/rgw_role.cc @@ -31,7 +31,7 @@ int RGWRole::store_info(bool exclusive) bufferlist bl; encode(*this, bl); return rgw_put_system_obj(store, store->get_zone_params().roles_pool, oid, - bl.c_str(), bl.length(), exclusive, NULL, real_time(), NULL); + bl, exclusive, NULL, real_time(), NULL); } int RGWRole::store_name(bool exclusive) @@ -45,15 +45,16 @@ int RGWRole::store_name(bool exclusive) using ceph::encode; encode(nameToId, bl); return rgw_put_system_obj(store, store->get_zone_params().roles_pool, oid, - bl.c_str(), bl.length(), exclusive, NULL, real_time(), NULL); + bl, exclusive, NULL, real_time(), NULL); } int RGWRole::store_path(bool exclusive) { string oid = tenant + get_path_oid_prefix() + path + get_info_oid_prefix() + id; + bufferlist bl; return rgw_put_system_obj(store, store->get_zone_params().roles_pool, oid, - NULL, 0, exclusive, NULL, real_time(), NULL); + bl, exclusive, NULL, real_time(), NULL); } int RGWRole::create(bool exclusive) diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index 088fcc622e3cd..504bb18421220 100644 --- a/src/rgw/rgw_tools.cc +++ b/src/rgw/rgw_tools.cc @@ -18,7 +18,7 @@ static std::map* ext_mime_map; -int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, const char *data, size_t size, bool exclusive, +int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, bufferlist& data, bool exclusive, RGWObjVersionTracker *objv_tracker, real_time set_mtime, map *pattrs) { map no_attrs; @@ -27,12 +27,12 @@ int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& o rgw_raw_obj obj(pool, oid); - int ret = rgwstore->put_system_obj(NULL, obj, data, size, exclusive, NULL, *pattrs, objv_tracker, set_mtime); + int ret = rgwstore->put_system_obj(NULL, obj, data, exclusive, NULL, *pattrs, objv_tracker, set_mtime); if (ret == -ENOENT) { ret = rgwstore->create_pool(pool); if (ret >= 0) - ret = rgwstore->put_system_obj(NULL, obj, data, size, exclusive, NULL, *pattrs, objv_tracker, set_mtime); + ret = rgwstore->put_system_obj(NULL, obj, data, exclusive, NULL, *pattrs, objv_tracker, set_mtime); } return ret; diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h index 00f404a6d1ca6..d9d3f1484e18a 100644 --- a/src/rgw/rgw_tools.h +++ b/src/rgw/rgw_tools.h @@ -16,7 +16,7 @@ struct RGWObjVersionTracker; struct obj_version; -int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, const char *data, size_t size, bool exclusive, +int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, bufferlist& data, bool exclusive, RGWObjVersionTracker *objv_tracker, real_time set_mtime, map *pattrs = NULL); int rgw_get_system_obj(RGWRados *rgwstore, RGWObjectCtx& obj_ctx, const rgw_pool& pool, const string& key, bufferlist& bl, RGWObjVersionTracker *objv_tracker, real_time *pmtime, map *pattrs = NULL, diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index cc0af138bebd0..9f4de11935d0a 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -209,7 +209,7 @@ int rgw_store_user_info(RGWRados *store, if (!old_info || old_info->user_email.compare(info.user_email) != 0) { /* only if new index changed */ ret = rgw_put_system_obj(store, store->get_zone_params().user_email_pool, info.user_email, - link_bl.c_str(), link_bl.length(), exclusive, NULL, real_time()); + link_bl, exclusive, NULL, real_time()); if (ret < 0) return ret; } @@ -223,8 +223,7 @@ int rgw_store_user_info(RGWRados *store, continue; ret = rgw_put_system_obj(store, store->get_zone_params().user_keys_pool, k.id, - link_bl.c_str(), link_bl.length(), exclusive, - NULL, real_time()); + link_bl, exclusive, NULL, real_time()); if (ret < 0) return ret; } @@ -237,8 +236,7 @@ int rgw_store_user_info(RGWRados *store, continue; ret = rgw_put_system_obj(store, store->get_zone_params().user_swift_pool, k.id, - link_bl.c_str(), link_bl.length(), exclusive, - NULL, real_time()); + link_bl, exclusive, NULL, real_time()); if (ret < 0) return ret; } -- 2.39.5