diff options
author | Pritha Srivastava <prsrivas@redhat.com> | 2023-10-31 07:41:30 +0100 |
---|---|---|
committer | Pritha Srivastava <prsrivas@redhat.com> | 2024-04-02 17:54:51 +0200 |
commit | 07ca4051519b6805900ad3e86d2f14bb47dfa8b6 (patch) | |
tree | f9be83cbaf01093fbb7c61356fe0d8aad078d617 /src/rgw/rgw_ssd_driver.cc | |
parent | rgw/d4n: copying over read op params of the filter driver to (diff) | |
download | ceph-07ca4051519b6805900ad3e86d2f14bb47dfa8b6.tar.xz ceph-07ca4051519b6805900ad3e86d2f14bb47dfa8b6.zip |
rgw/cache: fixing update_attrs and get_attrs in ssd backed cache backend.
update_attrs did not check whether an xattr already existed before
modifying it - added check for that. corrected converting bufferlist
to string.
get_attrs did not check whether attribute size is zero or negative -
added check for that.
Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
Diffstat (limited to 'src/rgw/rgw_ssd_driver.cc')
-rw-r--r-- | src/rgw/rgw_ssd_driver.cc | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/rgw/rgw_ssd_driver.cc b/src/rgw/rgw_ssd_driver.cc index c6e974d6513..8dea916d71f 100644 --- a/src/rgw/rgw_ssd_driver.cc +++ b/src/rgw/rgw_ssd_driver.cc @@ -1,4 +1,5 @@ #include "common/async/completion.h" +#include "common/errno.h" #include "rgw_ssd_driver.h" #if defined(__linux__) #include <features.h> @@ -399,11 +400,18 @@ int SSDDriver::update_attrs(const DoutPrefixProvider* dpp, const std::string& ke for (auto& it : attrs) { std::string attr_name, attr_val; - ceph::decode(attr_val, it.second); attr_name = it.first; - auto ret = setxattr(location.c_str(), attr_name.c_str(), attr_val.c_str(), attr_val.size(), XATTR_REPLACE); + attr_val = it.second.c_str(); + std::string old_attr_val = get_attr(dpp, key, attr_name, y); + int ret; + if (old_attr_val.empty()) { + ret = setxattr(location.c_str(), attr_name.c_str(), attr_val.c_str(), attr_val.size(), XATTR_CREATE); + } else { + ret = setxattr(location.c_str(), attr_name.c_str(), attr_val.c_str(), attr_val.size(), XATTR_REPLACE); + } if (ret < 0) { - ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not modify attr value for attr name: " << attr_name << " key: " << key << dendl; + auto e = errno; + ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not modify attr value for attr name: " << attr_name << " key: " << key << " ERROR: " << cpp_strerror(e) <<dendl; return ret; } } @@ -480,13 +488,23 @@ int SSDDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key, std::string SSDDriver::get_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, optional_yield y) { std::string location = partition_info.location + key; + std::string attr_val; ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl; ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): get_attr: key: " << attr_name << dendl; int attr_size = getxattr(location.c_str(), attr_name.c_str(), nullptr, 0); + if (attr_size < 0) { + auto ret = errno; + ldpp_dout(dpp, 0) << "ERROR: could not get attribute " << attr_name << ": " << cpp_strerror(ret) << dendl; + return attr_val; + } + + if (attr_size == 0) { + ldpp_dout(dpp, 0) << "ERROR: no attribute value found for attr_name: " << attr_name << dendl; + return attr_val; + } - std::string attr_val; attr_val.reserve(attr_size + 1); char* attr_val_ptr = &attr_val[0]; |