core: add truncate function to file class
This commit is contained in:
@@ -56,6 +56,7 @@ public:
|
||||
virtual future<size_t> read_dma(uint64_t pos, std::vector<iovec> iov) = 0;
|
||||
virtual future<> flush(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;
|
||||
virtual future<size_t> size(void) = 0;
|
||||
virtual subscription<directory_entry> list_directory(std::function<future<> (directory_entry de)> next) = 0;
|
||||
@@ -79,6 +80,7 @@ public:
|
||||
future<size_t> read_dma(uint64_t pos, std::vector<iovec> iov);
|
||||
future<> flush(void);
|
||||
future<struct stat> stat(void);
|
||||
future<> truncate(uint64_t length);
|
||||
future<> discard(uint64_t offset, uint64_t length);
|
||||
future<size_t> size(void);
|
||||
virtual subscription<directory_entry> list_directory(std::function<future<> (directory_entry de)> next) override;
|
||||
@@ -87,6 +89,7 @@ public:
|
||||
class blockdev_file_impl : public posix_file_impl {
|
||||
public:
|
||||
blockdev_file_impl(int fd) : posix_file_impl(fd) {}
|
||||
future<> truncate(uint64_t length) override;
|
||||
future<> discard(uint64_t offset, uint64_t length) override;
|
||||
future<size_t> size(void) override;
|
||||
};
|
||||
@@ -136,6 +139,10 @@ public:
|
||||
return _file_impl->stat();
|
||||
}
|
||||
|
||||
future<> truncate(uint64_t length) {
|
||||
return _file_impl->truncate(length);
|
||||
}
|
||||
|
||||
future<> discard(uint64_t offset, uint64_t length) {
|
||||
return _file_impl->discard(offset, length);
|
||||
}
|
||||
|
||||
@@ -424,6 +424,21 @@ posix_file_impl::stat(void) {
|
||||
});
|
||||
}
|
||||
|
||||
future<>
|
||||
posix_file_impl::truncate(uint64_t length) {
|
||||
return engine()._thread_pool.submit<syscall_result<int>>([this, length] {
|
||||
return wrap_syscall<int>(::ftruncate(_fd, length));
|
||||
}).then([] (syscall_result<int> sr) {
|
||||
sr.throw_if_error();
|
||||
return make_ready_future<>();
|
||||
});
|
||||
}
|
||||
|
||||
future<>
|
||||
blockdev_file_impl::truncate(uint64_t length) {
|
||||
return make_ready_future<>();
|
||||
}
|
||||
|
||||
future<>
|
||||
posix_file_impl::discard(uint64_t offset, uint64_t length) {
|
||||
return engine()._thread_pool.submit<syscall_result<int>>([this, offset, length] () mutable {
|
||||
|
||||
Reference in New Issue
Block a user