Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file: add file_system_space #2597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bhalevy
Copy link
Member

@bhalevy bhalevy commented Dec 23, 2024

Return space_info for the filesystem identified
by the given file name.

space_info provides simpler and standard space information about the filesystem, in contrast to the posix statvfs which requires knowledge about the how to convert
f_block to bytes by multiplying by f_frsize.

Return space_info for the filesystem identified
by the given file name.

space_info provides simpler and standard space information
about the filesystem, in contrast to the posix statvfs
which requires knowledge about the how to convert
f_block to bytes by multiplying by f_frsize.

Signed-off-by: Benny Halevy <[email protected]>
@bhalevy bhalevy requested a review from xemul December 23, 2024 11:42
struct space_info {
std::uintmax_t capacity;
std::uintmax_t free_space;
std::uintmax_t available_space;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint64_t is sufficient, uintmax_t could be 128-but or whatever.

@@ -158,6 +159,18 @@ inline constexpr file_permissions operator&(file_permissions a, file_permissions
return file_permissions(std::underlying_type_t<file_permissions>(a) & std::underlying_type_t<file_permissions>(b));
}

/// seastar::space_info is equivalent to std::filesystem::space_info
/// with renamed members, to prevent a conflict with future::available()
struct space_info {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use std::filesystem::space_info?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned it in a comment.
The compiler complains about it due to the available member conflicting with future::available. I can reproduce and quote the error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can it conflict with future::available? It's in a different class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the problem.


bool operator==(const space_info& o) const noexcept {
return capacity == o.capacity && free_space == o.free_space && available_space == o.available_space;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= default

};
});
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use coroutines in new code.


BOOST_REQUIRE_EQUAL(st.f_blocks * st.f_frsize, si.capacity);
BOOST_REQUIRE_EQUAL(st.f_bfree * st.f_frsize, si.free_space);
BOOST_REQUIRE_EQUAL(st.f_bavail * st.f_frsize, si.available_space);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't guaranteed to pass. If a byte is added to the filesystem after assignment to si and removed after assignment to st, si == si1 && si != st.

There isn't a simple way to test this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without syncing the filesystem, it is auto-synced rarely (every 30 seconds?), so we shouldn't see these fluctuations in practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who says space is updated on sync?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants