]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw/cache: Make `bl` and `attrs` params `const` for cache write ops
authorsamarah <suriarte@redhat.com>
Mon, 11 Dec 2023 19:48:32 +0000 (14:48 -0500)
committerPritha Srivastava <prsrivas@redhat.com>
Tue, 2 Apr 2024 15:54:52 +0000 (21:24 +0530)
Signed-off-by: samarah <suriarte@redhat.com>
src/rgw/rgw_cache_driver.h
src/rgw/rgw_redis_driver.cc
src/rgw/rgw_redis_driver.h
src/rgw/rgw_ssd_driver.cc
src/rgw/rgw_ssd_driver.h

index e6c0969fd322a4c9968d5e93ad451baa95cab028..a1995d110e660cd649a1ad8d1be886427e217773 100644 (file)
@@ -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;
index 2b9e1dd387a2916f7f42381bef76de9796664902..8158c595a6e2cc22a8dcdc73a6f725a3a0bcacc8 100644 (file)
@@ -7,14 +7,13 @@
 
 namespace rgw { namespace cache {
 
-std::list<std::string> build_attrs(rgw::sal::Attrs* binary) 
+std::list<std::string> build_attrs(const rgw::sal::Attrs& binary) 
 {
   std::list<std::string> 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<std::string> 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<int> 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<std::string> resp;
     std::string result;
-    std::list<std::string> redisAttrs = build_attrs(&attrs);
+    std::list<std::string> 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<std::string> 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<int> 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;
 } 
index b51924103cdabc69a81a3f714c462c8846d36978..bf78496e573e82b6f44e89cff89bd5378814e895 100644 (file)
@@ -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;
index 85a929c69fee3051965f17f8d5bc1fa2e39464ca..6c68877ff6ab6e87f8fc3da67836492914dd39d6 100644 (file)
@@ -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;
index 9d039cefd12090a28cd0cc15b7f832c061140736..5ab82763e63c661b847ffdc924bb5b73dda9b581 100644 (file)
@@ -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;