Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_files.c @ 8717:e06283038ec8 quic
QUIC: clear SSL_OP_ENABLE_MIDDLEBOX_COMPAT on SSL context switch.
The SSL_OP_ENABLE_MIDDLEBOX_COMPAT option is provided by QuicTLS and enabled
by default in the newly created SSL contexts. SSL_set_quic_method() is used
to clear it, which is required for SSL handshake to work on QUIC connections.
Switching context in the ngx_http_ssl_servername() SNI callback overrides SSL
options from the new SSL context. This results in the option set again.
Fix is to explicitly clear it when switching to another SSL context.
Initially reported here (in Russian):
http://mailman.nginx.org/pipermail/nginx-ru/2021-November/063989.html
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 07 Dec 2021 15:49:51 +0300 |
parents | ccb5ff87ab3e |
children |
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); |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
15 static void ngx_thread_write_chain_to_file_handler(void *data, ngx_log_t *log); |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
16 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
17 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
18 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
|
19 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
|
20 off_t offset); |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
21 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
22 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
23 #if (NGX_HAVE_FILE_AIO) |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
24 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
25 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
|
26 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
27 #endif |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
28 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
29 |
561 | 30 ssize_t |
31 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
|
32 { |
561 | 33 ssize_t n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
35 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
461 | 36 "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
|
37 |
469 | 38 #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
|
39 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
40 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
|
41 |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
42 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
|
43 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
|
44 "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
|
45 return NGX_ERROR; |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
46 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
47 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
48 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
49 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 "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
|
54 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
55 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
56 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
57 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
|
58 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
59 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
60 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
|
61 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
62 if (n == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
63 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
|
64 "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
|
65 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
66 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
67 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
68 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
|
69 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
70 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
71 |
35
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
72 file->offset += n; |
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
73 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
74 return n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 } |
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
77 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
78 #if (NGX_THREADS) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
79 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
80 typedef struct { |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
81 ngx_fd_t fd; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
82 ngx_uint_t write; /* unsigned write:1; */ |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
83 |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
84 u_char *buf; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
85 size_t size; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
86 ngx_chain_t *chain; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
87 off_t offset; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
88 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
89 size_t nbytes; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
90 ngx_err_t err; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
91 } ngx_thread_file_ctx_t; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
92 |
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 ssize_t |
6441
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6421
diff
changeset
|
95 ngx_thread_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, |
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6421
diff
changeset
|
96 ngx_pool_t *pool) |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
97 { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
98 ngx_thread_task_t *task; |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
99 ngx_thread_file_ctx_t *ctx; |
6022
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 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
|
102 "thread read: %d, %p, %uz, %O", |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
103 file->fd, buf, size, offset); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
104 |
6441
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6421
diff
changeset
|
105 task = file->thread_task; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
106 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
107 if (task == NULL) { |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
108 task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_file_ctx_t)); |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
109 if (task == NULL) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
110 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
111 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
112 |
6441
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6421
diff
changeset
|
113 file->thread_task = task; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
114 } |
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 ctx = task->ctx; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
117 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
118 if (task->event.complete) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
119 task->event.complete = 0; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
120 |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
121 if (ctx->write) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
122 ngx_log_error(NGX_LOG_ALERT, file->log, 0, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
123 "invalid thread call, read instead of write"); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
124 return NGX_ERROR; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
125 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
126 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
127 if (ctx->err) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
128 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
|
129 "pread() \"%s\" failed", file->name.data); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
130 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
131 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
132 |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
133 return ctx->nbytes; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
134 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
135 |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
136 task->handler = ngx_thread_read_handler; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
137 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
138 ctx->write = 0; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
139 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
140 ctx->fd = file->fd; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
141 ctx->buf = buf; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
142 ctx->size = size; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
143 ctx->offset = offset; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
144 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
145 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
|
146 return NGX_ERROR; |
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 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
149 return NGX_AGAIN; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
150 } |
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 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
153 #if (NGX_HAVE_PREAD) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
154 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
155 static void |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
156 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
|
157 { |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
158 ngx_thread_file_ctx_t *ctx = data; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
159 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
160 ssize_t n; |
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 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
|
163 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
164 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
|
165 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
166 if (n == -1) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
167 ctx->err = ngx_errno; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
168 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
169 } else { |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
170 ctx->nbytes = n; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
171 ctx->err = 0; |
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 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
174 #if 0 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
175 ngx_time_update(); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
176 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
177 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
178 ngx_log_debug4(NGX_LOG_DEBUG_CORE, log, 0, |
6480 | 179 "pread: %z (err: %d) of %uz @%O", |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
180 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
|
181 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
182 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
183 #else |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
184 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
185 #error pread() is required! |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
186 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
187 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
188 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
189 #endif /* NGX_THREADS */ |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
190 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
4943
diff
changeset
|
191 |
561 | 192 ssize_t |
193 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
|
194 { |
6299
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
195 ssize_t n, written; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
196 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
|
197 |
461 | 198 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
199 "write: %d, %p, %uz, %O", file->fd, buf, size, offset); | |
200 | |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
201 written = 0; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
202 |
469 | 203 #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
|
204 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
205 for ( ;; ) { |
3657 | 206 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
|
207 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
208 if (n == -1) { |
6299
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
209 err = ngx_errno; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
210 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
211 if (err == NGX_EINTR) { |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
212 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
|
213 "pwrite() was interrupted"); |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
214 continue; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
215 } |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
216 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
217 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
|
218 "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
|
219 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
|
220 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
221 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
222 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
|
223 written += n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
224 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
225 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
|
226 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
227 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
228 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
229 offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
230 size -= n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
231 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
232 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
233 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
234 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 "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
|
239 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
240 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
241 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
242 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
|
243 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
244 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
245 for ( ;; ) { |
3657 | 246 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
|
247 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
248 if (n == -1) { |
6299
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
249 err = ngx_errno; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
250 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
251 if (err == NGX_EINTR) { |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
252 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
|
253 "write() was interrupted"); |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
254 continue; |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
255 } |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
256 |
5170c3040ce1
Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents:
6298
diff
changeset
|
257 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
|
258 "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
|
259 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
|
260 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
261 |
6298
8f6d753c1953
Adjusted file->sys_offset after the write() syscall.
Valentin Bartenev <vbart@nginx.com>
parents:
6241
diff
changeset
|
262 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
|
263 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
|
264 written += n; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
265 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
266 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
|
267 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
268 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
269 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
270 size -= n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
271 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
272 #endif |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
273 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
274 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
275 |
561 | 276 ngx_fd_t |
1046 | 277 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
|
278 { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
279 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
|
280 |
1046 | 281 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, |
282 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
|
283 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
284 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
|
285 (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
|
286 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
287 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
288 return fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
289 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
290 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
291 |
561 | 292 ssize_t |
293 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
294 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
|
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 ssize_t total, n; |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
297 ngx_iovec_t vec; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
298 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
|
299 |
461 | 300 /* 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
|
301 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
302 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
|
303 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
|
304 (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
|
305 offset); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
306 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
307 |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
308 total = 0; |
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
309 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
310 vec.iovs = iovs; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
311 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
|
312 |
461 | 313 do { |
314 /* 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
|
315 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
|
316 |
461 | 317 /* 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
|
318 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
319 if (vec.count == 1) { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
320 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
|
321 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
|
322 |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
323 if (n == NGX_ERROR) { |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
324 return n; |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
325 } |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
326 |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
327 return total + n; |
461 | 328 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
329 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
330 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
|
331 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
332 if (n == NGX_ERROR) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
333 return n; |
461 | 334 } |
335 | |
4938
64ffc28850bb
Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4919
diff
changeset
|
336 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
|
337 total += n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
338 |
461 | 339 } while (cl); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
340 |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
341 return total; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
342 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
343 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
344 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
345 static ngx_chain_t * |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
346 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
|
347 { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
348 size_t total, size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
349 u_char *prev; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
350 ngx_uint_t n; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
351 struct iovec *iov; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
352 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
353 iov = NULL; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
354 prev = NULL; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
355 total = 0; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
356 n = 0; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
357 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
358 for ( /* void */ ; cl; cl = cl->next) { |
6574
7eb19447b2de
Core: skip special buffers on writing (ticket #981).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
359 |
7eb19447b2de
Core: skip special buffers on writing (ticket #981).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
360 if (ngx_buf_special(cl->buf)) { |
7eb19447b2de
Core: skip special buffers on writing (ticket #981).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
361 continue; |
7eb19447b2de
Core: skip special buffers on writing (ticket #981).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
362 } |
7eb19447b2de
Core: skip special buffers on writing (ticket #981).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
363 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
364 size = cl->buf->last - cl->buf->pos; |
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 if (prev == cl->buf->pos) { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
367 iov->iov_len += size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
368 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
369 } else { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
370 if (n == vec->nalloc) { |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
371 break; |
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 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
374 iov = &vec->iovs[n++]; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
375 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
376 iov->iov_base = (void *) cl->buf->pos; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
377 iov->iov_len = size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
378 } |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
379 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
380 prev = cl->buf->pos + size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
381 total += size; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
382 } |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
383 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
384 vec->count = n; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
385 vec->size = total; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
386 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
387 return cl; |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
388 } |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
389 |
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
390 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
391 static ssize_t |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
392 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
|
393 { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
394 ssize_t n; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
395 ngx_err_t err; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
396 |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
397 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
|
398 "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
|
399 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
400 #if (NGX_HAVE_PWRITEV) |
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 eintr: |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
403 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
404 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
|
405 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
406 if (n == -1) { |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
407 err = ngx_errno; |
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 if (err == NGX_EINTR) { |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
410 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
|
411 "pwritev() was interrupted"); |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
412 goto eintr; |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
413 } |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
414 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
415 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
|
416 "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
|
417 return NGX_ERROR; |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
418 } |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
419 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
420 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
|
421 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
|
422 "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
|
423 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
|
424 return NGX_ERROR; |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
425 } |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
426 |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
427 #else |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
428 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
429 if (file->sys_offset != offset) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
430 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
|
431 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
|
432 "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
|
433 return NGX_ERROR; |
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 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
436 file->sys_offset = offset; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
437 } |
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 eintr: |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
440 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
441 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
|
442 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
443 if (n == -1) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
444 err = ngx_errno; |
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 if (err == NGX_EINTR) { |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
447 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
|
448 "writev() was interrupted"); |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
449 goto eintr; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
450 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
451 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
452 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
|
453 "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
|
454 return NGX_ERROR; |
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 |
6421
3832b608dc8d
Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
6301
diff
changeset
|
457 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
|
458 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
|
459 "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
|
460 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
|
461 return NGX_ERROR; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
462 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
463 |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
464 file->sys_offset += n; |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
465 |
6301
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
466 #endif |
b5a87b51be24
Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents:
6300
diff
changeset
|
467 |
6300
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
468 file->offset += n; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
469 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
470 return n; |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
471 } |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
472 |
be6af0906a4d
Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
6299
diff
changeset
|
473 |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
474 #if (NGX_THREADS) |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
475 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
476 ssize_t |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
477 ngx_thread_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
478 ngx_pool_t *pool) |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
479 { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
480 ngx_thread_task_t *task; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
481 ngx_thread_file_ctx_t *ctx; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
482 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
483 ngx_log_debug3(NGX_LOG_DEBUG_CORE, file->log, 0, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
484 "thread write chain: %d, %p, %O", |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
485 file->fd, cl, offset); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
486 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
487 task = file->thread_task; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
488 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
489 if (task == NULL) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
490 task = ngx_thread_task_alloc(pool, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
491 sizeof(ngx_thread_file_ctx_t)); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
492 if (task == NULL) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
493 return NGX_ERROR; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
494 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
495 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
496 file->thread_task = task; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
497 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
498 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
499 ctx = task->ctx; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
500 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
501 if (task->event.complete) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
502 task->event.complete = 0; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
503 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
504 if (!ctx->write) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
505 ngx_log_error(NGX_LOG_ALERT, file->log, 0, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
506 "invalid thread call, write instead of read"); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
507 return NGX_ERROR; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
508 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
509 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
510 if (ctx->err || ctx->nbytes == 0) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
511 ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
512 "pwritev() \"%s\" failed", file->name.data); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
513 return NGX_ERROR; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
514 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
515 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
516 file->offset += ctx->nbytes; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
517 return ctx->nbytes; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
518 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
519 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
520 task->handler = ngx_thread_write_chain_to_file_handler; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
521 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
522 ctx->write = 1; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
523 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
524 ctx->fd = file->fd; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
525 ctx->chain = cl; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
526 ctx->offset = offset; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
527 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
528 if (file->thread_handler(task, file) != NGX_OK) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
529 return NGX_ERROR; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
530 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
531 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
532 return NGX_AGAIN; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
533 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
534 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
535 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
536 static void |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
537 ngx_thread_write_chain_to_file_handler(void *data, ngx_log_t *log) |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
538 { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
539 ngx_thread_file_ctx_t *ctx = data; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
540 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
541 #if (NGX_HAVE_PWRITEV) |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
542 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
543 off_t offset; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
544 ssize_t n; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
545 ngx_err_t err; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
546 ngx_chain_t *cl; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
547 ngx_iovec_t vec; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
548 struct iovec iovs[NGX_IOVS_PREALLOCATE]; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
549 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
550 vec.iovs = iovs; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
551 vec.nalloc = NGX_IOVS_PREALLOCATE; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
552 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
553 cl = ctx->chain; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
554 offset = ctx->offset; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
555 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
556 ctx->nbytes = 0; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
557 ctx->err = 0; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
558 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
559 do { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
560 /* create the iovec and coalesce the neighbouring bufs */ |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
561 cl = ngx_chain_to_iovec(&vec, cl); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
562 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
563 eintr: |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
564 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
565 n = pwritev(ctx->fd, iovs, vec.count, offset); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
566 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
567 if (n == -1) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
568 err = ngx_errno; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
569 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
570 if (err == NGX_EINTR) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
571 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, err, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
572 "pwritev() was interrupted"); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
573 goto eintr; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
574 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
575 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
576 ctx->err = err; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
577 return; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
578 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
579 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
580 if ((size_t) n != vec.size) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
581 ctx->nbytes = 0; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
582 return; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
583 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
584 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
585 ctx->nbytes += n; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
586 offset += n; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
587 } while (cl); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
588 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
589 #else |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
590 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
591 ctx->err = NGX_ENOSYS; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
592 return; |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
593 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
594 #endif |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
595 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
596 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
597 #endif /* NGX_THREADS */ |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
598 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6441
diff
changeset
|
599 |
561 | 600 ngx_int_t |
681 | 601 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
602 { | |
603 struct timeval tv[2]; | |
604 | |
3861
cf80c0b0109a
set current atime while setting mtime
Igor Sysoev <igor@sysoev.ru>
parents:
3657
diff
changeset
|
605 tv[0].tv_sec = ngx_time(); |
681 | 606 tv[0].tv_usec = 0; |
607 tv[1].tv_sec = s; | |
608 tv[1].tv_usec = 0; | |
609 | |
610 if (utimes((char *) name, tv) != -1) { | |
611 return NGX_OK; | |
612 } | |
613 | |
614 return NGX_ERROR; | |
615 } | |
616 | |
617 | |
618 ngx_int_t | |
3651 | 619 ngx_create_file_mapping(ngx_file_mapping_t *fm) |
620 { | |
621 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
622 NGX_FILE_DEFAULT_ACCESS); | |
7086 | 623 |
3651 | 624 if (fm->fd == NGX_INVALID_FILE) { |
625 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
626 ngx_open_file_n " \"%s\" failed", fm->name); | |
627 return NGX_ERROR; | |
628 } | |
629 | |
630 if (ftruncate(fm->fd, fm->size) == -1) { | |
631 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
632 "ftruncate() \"%s\" failed", fm->name); | |
633 goto failed; | |
634 } | |
635 | |
636 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED, | |
637 fm->fd, 0); | |
638 if (fm->addr != MAP_FAILED) { | |
639 return NGX_OK; | |
640 } | |
641 | |
642 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
643 "mmap(%uz) \"%s\" failed", fm->size, fm->name); | |
644 | |
645 failed: | |
646 | |
647 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
648 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
649 ngx_close_file_n " \"%s\" failed", fm->name); | |
650 } | |
651 | |
652 return NGX_ERROR; | |
653 } | |
654 | |
655 | |
656 void | |
657 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
658 { | |
659 if (munmap(fm->addr, fm->size) == -1) { | |
660 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
661 "munmap(%uz) \"%s\" failed", fm->size, fm->name); | |
662 } | |
663 | |
664 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
665 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
666 ngx_close_file_n " \"%s\" failed", fm->name); | |
667 } | |
668 } | |
669 | |
670 | |
671 ngx_int_t | |
561 | 672 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
|
673 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
674 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
|
675 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
676 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
|
677 return NGX_ERROR; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
678 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
679 |
457 | 680 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
|
681 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
682 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
683 } |
561 | 684 |
685 | |
727 | 686 ngx_int_t |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
687 ngx_read_dir(ngx_dir_t *dir) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
688 { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
689 dir->de = readdir(dir->dir); |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
690 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
691 if (dir->de) { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
692 #if (NGX_HAVE_D_TYPE) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
693 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
|
694 #else |
3200
26784c34e8be
*) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents:
3164
diff
changeset
|
695 dir->type = 0; |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
696 #endif |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
697 return NGX_OK; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
698 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
699 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
700 return NGX_ERROR; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
701 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
702 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
703 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
704 ngx_int_t |
727 | 705 ngx_open_glob(ngx_glob_t *gl) |
706 { | |
1980 | 707 int n; |
708 | |
4943
1e2d5d3f9f6b
Core: removed GLOB_NOSORT glob option.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4938
diff
changeset
|
709 n = glob((char *) gl->pattern, 0, NULL, &gl->pglob); |
1980 | 710 |
711 if (n == 0) { | |
712 return NGX_OK; | |
713 } | |
714 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
715 #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
|
716 |
1980 | 717 if (n == GLOB_NOMATCH && gl->test) { |
727 | 718 return NGX_OK; |
719 } | |
720 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
721 #endif |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
722 |
727 | 723 return NGX_ERROR; |
724 } | |
725 | |
726 | |
727 ngx_int_t | |
728 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
729 { | |
2210
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
730 size_t count; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
731 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
732 #ifdef GLOB_NOMATCH |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
733 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
|
734 #else |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
735 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
|
736 #endif |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
737 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
738 if (gl->n < count) { |
727 | 739 |
740 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]); | |
741 name->data = (u_char *) gl->pglob.gl_pathv[gl->n]; | |
742 gl->n++; | |
743 | |
744 return NGX_OK; | |
745 } | |
746 | |
747 return NGX_DONE; | |
748 } | |
749 | |
750 | |
751 void | |
752 ngx_close_glob(ngx_glob_t *gl) | |
753 { | |
754 globfree(&gl->pglob); | |
755 } | |
756 | |
757 | |
611 | 758 ngx_err_t |
759 ngx_trylock_fd(ngx_fd_t fd) | |
561 | 760 { |
761 struct flock fl; | |
762 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
763 ngx_memzero(&fl, sizeof(struct flock)); |
611 | 764 fl.l_type = F_WRLCK; |
561 | 765 fl.l_whence = SEEK_SET; |
611 | 766 |
767 if (fcntl(fd, F_SETLK, &fl) == -1) { | |
768 return ngx_errno; | |
769 } | |
770 | |
771 return 0; | |
772 } | |
773 | |
774 | |
775 ngx_err_t | |
776 ngx_lock_fd(ngx_fd_t fd) | |
777 { | |
778 struct flock fl; | |
779 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
780 ngx_memzero(&fl, sizeof(struct flock)); |
561 | 781 fl.l_type = F_WRLCK; |
611 | 782 fl.l_whence = SEEK_SET; |
561 | 783 |
611 | 784 if (fcntl(fd, F_SETLKW, &fl) == -1) { |
785 return ngx_errno; | |
561 | 786 } |
787 | |
611 | 788 return 0; |
561 | 789 } |
790 | |
791 | |
611 | 792 ngx_err_t |
793 ngx_unlock_fd(ngx_fd_t fd) | |
561 | 794 { |
795 struct flock fl; | |
796 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
797 ngx_memzero(&fl, sizeof(struct flock)); |
561 | 798 fl.l_type = F_UNLCK; |
611 | 799 fl.l_whence = SEEK_SET; |
561 | 800 |
611 | 801 if (fcntl(fd, F_SETLK, &fl) == -1) { |
802 return ngx_errno; | |
561 | 803 } |
804 | |
611 | 805 return 0; |
561 | 806 } |
2129 | 807 |
808 | |
4299
11e47bf300db
FreeBSD 10-current has recently gotten POSIX_FADV_* macros.
Maxim Konovalov <maxim@nginx.com>
parents:
4221
diff
changeset
|
809 #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
|
810 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
811 ngx_int_t |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
812 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
|
813 { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
814 int err; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
815 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
816 err = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
817 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
818 if (err == 0) { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
819 return 0; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
820 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
821 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
822 ngx_set_errno(err); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
823 return NGX_FILE_ERROR; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
824 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
825 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
826 #endif |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
827 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
828 |
2129 | 829 #if (NGX_HAVE_O_DIRECT) |
830 | |
831 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
832 ngx_directio_on(ngx_fd_t fd) |
2129 | 833 { |
834 int flags; | |
835 | |
836 flags = fcntl(fd, F_GETFL); | |
837 | |
838 if (flags == -1) { | |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
839 return NGX_FILE_ERROR; |
2129 | 840 } |
841 | |
842 return fcntl(fd, F_SETFL, flags | O_DIRECT); | |
843 } | |
844 | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
845 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
846 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
847 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
848 { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
849 int flags; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
850 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
851 flags = fcntl(fd, F_GETFL); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
852 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
853 if (flags == -1) { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
854 return NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
855 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
856 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
857 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
|
858 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
859 |
2129 | 860 #endif |
2615 | 861 |
862 | |
863 #if (NGX_HAVE_STATFS) | |
864 | |
865 size_t | |
866 ngx_fs_bsize(u_char *name) | |
867 { | |
868 struct statfs fs; | |
869 | |
870 if (statfs((char *) name, &fs) == -1) { | |
871 return 512; | |
872 } | |
873 | |
874 if ((fs.f_bsize % 512) != 0) { | |
875 return 512; | |
876 } | |
877 | |
7971
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
878 #if (NGX_LINUX) |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
879 if ((size_t) fs.f_bsize > ngx_pagesize) { |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
880 return 512; |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
881 } |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
882 #endif |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
883 |
2615 | 884 return (size_t) fs.f_bsize; |
885 } | |
886 | |
7973
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
887 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
888 off_t |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
889 ngx_fs_available(u_char *name) |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
890 { |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
891 struct statfs fs; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
892 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
893 if (statfs((char *) name, &fs) == -1) { |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
894 return NGX_MAX_OFF_T_VALUE; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
895 } |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
896 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
897 return (off_t) fs.f_bavail * fs.f_bsize; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
898 } |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
899 |
2615 | 900 #elif (NGX_HAVE_STATVFS) |
901 | |
902 size_t | |
903 ngx_fs_bsize(u_char *name) | |
904 { | |
905 struct statvfs fs; | |
906 | |
907 if (statvfs((char *) name, &fs) == -1) { | |
908 return 512; | |
909 } | |
910 | |
911 if ((fs.f_frsize % 512) != 0) { | |
912 return 512; | |
913 } | |
914 | |
7971
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
915 #if (NGX_LINUX) |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
916 if ((size_t) fs.f_frsize > ngx_pagesize) { |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
917 return 512; |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
918 } |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
919 #endif |
0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7086
diff
changeset
|
920 |
2615 | 921 return (size_t) fs.f_frsize; |
922 } | |
923 | |
7973
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
924 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
925 off_t |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
926 ngx_fs_available(u_char *name) |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
927 { |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
928 struct statvfs fs; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
929 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
930 if (statvfs((char *) name, &fs) == -1) { |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
931 return NGX_MAX_OFF_T_VALUE; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
932 } |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
933 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
934 return (off_t) fs.f_bavail * fs.f_frsize; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
935 } |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
936 |
2615 | 937 #else |
938 | |
939 size_t | |
940 ngx_fs_bsize(u_char *name) | |
941 { | |
942 return 512; | |
943 } | |
944 | |
7973
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
945 |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
946 off_t |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
947 ngx_fs_available(u_char *name) |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
948 { |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
949 return NGX_MAX_OFF_T_VALUE; |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
950 } |
ccb5ff87ab3e
Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7971
diff
changeset
|
951 |
2615 | 952 #endif |