Loading CHANGELOG.md +1 −0 Original line number Original line Diff line number Diff line Loading @@ -12,6 +12,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Additional tests to increase code coverage ([!141](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/141)). - Additional tests to increase code coverage ([!141](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/141)). - GKFS_ENABLE_UNUSED_FUNCTIONS added to disable code to increase code coverage. - GKFS_ENABLE_UNUSED_FUNCTIONS added to disable code to increase code coverage. - Updated Parallax version to new API (parallax option needs kv_format.parallax in the path, and the database in a device with O_DIRECT) - Updated Parallax version to new API (parallax option needs kv_format.parallax in the path, and the database in a device with O_DIRECT) - Support for increasing file size via `truncate()` added ([!159](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/159) ### Changed ### Changed Loading src/client/gkfs_functions.cpp +25 −4 Original line number Original line Diff line number Diff line Loading @@ -143,6 +143,7 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { errno = ENOTSUP; errno = ENOTSUP; return -1; return -1; } } // metadata object filled during create or stat // metadata object filled during create or stat gkfs::metadata::Metadata md{}; gkfs::metadata::Metadata md{}; if(flags & O_CREAT) { if(flags & O_CREAT) { Loading Loading @@ -578,10 +579,28 @@ gkfs_truncate(const std::string& path, off_t length) { auto size = md->size(); auto size = md->size(); if(static_cast<unsigned long>(length) > size) { if(static_cast<unsigned long>(length) > size) { LOG(DEBUG, "Length is greater then file size: {} > {}", length, size); LOG(DEBUG, "Length is greater then file size: '{}' > '{}'", length, size); auto output_fd = gkfs_open(path, md->mode(), O_WRONLY); if(output_fd == -1) { errno = EINVAL; errno = EINVAL; return -1; return -1; } } gkfs_lseek(output_fd, 0, SEEK_END); ssize_t n = static_cast<unsigned long>(length) - size; // Zeroes the buffer. All make_* are value initialized auto buf = std::make_unique<char[]>(n); if(!buf) { errno = ENOMEM; return -1; } if(gkfs_write(output_fd, buf.get(), (size_t) n) != n) { errno = EINVAL; return -1; } CTX->file_map()->remove(output_fd); return 0; } return gkfs_truncate(path, size, length); return gkfs_truncate(path, size, length); } } Loading Loading @@ -677,8 +696,10 @@ ssize_t gkfs_write(int fd, const void* buf, size_t count) { gkfs_write(int fd, const void* buf, size_t count) { auto gkfs_fd = CTX->file_map()->get(fd); auto gkfs_fd = CTX->file_map()->get(fd); auto pos = gkfs_fd->pos(); // retrieve the current offset auto pos = gkfs_fd->pos(); // retrieve the current offset if(gkfs_fd->get_flag(gkfs::filemap::OpenFile_flags::append)) if(gkfs_fd->get_flag(gkfs::filemap::OpenFile_flags::append)) { gkfs_lseek(gkfs_fd, 0, SEEK_END); gkfs_lseek(gkfs_fd, 0, SEEK_END); pos = gkfs_fd->pos(); // Pos should be updated with append } auto ret = gkfs_pwrite(gkfs_fd, reinterpret_cast<const char*>(buf), count, auto ret = gkfs_pwrite(gkfs_fd, reinterpret_cast<const char*>(buf), count, pos); pos); // Update offset in file descriptor in the file map // Update offset in file descriptor in the file map Loading tests/integration/data/test_truncate.py +6 −2 Original line number Original line Diff line number Diff line Loading @@ -150,7 +150,11 @@ def test_fail_truncate(gkfs_daemon, gkfs_client): # Truncate to a size greater than the file size # Truncate to a size greater than the file size ret = gkfs_client.truncate(truncfile, buf_length + 1) ret = gkfs_client.truncate(truncfile, buf_length + 1) assert ret.retval == -1 assert ret.retval == 0 assert ret.errno == errno.EINVAL # Size should increase ret = gkfs_client.stat(truncfile) assert ret.statbuf.st_size == buf_length+1 Loading
CHANGELOG.md +1 −0 Original line number Original line Diff line number Diff line Loading @@ -12,6 +12,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Additional tests to increase code coverage ([!141](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/141)). - Additional tests to increase code coverage ([!141](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/141)). - GKFS_ENABLE_UNUSED_FUNCTIONS added to disable code to increase code coverage. - GKFS_ENABLE_UNUSED_FUNCTIONS added to disable code to increase code coverage. - Updated Parallax version to new API (parallax option needs kv_format.parallax in the path, and the database in a device with O_DIRECT) - Updated Parallax version to new API (parallax option needs kv_format.parallax in the path, and the database in a device with O_DIRECT) - Support for increasing file size via `truncate()` added ([!159](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/159) ### Changed ### Changed Loading
src/client/gkfs_functions.cpp +25 −4 Original line number Original line Diff line number Diff line Loading @@ -143,6 +143,7 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { errno = ENOTSUP; errno = ENOTSUP; return -1; return -1; } } // metadata object filled during create or stat // metadata object filled during create or stat gkfs::metadata::Metadata md{}; gkfs::metadata::Metadata md{}; if(flags & O_CREAT) { if(flags & O_CREAT) { Loading Loading @@ -578,10 +579,28 @@ gkfs_truncate(const std::string& path, off_t length) { auto size = md->size(); auto size = md->size(); if(static_cast<unsigned long>(length) > size) { if(static_cast<unsigned long>(length) > size) { LOG(DEBUG, "Length is greater then file size: {} > {}", length, size); LOG(DEBUG, "Length is greater then file size: '{}' > '{}'", length, size); auto output_fd = gkfs_open(path, md->mode(), O_WRONLY); if(output_fd == -1) { errno = EINVAL; errno = EINVAL; return -1; return -1; } } gkfs_lseek(output_fd, 0, SEEK_END); ssize_t n = static_cast<unsigned long>(length) - size; // Zeroes the buffer. All make_* are value initialized auto buf = std::make_unique<char[]>(n); if(!buf) { errno = ENOMEM; return -1; } if(gkfs_write(output_fd, buf.get(), (size_t) n) != n) { errno = EINVAL; return -1; } CTX->file_map()->remove(output_fd); return 0; } return gkfs_truncate(path, size, length); return gkfs_truncate(path, size, length); } } Loading Loading @@ -677,8 +696,10 @@ ssize_t gkfs_write(int fd, const void* buf, size_t count) { gkfs_write(int fd, const void* buf, size_t count) { auto gkfs_fd = CTX->file_map()->get(fd); auto gkfs_fd = CTX->file_map()->get(fd); auto pos = gkfs_fd->pos(); // retrieve the current offset auto pos = gkfs_fd->pos(); // retrieve the current offset if(gkfs_fd->get_flag(gkfs::filemap::OpenFile_flags::append)) if(gkfs_fd->get_flag(gkfs::filemap::OpenFile_flags::append)) { gkfs_lseek(gkfs_fd, 0, SEEK_END); gkfs_lseek(gkfs_fd, 0, SEEK_END); pos = gkfs_fd->pos(); // Pos should be updated with append } auto ret = gkfs_pwrite(gkfs_fd, reinterpret_cast<const char*>(buf), count, auto ret = gkfs_pwrite(gkfs_fd, reinterpret_cast<const char*>(buf), count, pos); pos); // Update offset in file descriptor in the file map // Update offset in file descriptor in the file map Loading
tests/integration/data/test_truncate.py +6 −2 Original line number Original line Diff line number Diff line Loading @@ -150,7 +150,11 @@ def test_fail_truncate(gkfs_daemon, gkfs_client): # Truncate to a size greater than the file size # Truncate to a size greater than the file size ret = gkfs_client.truncate(truncfile, buf_length + 1) ret = gkfs_client.truncate(truncfile, buf_length + 1) assert ret.retval == -1 assert ret.retval == 0 assert ret.errno == errno.EINVAL # Size should increase ret = gkfs_client.stat(truncfile) assert ret.statbuf.st_size == buf_length+1