Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libos/include/libos_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct libos_process {
LISTP_TYPE(libos_child_process) zombies;

struct libos_lock children_lock;

/* If g_dcache_lock is also required, acquire g_dcache_lock first and then fs_lock */
struct libos_lock fs_lock;

/* Complete command line for the process, as reported by /proc/[pid]/cmdline; currently filled
Expand Down
10 changes: 0 additions & 10 deletions libos/src/bookkeep/libos_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,6 @@ int set_new_fd_handle_above_fd(uint32_t fd, struct libos_handle* hdl, int fd_fla
return __set_new_fd_handle(fd, hdl, fd_flags, handle_map, /*find_first=*/true);
}

static inline __attribute__((unused)) const char* __handle_name(struct libos_handle* hdl) {
if (hdl->uri)
return hdl->uri;
if (hdl->dentry && hdl->dentry->name[0] != '\0')
return hdl->dentry->name;
if (hdl->fs)
return hdl->fs->name;
return "(unknown)";
}

void get_handle(struct libos_handle* hdl) {
refcount_inc(&hdl->ref_count);
}
Expand Down
15 changes: 11 additions & 4 deletions libos/src/sys/libos_getcwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,33 @@ long libos_syscall_fchdir(int fd) {
if (!hdl)
return -EBADF;

int ret;
lock(&g_dcache_lock);

struct libos_dentry* dent = hdl->dentry;

if (!dent) {
log_debug("FD=%d has no path in the filesystem", fd);
return -ENOTDIR;
ret = -ENOTDIR;
goto out;
}
if (!dent->inode || dent->inode->type != S_IFDIR) {
char* path = NULL;
dentry_abs_path(dent, &path, /*size=*/NULL);
log_debug("%s is not a directory", path);
free(path);
put_handle(hdl);
return -ENOTDIR;
ret = -ENOTDIR;
goto out;
}

lock(&g_process.fs_lock);
get_dentry(dent);
put_dentry(g_process.cwd);
g_process.cwd = dent;
unlock(&g_process.fs_lock);
ret = 0;
out:
put_handle(hdl);
return 0;
unlock(&g_dcache_lock);
return ret;
}
5 changes: 3 additions & 2 deletions libos/src/sys/libos_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ static ssize_t do_getdents(int fd, uint8_t* buf, size_t buf_size, bool is_getden
goto out_no_unlock;
}

lock(&g_dcache_lock);
if (!hdl->dentry->inode) {
ret = -ENOENT;
goto out_no_unlock;
goto out_unlock_only_dcache_lock;
}

lock(&g_dcache_lock);
maybe_lock_pos_handle(hdl);
lock(&hdl->lock);

Expand Down Expand Up @@ -467,6 +467,7 @@ static ssize_t do_getdents(int fd, uint8_t* buf, size_t buf_size, bool is_getden
out:
unlock(&hdl->lock);
maybe_unlock_pos_handle(hdl);
out_unlock_only_dcache_lock:
unlock(&g_dcache_lock);
out_no_unlock:
put_handle(hdl);
Expand Down