Skip to content

Commit

Permalink
Inline the AIOCTX structure inside the task.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmeisthax committed Nov 21, 2021
1 parent 60e6c82 commit 15f09b2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
9 changes: 4 additions & 5 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,17 @@ signed int aioctx_get_pending_event(struct aioctx *ctx, unsigned int index, stru
return 0;
}

struct aioctx_table *aioctx_table_new(unsigned int capacity) {
struct aioctx_table *tbl = malloc(sizeof(struct aioctx_table));
if (tbl == NULL) return NULL;
signed int aioctx_table_new(struct aioctx_table *tbl, unsigned int capacity) {
if (tbl == NULL) return _EINVAL;

tbl->capacity = 0;
tbl->contexts = NULL;
lock_init(&tbl->lock);

int err = _aioctx_table_ensure(tbl, capacity);
if (err < 0) return ERR_PTR(err);
if (err < 0) return err;

return tbl;
return 0;
}

void aioctx_table_delete(struct aioctx_table *tbl) {
Expand Down
7 changes: 6 additions & 1 deletion fs/aio.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ struct aioctx_table {
struct aioctx **contexts;
};

struct aioctx_table *aioctx_table_new(unsigned int capacity);
// In-place construct an AIO context table.
//
// Returns an error value if internal table buffers could not be allocated.
signed int aioctx_table_new(struct aioctx_table *tbl, unsigned int capacity);

// In-place destroy an AIO context table.
void aioctx_table_delete(struct aioctx_table *tbl);

// Insert an AIO context into a given table.
Expand Down
8 changes: 4 additions & 4 deletions kernel/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dword_t sys_io_setup(dword_t nr_events, addr_t ctx_idp) {
if (ctx == NULL) return _ENOMEM;
if (IS_ERR(ctx)) return PTR_ERR(ctx);

int ctx_id = aioctx_table_insert(current->aioctx, ctx);
int ctx_id = aioctx_table_insert(&current->aioctx, ctx);
aioctx_release(ctx);
if (ctx_id < 0) {
return ctx_id;
Expand All @@ -53,7 +53,7 @@ dword_t sys_io_setup(dword_t nr_events, addr_t ctx_idp) {
dword_t sys_io_destroy(dword_t ctx_id) {
STRACE("io_destroy(%d)", ctx_id);

int err = aioctx_table_remove(current->aioctx, ctx_id) < 0;
int err = aioctx_table_remove(&current->aioctx, ctx_id) < 0;
if (err < 0) {
return err;
}
Expand All @@ -64,7 +64,7 @@ dword_t sys_io_destroy(dword_t ctx_id) {
dword_t sys_io_getevents(dword_t ctx_id, dword_t min_nr, dword_t nr, addr_t events, addr_t timeout_addr) {
STRACE("io_getevents(0x%x, %d, %d, 0x%x, 0x%x)", ctx_id, min_nr, nr, events, timeout_addr);

struct aioctx *ctx = aioctx_table_get_and_retain(current->aioctx, ctx_id);
struct aioctx *ctx = aioctx_table_get_and_retain(&current->aioctx, ctx_id);
if (ctx == NULL) return _EINVAL;
if (events == 0) return _EFAULT;

Expand Down Expand Up @@ -115,7 +115,7 @@ dword_t sys_io_submit(dword_t ctx_id, dword_t u_nr, addr_t iocbpp) {

if (nr < 0) return _EINVAL;

struct aioctx *ctx = aioctx_table_get_and_retain(current->aioctx, ctx_id);
struct aioctx *ctx = aioctx_table_get_and_retain(&current->aioctx, ctx_id);
if (ctx == NULL) return _EINVAL;

sdword_t i;
Expand Down
5 changes: 2 additions & 3 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ static int copy_task(struct task *task, dword_t flags, addr_t stack, addr_t ptid
task->clear_tid = ctid_addr;
task->exit_signal = flags & CSIGNAL_;

task->aioctx = aioctx_table_new(0);
if (IS_ERR(task->aioctx)) {
err = PTR_ERR(task->aioctx);
err = aioctx_table_new(&task->aioctx, 0);
if (err < 0) {
goto fail_free_sighand;
}

Expand Down
4 changes: 3 additions & 1 deletion kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ static struct task *construct_task(struct task *parent) {
task_set_mm(task, mm_new());
task->sighand = sighand_new();
task->files = fdtable_new(3); // why is there a 3 here
task->aioctx = aioctx_table_new(0);

signed int err = aioctx_table_new(&task->aioctx, 0);
if (err < 0) return ERR_PTR(err);

task->fs = fs_info_new();
task->fs->umask = 0022;
Expand Down
2 changes: 1 addition & 1 deletion kernel/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct task *task_create_(struct task *parent) {
void task_destroy(struct task *task) {
list_remove(&task->siblings);
pid_get(task->pid)->task = NULL;
aioctx_table_delete(task->aioctx);
aioctx_table_delete(&task->aioctx);
free(task);
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct task {
struct fs_info *fs;

// Currently active AIO contexts. Contains internal lock.
struct aioctx_table *aioctx;
struct aioctx_table aioctx;

// locked by sighand->lock
struct sighand *sighand;
Expand Down

0 comments on commit 15f09b2

Please sign in to comment.