Commit 269a0a8c authored by Marc Vef's avatar Marc Vef
Browse files

To be investigated further: Avoid race condition and segfault during read/write

parent 13ef8009
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -1045,10 +1045,12 @@ gkfs_pwrite(int fd, const void* buf, size_t count, off64_t offset) {
 */
 */
ssize_t
ssize_t
gkfs_write(int fd, const void* buf, size_t count) {
gkfs_write(int fd, const void* buf, size_t count) {
    auto gkfs_file = CTX->file_map()->get(fd);
    auto gkfs_fd = CTX->file_map()->get(fd);
    if(!gkfs_fd)
        return 0;
    // call pwrite and update pos
    // call pwrite and update pos
    auto ret = gkfs_write_ws(*gkfs_file, reinterpret_cast<const char*>(buf),
    auto ret = gkfs_write_ws(*gkfs_fd, reinterpret_cast<const char*>(buf),
                             count, gkfs_file->pos(), true);
                             count, gkfs_fd->pos(), true);
    return ret;
    return ret;
}
}


@@ -1217,6 +1219,8 @@ gkfs_pread(int fd, void* buf, size_t count, off64_t offset) {
ssize_t
ssize_t
gkfs_read(int fd, void* buf, size_t count) {
gkfs_read(int fd, void* buf, size_t count) {
    auto gkfs_fd = CTX->file_map()->get(fd);
    auto gkfs_fd = CTX->file_map()->get(fd);
    if(!gkfs_fd)
        return 0;
    auto pos = gkfs_fd->pos(); // retrieve the current offset
    auto pos = gkfs_fd->pos(); // retrieve the current offset
    auto ret = gkfs_read_ws(*gkfs_fd, reinterpret_cast<char*>(buf), count, pos);
    auto ret = gkfs_read_ws(*gkfs_fd, reinterpret_cast<char*>(buf), count, pos);
    // Update offset in file descriptor in the file map
    // Update offset in file descriptor in the file map