Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_files.c @ 6428:545b5e4d83b2
Upstream: avoid closing client connection in edge case.
If proxy_cache is enabled, and proxy_no_cache tests true, it was previously
possible for the client connection to be closed after a 304. The fix is to
recheck r->header_only after the final cacheability is determined, and end the
request if no longer cacheable.
Example configuration:
proxy_cache foo;
proxy_cache_bypass 1;
proxy_no_cache 1;
If a client sends If-None-Match, and the upstream server returns 200 with a
matching ETag, no body should be returned to the client. At the start of
ngx_http_upstream_send_response proxy_no_cache is not yet tested, thus cacheable
is still 1 and downstream_error is set.
However, by the time the downstream_error check is done in process_request,
proxy_no_cache has been tested and cacheable is set to 0. The client connection
is then closed, regardless of keepalive.
author | Justin Li <jli.justinli@gmail.com> |
---|---|
date | Tue, 08 Mar 2016 22:31:55 -0500 |
parents | 3832b608dc8d |
children | 9fd738b85fad |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
6 |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
33
b2e039840718
nginx-0.0.1-2002-12-19-20:49:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
8 #include <ngx_config.h> |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
9 #include <ngx_core.h> |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
10 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
11 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
12 #if (NGX_THREADS) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
13 #include <ngx_thread_pool.h> |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
14 static void ngx_thread_read_handler(void *data, ngx_log_t *log); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
15 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
16 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
17 static ngx_chain_t *ngx_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *cl); |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
18 static ssize_t ngx_writev_file(ngx_file_t *file, ngx_iovec_t *vec, |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
19 off_t offset); |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
20 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
21 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
22 #if (NGX_HAVE_FILE_AIO) |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
23 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
24 ngx_uint_t ngx_file_aio = 1; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
25 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
26 #endif |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
27 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
28 |
561 | 29 ssize_t |
30 ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
31 { |
561 | 32 ssize_t n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
34 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
461 | 35 "read: %d, %p, %uz, %O", file->fd, buf, size, offset); |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
36 |
469 | 37 #if (NGX_HAVE_PREAD) |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
38 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
39 n = pread(file->fd, buf, size, offset); |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
40 |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
41 if (n == -1) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
42 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
43 "pread() \"%s\" failed", file->name.data); |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
44 return NGX_ERROR; |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
45 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
46 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
47 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
48 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
49 if (file->sys_offset != offset) { |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
50 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
51 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
52 "lseek() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
53 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
54 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
55 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
56 file->sys_offset = offset; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
57 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
58 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
59 n = read(file->fd, buf, size); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
60 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
61 if (n == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
62 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
63 "read() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
64 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
65 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
66 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
67 file->sys_offset += n; |
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
68 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
69 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
70 |
35
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
71 file->offset += n; |
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
72 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
73 return n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 } |
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
76 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
77 #if (NGX_THREADS) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
78 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
79 typedef struct { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
80 ngx_fd_t fd; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
81 u_char *buf; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
82 size_t size; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
83 off_t offset; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
84 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
85 size_t read; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
86 ngx_err_t err; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
87 } ngx_thread_read_ctx_t; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
88 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
89 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
90 ssize_t |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
91 ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf, |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
92 size_t size, off_t offset, ngx_pool_t *pool) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
93 { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
94 ngx_thread_task_t *task; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
95 ngx_thread_read_ctx_t *ctx; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
96 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
97 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
98 "thread read: %d, %p, %uz, %O", |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
99 file->fd, buf, size, offset); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
100 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
101 task = *taskp; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
102 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
103 if (task == NULL) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
104 task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t)); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
105 if (task == NULL) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
106 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
107 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
108 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
109 task->handler = ngx_thread_read_handler; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
110 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
111 *taskp = task; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
112 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
113 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
114 ctx = task->ctx; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
115 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
116 if (task->event.complete) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
117 task->event.complete = 0; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
118 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
119 if (ctx->err) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
120 ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err, |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
121 "pread() \"%s\" failed", file->name.data); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
122 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
123 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
124 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
125 return ctx->read; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
126 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
127 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
128 ctx->fd = file->fd; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
129 ctx->buf = buf; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
130 ctx->size = size; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
131 ctx->offset = offset; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
132 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
133 if (file->thread_handler(task, file) != NGX_OK) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
134 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
135 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
136 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
137 return NGX_AGAIN; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
138 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
139 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
140 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
141 #if (NGX_HAVE_PREAD) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
142 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
143 static void |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
144 ngx_thread_read_handler(void *data, ngx_log_t *log) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
145 { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
146 ngx_thread_read_ctx_t *ctx = data; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
147 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
148 ssize_t n; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
149 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
150 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "thread read handler"); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
151 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
152 n = pread(ctx->fd, ctx->buf, ctx->size, ctx->offset); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
153 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
154 if (n == -1) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
155 ctx->err = ngx_errno; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
156 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
157 } else { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
158 ctx->read = n; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
159 ctx->err = 0; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
160 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
161 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
162 #if 0 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
163 ngx_time_update(); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
164 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
165 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
166 ngx_log_debug4(NGX_LOG_DEBUG_CORE, log, 0, |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
167 "pread: %z (err: %i) of %uz @%O", |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
168 n, ctx->err, ctx->size, ctx->offset); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
169 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
170 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
171 #else |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
172 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
173 #error pread() is required! |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
174 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
175 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
176 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
177 #endif /* NGX_THREADS */ |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
178 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
179 |
561 | 180 ssize_t |
181 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
182 { |
6299
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
183 ssize_t n, written; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
184 ngx_err_t err; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
185 |
461 | 186 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
187 "write: %d, %p, %uz, %O", file->fd, buf, size, offset); | |
188 | |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
189 written = 0; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
190 |
469 | 191 #if (NGX_HAVE_PWRITE) |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
192 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
193 for ( ;; ) { |
3657 | 194 n = pwrite(file->fd, buf + written, size, offset); |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
195 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
196 if (n == -1) { |
6299
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
197 err = ngx_errno; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
198 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
199 if (err == NGX_EINTR) { |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
200 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err, |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
201 "pwrite() was interrupted"); |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
202 continue; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
203 } |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
204 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
205 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
206 "pwrite() \"%s\" failed", file->name.data); |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
207 return NGX_ERROR; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
208 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
209 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
210 file->offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
211 written += n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
212 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
213 if ((size_t) n == size) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
214 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
215 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
216 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
217 offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
218 size -= n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
219 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
220 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
221 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
222 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
223 if (file->sys_offset != offset) { |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
224 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
225 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
226 "lseek() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
227 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
228 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
229 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
230 file->sys_offset = offset; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
231 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
232 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
233 for ( ;; ) { |
3657 | 234 n = write(file->fd, buf + written, size); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
235 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
236 if (n == -1) { |
6299
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
237 err = ngx_errno; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
238 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
239 if (err == NGX_EINTR) { |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
240 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err, |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
241 "write() was interrupted"); |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
242 continue; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
243 } |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
244 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
245 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
246 "write() \"%s\" failed", file->name.data); |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
247 return NGX_ERROR; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
248 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
249 |
6298
8f6d753c1953
Adjusted file->sys_offset after the write() syscall.
Valentin Bartenev <vbart@nginx.com>
parents:
6241
diff
changeset
|
250 file->sys_offset += n; |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
251 file->offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
252 written += n; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
253 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
254 if ((size_t) n == size) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
255 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
256 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
257 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
258 size -= n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
259 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
260 #endif |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
261 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
262 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
263 |
561 | 264 ngx_fd_t |
1046 | 265 ngx_open_tempfile(u_char *name, ngx_uint_t persistent, ngx_uint_t access) |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
266 { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
267 ngx_fd_t fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
268 |
1046 | 269 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, |
270 access ? access : 0600); | |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
271 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
272 if (fd != -1 && !persistent) { |
4794
4163fb9dcfcb
Explicitly ignore returned value from unlink() in ngx_open_tempfile().
Andrey Belov <defan@nginx.com>
parents:
4737
diff
changeset
|
273 (void) unlink((const char *) name); |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
274 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
275 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
276 return fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
277 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
278 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
279 |
561 | 280 ssize_t |
281 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
282 ngx_pool_t *pool) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
283 { |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
284 ssize_t total, n; |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
285 ngx_iovec_t vec; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
286 struct iovec iovs[NGX_IOVS_PREALLOCATE]; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
287 |
461 | 288 /* use pwrite() if there is the only buf in a chain */ |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
289 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
290 if (cl->next == NULL) { |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
291 return ngx_write_file(file, cl->buf->pos, |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
292 (size_t) (cl->buf->last - cl->buf->pos), |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
191
diff
changeset
|
293 offset); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
294 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
295 |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
296 total = 0; |
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
297 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
298 vec.iovs = iovs; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
299 vec.nalloc = NGX_IOVS_PREALLOCATE; |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
300 |
461 | 301 do { |
302 /* create the iovec and coalesce the neighbouring bufs */ | |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
303 cl = ngx_chain_to_iovec(&vec, cl); |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
304 |
461 | 305 /* use pwrite() if there is the only iovec buffer */ |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
306 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
307 if (vec.count == 1) { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
308 n = ngx_write_file(file, (u_char *) iovs[0].iov_base, |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
309 iovs[0].iov_len, offset); |
4221
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
310 |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
311 if (n == NGX_ERROR) { |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
312 return n; |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
313 } |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
314 |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
315 return total + n; |
461 | 316 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
317 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
318 n = ngx_writev_file(file, &vec, offset); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
319 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
320 if (n == NGX_ERROR) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
321 return n; |
461 | 322 } |
323 | |
4938
64ffc28850bb
Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4919
diff
changeset
|
324 offset += n; |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
325 total += n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
326 |
461 | 327 } while (cl); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
328 |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
329 return total; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
330 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
331 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
332 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
333 static ngx_chain_t * |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
334 ngx_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *cl) |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
335 { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
336 size_t total, size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
337 u_char *prev; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
338 ngx_uint_t n; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
339 struct iovec *iov; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
340 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
341 iov = NULL; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
342 prev = NULL; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
343 total = 0; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
344 n = 0; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
345 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
346 for ( /* void */ ; cl; cl = cl->next) { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
347 size = cl->buf->last - cl->buf->pos; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
348 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
349 if (prev == cl->buf->pos) { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
350 iov->iov_len += size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
351 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
352 } else { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
353 if (n == vec->nalloc) { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
354 break; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
355 } |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
356 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
357 iov = &vec->iovs[n++]; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
358 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
359 iov->iov_base = (void *) cl->buf->pos; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
360 iov->iov_len = size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
361 } |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
362 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
363 prev = cl->buf->pos + size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
364 total += size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
365 } |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
366 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
367 vec->count = n; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
368 vec->size = total; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
369 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
370 return cl; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
371 } |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
372 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
373 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
374 static ssize_t |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
375 ngx_writev_file(ngx_file_t *file, ngx_iovec_t *vec, off_t offset) |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
376 { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
377 ssize_t n; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
378 ngx_err_t err; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
379 |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
380 ngx_log_debug3(NGX_LOG_DEBUG_CORE, file->log, 0, |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
381 "writev: %d, %uz, %O", file->fd, vec->size, offset); |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
382 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
383 #if (NGX_HAVE_PWRITEV) |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
384 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
385 eintr: |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
386 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
387 n = pwritev(file->fd, vec->iovs, vec->count, offset); |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
388 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
389 if (n == -1) { |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
390 err = ngx_errno; |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
391 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
392 if (err == NGX_EINTR) { |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
393 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err, |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
394 "pwritev() was interrupted"); |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
395 goto eintr; |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
396 } |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
397 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
398 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
399 "pwritev() \"%s\" failed", file->name.data); |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
400 return NGX_ERROR; |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
401 } |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
402 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
403 if ((size_t) n != vec->size) { |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
404 ngx_log_error(NGX_LOG_CRIT, file->log, 0, |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
405 "pwritev() \"%s\" has written only %z of %uz", |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
406 file->name.data, n, vec->size); |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
407 return NGX_ERROR; |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
408 } |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
409 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
410 #else |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
411 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
412 if (file->sys_offset != offset) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
413 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
414 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
415 "lseek() \"%s\" failed", file->name.data); |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
416 return NGX_ERROR; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
417 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
418 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
419 file->sys_offset = offset; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
420 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
421 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
422 eintr: |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
423 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
424 n = writev(file->fd, vec->iovs, vec->count); |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
425 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
426 if (n == -1) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
427 err = ngx_errno; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
428 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
429 if (err == NGX_EINTR) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
430 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err, |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
431 "writev() was interrupted"); |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
432 goto eintr; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
433 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
434 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
435 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
436 "writev() \"%s\" failed", file->name.data); |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
437 return NGX_ERROR; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
438 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
439 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
440 if ((size_t) n != vec->size) { |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
441 ngx_log_error(NGX_LOG_CRIT, file->log, 0, |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
442 "writev() \"%s\" has written only %z of %uz", |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
443 file->name.data, n, vec->size); |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
444 return NGX_ERROR; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
445 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
446 |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
447 file->sys_offset += n; |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
448 |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
449 #endif |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
450 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
451 file->offset += n; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
452 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
453 return n; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
454 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
455 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
456 |
561 | 457 ngx_int_t |
681 | 458 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
459 { | |
460 struct timeval tv[2]; | |
461 | |
3861
cf80c0b0109a
set current atime while setting mtime
Igor Sysoev <igor@sysoev.ru>
parents:
3657
diff
changeset
|
462 tv[0].tv_sec = ngx_time(); |
681 | 463 tv[0].tv_usec = 0; |
464 tv[1].tv_sec = s; | |
465 tv[1].tv_usec = 0; | |
466 | |
467 if (utimes((char *) name, tv) != -1) { | |
468 return NGX_OK; | |
469 } | |
470 | |
471 return NGX_ERROR; | |
472 } | |
473 | |
474 | |
475 ngx_int_t | |
3651 | 476 ngx_create_file_mapping(ngx_file_mapping_t *fm) |
477 { | |
478 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
479 NGX_FILE_DEFAULT_ACCESS); | |
480 if (fm->fd == NGX_INVALID_FILE) { | |
481 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
482 ngx_open_file_n " \"%s\" failed", fm->name); | |
483 return NGX_ERROR; | |
484 } | |
485 | |
486 if (ftruncate(fm->fd, fm->size) == -1) { | |
487 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
488 "ftruncate() \"%s\" failed", fm->name); | |
489 goto failed; | |
490 } | |
491 | |
492 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED, | |
493 fm->fd, 0); | |
494 if (fm->addr != MAP_FAILED) { | |
495 return NGX_OK; | |
496 } | |
497 | |
498 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
499 "mmap(%uz) \"%s\" failed", fm->size, fm->name); | |
500 | |
501 failed: | |
502 | |
503 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
504 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
505 ngx_close_file_n " \"%s\" failed", fm->name); | |
506 } | |
507 | |
508 return NGX_ERROR; | |
509 } | |
510 | |
511 | |
512 void | |
513 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
514 { | |
515 if (munmap(fm->addr, fm->size) == -1) { | |
516 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
517 "munmap(%uz) \"%s\" failed", fm->size, fm->name); | |
518 } | |
519 | |
520 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
521 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
522 ngx_close_file_n " \"%s\" failed", fm->name); | |
523 } | |
524 } | |
525 | |
526 | |
527 ngx_int_t | |
561 | 528 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
529 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
530 dir->dir = opendir((const char *) name->data); |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
531 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
532 if (dir->dir == NULL) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
533 return NGX_ERROR; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
534 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
535 |
457 | 536 dir->valid_info = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
537 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
538 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
539 } |
561 | 540 |
541 | |
727 | 542 ngx_int_t |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
543 ngx_read_dir(ngx_dir_t *dir) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
544 { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
545 dir->de = readdir(dir->dir); |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
546 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
547 if (dir->de) { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
548 #if (NGX_HAVE_D_TYPE) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
549 dir->type = dir->de->d_type; |
2550
5e87ddb4764f
XFS on Linux does not set dirent.d_type,
Igor Sysoev <igor@sysoev.ru>
parents:
2248
diff
changeset
|
550 #else |
3200
26784c34e8be
*) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents:
3164
diff
changeset
|
551 dir->type = 0; |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
552 #endif |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
553 return NGX_OK; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
554 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
555 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
556 return NGX_ERROR; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
557 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
558 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
559 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
560 ngx_int_t |
727 | 561 ngx_open_glob(ngx_glob_t *gl) |
562 { | |
1980 | 563 int n; |
564 | |
4943
1e2d5d3f9f6b
Core: removed GLOB_NOSORT glob option.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4938
diff
changeset
|
565 n = glob((char *) gl->pattern, 0, NULL, &gl->pglob); |
1980 | 566 |
567 if (n == 0) { | |
568 return NGX_OK; | |
569 } | |
570 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
571 #ifdef GLOB_NOMATCH |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
572 |
1980 | 573 if (n == GLOB_NOMATCH && gl->test) { |
727 | 574 return NGX_OK; |
575 } | |
576 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
577 #endif |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
578 |
727 | 579 return NGX_ERROR; |
580 } | |
581 | |
582 | |
583 ngx_int_t | |
584 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
585 { | |
2210
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
586 size_t count; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
587 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
588 #ifdef GLOB_NOMATCH |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
589 count = (size_t) gl->pglob.gl_pathc; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
590 #else |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
591 count = (size_t) gl->pglob.gl_matchc; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
592 #endif |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
593 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
594 if (gl->n < count) { |
727 | 595 |
596 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]); | |
597 name->data = (u_char *) gl->pglob.gl_pathv[gl->n]; | |
598 gl->n++; | |
599 | |
600 return NGX_OK; | |
601 } | |
602 | |
603 return NGX_DONE; | |
604 } | |
605 | |
606 | |
607 void | |
608 ngx_close_glob(ngx_glob_t *gl) | |
609 { | |
610 globfree(&gl->pglob); | |
611 } | |
612 | |
613 | |
611 | 614 ngx_err_t |
615 ngx_trylock_fd(ngx_fd_t fd) | |
561 | 616 { |
617 struct flock fl; | |
618 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
619 ngx_memzero(&fl, sizeof(struct flock)); |
611 | 620 fl.l_type = F_WRLCK; |
561 | 621 fl.l_whence = SEEK_SET; |
611 | 622 |
623 if (fcntl(fd, F_SETLK, &fl) == -1) { | |
624 return ngx_errno; | |
625 } | |
626 | |
627 return 0; | |
628 } | |
629 | |
630 | |
631 ngx_err_t | |
632 ngx_lock_fd(ngx_fd_t fd) | |
633 { | |
634 struct flock fl; | |
635 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
636 ngx_memzero(&fl, sizeof(struct flock)); |
561 | 637 fl.l_type = F_WRLCK; |
611 | 638 fl.l_whence = SEEK_SET; |
561 | 639 |
611 | 640 if (fcntl(fd, F_SETLKW, &fl) == -1) { |
641 return ngx_errno; | |
561 | 642 } |
643 | |
611 | 644 return 0; |
561 | 645 } |
646 | |
647 | |
611 | 648 ngx_err_t |
649 ngx_unlock_fd(ngx_fd_t fd) | |
561 | 650 { |
651 struct flock fl; | |
652 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
653 ngx_memzero(&fl, sizeof(struct flock)); |
561 | 654 fl.l_type = F_UNLCK; |
611 | 655 fl.l_whence = SEEK_SET; |
561 | 656 |
611 | 657 if (fcntl(fd, F_SETLK, &fl) == -1) { |
658 return ngx_errno; | |
561 | 659 } |
660 | |
611 | 661 return 0; |
561 | 662 } |
2129 | 663 |
664 | |
4299
11e47bf300db
FreeBSD 10-current has recently gotten POSIX_FADV_* macros.
Maxim Konovalov <maxim@nginx.com>
parents:
4221
diff
changeset
|
665 #if (NGX_HAVE_POSIX_FADVISE) && !(NGX_HAVE_F_READAHEAD) |
3322
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
666 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
667 ngx_int_t |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
668 ngx_read_ahead(ngx_fd_t fd, size_t n) |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
669 { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
670 int err; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
671 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
672 err = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
673 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
674 if (err == 0) { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
675 return 0; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
676 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
677 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
678 ngx_set_errno(err); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
679 return NGX_FILE_ERROR; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
680 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
681 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
682 #endif |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
683 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
684 |
2129 | 685 #if (NGX_HAVE_O_DIRECT) |
686 | |
687 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
688 ngx_directio_on(ngx_fd_t fd) |
2129 | 689 { |
690 int flags; | |
691 | |
692 flags = fcntl(fd, F_GETFL); | |
693 | |
694 if (flags == -1) { | |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
695 return NGX_FILE_ERROR; |
2129 | 696 } |
697 | |
698 return fcntl(fd, F_SETFL, flags | O_DIRECT); | |
699 } | |
700 | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
701 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
702 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
703 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
704 { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
705 int flags; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
706 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
707 flags = fcntl(fd, F_GETFL); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
708 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
709 if (flags == -1) { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
710 return NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
711 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
712 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
713 return fcntl(fd, F_SETFL, flags & ~O_DIRECT); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
714 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
715 |
2129 | 716 #endif |
2615 | 717 |
718 | |
719 #if (NGX_HAVE_STATFS) | |
720 | |
721 size_t | |
722 ngx_fs_bsize(u_char *name) | |
723 { | |
724 struct statfs fs; | |
725 | |
726 if (statfs((char *) name, &fs) == -1) { | |
727 return 512; | |
728 } | |
729 | |
730 if ((fs.f_bsize % 512) != 0) { | |
731 return 512; | |
732 } | |
733 | |
734 return (size_t) fs.f_bsize; | |
735 } | |
736 | |
737 #elif (NGX_HAVE_STATVFS) | |
738 | |
739 size_t | |
740 ngx_fs_bsize(u_char *name) | |
741 { | |
742 struct statvfs fs; | |
743 | |
744 if (statvfs((char *) name, &fs) == -1) { | |
745 return 512; | |
746 } | |
747 | |
748 if ((fs.f_frsize % 512) != 0) { | |
749 return 512; | |
750 } | |
751 | |
752 return (size_t) fs.f_frsize; | |
753 } | |
754 | |
755 #else | |
756 | |
757 size_t | |
758 ngx_fs_bsize(u_char *name) | |
759 { | |
760 return 512; | |
761 } | |
762 | |
763 #endif |