Klaus Demo nginx / 4134b48
Fixing Linux AIO syscalls return value handling: syscall(2) uses usual libc convention, it returns -1 on error and sets errno. Obsolete _syscall(2) returns negative value of error. Thanks to Hagai Avrahami. Igor Sysoev 10 years ago
2 changed file(s) with 19 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
183183 * into single eventfd() function with different number of parameters.
184184 */
185185
186 static long
186 static int
187187 io_setup(u_int nr_reqs, aio_context_t *ctx)
188188 {
189189 return syscall(SYS_io_setup, nr_reqs, ctx);
197197 }
198198
199199
200 static long
200 static int
201201 io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events,
202202 struct timespec *tmo)
203203 {
246246 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
247247 "eventfd: %d", ngx_eventfd);
248248
249 n = io_setup(1024, &ngx_aio_ctx);
250
251 if (n != 0) {
252 ngx_log_error(NGX_LOG_EMERG, cycle->log, -n, "io_setup() failed");
249 if (io_setup(1024, &ngx_aio_ctx) == -1) {
250
251 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
252 "io_setup() failed");
253253 return NGX_ERROR;
254254 }
255255
315315
316316 #if (NGX_HAVE_FILE_AIO)
317317
318 if (io_destroy(ngx_aio_ctx) != 0) {
318 if (io_destroy(ngx_aio_ctx) == -1) {
319319 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
320320 "io_destroy() failed");
321321 }
666666 static void
667667 ngx_epoll_eventfd_handler(ngx_event_t *ev)
668668 {
669 int n;
670 long i, events;
669 int n, events;
670 long i;
671671 uint64_t ready;
672672 ngx_err_t err;
673673 ngx_event_t *e;
737737 return;
738738 }
739739
740 /* events < 0 */
741 ngx_log_error(NGX_LOG_ALERT, ev->log, -events, "io_getevents() failed");
740 /* events == -1 */
741 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
742 "io_getevents() failed");
742743 return;
743744 }
744745 }
1515 static void ngx_file_aio_event_handler(ngx_event_t *ev);
1616
1717
18 static long
18 static int
1919 io_submit(aio_context_t ctx, long n, struct iocb **paiocb)
2020 {
2121 return syscall(SYS_io_submit, ctx, n, paiocb);
2626 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
2727 ngx_pool_t *pool)
2828 {
29 long n;
29 ngx_err_t err;
3030 struct iocb *piocb[1];
3131 ngx_event_t *ev;
3232 ngx_event_aio_t *aio;
9595
9696 piocb[0] = &aio->aiocb;
9797
98 n = io_submit(ngx_aio_ctx, 1, piocb);
99
100 if (n == 1) {
98 if (io_submit(ngx_aio_ctx, 1, piocb) == 1) {
10199 ev->active = 1;
102100 ev->ready = 0;
103101 ev->complete = 0;
105103 return NGX_AGAIN;
106104 }
107105
108 n = -n;
106 err = ngx_errno;
109107
110 if (n == NGX_EAGAIN) {
108 if (err == NGX_EAGAIN) {
111109 return ngx_read_file(file, buf, size, offset);
112110 }
113111
114 ngx_log_error(NGX_LOG_CRIT, file->log, n,
112 ngx_log_error(NGX_LOG_CRIT, file->log, err,
115113 "io_submit(\"%V\") failed", &file->name);
116114
117 if (n == NGX_ENOSYS) {
115 if (err == NGX_ENOSYS) {
118116 ngx_file_aio = 0;
119117 return ngx_read_file(file, buf, size, offset);
120118 }