mirror of
https://github.com/nginx/nginx.git
synced 2025-06-08 02:02:38 +08:00
export aio presence knowledge to prevent using "aio sendfile",
if aio does not present
This commit is contained in:
parent
9b67ca0e41
commit
4121aa3440
@ -118,7 +118,7 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
ctx->filter_ctx = r;
|
ctx->filter_ctx = r;
|
||||||
|
|
||||||
#if (NGX_HAVE_FILE_AIO)
|
#if (NGX_HAVE_FILE_AIO)
|
||||||
if (clcf->aio) {
|
if (ngx_file_aio && clcf->aio) {
|
||||||
ctx->aio_handler = ngx_http_copy_aio_handler;
|
ctx->aio_handler = ngx_http_copy_aio_handler;
|
||||||
#if (NGX_HAVE_AIO_SENDFILE)
|
#if (NGX_HAVE_AIO_SENDFILE)
|
||||||
c->aio_sendfile = (clcf->aio == NGX_HTTP_AIO_SENDFILE);
|
c->aio_sendfile = (clcf->aio == NGX_HTTP_AIO_SENDFILE);
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r,
|
static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r,
|
||||||
ngx_http_cache_t *c);
|
ngx_http_cache_t *c);
|
||||||
|
static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r,
|
||||||
|
ngx_http_cache_t *c);
|
||||||
#if (NGX_HAVE_FILE_AIO)
|
#if (NGX_HAVE_FILE_AIO)
|
||||||
static void ngx_http_cache_aio_event_handler(ngx_event_t *ev);
|
static void ngx_http_cache_aio_event_handler(ngx_event_t *ev);
|
||||||
#endif
|
#endif
|
||||||
@ -330,36 +332,9 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
|
|||||||
|
|
||||||
c = r->cache;
|
c = r->cache;
|
||||||
|
|
||||||
#if (NGX_HAVE_FILE_AIO)
|
n = ngx_http_file_cache_aio_read(r, c);
|
||||||
{
|
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
if (n < 0) {
|
||||||
|
|
||||||
if (clcf->aio) {
|
|
||||||
n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
|
|
||||||
|
|
||||||
if (n == NGX_AGAIN) {
|
|
||||||
c->file.aio->data = r;
|
|
||||||
c->file.aio->handler = ngx_http_cache_aio_event_handler;
|
|
||||||
|
|
||||||
r->main->blocked++;
|
|
||||||
r->aio = 1;
|
|
||||||
|
|
||||||
return NGX_AGAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
n = ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
|
|
||||||
n = ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (n == NGX_ERROR) {
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,8 +407,46 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c)
|
||||||
|
{
|
||||||
#if (NGX_HAVE_FILE_AIO)
|
#if (NGX_HAVE_FILE_AIO)
|
||||||
|
ssize_t n;
|
||||||
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
|
|
||||||
|
if (!ngx_file_aio) {
|
||||||
|
goto noaio;
|
||||||
|
}
|
||||||
|
|
||||||
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
|
if (!clcf->aio) {
|
||||||
|
goto noaio;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
|
||||||
|
|
||||||
|
if (n != NGX_AGAIN) {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->file.aio->data = r;
|
||||||
|
c->file.aio->handler = ngx_http_cache_aio_event_handler;
|
||||||
|
|
||||||
|
r->main->blocked++;
|
||||||
|
r->aio = 1;
|
||||||
|
|
||||||
|
return NGX_AGAIN;
|
||||||
|
|
||||||
|
noaio:
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if (NGX_HAVE_FILE_AIO)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ngx_http_cache_aio_event_handler(ngx_event_t *ev)
|
ngx_http_cache_aio_event_handler(ngx_event_t *ev)
|
||||||
|
@ -39,12 +39,11 @@ ssize_t
|
|||||||
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
|
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
|
||||||
ngx_pool_t *pool)
|
ngx_pool_t *pool)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
ngx_event_t *ev;
|
ngx_event_t *ev;
|
||||||
ngx_event_aio_t *aio;
|
ngx_event_aio_t *aio;
|
||||||
static ngx_uint_t enosys = 0;
|
|
||||||
|
|
||||||
if (enosys) {
|
if (!ngx_file_aio) {
|
||||||
return ngx_read_file(file, buf, size, offset);
|
return ngx_read_file(file, buf, size, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +115,7 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
|
|||||||
"aio_read(\"%V\") failed", &file->name);
|
"aio_read(\"%V\") failed", &file->name);
|
||||||
|
|
||||||
if (n == NGX_ENOSYS) {
|
if (n == NGX_ENOSYS) {
|
||||||
enosys = 1;
|
ngx_file_aio = 0;
|
||||||
return ngx_read_file(file, buf, size, offset);
|
return ngx_read_file(file, buf, size, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,13 @@
|
|||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
|
#if (NGX_HAVE_FILE_AIO)
|
||||||
|
|
||||||
|
ngx_uint_t ngx_file_aio = 1;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
|
ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
|
||||||
{
|
{
|
||||||
|
@ -313,6 +313,8 @@ size_t ngx_fs_bsize(u_char *name);
|
|||||||
ssize_t ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size,
|
ssize_t ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size,
|
||||||
off_t offset, ngx_pool_t *pool);
|
off_t offset, ngx_pool_t *pool);
|
||||||
|
|
||||||
|
extern ngx_uint_t ngx_file_aio;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,13 +27,12 @@ ssize_t
|
|||||||
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
|
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
|
||||||
ngx_pool_t *pool)
|
ngx_pool_t *pool)
|
||||||
{
|
{
|
||||||
long n;
|
long n;
|
||||||
struct iocb *piocb[1];
|
struct iocb *piocb[1];
|
||||||
ngx_event_t *ev;
|
ngx_event_t *ev;
|
||||||
ngx_event_aio_t *aio;
|
ngx_event_aio_t *aio;
|
||||||
static ngx_uint_t enosys = 0;
|
|
||||||
|
|
||||||
if (enosys) {
|
if (!ngx_file_aio) {
|
||||||
return ngx_read_file(file, buf, size, offset);
|
return ngx_read_file(file, buf, size, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +108,7 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
|
|||||||
"io_submit(\"%V\") failed", &file->name);
|
"io_submit(\"%V\") failed", &file->name);
|
||||||
|
|
||||||
if (n == NGX_ENOSYS) {
|
if (n == NGX_ENOSYS) {
|
||||||
enosys = 1;
|
ngx_file_aio = 0;
|
||||||
return ngx_read_file(file, buf, size, offset);
|
return ngx_read_file(file, buf, size, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user