Skip to content

Commit

Permalink
stat: Add param to identify storage reservation type
Browse files Browse the repository at this point in the history
We have three knobs to control storage reservation:
1. The knob/param to set storage reservation for apps. The same value
   for both the skopeo and docker storage even if they are located on
   different volumes.
2. The knob to set `min-free-space-percent` parameter of the sysroot's
   ostree repo. This value is used by libostree during committing/adding
   an object to a repo. The check occurs per each object, just before
   adding it.
3. The knob to set the reserved space value that is used before pulling
   an ostree commit if static delta statistic is available.

Therefore, we need a way to identify these three types of knobs. For
example, it's useful to see in the storage usage statistic which of the
knobs is applied in a given case.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Sep 1, 2023
1 parent 3b1d331 commit 3bd3326
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/rootfstreemanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ std::tuple<bool, std::string> RootfsTreeManager::prePullCheck(const DeltaStat& d
bool ok{true};

try {
storage::Volume::getUsageInfo(sysroot_->repoPath(), sysroot_->reservedStorageSpacePercentageDelta(), usage_info);
storage::Volume::getUsageInfo(sysroot_->repoPath(), sysroot_->reservedStorageSpacePercentageDelta(),
OSTree::Sysroot::Config::ReservedStorageSpacePercentageDeltaParamName, usage_info);
ok = usage_info.available.first >= delta_stat.uncompressedSize;
msg << "required: " << usage_info.toRelativeType(delta_stat.uncompressedSize) << ", " << usage_info;
} catch (const std::exception& exc) {
Expand Down
8 changes: 5 additions & 3 deletions src/storage/stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ static void getStat(const std::string& path, Stat& stat) {
stat.blockSize = fs_stat.f_bsize; // f_frsize == f_bsize on the linux-based systems
}

void Volume::getUsageInfo(const std::string& path, unsigned int reserved_percentage, UsageInfo& usage_info) {
void Volume::getUsageInfo(const std::string& path, unsigned int reserved_percentage, const std::string& reserved_by,
UsageInfo& usage_info) {
Stat stat{};
getStat(path, stat);

Expand All @@ -50,6 +51,7 @@ void Volume::getUsageInfo(const std::string& path, unsigned int reserved_percent
(usage_info.free.first > usage_info.reserved.first) ? (usage_info.free.first - usage_info.reserved.first) : 0,
(usage_info.free.second > usage_info.reserved.second) ? (usage_info.free.second - usage_info.reserved.second)
: 0};
usage_info.reserved_by = reserved_by;
}

Volume::UsageInfo::Type Volume::UsageInfo::toRelativeType(const uint64_t& val) const {
Expand All @@ -68,8 +70,8 @@ ostream& operator<<(ostream& os, const storage::Volume::UsageInfo::Type& t) {
}

ostream& operator<<(ostream& os, const storage::Volume::UsageInfo& t) {
os << "path " << t.path << ", size: " << t.size << ", free: " << t.free << ", reserved: " << t.reserved
<< ", available: " << t.available;
os << "path " << t.path << ", size: " << t.size << ", free: " << t.free << ", reserved: " << t.reserved << "(by `"
<< t.reserved_by << "`), available: " << t.available;
return os;
}

Expand Down
4 changes: 3 additions & 1 deletion src/storage/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ struct Volume {
Type free;
Type reserved;
Type available;
std::string reserved_by;

Type toRelativeType(const uint64_t& val) const;
};

static void getUsageInfo(const std::string& path, unsigned int reserved_percentage, UsageInfo& usage_info);
static void getUsageInfo(const std::string& path, unsigned int reserved_percentage, const std::string& reserved_by,
UsageInfo& usage_info);
};

} // namespace storage
Expand Down
8 changes: 5 additions & 3 deletions tests/nospace_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ TEST(StorageStat, UsageInfo) {
uint64_t block_numb{100};
unsigned int free_percentage{15};
unsigned int reserved_percentage{10};
const auto reserved_by{"ostree_min_free_space"};

storage::Volume::UsageInfo::Type free{std::ceil(block_numb * (free_percentage / 100.0)) * block_size,
free_percentage};
Expand All @@ -94,11 +95,12 @@ TEST(StorageStat, UsageInfo) {
SetBlockSize(block_size);
SetFreeBlockNumb(std::ceil(block_numb * (free_percentage / 100.0)), block_numb);
storage::Volume::UsageInfo usage_info;
storage::Volume::getUsageInfo("./", reserved_percentage, usage_info);
storage::Volume::getUsageInfo("./", reserved_percentage, reserved_by, usage_info);
ASSERT_EQ(free, usage_info.free) << usage_info.free.first;
ASSERT_EQ(reserved, usage_info.reserved) << usage_info.free.first;
ASSERT_EQ((free.first - reserved.first), usage_info.available.first) << usage_info.available.first;
ASSERT_EQ((free.second - reserved.second), usage_info.available.second) << usage_info.available.second;
ASSERT_EQ(reserved_by, usage_info.reserved_by) << usage_info.reserved_by;
}
{
// The same amount of free and reserved space
Expand All @@ -117,7 +119,7 @@ TEST(StorageStat, UsageInfo) {
SetBlockSize(block_size);
SetFreeBlockNumb(std::ceil(block_numb * (free_percentage / 100.0)), block_numb);
storage::Volume::UsageInfo usage_info;
storage::Volume::getUsageInfo("./", reserved_percentage, usage_info);
storage::Volume::getUsageInfo("./", reserved_percentage, "", usage_info);
ASSERT_EQ(free, usage_info.free) << usage_info.free.first;
ASSERT_EQ(reserved, usage_info.reserved) << usage_info.reserved.first;
ASSERT_EQ((free.first - reserved.first), usage_info.available.first) << usage_info.available.first;
Expand All @@ -141,7 +143,7 @@ TEST(StorageStat, UsageInfo) {
SetBlockSize(block_size);
SetFreeBlockNumb(std::ceil(block_numb * (free_percentage / 100.0)), block_numb);
storage::Volume::UsageInfo usage_info;
storage::Volume::getUsageInfo("./", reserved_percentage, usage_info);
storage::Volume::getUsageInfo("./", reserved_percentage, "", usage_info);
ASSERT_EQ(free, usage_info.free) << usage_info.free.first;
ASSERT_EQ(reserved, usage_info.reserved) << usage_info.reserved.first;
ASSERT_EQ(storage::Volume::UsageInfo::Type(0, 0), usage_info.available) << usage_info.available.first;
Expand Down

0 comments on commit 3bd3326

Please sign in to comment.