From: Pritha Srivastava Date: Tue, 31 Oct 2023 06:41:30 +0000 (+0530) Subject: rgw/cache: fixing update_attrs and get_attrs in ssd backed cache backend. X-Git-Tag: v20.0.0~2219^2~57 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07ca4051519b6805900ad3e86d2f14bb47dfa8b6;p=ceph.git 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 --- diff --git a/src/rgw/rgw_ssd_driver.cc b/src/rgw/rgw_ssd_driver.cc index c6e974d65139..8dea916d71ff 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 @@ -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) <