Skip to content

Commit 15f09b2

Browse files
committed
Inline the AIOCTX structure inside the task.
1 parent 60e6c82 commit 15f09b2

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

fs/aio.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,17 @@ signed int aioctx_get_pending_event(struct aioctx *ctx, unsigned int index, stru
207207
return 0;
208208
}
209209

210-
struct aioctx_table *aioctx_table_new(unsigned int capacity) {
211-
struct aioctx_table *tbl = malloc(sizeof(struct aioctx_table));
212-
if (tbl == NULL) return NULL;
210+
signed int aioctx_table_new(struct aioctx_table *tbl, unsigned int capacity) {
211+
if (tbl == NULL) return _EINVAL;
213212

214213
tbl->capacity = 0;
215214
tbl->contexts = NULL;
216215
lock_init(&tbl->lock);
217216

218217
int err = _aioctx_table_ensure(tbl, capacity);
219-
if (err < 0) return ERR_PTR(err);
218+
if (err < 0) return err;
220219

221-
return tbl;
220+
return 0;
222221
}
223222

224223
void aioctx_table_delete(struct aioctx_table *tbl) {

fs/aio.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ struct aioctx_table {
129129
struct aioctx **contexts;
130130
};
131131

132-
struct aioctx_table *aioctx_table_new(unsigned int capacity);
132+
// In-place construct an AIO context table.
133+
//
134+
// Returns an error value if internal table buffers could not be allocated.
135+
signed int aioctx_table_new(struct aioctx_table *tbl, unsigned int capacity);
136+
137+
// In-place destroy an AIO context table.
133138
void aioctx_table_delete(struct aioctx_table *tbl);
134139

135140
// Insert an AIO context into a given table.

kernel/aio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dword_t sys_io_setup(dword_t nr_events, addr_t ctx_idp) {
3737
if (ctx == NULL) return _ENOMEM;
3838
if (IS_ERR(ctx)) return PTR_ERR(ctx);
3939

40-
int ctx_id = aioctx_table_insert(current->aioctx, ctx);
40+
int ctx_id = aioctx_table_insert(&current->aioctx, ctx);
4141
aioctx_release(ctx);
4242
if (ctx_id < 0) {
4343
return ctx_id;
@@ -53,7 +53,7 @@ dword_t sys_io_setup(dword_t nr_events, addr_t ctx_idp) {
5353
dword_t sys_io_destroy(dword_t ctx_id) {
5454
STRACE("io_destroy(%d)", ctx_id);
5555

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

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

@@ -115,7 +115,7 @@ dword_t sys_io_submit(dword_t ctx_id, dword_t u_nr, addr_t iocbpp) {
115115

116116
if (nr < 0) return _EINVAL;
117117

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

121121
sdword_t i;

kernel/fork.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ static int copy_task(struct task *task, dword_t flags, addr_t stack, addr_t ptid
123123
task->clear_tid = ctid_addr;
124124
task->exit_signal = flags & CSIGNAL_;
125125

126-
task->aioctx = aioctx_table_new(0);
127-
if (IS_ERR(task->aioctx)) {
128-
err = PTR_ERR(task->aioctx);
126+
err = aioctx_table_new(&task->aioctx, 0);
127+
if (err < 0) {
129128
goto fail_free_sighand;
130129
}
131130

kernel/init.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ static struct task *construct_task(struct task *parent) {
7272
task_set_mm(task, mm_new());
7373
task->sighand = sighand_new();
7474
task->files = fdtable_new(3); // why is there a 3 here
75-
task->aioctx = aioctx_table_new(0);
75+
76+
signed int err = aioctx_table_new(&task->aioctx, 0);
77+
if (err < 0) return ERR_PTR(err);
7678

7779
task->fs = fs_info_new();
7880
task->fs->umask = 0022;

kernel/task.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct task *task_create_(struct task *parent) {
9393
void task_destroy(struct task *task) {
9494
list_remove(&task->siblings);
9595
pid_get(task->pid)->task = NULL;
96-
aioctx_table_delete(task->aioctx);
96+
aioctx_table_delete(&task->aioctx);
9797
free(task);
9898
}
9999

kernel/task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct task {
3838
struct fs_info *fs;
3939

4040
// Currently active AIO contexts. Contains internal lock.
41-
struct aioctx_table *aioctx;
41+
struct aioctx_table aioctx;
4242

4343
// locked by sighand->lock
4444
struct sighand *sighand;

0 commit comments

Comments
 (0)