From 3cc27f0ee6d00ef7a902d5d4b47df1bade020018 Mon Sep 17 00:00:00 2001 From: Pritha Srivastava Date: Mon, 28 Aug 2023 17:13:38 +0530 Subject: [PATCH] rgw/cache: This commit fixes two things in ssd backed cache backend: 1. fixing free space calcuation when data is deleted. 2. implementation of append_data(). Signed-off-by: Pritha Srivastava --- src/rgw/rgw_ssd_driver.cc | 42 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/rgw/rgw_ssd_driver.cc b/src/rgw/rgw_ssd_driver.cc index cf581fb1aaf89..b4862219544b6 100644 --- a/src/rgw/rgw_ssd_driver.cc +++ b/src/rgw/rgw_ssd_driver.cc @@ -179,6 +179,39 @@ 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) +{ + std::string location = partition_info.location + key; + + ldpp_dout(dpp, 20) << __func__ << "(): location=" << location << dendl; + FILE *cache_file = nullptr; + int r = 0; + size_t nbytes = 0; + + cache_file = fopen(location.c_str(), "a+"); + if (cache_file == nullptr) { + ldpp_dout(dpp, 0) << "ERROR: put::fopen file has return error, errno=" << errno << dendl; + return -errno; + } + + nbytes = fwrite(bl_data.c_str(), 1, bl_data.length(), cache_file); + if (nbytes != bl_data.length()) { + ldpp_dout(dpp, 0) << "ERROR: append_data: fwrite has returned error: nbytes!=len, nbytes=" << nbytes << ", len=" << bl_data.length() << dendl; + return -EIO; + } + + r = fclose(cache_file); + if (r != 0) { + ldpp_dout(dpp, 0) << "ERROR: append_data::fclose file has return error, errno=" << errno << dendl; + return -errno; + } + + efs::space_info space = efs::space(partition_info.location); + this->free_space = space.available; + + return 0; +} + template auto SSDDriver::AsyncReadOp::create(const Executor1& ex1, CompletionHandler&& handler) { @@ -281,15 +314,6 @@ int SSDDriver::delete_data(const DoutPrefixProvider* dpp, const::std::string& ke return 0; } -int SSDDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& key, bufferlist& bl_data, optional_yield y) -{ - std::string location = partition_info.location + key; - - //TODO - Implement append_data - - return 0; -} - int SSDDriver::AsyncWriteRequest::prepare_libaio_write_op(const DoutPrefixProvider *dpp, bufferlist& bl, unsigned int len, std::string key, std::string cache_location) { std::string location = cache_location + key; -- 2.39.5