Skip to content

Commit

Permalink
rgw/cache: fixing the free space available in ssd backed cache
Browse files Browse the repository at this point in the history
backend by taking into account the size of xattrs in addition to
the file size.

Signed-off-by: Pritha Srivastava <[email protected]>
  • Loading branch information
pritha-srivastava committed Apr 2, 2024
1 parent c38b8b2 commit 9f33580
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions src/rgw/rgw_ssd_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ int SSDDriver::remove_partition_info(Partition& info)
return partitions.erase(key);
}

SSDDriver::SSDDriver(Partition& partition_info) : partition_info(partition_info),
free_space(partition_info.size)
SSDDriver::SSDDriver(Partition& partition_info) : partition_info(partition_info)
{
add_partition_info(partition_info);
}
Expand Down Expand Up @@ -96,6 +95,10 @@ int SSDDriver::initialize(CephContext* cct, const DoutPrefixProvider* dpp)
aio_init(&ainit);
#endif

efs::space_info space = efs::space(partition_info.location);
//currently partition_info.size is unused
this->free_space = space.available;

return 0;
}

Expand Down Expand Up @@ -126,9 +129,6 @@ int SSDDriver::put(const DoutPrefixProvider* dpp, const std::string& key, buffer
return -errno;
}

efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;

if (attrs.size() > 0) {
r = set_attrs(dpp, key, attrs, y);
if (r < 0) {
Expand All @@ -137,6 +137,9 @@ int SSDDriver::put(const DoutPrefixProvider* dpp, const std::string& key, buffer
}
}

efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;

return 0;
}

Expand Down Expand Up @@ -410,11 +413,12 @@ int SSDDriver::update_attrs(const DoutPrefixProvider* dpp, const std::string& ke
ret = setxattr(location.c_str(), attr_name.c_str(), attr_val.c_str(), attr_val.size(), XATTR_REPLACE);
}
if (ret < 0) {
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;
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not modify attr value for attr name: " << attr_name << " key: " << key << " ERROR: " << cpp_strerror(errno) <<dendl;
return ret;
}
}
efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;
return 0;
}

Expand All @@ -426,10 +430,14 @@ int SSDDriver::delete_attrs(const DoutPrefixProvider* dpp, const std::string& ke
for (auto& it : del_attrs) {
auto ret = delete_attr(dpp, key, it.first);
if (ret < 0) {
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not remove attr value for attr name: " << it.first << " key: " << key << dendl;
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not remove attr value for attr name: " << it.first << " key: " << key << cpp_strerror(errno) << dendl;
return ret;
}
}

efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;

return 0;
}

Expand Down Expand Up @@ -477,11 +485,15 @@ int SSDDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key,
if (attr_val_bl.length() != 0) {
auto ret = set_attr(dpp, key, attr_name, attr_val_bl.c_str(), y);
if (ret < 0) {
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not set attr value for attr name: " << attr_name << " key: " << key << dendl;
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not set attr value for attr name: " << attr_name << " key: " << key << cpp_strerror(errno) << dendl;
return ret;
}
}
}

efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;

return 0;
}

Expand Down Expand Up @@ -518,27 +530,39 @@ std::string SSDDriver::get_attr(const DoutPrefixProvider* dpp, const std::string

int SSDDriver::set_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, const std::string& attr_val, optional_yield y)
{
int e;
std::string location = partition_info.location + key;
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;

ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): set_attr: key: " << attr_name << " val: " << attr_val << dendl;

int ret = setxattr(location.c_str(), attr_name.c_str(), attr_val.c_str(), attr_val.size(), 0);
auto ret = setxattr(location.c_str(), attr_name.c_str(), attr_val.c_str(), attr_val.size(), 0);
if (ret < 0) {
e = errno;
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): ERROR: " << cpp_strerror(e) << dendl;
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not set attr value for attr name: " << attr_name << " key: " << key << cpp_strerror(errno) << dendl;
return ret;
}

return ret;
efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;

return 0;
}

int SSDDriver::delete_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name)
{
std::string location = partition_info.location + key;
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;

return removexattr(location.c_str(), attr_name.c_str());
auto attr_val = get_attr(dpp, key, attr_name, null_yield); //need this for free space calculation.
auto ret = removexattr(location.c_str(), attr_name.c_str());
if (ret < 0) {
ldpp_dout(dpp, 0) << "SSDCache: " << __func__ << "(): could not remove attr value for attr name: " << attr_name << " key: " << key << cpp_strerror(errno) << dendl;
return ret;
}

efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;

return 0;
}

} } // namespace rgw::cache

0 comments on commit 9f33580

Please sign in to comment.