annotate src/os/unix/ngx_files.c @ 6516:ab16126a06a0

HTTP/2: write logs when refusing streams with data. Refusing streams is known to be incorrectly handled at least by IE, Edge and Safari. Make sure to provide appropriate logging to simplify fixing this in the affected browsers.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 18 Apr 2016 21:18:24 +0300
parents f01ab2dbcfdc
children 7eb19447b2de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4299
diff changeset
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
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
30 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
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
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
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
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
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
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
38 #if (NGX_HAVE_PREAD)
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
39
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
40 n = pread(file->fd, buf, size, offset);
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
41
9
6f58641241bb nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
42 if (n == -1) {
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 196
diff changeset
43 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
3157
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
44 "pread() \"%s\" failed", file->name.data);
9
6f58641241bb nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
45 return NGX_ERROR;
6f58641241bb nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
46 }
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
47
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
48 #else
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
49
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
50 if (file->sys_offset != offset) {
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
51 if (lseek(file->fd, offset, SEEK_SET) == -1) {
3157
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
52 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
53 "lseek() \"%s\" failed", file->name.data);
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
54 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
55 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
56
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
57 file->sys_offset = offset;
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
58 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
59
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
60 n = read(file->fd, buf, size);
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
61
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
62 if (n == -1) {
3157
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
63 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
64 "read() \"%s\" failed", file->name.data);
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
65 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
66 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
67
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
68 file->sys_offset += n;
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
69
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
70 #endif
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
71
35
79c1fce18e71 nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 33
diff changeset
72 file->offset += n;
79c1fce18e71 nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 33
diff changeset
73
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
74 return n;
5
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 }
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
77
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
78 #if (NGX_THREADS)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
79
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
80 typedef struct {
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
81 ngx_fd_t fd;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
82 ngx_uint_t write; /* unsigned write:1; */
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
83
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
84 u_char *buf;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
85 size_t size;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
86 ngx_chain_t *chain;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
87 off_t offset;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
88
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
89 size_t nbytes;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
90 ngx_err_t err;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
91 } ngx_thread_file_ctx_t;
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
92
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
93
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
94 ssize_t
6441
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6421
diff changeset
95 ngx_thread_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6421
diff changeset
96 ngx_pool_t *pool)
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
97 {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
98 ngx_thread_task_t *task;
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
99 ngx_thread_file_ctx_t *ctx;
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
100
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
101 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
102 "thread read: %d, %p, %uz, %O",
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
103 file->fd, buf, size, offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
104
6441
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6421
diff changeset
105 task = file->thread_task;
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
106
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
107 if (task == NULL) {
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
108 task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_file_ctx_t));
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
109 if (task == NULL) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
110 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
111 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
112
6441
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6421
diff changeset
113 file->thread_task = task;
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
114 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
115
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
116 ctx = task->ctx;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
117
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
118 if (task->event.complete) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
119 task->event.complete = 0;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
120
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
121 if (ctx->write) {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
122 ngx_log_error(NGX_LOG_ALERT, file->log, 0,
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
123 "invalid thread call, read instead of write");
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
124 return NGX_ERROR;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
125 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
126
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
127 if (ctx->err) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
128 ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
129 "pread() \"%s\" failed", file->name.data);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
130 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
131 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
132
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
133 return ctx->nbytes;
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
134 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
135
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
136 task->handler = ngx_thread_read_handler;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
137
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
138 ctx->write = 0;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
139
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
140 ctx->fd = file->fd;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
141 ctx->buf = buf;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
142 ctx->size = size;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
143 ctx->offset = offset;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
144
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
145 if (file->thread_handler(task, file) != NGX_OK) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
146 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
147 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
148
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
149 return NGX_AGAIN;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
150 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
151
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
152
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
153 #if (NGX_HAVE_PREAD)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
154
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
155 static void
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
156 ngx_thread_read_handler(void *data, ngx_log_t *log)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
157 {
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
158 ngx_thread_file_ctx_t *ctx = data;
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
159
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
160 ssize_t n;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
161
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
162 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "thread read handler");
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
163
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
164 n = pread(ctx->fd, ctx->buf, ctx->size, ctx->offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
165
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
166 if (n == -1) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
167 ctx->err = ngx_errno;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
168
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
169 } else {
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
170 ctx->nbytes = n;
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
171 ctx->err = 0;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
172 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
173
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
174 #if 0
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
175 ngx_time_update();
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
176 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
177
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
178 ngx_log_debug4(NGX_LOG_DEBUG_CORE, log, 0,
6480
f01ab2dbcfdc Fixed logging.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6442
diff changeset
179 "pread: %z (err: %d) of %uz @%O",
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
180 n, ctx->err, ctx->size, ctx->offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
181 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
182
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
183 #else
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
184
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
185 #error pread() is required!
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
186
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
187 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
188
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
189 #endif /* NGX_THREADS */
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
190
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
191
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
192 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
193 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
194 {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
195 ssize_t n, written;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
196 ngx_err_t err;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
197
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
198 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
199 "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
200
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
201 written = 0;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
202
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
203 #if (NGX_HAVE_PWRITE)
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
204
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
205 for ( ;; ) {
3657
fbd7dad43a4e fix ngx_write_file() buf
Igor Sysoev <igor@sysoev.ru>
parents: 3651
diff changeset
206 n = pwrite(file->fd, buf + written, size, offset);
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
207
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
208 if (n == -1) {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
209 err = ngx_errno;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
210
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
211 if (err == NGX_EINTR) {
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
212 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
213 "pwrite() was interrupted");
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
214 continue;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
215 }
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
216
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
217 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
218 "pwrite() \"%s\" failed", file->name.data);
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
219 return NGX_ERROR;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
220 }
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
221
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
222 file->offset += n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
223 written += n;
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
224
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
225 if ((size_t) n == size) {
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
226 return written;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
227 }
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
228
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
229 offset += n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
230 size -= n;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
231 }
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
232
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
233 #else
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
234
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
235 if (file->sys_offset != offset) {
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
236 if (lseek(file->fd, offset, SEEK_SET) == -1) {
3157
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
237 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
238 "lseek() \"%s\" failed", file->name.data);
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
239 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
240 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
241
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
242 file->sys_offset = offset;
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
243 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
244
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
245 for ( ;; ) {
3657
fbd7dad43a4e fix ngx_write_file() buf
Igor Sysoev <igor@sysoev.ru>
parents: 3651
diff changeset
246 n = write(file->fd, buf + written, size);
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
247
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
248 if (n == -1) {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
249 err = ngx_errno;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
250
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
251 if (err == NGX_EINTR) {
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
252 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
253 "write() was interrupted");
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
254 continue;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
255 }
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
256
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
257 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
258 "write() \"%s\" failed", file->name.data);
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
259 return NGX_ERROR;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
260 }
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
261
6298
8f6d753c1953 Adjusted file->sys_offset after the write() syscall.
Valentin Bartenev <vbart@nginx.com>
parents: 6241
diff changeset
262 file->sys_offset += n;
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
263 file->offset += n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
264 written += n;
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
265
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
266 if ((size_t) n == size) {
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
267 return written;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
268 }
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
269
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
270 size -= n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
271 }
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
272 #endif
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
273 }
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
274
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
275
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
276 ngx_fd_t
1046
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
277 ngx_open_tempfile(u_char *name, ngx_uint_t persistent, ngx_uint_t access)
303
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
278 {
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
279 ngx_fd_t fd;
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
280
1046
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
281 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR,
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
282 access ? access : 0600);
303
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
283
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
284 if (fd != -1 && !persistent) {
4794
4163fb9dcfcb Explicitly ignore returned value from unlink() in ngx_open_tempfile().
Andrey Belov <defan@nginx.com>
parents: 4737
diff changeset
285 (void) unlink((const char *) name);
303
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
286 }
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
287
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
288 return fd;
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
289 }
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
290
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
291
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
292 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
293 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
294 ngx_pool_t *pool)
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
295 {
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
296 ssize_t total, n;
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
297 ngx_iovec_t vec;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
298 struct iovec iovs[NGX_IOVS_PREALLOCATE];
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
299
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
300 /* use pwrite() if there is the only buf in a chain */
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
301
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
302 if (cl->next == NULL) {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
303 return ngx_write_file(file, cl->buf->pos,
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
304 (size_t) (cl->buf->last - cl->buf->pos),
194
2357fa41738a nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 191
diff changeset
305 offset);
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
306 }
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
307
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
308 total = 0;
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
309
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
310 vec.iovs = iovs;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
311 vec.nalloc = NGX_IOVS_PREALLOCATE;
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
312
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
313 do {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
314 /* create the iovec and coalesce the neighbouring bufs */
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
315 cl = ngx_chain_to_iovec(&vec, cl);
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
316
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
317 /* use pwrite() if there is the only iovec buffer */
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
318
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
319 if (vec.count == 1) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
320 n = ngx_write_file(file, (u_char *) iovs[0].iov_base,
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
321 iovs[0].iov_len, offset);
4221
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
322
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
323 if (n == NGX_ERROR) {
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
324 return n;
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
325 }
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
326
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
327 return total + n;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
328 }
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
329
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
330 n = ngx_writev_file(file, &vec, offset);
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
331
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
332 if (n == NGX_ERROR) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
333 return n;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
334 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
335
4938
64ffc28850bb Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4919
diff changeset
336 offset += n;
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
337 total += n;
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
338
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
339 } while (cl);
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
340
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
341 return total;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
342 }
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
343
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
344
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
345 static ngx_chain_t *
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
346 ngx_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *cl)
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
347 {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
348 size_t total, size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
349 u_char *prev;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
350 ngx_uint_t n;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
351 struct iovec *iov;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
352
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
353 iov = NULL;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
354 prev = NULL;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
355 total = 0;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
356 n = 0;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
357
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
358 for ( /* void */ ; cl; cl = cl->next) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
359 size = cl->buf->last - cl->buf->pos;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
360
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
361 if (prev == cl->buf->pos) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
362 iov->iov_len += size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
363
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
364 } else {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
365 if (n == vec->nalloc) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
366 break;
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
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
369 iov = &vec->iovs[n++];
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 iov->iov_base = (void *) cl->buf->pos;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
372 iov->iov_len = size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
373 }
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
374
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
375 prev = cl->buf->pos + size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
376 total += size;
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
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
379 vec->count = n;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
380 vec->size = total;
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 return cl;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
383 }
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
384
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
385
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
386 static ssize_t
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
387 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
388 {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
389 ssize_t n;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
390 ngx_err_t err;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
391
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
392 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
393 "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
394
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
395 #if (NGX_HAVE_PWRITEV)
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
396
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
397 eintr:
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
398
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
399 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
400
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
401 if (n == -1) {
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
402 err = ngx_errno;
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 if (err == NGX_EINTR) {
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
405 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
406 "pwritev() was interrupted");
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
407 goto eintr;
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
408 }
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
409
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
410 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
411 "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
412 return NGX_ERROR;
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
413 }
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
414
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
415 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
416 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
417 "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
418 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
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
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
422 #else
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
423
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
424 if (file->sys_offset != offset) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
425 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
426 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
427 "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
428 return NGX_ERROR;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
429 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
430
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
431 file->sys_offset = offset;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
432 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
433
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
434 eintr:
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
435
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
436 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
437
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
438 if (n == -1) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
439 err = ngx_errno;
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 if (err == NGX_EINTR) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
442 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
443 "writev() was interrupted");
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
444 goto eintr;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
445 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
446
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
447 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
448 "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
449 return NGX_ERROR;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
450 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
451
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
452 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
453 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
454 "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
455 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
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
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
459 file->sys_offset += n;
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
460
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
461 #endif
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
462
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
463 file->offset += n;
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 return n;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
466 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
467
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
468
6442
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
469 #if (NGX_THREADS)
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
470
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
471 ssize_t
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
472 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
473 ngx_pool_t *pool)
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
474 {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
475 ngx_thread_task_t *task;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
476 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
477
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
478 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
479 "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
480 file->fd, cl, offset);
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 task = file->thread_task;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
483
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
484 if (task == NULL) {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
485 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
486 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
487 if (task == NULL) {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
488 return NGX_ERROR;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
489 }
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 file->thread_task = task;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
492 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
493
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
494 ctx = task->ctx;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
495
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
496 if (task->event.complete) {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
497 task->event.complete = 0;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
498
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
499 if (!ctx->write) {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
500 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
501 "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
502 return NGX_ERROR;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
503 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
504
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
505 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
506 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
507 "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
508 return NGX_ERROR;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
509 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
510
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
511 file->offset += ctx->nbytes;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
512 return ctx->nbytes;
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
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
515 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
516
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
517 ctx->write = 1;
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 ctx->fd = file->fd;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
520 ctx->chain = cl;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
521 ctx->offset = offset;
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 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
524 return NGX_ERROR;
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
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
527 return NGX_AGAIN;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
528 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
529
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
530
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
531 static void
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
532 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
533 {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
534 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
535
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
536 #if (NGX_HAVE_PWRITEV)
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 off_t offset;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
539 ssize_t n;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
540 ngx_err_t err;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
541 ngx_chain_t *cl;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
542 ngx_iovec_t vec;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
543 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
544
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
545 vec.iovs = iovs;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
546 vec.nalloc = NGX_IOVS_PREALLOCATE;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
547
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
548 cl = ctx->chain;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
549 offset = ctx->offset;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
550
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
551 ctx->nbytes = 0;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
552 ctx->err = 0;
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 do {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
555 /* 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
556 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
557
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
558 eintr:
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 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
561
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
562 if (n == -1) {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
563 err = ngx_errno;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
564
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
565 if (err == NGX_EINTR) {
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
566 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
567 "pwritev() was interrupted");
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
568 goto eintr;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
569 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
570
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
571 ctx->err = err;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
572 return;
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
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
575 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
576 ctx->nbytes = 0;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
577 return;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
578 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
579
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
580 ctx->nbytes += n;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
581 offset += n;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
582 } while (cl);
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 #else
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
585
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
586 ctx->err = NGX_ENOSYS;
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
587 return;
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 #endif
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
590 }
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
591
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
592 #endif /* NGX_THREADS */
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
593
6e10518f95d8 Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6441
diff changeset
594
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
595 ngx_int_t
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
596 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s)
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
597 {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
598 struct timeval tv[2];
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
599
3861
cf80c0b0109a set current atime while setting mtime
Igor Sysoev <igor@sysoev.ru>
parents: 3657
diff changeset
600 tv[0].tv_sec = ngx_time();
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
601 tv[0].tv_usec = 0;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
602 tv[1].tv_sec = s;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
603 tv[1].tv_usec = 0;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
604
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
605 if (utimes((char *) name, tv) != -1) {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
606 return NGX_OK;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
607 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
608
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
609 return NGX_ERROR;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
610 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
611
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
612
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
613 ngx_int_t
3651
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
614 ngx_create_file_mapping(ngx_file_mapping_t *fm)
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
615 {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
616 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
617 NGX_FILE_DEFAULT_ACCESS);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
618 if (fm->fd == NGX_INVALID_FILE) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
619 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
620 ngx_open_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
621 return NGX_ERROR;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
622 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
623
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
624 if (ftruncate(fm->fd, fm->size) == -1) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
625 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
626 "ftruncate() \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
627 goto failed;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
628 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
629
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
630 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
631 fm->fd, 0);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
632 if (fm->addr != MAP_FAILED) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
633 return NGX_OK;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
634 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
635
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
636 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
637 "mmap(%uz) \"%s\" failed", fm->size, fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
638
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
639 failed:
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
640
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
641 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
642 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
643 ngx_close_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
644 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
645
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
646 return NGX_ERROR;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
647 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
648
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
649
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
650 void
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
651 ngx_close_file_mapping(ngx_file_mapping_t *fm)
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
652 {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
653 if (munmap(fm->addr, fm->size) == -1) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
654 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
655 "munmap(%uz) \"%s\" failed", fm->size, fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
656 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
657
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
658 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
659 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
660 ngx_close_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
661 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
662 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
663
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
664
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
665 ngx_int_t
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
666 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
667 {
290
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 278
diff changeset
668 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
669
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
670 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
671 return NGX_ERROR;
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
672 }
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
673
457
ded1284520cc nginx-0.1.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
674 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
675
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
676 return NGX_OK;
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
677 }
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
678
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
679
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
680 ngx_int_t
2234
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
681 ngx_read_dir(ngx_dir_t *dir)
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
682 {
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
683 dir->de = readdir(dir->dir);
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
684
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
685 if (dir->de) {
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
686 #if (NGX_HAVE_D_TYPE)
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
687 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
688 #else
3200
26784c34e8be *) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents: 3164
diff changeset
689 dir->type = 0;
2234
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
690 #endif
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
691 return NGX_OK;
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
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
694 return NGX_ERROR;
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
695 }
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
696
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
697
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
698 ngx_int_t
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
699 ngx_open_glob(ngx_glob_t *gl)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
700 {
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
701 int n;
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
702
4943
1e2d5d3f9f6b Core: removed GLOB_NOSORT glob option.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4938
diff changeset
703 n = glob((char *) gl->pattern, 0, NULL, &gl->pglob);
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
704
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
705 if (n == 0) {
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
706 return NGX_OK;
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
707 }
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
708
2199
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
709 #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
710
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
711 if (n == GLOB_NOMATCH && gl->test) {
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
712 return NGX_OK;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
713 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
714
2199
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
715 #endif
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
716
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
717 return NGX_ERROR;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
718 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
719
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
720
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
721 ngx_int_t
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
722 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
723 {
2210
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
724 size_t count;
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
725
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
726 #ifdef GLOB_NOMATCH
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
727 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
728 #else
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
729 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
730 #endif
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
731
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
732 if (gl->n < count) {
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
733
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
734 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]);
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
735 name->data = (u_char *) gl->pglob.gl_pathv[gl->n];
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
736 gl->n++;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
737
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
738 return NGX_OK;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
739 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
740
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
741 return NGX_DONE;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
742 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
743
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
744
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
745 void
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
746 ngx_close_glob(ngx_glob_t *gl)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
747 {
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
748 globfree(&gl->pglob);
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
749 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
750
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
751
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
752 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
753 ngx_trylock_fd(ngx_fd_t fd)
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
754 {
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
755 struct flock fl;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
756
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
757 ngx_memzero(&fl, sizeof(struct flock));
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
758 fl.l_type = F_WRLCK;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
759 fl.l_whence = SEEK_SET;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
760
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
761 if (fcntl(fd, F_SETLK, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
762 return ngx_errno;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
763 }
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
764
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
765 return 0;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
766 }
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
767
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
768
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
769 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
770 ngx_lock_fd(ngx_fd_t fd)
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
771 {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
772 struct flock fl;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
773
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
774 ngx_memzero(&fl, sizeof(struct flock));
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
775 fl.l_type = F_WRLCK;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
776 fl.l_whence = SEEK_SET;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
777
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
778 if (fcntl(fd, F_SETLKW, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
779 return ngx_errno;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
780 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
781
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
782 return 0;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
783 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
784
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
785
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
786 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
787 ngx_unlock_fd(ngx_fd_t fd)
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
788 {
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
789 struct flock fl;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
790
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
791 ngx_memzero(&fl, sizeof(struct flock));
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
792 fl.l_type = F_UNLCK;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
793 fl.l_whence = SEEK_SET;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
794
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
795 if (fcntl(fd, F_SETLK, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
796 return ngx_errno;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
797 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
798
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
799 return 0;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
800 }
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
801
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
802
4299
11e47bf300db FreeBSD 10-current has recently gotten POSIX_FADV_* macros.
Maxim Konovalov <maxim@nginx.com>
parents: 4221
diff changeset
803 #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
804
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
805 ngx_int_t
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
806 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
807 {
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
808 int err;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
809
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
810 err = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
811
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
812 if (err == 0) {
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
813 return 0;
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
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
816 ngx_set_errno(err);
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
817 return NGX_FILE_ERROR;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
818 }
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 #endif
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
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
823 #if (NGX_HAVE_O_DIRECT)
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
824
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
825 ngx_int_t
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
826 ngx_directio_on(ngx_fd_t fd)
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
827 {
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
828 int flags;
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
829
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
830 flags = fcntl(fd, F_GETFL);
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
831
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
832 if (flags == -1) {
3164
b1b1775698d5 uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents: 3163
diff changeset
833 return NGX_FILE_ERROR;
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
834 }
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
835
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
836 return fcntl(fd, F_SETFL, flags | O_DIRECT);
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
837 }
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
838
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
839
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
840 ngx_int_t
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
841 ngx_directio_off(ngx_fd_t fd)
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
842 {
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
843 int flags;
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
844
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
845 flags = fcntl(fd, F_GETFL);
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
846
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
847 if (flags == -1) {
3164
b1b1775698d5 uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents: 3163
diff changeset
848 return NGX_FILE_ERROR;
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
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
851 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
852 }
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
853
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
854 #endif
2615
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
855
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
856
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
857 #if (NGX_HAVE_STATFS)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
858
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
859 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
860 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
861 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
862 struct statfs fs;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
863
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
864 if (statfs((char *) name, &fs) == -1) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
865 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
866 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
867
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
868 if ((fs.f_bsize % 512) != 0) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
869 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
870 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
871
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
872 return (size_t) fs.f_bsize;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
873 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
874
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
875 #elif (NGX_HAVE_STATVFS)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
876
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
877 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
878 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
879 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
880 struct statvfs fs;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
881
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
882 if (statvfs((char *) name, &fs) == -1) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
883 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
884 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
885
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
886 if ((fs.f_frsize % 512) != 0) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
887 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
888 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
889
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
890 return (size_t) fs.f_frsize;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
891 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
892
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
893 #else
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
894
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
895 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
896 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
897 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
898 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
899 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
900
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
901 #endif