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: wrap syncfs syscall #47

Open
wants to merge 1 commit into
base: v23.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/seastar/core/file.hh
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public:
}

virtual future<> flush(void) = 0;
virtual future<> syncfs(void) = 0;
virtual future<struct stat> stat(void) = 0;
virtual future<> truncate(uint64_t length) = 0;
virtual future<> discard(uint64_t offset, uint64_t length) = 0;
Expand Down Expand Up @@ -374,6 +375,10 @@ public:
/// a flush, data is guaranteed to be on disk.
future<> flush() noexcept;

/// Causes any dirty data on any file on the same filesystem as this file to
/// be flushed to disk.
future<> syncfs() noexcept;

/// Returns \c stat information about the file.
future<struct stat> stat() noexcept;

Expand Down
1 change: 1 addition & 0 deletions include/seastar/core/reactor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ private:

future<struct stat> fstat(int fd) noexcept;
future<struct statfs> fstatfs(int fd) noexcept;
future<> syncfs(int fd) noexcept;
friend future<shared_ptr<file_impl>> make_file_impl(int fd, file_open_options options, int flags) noexcept;
public:
future<> readable(pollable_fd_state& fd);
Expand Down
1 change: 1 addition & 0 deletions src/core/file-impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected:
public:
virtual ~posix_file_impl() override;
future<> flush(void) noexcept override;
future<> syncfs(void) noexcept override;
future<struct stat> stat(void) noexcept override;
future<> truncate(uint64_t length) noexcept override;
future<> discard(uint64_t offset, uint64_t length) noexcept override;
Expand Down
13 changes: 13 additions & 0 deletions src/core/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ posix_file_impl::flush(void) noexcept {
return engine().fdatasync(_fd);
}

future<>
posix_file_impl::syncfs(void) noexcept {
return engine().syncfs(_fd);
}

future<struct stat>
posix_file_impl::stat() noexcept {
return engine().fstat(_fd);
Expand Down Expand Up @@ -1220,6 +1225,14 @@ future<> file::flush() noexcept {
}
}

future<> file::syncfs() noexcept {
try {
return _file_impl->syncfs();
} catch (...) {
return current_exception_as_future();
}
}

future<size_t> file::dma_write(uint64_t pos, std::vector<iovec> iov, const io_priority_class& pc, io_intent* intent) noexcept {
try {
return _file_impl->write_dma(pos, std::move(iov), pc, intent);
Expand Down
10 changes: 10 additions & 0 deletions src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,16 @@ reactor::fstatfs(int fd) noexcept {
});
}

future<>
reactor::syncfs(int fd) noexcept {
return _thread_pool->submit<syscall_result<int>>([fd] {
auto ret = ::syncfs(fd);
return wrap_syscall(ret);
}).then([] (syscall_result<int> sr) {
sr.throw_if_error();
});
}

future<struct statvfs>
reactor::statvfs(std::string_view pathname) noexcept {
// Allocating memory for a sstring can throw, hence the futurize_invoke
Expand Down