Skip to content

Commit

Permalink
[LibOS] Fix dentry of open files after rename
Browse files Browse the repository at this point in the history
Signed-off-by: g2flyer <michael.steiner@intel.com>
  • Loading branch information
g2flyer committed Sep 3, 2024
1 parent 32a2511 commit b4b13dd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libos/src/sys/libos_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,31 @@ static int do_rename(struct libos_dentry* old_dent, struct libos_dentry* new_den

if (new_dent->inode)
put_inode(new_dent->inode);

new_dent->inode = old_dent->inode;
old_dent->inode = NULL;

/* also update dentry of any potentially open fd pointing to old_dent */
struct libos_handle_map* handle_map = get_thread_handle_map(NULL);
assert(handle_map != NULL);
rwlock_read_lock(&handle_map->lock);

for (uint32_t i = 0; handle_map->fd_top != FD_NULL && i <= handle_map->fd_top; i++) {
struct libos_fd_handle* fd_handle = handle_map->map[i];
if (!HANDLE_ALLOCATED(fd_handle))
continue;
struct libos_handle* handle = fd_handle->handle;
/* see comment in libos_handle.h on loocking strategy protecting handle->lock */
assert(locked(&g_dcache_lock));
lock(&handle->lock);
if ((handle->dentry == old_dent) && (handle->inode == new_dent->inode)) {
handle->dentry = new_dent;
put_dentry(old_dent);
get_dentry(new_dent);
}
unlock(&handle->lock);
}
rwlock_read_unlock(&handle_map->lock);
return 0;
}

Expand Down

0 comments on commit b4b13dd

Please sign in to comment.