From 5f12f1efd48211573e46bad87a4f3f933e818b6b Mon Sep 17 00:00:00 2001 From: samarah Date: Mon, 11 Dec 2023 14:48:32 -0500 Subject: [PATCH] rgw/cache: Make `bl` and `attrs` params `const` for cache write ops Signed-off-by: samarah --- src/rgw/rgw_cache_driver.h | 10 +++++----- src/rgw/rgw_redis_driver.cc | 25 ++++++++++++------------- src/rgw/rgw_redis_driver.h | 10 +++++----- src/rgw/rgw_ssd_driver.cc | 21 ++++++++++++--------- src/rgw/rgw_ssd_driver.h | 10 +++++----- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/rgw/rgw_cache_driver.h b/src/rgw/rgw_cache_driver.h index e6c0969fd32..a1995d110e6 100644 --- a/src/rgw/rgw_cache_driver.h +++ b/src/rgw/rgw_cache_driver.h @@ -18,16 +18,16 @@ class CacheDriver { virtual ~CacheDriver() = default; virtual int initialize(const DoutPrefixProvider* dpp) = 0; - virtual int put(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs, optional_yield y) = 0; + virtual int put(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs, optional_yield y) = 0; virtual int get(const DoutPrefixProvider* dpp, const std::string& key, off_t offset, uint64_t len, bufferlist& bl, rgw::sal::Attrs& attrs, optional_yield y) = 0; virtual int del(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) = 0; virtual rgw::AioResultList get_async (const DoutPrefixProvider* dpp, optional_yield y, rgw::Aio* aio, const std::string& key, off_t ofs, uint64_t len, uint64_t cost, uint64_t id) = 0; - virtual int put_async(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs) = 0; - virtual int append_data(const DoutPrefixProvider* dpp, const::std::string& key, bufferlist& bl_data, optional_yield y) = 0; + virtual int put_async(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs) = 0; + virtual int append_data(const DoutPrefixProvider* dpp, const::std::string& key, const bufferlist& bl_data, optional_yield y) = 0; virtual int delete_data(const DoutPrefixProvider* dpp, const::std::string& key, optional_yield y) = 0; virtual int get_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) = 0; - virtual int set_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) = 0; - virtual int update_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) = 0; + virtual int set_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) = 0; + virtual int update_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) = 0; virtual int delete_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& del_attrs, optional_yield y) = 0; virtual int get_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, std::string& attr_val, optional_yield y) = 0; virtual int set_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, const std::string& attr_val, optional_yield y) = 0; diff --git a/src/rgw/rgw_redis_driver.cc b/src/rgw/rgw_redis_driver.cc index 2b9e1dd387a..8158c595a6e 100644 --- a/src/rgw/rgw_redis_driver.cc +++ b/src/rgw/rgw_redis_driver.cc @@ -7,14 +7,13 @@ namespace rgw { namespace cache { -std::list build_attrs(rgw::sal::Attrs* binary) +std::list build_attrs(const rgw::sal::Attrs& binary) { std::list values; - rgw::sal::Attrs::iterator attrs; /* Convert to vector */ - if (binary != NULL) { - for (attrs = binary->begin(); attrs != binary->end(); ++attrs) { + if (!binary.empty()) { + for (auto attrs = binary.begin(); attrs != binary.end(); ++attrs) { values.push_back(attrs->first); values.push_back(attrs->second.to_str()); } @@ -81,7 +80,7 @@ int RedisDriver::initialize(const DoutPrefixProvider* dpp) return 0; } -int RedisDriver::put(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs, optional_yield y) +int RedisDriver::put(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs, optional_yield y) { std::string entry = partition_info.location + key; @@ -89,7 +88,7 @@ int RedisDriver::put(const DoutPrefixProvider* dpp, const std::string& key, buff try { boost::system::error_code ec; response resp; - auto redisAttrs = build_attrs(&attrs); + auto redisAttrs = build_attrs(attrs); if (bl.length()) { redisAttrs.push_back("data"); @@ -199,7 +198,7 @@ int RedisDriver::del(const DoutPrefixProvider* dpp, const std::string& key, opti return 0; } -int RedisDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& key, bufferlist& bl_data, optional_yield y) +int RedisDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& key, const bufferlist& bl_data, optional_yield y) { response exists; std::string value; @@ -347,7 +346,7 @@ int RedisDriver::get_attrs(const DoutPrefixProvider* dpp, const std::string& key return 0; } -int RedisDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) +int RedisDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) { if (attrs.empty()) return -1; @@ -359,7 +358,7 @@ int RedisDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key boost::system::error_code ec; response resp; std::string result; - std::list redisAttrs = build_attrs(&attrs); + std::list redisAttrs = build_attrs(attrs); request req; req.push_range("HMSET", entry, redisAttrs); @@ -376,14 +375,14 @@ int RedisDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key return 0; } -int RedisDriver::update_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) +int RedisDriver::update_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) { std::string entry = partition_info.location + key; try { boost::system::error_code ec; response resp; - auto redisAttrs = build_attrs(&attrs); + auto redisAttrs = build_attrs(attrs); request req; req.push_range("HMSET", entry, redisAttrs); @@ -407,7 +406,7 @@ int RedisDriver::delete_attrs(const DoutPrefixProvider* dpp, const std::string& try { boost::system::error_code ec; response resp; - auto redisAttrs = build_attrs(&del_attrs); + auto redisAttrs = build_attrs(del_attrs); request req; req.push_range("HDEL", entry, redisAttrs); @@ -524,7 +523,7 @@ rgw::AioResultList RedisDriver::get_async(const DoutPrefixProvider* dpp, optiona return aio->get(r_obj, redis_read_op(y, conn, ofs, len, entry), cost, id); } -int RedisDriver::put_async(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs) { +int RedisDriver::put_async(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs) { // TODO: implement return -1; } diff --git a/src/rgw/rgw_redis_driver.h b/src/rgw/rgw_redis_driver.h index b51924103cd..bf78496e573 100644 --- a/src/rgw/rgw_redis_driver.h +++ b/src/rgw/rgw_redis_driver.h @@ -33,16 +33,16 @@ class RedisDriver : public CacheDriver { virtual uint64_t get_free_space(const DoutPrefixProvider* dpp) override { return free_space; } virtual int initialize(const DoutPrefixProvider* dpp) override; - virtual int put(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs, optional_yield y) override; - virtual int put_async(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs) override; + virtual int put(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs, optional_yield y) override; + virtual int put_async(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs) override; virtual int get(const DoutPrefixProvider* dpp, const std::string& key, off_t offset, uint64_t len, bufferlist& bl, rgw::sal::Attrs& attrs, optional_yield y) override; virtual rgw::AioResultList get_async(const DoutPrefixProvider* dpp, optional_yield y, rgw::Aio* aio, const std::string& key, off_t ofs, uint64_t len, uint64_t cost, uint64_t id) override; virtual int del(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override; - virtual int append_data(const DoutPrefixProvider* dpp, const::std::string& key, bufferlist& bl_data, optional_yield y) override; + virtual int append_data(const DoutPrefixProvider* dpp, const::std::string& key, const bufferlist& bl_data, optional_yield y) override; virtual int delete_data(const DoutPrefixProvider* dpp, const::std::string& key, optional_yield y) override; - virtual int set_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) override; + virtual int set_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) override; virtual int get_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) override; - virtual int update_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) override; + virtual int update_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) override; virtual int delete_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& del_attrs, optional_yield y) override; virtual int set_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, const std::string& attr_val, optional_yield y) override; virtual int get_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, std::string& attr_val, optional_yield y) override; diff --git a/src/rgw/rgw_ssd_driver.cc b/src/rgw/rgw_ssd_driver.cc index 85a929c69fe..6c68877ff6a 100644 --- a/src/rgw/rgw_ssd_driver.cc +++ b/src/rgw/rgw_ssd_driver.cc @@ -52,8 +52,9 @@ int SSDDriver::initialize(const DoutPrefixProvider* dpp) return 0; } -int SSDDriver::put(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs, optional_yield y) +int SSDDriver::put(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs, optional_yield y) { + bufferlist src = bl; std::string location = partition_info.location + key; ldpp_dout(dpp, 20) << __func__ << "(): location=" << location << dendl; @@ -67,7 +68,7 @@ int SSDDriver::put(const DoutPrefixProvider* dpp, const std::string& key, buffer return -errno; } - nbytes = fwrite(bl.c_str(), 1, len, cache_file); + nbytes = fwrite(src.c_str(), 1, len, cache_file); if (nbytes != len) { ldpp_dout(dpp, 0) << "ERROR: put::io_write: fwrite has returned error: nbytes!=len, nbytes=" << nbytes << ", len=" << len << dendl; return -EIO; @@ -135,8 +136,9 @@ int SSDDriver::get(const DoutPrefixProvider* dpp, const std::string& key, off_t return 0; } -int SSDDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& key, bufferlist& bl_data, optional_yield y) +int SSDDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& key, const bufferlist& bl_data, optional_yield y) { + bufferlist src = bl_data; std::string location = partition_info.location + key; ldpp_dout(dpp, 20) << __func__ << "(): location=" << location << dendl; @@ -150,8 +152,8 @@ int SSDDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& ke return -errno; } - nbytes = fwrite(bl_data.c_str(), 1, bl_data.length(), cache_file); - if (nbytes != bl_data.length()) { + nbytes = fwrite(src.c_str(), 1, src.length(), cache_file); + if (nbytes != src.length()) { ldpp_dout(dpp, 0) << "ERROR: append_data: fwrite has returned error: nbytes!=len, nbytes=" << nbytes << ", len=" << bl_data.length() << dendl; return -EIO; } @@ -231,12 +233,13 @@ void SSDDriver::libaio_write_completion_cb(AsyncWriteRequest* c) this->free_space = space.available; } -int SSDDriver::put_async(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs) +int SSDDriver::put_async(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs) { ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): Write To Cache, oid=" << key << ", len=" << len << dendl; + bufferlist src = bl; struct AsyncWriteRequest* wr = new struct AsyncWriteRequest(dpp); int r = 0; - if ((r = wr->prepare_libaio_write_op(dpp, bl, len, key, partition_info.location)) < 0) { + if ((r = wr->prepare_libaio_write_op(dpp, src, len, key, partition_info.location)) < 0) { ldpp_dout(dpp, 0) << "ERROR: SSDCache: " << __func__ << "() prepare libaio write op r=" << r << dendl; return r; } @@ -348,7 +351,7 @@ void SSDDriver::AsyncReadOp::libaio_cb_aio_dispatch(sigval sigval) ceph::async::dispatch(std::move(p), ec, std::move(op.result)); } -int SSDDriver::update_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) +int SSDDriver::update_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) { std::string location = partition_info.location + key; ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl; @@ -426,7 +429,7 @@ int SSDDriver::get_attrs(const DoutPrefixProvider* dpp, const std::string& key, return 0; } -int SSDDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) +int SSDDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) { std::string location = partition_info.location + key; ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl; diff --git a/src/rgw/rgw_ssd_driver.h b/src/rgw/rgw_ssd_driver.h index 9d039cefd12..5ab82763e63 100644 --- a/src/rgw/rgw_ssd_driver.h +++ b/src/rgw/rgw_ssd_driver.h @@ -12,16 +12,16 @@ public: virtual ~SSDDriver() {} virtual int initialize(const DoutPrefixProvider* dpp) override; - virtual int put(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs, optional_yield y) override; + virtual int put(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs, optional_yield y) override; virtual int get(const DoutPrefixProvider* dpp, const std::string& key, off_t offset, uint64_t len, bufferlist& bl, rgw::sal::Attrs& attrs, optional_yield y) override; virtual int del(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override { return -1; } // TODO: implement virtual rgw::AioResultList get_async (const DoutPrefixProvider* dpp, optional_yield y, rgw::Aio* aio, const std::string& key, off_t ofs, uint64_t len, uint64_t cost, uint64_t id) override; - virtual int put_async(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs) override; - virtual int append_data(const DoutPrefixProvider* dpp, const::std::string& key, bufferlist& bl_data, optional_yield y) override; + virtual int put_async(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs) override; + virtual int append_data(const DoutPrefixProvider* dpp, const::std::string& key, const bufferlist& bl_data, optional_yield y) override; virtual int delete_data(const DoutPrefixProvider* dpp, const::std::string& key, optional_yield y) override; virtual int get_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) override; - virtual int set_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) override; - virtual int update_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y) override; + virtual int set_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) override; + virtual int update_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y) override; virtual int delete_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& del_attrs, optional_yield y) override; virtual int get_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, std::string& attr_val, optional_yield y) override; virtual int set_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, const std::string& attr_val, optional_yield y) override; -- 2.39.5