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