annotate src/os/unix/ngx_file_aio_read.c @ 7660:d33e17499088

Version bump.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 26 May 2020 22:03:00 +0300
parents 7f035fd1ec7b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4133
diff changeset
4 * Copyright (C) Nginx, Inc.
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_event.h>
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 /*
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 * FreeBSD file AIO features and quirks:
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 *
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 * if an asked data are already in VM cache, then aio_error() returns 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 * and the data are already copied in buffer;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 *
3065
113cd532b328 aio sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
19 * aio_read() preread in VM cache as minimum 16K (probably BKVASIZE);
113cd532b328 aio sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
20 * the first AIO preload may be up to 128K;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 *
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 * aio_read/aio_error() may return EINPROGRESS for just written data;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 *
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 * kqueue EVFILT_AIO filter is level triggered only: an event repeats
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 * until aio_return() will be called;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 *
4133
59b99f217c6d Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents: 4076
diff changeset
27 * aio_cancel() cannot cancel file AIO: it returns AIO_NOTCANCELED always.
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 */
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 extern int ngx_kqueue;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 static ssize_t ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 ngx_event_t *ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 static void ngx_file_aio_event_handler(ngx_event_t *ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
5980
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
39 ngx_int_t
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
40 ngx_file_aio_init(ngx_file_t *file, ngx_pool_t *pool)
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
41 {
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
42 ngx_event_aio_t *aio;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
43
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
44 aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t));
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
45 if (aio == NULL) {
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
46 return NGX_ERROR;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
47 }
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
48
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
49 aio->file = file;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
50 aio->fd = file->fd;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
51 aio->event.data = aio;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
52 aio->event.ready = 1;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
53 aio->event.log = file->log;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
54
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
55 file->aio = aio;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
56
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
57 return NGX_OK;
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
58 }
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
59
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
60
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 ssize_t
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 ngx_pool_t *pool)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 {
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
65 int n;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
66 ngx_event_t *ev;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
67 ngx_event_aio_t *aio;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
69 if (!ngx_file_aio) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 return ngx_read_file(file, buf, size, offset);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72
5980
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
73 if (file->aio == NULL && ngx_file_aio_init(file, pool) != NGX_OK) {
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
74 return NGX_ERROR;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76
5980
ccad84a174e0 Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents: 4415
diff changeset
77 aio = file->aio;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 ev = &aio->event;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 if (!ev->ready) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 ngx_log_error(NGX_LOG_ALERT, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 "second aio post for \"%V\"", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 return NGX_AGAIN;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
6480
f01ab2dbcfdc Fixed logging.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5980
diff changeset
87 "aio complete:%d @%O:%uz %V",
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 ev->complete, offset, size, &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 if (ev->complete) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 ev->complete = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 ngx_set_errno(aio->err);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 if (aio->err == 0) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 return aio->nbytes;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
4076
37da005a5808 Bugfix: open_file_cache lost is_directio flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3294
diff changeset
98 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
37da005a5808 Bugfix: open_file_cache lost is_directio flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3294
diff changeset
99 "aio read \"%s\" failed", file->name.data);
37da005a5808 Bugfix: open_file_cache lost is_directio flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3294
diff changeset
100
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 ngx_memzero(&aio->aiocb, sizeof(struct aiocb));
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 aio->aiocb.aio_fildes = file->fd;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 aio->aiocb.aio_offset = offset;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 aio->aiocb.aio_buf = buf;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 aio->aiocb.aio_nbytes = size;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 #if (NGX_HAVE_KQUEUE)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
7448
7f035fd1ec7b Fixed portability issues with union sigval.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6480
diff changeset
113 aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 #endif
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 ev->handler = ngx_file_aio_event_handler;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117 n = aio_read(&aio->aiocb);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 if (n == -1) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 n = ngx_errno;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 if (n == NGX_EAGAIN) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 return ngx_read_file(file, buf, size, offset);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 ngx_log_error(NGX_LOG_CRIT, file->log, n,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 "aio_read(\"%V\") failed", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 if (n == NGX_ENOSYS) {
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
130 ngx_file_aio = 0;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 return ngx_read_file(file, buf, size, offset);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 "aio_read: fd:%d %d", file->fd, n);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 ev->active = 1;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 ev->ready = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 ev->complete = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 return ngx_file_aio_result(aio->file, aio, ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 static ssize_t
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio, ngx_event_t *ev)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 int n;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 ngx_err_t err;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 n = aio_error(&aio->aiocb);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 "aio_error: fd:%d %d", file->fd, n);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 if (n == -1) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 err = ngx_errno;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 aio->err = err;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 ngx_log_error(NGX_LOG_ALERT, file->log, err,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 "aio_error(\"%V\") failed", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
168 if (n == NGX_EINPROGRESS) {
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
169 if (ev->ready) {
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
170 ev->ready = 0;
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
171 ngx_log_error(NGX_LOG_ALERT, file->log, n,
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
172 "aio_read(\"%V\") still in progress",
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
173 &file->name);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
176 return NGX_AGAIN;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 n = aio_return(&aio->aiocb);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 if (n == -1) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 err = ngx_errno;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 aio->err = err;
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
184 ev->ready = 1;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
186 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 "aio_return(\"%V\") failed", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 aio->err = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 aio->nbytes = n;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 ev->ready = 1;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 ev->active = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 "aio_return: fd:%d %d", file->fd, n);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 return n;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 static void
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204 ngx_file_aio_event_handler(ngx_event_t *ev)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 ngx_event_aio_t *aio;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 aio = ev->data;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ev->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 "aio event handler fd:%d %V", aio->fd, &aio->file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 if (ngx_file_aio_result(aio->file, aio, ev) != NGX_AGAIN) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 aio->handler(ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 }