1 | /* 13.t - uses testdir/rwfile |
---|
2 | - Submit multiple writes larger than aio-max-size (deadlocks on older |
---|
3 | aio code) |
---|
4 | */ |
---|
5 | #include "aio_setup.h" |
---|
6 | |
---|
7 | #include <sys/time.h> |
---|
8 | #include <sys/resource.h> |
---|
9 | #include <unistd.h> |
---|
10 | |
---|
11 | int test_main(void) |
---|
12 | { |
---|
13 | #define SIZE (1024 * 1024) |
---|
14 | #define IOS 8 |
---|
15 | struct iocb iocbs[IOS]; |
---|
16 | struct iocb *iocb_list[IOS]; |
---|
17 | char *bufs[IOS]; |
---|
18 | int rwfd; |
---|
19 | int status = 0, res; |
---|
20 | int i; |
---|
21 | |
---|
22 | rwfd = open("testdir/rwfile", O_RDWR|O_CREAT|O_TRUNC, 0600); |
---|
23 | assert(rwfd != -1); |
---|
24 | res = ftruncate(rwfd, 0); assert(res == 0); |
---|
25 | |
---|
26 | for (i=0; i<IOS; i++) { |
---|
27 | bufs[i] = malloc(SIZE); |
---|
28 | assert(bufs[i] != NULL); |
---|
29 | memset(bufs[i], 0, SIZE); |
---|
30 | |
---|
31 | io_prep_pwrite(&iocbs[i], rwfd, bufs[i], SIZE, i * SIZE); |
---|
32 | iocb_list[i] = &iocbs[i]; |
---|
33 | } |
---|
34 | |
---|
35 | status |= attempt_io_submit(io_ctx, IOS, iocb_list, IOS); |
---|
36 | |
---|
37 | for (i=0; i<IOS; i++) { |
---|
38 | struct timespec ts = { tv_sec: 30, tv_nsec: 0 }; |
---|
39 | struct io_event event; |
---|
40 | struct iocb *iocb; |
---|
41 | |
---|
42 | res = io_getevents(io_ctx, 0, 1, &event, &ts); |
---|
43 | if (res != 1) { |
---|
44 | status |= 1; |
---|
45 | printf("io_getevents failed [%d] with res=%d [%s]\n", |
---|
46 | i, res, (res < 0) ? strerror(-res) : "okay"); |
---|
47 | break; |
---|
48 | } |
---|
49 | |
---|
50 | if (event.res != SIZE) |
---|
51 | status |= 1; |
---|
52 | |
---|
53 | iocb = (void *)event.obj; |
---|
54 | printf("event[%d]: write[%d] %s, returned: %ld [%s]\n", |
---|
55 | i, (int)(iocb - &iocbs[0]), |
---|
56 | (event.res != SIZE) ? "failed" : "okay", |
---|
57 | (long)event.res, |
---|
58 | (event.res < 0) ? strerror(-event.res) : "okay" |
---|
59 | ); |
---|
60 | } |
---|
61 | |
---|
62 | res = ftruncate(rwfd, 0); assert(res == 0); |
---|
63 | res = close(rwfd); assert(res == 0); |
---|
64 | return status; |
---|
65 | } |
---|
66 | |
---|