From 8b80074ccb5f3ab04a4ea5128a5816be37b93d4d Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 10 Jan 2018 09:37:02 -0500 Subject: [PATCH 1/2] 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 d50782dfb3d..66aa0489eb0 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 cca45ea3814..0d79e58f07a 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 a3682eb147d..8f4b7d1fcf2 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 5c67e0980a5..8fe173d9cff 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 088fcc622e3..504bb184212 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 00f404a6d1c..d9d3f1484e1 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 cc0af138beb..9f4de11935d 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; } From 4f72b20f09fcbe0cec0cdfd020ca370d6707fc8d Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 12 Jan 2018 13:41:50 -0500 Subject: [PATCH 2/2] rgw: RGWRados::put_system_obj takes const bufferlist Signed-off-by: Casey Bodley --- src/rgw/rgw_cache.h | 8 ++++---- src/rgw/rgw_rados.cc | 4 ++-- src/rgw/rgw_rados.h | 8 ++++---- src/rgw/rgw_tools.cc | 2 +- src/rgw/rgw_tools.h | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index 3089723913d..4691232d03d 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -233,10 +233,10 @@ public: RGWObjVersionTracker *objv_tracker); int put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, real_time *mtime, map& attrs, int flags, - bufferlist& data, + const bufferlist& data, RGWObjVersionTracker *objv_tracker, real_time set_mtime) override; - int put_system_obj_data(void *ctx, rgw_raw_obj& obj, bufferlist& bl, off_t ofs, bool exclusive, + int put_system_obj_data(void *ctx, rgw_raw_obj& obj, const bufferlist& bl, off_t ofs, bool exclusive, RGWObjVersionTracker *objv_tracker = nullptr) override; int get_system_obj(RGWObjectCtx& obj_ctx, RGWRados::SystemObject::Read::GetObjState& read_state, @@ -393,7 +393,7 @@ int RGWCache::system_obj_set_attrs(void *ctx, rgw_raw_obj& obj, template int RGWCache::put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, real_time *mtime, map& attrs, int flags, - bufferlist& data, + const bufferlist& data, RGWObjVersionTracker *objv_tracker, real_time set_mtime) { @@ -431,7 +431,7 @@ int RGWCache::put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, real_time } template -int RGWCache::put_system_obj_data(void *ctx, rgw_raw_obj& obj, bufferlist& data, off_t ofs, bool exclusive, +int RGWCache::put_system_obj_data(void *ctx, rgw_raw_obj& obj, const bufferlist& data, off_t ofs, bool exclusive, RGWObjVersionTracker *objv_tracker) { rgw_pool pool; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 0d79e58f07a..16346d77b39 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -7124,7 +7124,7 @@ int RGWRados::Object::Write::write_meta(uint64_t size, uint64_t accounted_size, /** Write/overwrite a system object. */ int RGWRados::put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, real_time *mtime, map& attrs, int flags, - bufferlist& data, + const bufferlist& data, RGWObjVersionTracker *objv_tracker, real_time set_mtime /* 0 for don't set */) { @@ -7185,7 +7185,7 @@ int RGWRados::put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, real_time *mt return 0; } -int RGWRados::put_system_obj_data(void *ctx, rgw_raw_obj& obj, bufferlist& bl, +int RGWRados::put_system_obj_data(void *ctx, rgw_raw_obj& obj, const bufferlist& bl, off_t ofs, bool exclusive, RGWObjVersionTracker *objv_tracker) { diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 8f4b7d1fcf2..0aaff9a2610 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -3040,17 +3040,17 @@ public: /** Write/overwrite an object to the bucket storage. */ virtual int put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, ceph::real_time *mtime, map& attrs, int flags, - bufferlist& data, + const bufferlist& data, RGWObjVersionTracker *objv_tracker, ceph::real_time set_mtime /* 0 for don't set */); - virtual int put_system_obj_data(void *ctx, rgw_raw_obj& obj, bufferlist& bl, - off_t ofs, bool exclusive, + virtual int put_system_obj_data(void *ctx, rgw_raw_obj& obj, + const bufferlist& bl, off_t ofs, bool exclusive, RGWObjVersionTracker *objv_tracker = nullptr); 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, bufferlist& data, bool exclusive, + int put_system_obj(void *ctx, rgw_raw_obj& obj, const bufferlist& data, bool exclusive, ceph::real_time *mtime, map& attrs, RGWObjVersionTracker *objv_tracker, ceph::real_time set_mtime) { int flags = PUT_OBJ_CREATE; diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index 504bb184212..886bb316d5c 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, bufferlist& data, bool exclusive, +int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, const bufferlist& data, bool exclusive, RGWObjVersionTracker *objv_tracker, real_time set_mtime, map *pattrs) { map no_attrs; diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h index d9d3f1484e1..1c12da8fde8 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, bufferlist& data, bool exclusive, +int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, const 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,