~britco/nginx/master

« back to all changes in this revision

Viewing changes to src/os/unix/ngx_linux_aio_read.c

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry, Kartik Mistry, Michael Lustfield
  • Date: 2010-11-27 21:04:02 UTC
  • mfrom: (1.3.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20101127210402-14sgjpe6r3jup8a9
Tags: 0.8.53-1
[Kartik Mistry]
* debian/control:
  + Added Michael Lustfield as co-maintainer
* nginx.conf:
  + No need to use regex in gzip_disable for msie6, Thanks to António P. P.
    Almeida <appa@perusio.net> (Closes: #592147)
* conf/sites-available/default:
  + Fixed typo for "include fastcgi", Thanks to Mostafa Ghadamyari
    <nginx@gigfa.com> (Closes: #593142, #593143)
* debian/patches/fix_reloading_ipv6.diff:
  + Removed, merged upstream
* debian/init.d:
  + Added fix to control nginx by user in a simple way by setting DAEMON
    variable to an invalid name in /etc/default/nginx. Patch by Toni Mueller
    <support@oeko.net> (Closes: #594598)
* debian/NEWS.Debian:
  + Updated news for 0.8.x as stable branch

[Michael Lustfield]
* New upstream release (Closes: #602970)
  + 0.8.x branch is declared stable by upstream now
* Add a UFW profile set:
  + debian/nginx.ufw.profile: Added.
  + debian/control: nginx: Suggests ufw.
  + debian/dirs: Add 'etc/ufw/applications.d'
  + debian/rules: Add install rule for the nginx UFW profile.
* Moved debian/dirs to debian/nginx.dirs
* Added types_hash_max_size to nginx.conf
* Install simple default index.html file (Closes: #581416)
  + debian/dirs: Add 'usr/share/nginx/www'.
  + debian/nginx.install: Add 'html/* usr/share/nginx/www'.
* debian/patches/nginx-echo.diff:
  + Added Echo module
* Added files for nginx.docs
  - /usr/share/doc/nginx/
    + debian/help/docs/fcgiwrap
    + debian/help/docs/php
    + debian/help/docs/support-irc
    + debian/help/docs/upstream
* Added files for nginx.examples
  - /usr/share/doc/nginx/examples/
    + debian/help/docs/drupal
    + debian/help/docs/http
    + debian/help/docs/mail
    + debian/help/docs/mailman
    + debian/help/docs/nginx.conf
    + debian/help/docs/virtual_hosts
    + debian/help/docs/wordpress
* debian/conf/:
  + Removed excess spaces
  + Added tabs where appropriate
  + Added SCRIPT_FILENAME to fastcgi_params

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Copyright (C) Igor Sysoev
 
4
 */
 
5
 
 
6
 
 
7
#include <ngx_config.h>
 
8
#include <ngx_core.h>
 
9
#include <ngx_event.h>
 
10
 
 
11
 
 
12
extern int            ngx_eventfd;
 
13
extern aio_context_t  ngx_aio_ctx;
 
14
 
 
15
 
 
16
static void ngx_file_aio_event_handler(ngx_event_t *ev);
 
17
 
 
18
 
 
19
static long
 
20
io_submit(aio_context_t ctx, long n, struct iocb **paiocb)
 
21
{
 
22
    return syscall(SYS_io_submit, ctx, n, paiocb);
 
23
}
 
24
 
 
25
 
 
26
ssize_t
 
27
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
 
28
    ngx_pool_t *pool)
 
29
{
 
30
    long              n;
 
31
    struct iocb      *piocb[1];
 
32
    ngx_event_t      *ev;
 
33
    ngx_event_aio_t  *aio;
 
34
 
 
35
    if (!ngx_file_aio) {
 
36
        return ngx_read_file(file, buf, size, offset);
 
37
    }
 
38
 
 
39
    aio = file->aio;
 
40
 
 
41
    if (aio == NULL) {
 
42
        aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t));
 
43
        if (aio == NULL) {
 
44
            return NGX_ERROR;
 
45
        }
 
46
 
 
47
        aio->file = file;
 
48
        aio->fd = file->fd;
 
49
        aio->event.data = aio;
 
50
        aio->event.ready = 1;
 
51
        aio->event.log = file->log;
 
52
        file->aio = aio;
 
53
    }
 
54
 
 
55
    ev = &aio->event;
 
56
 
 
57
    if (!ev->ready) {
 
58
        ngx_log_error(NGX_LOG_ALERT, file->log, 0,
 
59
                      "second aio post for \"%V\"", &file->name);
 
60
        return NGX_AGAIN;
 
61
    }
 
62
 
 
63
    ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
 
64
                   "aio complete:%d @%O:%z %V",
 
65
                   ev->complete, offset, size, &file->name);
 
66
 
 
67
    if (ev->complete) {
 
68
        ev->active = 0;
 
69
        ev->complete = 0;
 
70
 
 
71
        if (aio->res >= 0) {
 
72
            ngx_set_errno(0);
 
73
            return aio->res;
 
74
        }
 
75
 
 
76
        ngx_set_errno(-aio->res);
 
77
        return NGX_ERROR;
 
78
    }
 
79
 
 
80
    ngx_memzero(&aio->aiocb, sizeof(struct iocb));
 
81
 
 
82
    aio->aiocb.aio_data = (uint64_t) (uintptr_t) ev;
 
83
    aio->aiocb.aio_lio_opcode = IOCB_CMD_PREAD;
 
84
    aio->aiocb.aio_fildes = file->fd;
 
85
    aio->aiocb.aio_buf = (uint64_t) (uintptr_t) buf;
 
86
    aio->aiocb.aio_nbytes = size;
 
87
    aio->aiocb.aio_offset = offset;
 
88
    aio->aiocb.aio_flags = IOCB_FLAG_RESFD;
 
89
    aio->aiocb.aio_resfd = ngx_eventfd;
 
90
 
 
91
    ev->handler = ngx_file_aio_event_handler;
 
92
 
 
93
    piocb[0] = &aio->aiocb;
 
94
 
 
95
    n = io_submit(ngx_aio_ctx, 1, piocb);
 
96
 
 
97
    if (n == 1) {
 
98
        ev->active = 1;
 
99
        ev->ready = 0;
 
100
        ev->complete = 0;
 
101
 
 
102
        return NGX_AGAIN;
 
103
    }
 
104
 
 
105
    n = -n;
 
106
 
 
107
    if (n == NGX_EAGAIN) {
 
108
        return ngx_read_file(file, buf, size, offset);
 
109
    }
 
110
 
 
111
    ngx_log_error(NGX_LOG_CRIT, file->log, n,
 
112
                  "io_submit(\"%V\") failed", &file->name);
 
113
 
 
114
    if (n == NGX_ENOSYS) {
 
115
        ngx_file_aio = 0;
 
116
        return ngx_read_file(file, buf, size, offset);
 
117
    }
 
118
 
 
119
    return NGX_ERROR;
 
120
}
 
121
 
 
122
 
 
123
static void
 
124
ngx_file_aio_event_handler(ngx_event_t *ev)
 
125
{
 
126
    ngx_event_aio_t  *aio;
 
127
 
 
128
    aio = ev->data;
 
129
 
 
130
    ngx_log_debug2(NGX_LOG_DEBUG_CORE, ev->log, 0,
 
131
                   "aio event handler fd:%d %V", aio->fd, &aio->file->name);
 
132
 
 
133
    aio->handler(ev);
 
134
}