Skip to content

Commit 166ba45

Browse files
committed
[LibOS] Fix dentry of open files after rename
Signed-off-by: g2flyer <[email protected]>
1 parent a0b4832 commit 166ba45

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

libos/src/sys/libos_file.c

+23
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,31 @@ static int do_rename(struct libos_dentry* old_dent, struct libos_dentry* new_den
347347

348348
if (new_dent->inode)
349349
put_inode(new_dent->inode);
350+
350351
new_dent->inode = old_dent->inode;
351352
old_dent->inode = NULL;
353+
354+
/* also update dentry of any potentially open fd pointing to old_dent */
355+
struct libos_handle_map* handle_map = get_thread_handle_map(NULL);
356+
assert(handle_map != NULL);
357+
rwlock_read_lock(&handle_map->lock);
358+
359+
for (uint32_t i = 0; handle_map->fd_top != FD_NULL && i <= handle_map->fd_top; i++) {
360+
struct libos_fd_handle* fd_handle = handle_map->map[i];
361+
if (!HANDLE_ALLOCATED(fd_handle))
362+
continue;
363+
struct libos_handle* handle = fd_handle->handle;
364+
/* see comment in libos_handle.h on loocking strategy protecting handle->lock */
365+
assert(locked(&g_dcache_lock));
366+
lock(&handle->lock);
367+
if ((handle->dentry == old_dent) && (handle->inode == new_dent->inode)) {
368+
handle->dentry = new_dent;
369+
put_dentry(old_dent);
370+
get_dentry(new_dent);
371+
}
372+
unlock(&handle->lock);
373+
}
374+
rwlock_read_unlock(&handle_map->lock);
352375
return 0;
353376
}
354377

0 commit comments

Comments
 (0)