annotate src/http/ngx_http_file_cache.c @ 632:5b73504dd4ba NGINX_1_1_0

nginx 1.1.0 *) Feature: cache loader run time decrease. *) Feature: "loader_files", "loader_sleep", and "loader_threshold" options of the "proxy/fastcgi/scgi/uwsgi_cache_path" directives. *) Feature: loading time decrease of configuration with large number of HTTPS sites. *) Feature: now nginx supports ECDHE key exchange ciphers. Thanks to Adrian Kotelba. *) Feature: the "lingering_close" directive. Thanks to Maxim Dounin. *) Bugfix: in closing connection for pipelined requests. Thanks to Maxim Dounin. *) Bugfix: nginx did not disable gzipping if client sent "gzip;q=0" in "Accept-Encoding" request header line. *) Bugfix: in timeout in unbuffered proxied mode. Thanks to Maxim Dounin. *) Bugfix: memory leaks when a "proxy_pass" directive contains variables and proxies to an HTTPS backend. Thanks to Maxim Dounin. *) Bugfix: in parameter validaiton of a "proxy_pass" directive with variables. Thanks to Lanshun Zhou. *) Bugfix: SSL did not work on QNX. Thanks to Maxim Dounin. *) Bugfix: SSL modules could not be built by gcc 4.6 without --with-debug option.
author Igor Sysoev <http://sysoev.ru>
date Mon, 01 Aug 2011 00:00:00 +0400
parents ad6fee8052d7
children 23ef0645ea57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
10 #include <ngx_md5.h>
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
13 static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r,
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
14 ngx_http_cache_t *c);
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
15 static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r,
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
16 ngx_http_cache_t *c);
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
17 #if (NGX_HAVE_FILE_AIO)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
18 static void ngx_http_cache_aio_event_handler(ngx_event_t *ev);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
19 #endif
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
20 static ngx_int_t ngx_http_file_cache_exists(ngx_http_file_cache_t *cache,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
21 ngx_http_cache_t *c);
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
22 static ngx_int_t ngx_http_file_cache_name(ngx_http_request_t *r,
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
23 ngx_path_t *path);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
24 static ngx_http_file_cache_node_t *
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
25 ngx_http_file_cache_lookup(ngx_http_file_cache_t *cache, u_char *key);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
26 static void ngx_http_file_cache_rbtree_insert_value(ngx_rbtree_node_t *temp,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
27 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
28 static void ngx_http_file_cache_cleanup(void *data);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
29 static time_t ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
30 static time_t ngx_http_file_cache_expire(ngx_http_file_cache_t *cache);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
31 static void ngx_http_file_cache_delete(ngx_http_file_cache_t *cache,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
32 ngx_queue_t *q, u_char *name);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
33 static ngx_int_t
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
34 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
35 static ngx_int_t ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx,
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
36 ngx_str_t *path);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
37 static ngx_int_t ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
38 ngx_str_t *path);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
39 static ngx_int_t ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
40 ngx_str_t *path);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
41 static ngx_int_t ngx_http_file_cache_add(ngx_http_file_cache_t *cache,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
42 ngx_http_cache_t *c);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
43 static ngx_int_t ngx_http_file_cache_delete_file(ngx_tree_ctx_t *ctx,
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
44 ngx_str_t *path);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46
502
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
47 ngx_str_t ngx_http_cache_status[] = {
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
48 ngx_string("MISS"),
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
49 ngx_string("BYPASS"),
502
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
50 ngx_string("EXPIRED"),
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
51 ngx_string("STALE"),
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
52 ngx_string("UPDATING"),
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
53 ngx_string("HIT")
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
54 };
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
55
f0cac61857ae nginx 0.8.3
Igor Sysoev <http://sysoev.ru>
parents: 500
diff changeset
56
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
57 static u_char ngx_http_file_cache_key[] = { LF, 'K', 'E', 'Y', ':', ' ' };
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
60 static ngx_int_t
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
61 ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
63 ngx_http_file_cache_t *ocache = data;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
65 size_t len;
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
66 ngx_uint_t n;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
67 ngx_http_file_cache_t *cache;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
69 cache = shm_zone->data;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
71 if (ocache) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
72 if (ngx_strcmp(cache->path->name.data, ocache->path->name.data) != 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
73 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
74 "cache \"%V\" uses the \"%V\" cache path "
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
75 "while previously it used the \"%V\" cache path",
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
76 &shm_zone->shm.name, &cache->path->name,
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
77 &ocache->path->name);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 return NGX_ERROR;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
82 for (n = 0; n < 3; n++) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
83 if (cache->path->level[n] != ocache->path->level[n]) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
84 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
85 "cache \"%V\" had previously different levels",
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
86 &shm_zone->shm.name);
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
87 return NGX_ERROR;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
88 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
89 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
90
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
91 cache->sh = ocache->sh;
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
92
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
93 cache->shpool = ocache->shpool;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
94 cache->bsize = ocache->bsize;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
95
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
96 cache->max_size /= cache->bsize;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
97
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
98 if (!cache->sh->cold || cache->sh->loading) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
99 cache->path->loader = NULL;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
100 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
101
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
102 return NGX_OK;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
103 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
104
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
105 cache->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
106
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
107 if (shm_zone->shm.exists) {
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
108 cache->sh = cache->shpool->data;
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
109 cache->bsize = ngx_fs_bsize(cache->path->name.data);
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
110
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
111 return NGX_OK;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
112 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
113
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
114 cache->sh = ngx_slab_alloc(cache->shpool, sizeof(ngx_http_file_cache_sh_t));
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
115 if (cache->sh == NULL) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
116 return NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
117 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
118
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
119 cache->shpool->data = cache->sh;
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
120
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
121 ngx_rbtree_init(&cache->sh->rbtree, &cache->sh->sentinel,
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
122 ngx_http_file_cache_rbtree_insert_value);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
123
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
124 ngx_queue_init(&cache->sh->queue);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
125
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
126 cache->sh->cold = 1;
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
127 cache->sh->loading = 0;
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
128 cache->sh->size = 0;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
129
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
130 cache->bsize = ngx_fs_bsize(cache->path->name.data);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
131
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
132 cache->max_size /= cache->bsize;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
133
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
134 len = sizeof(" in cache keys zone \"\"") + shm_zone->shm.name.len;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
135
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
136 cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
137 if (cache->shpool->log_ctx == NULL) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
138 return NGX_ERROR;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
139 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
140
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
141 ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
142 &shm_zone->shm.name);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
143
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
144 return NGX_OK;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
145 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
146
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
147
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
148 ngx_int_t
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
149 ngx_http_file_cache_new(ngx_http_request_t *r)
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
150 {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
151 ngx_http_cache_t *c;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
152
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
153 c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t));
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
154 if (c == NULL) {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
155 return NGX_ERROR;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
156 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
157
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
158 if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
159 return NGX_ERROR;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
160 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
161
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
162 r->cache = c;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
163 c->file.log = r->connection->log;
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
164 c->file.fd = NGX_INVALID_FILE;
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
165
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
166 return NGX_OK;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
167 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
168
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
169
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
170 ngx_int_t
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
171 ngx_http_file_cache_create(ngx_http_request_t *r)
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
172 {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
173 ngx_http_cache_t *c;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
174 ngx_pool_cleanup_t *cln;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
175 ngx_http_file_cache_t *cache;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
176
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
177 c = r->cache;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
178 cache = c->file_cache;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
179
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
180 cln = ngx_pool_cleanup_add(r->pool, 0);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
181 if (cln == NULL) {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
182 return NGX_ERROR;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
183 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
184
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
185 if (ngx_http_file_cache_exists(cache, c) == NGX_ERROR) {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
186 return NGX_ERROR;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
187 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
188
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
189 cln->handler = ngx_http_file_cache_cleanup;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
190 cln->data = c;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
191
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
192 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
193 return NGX_ERROR;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
194 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
195
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
196 return NGX_OK;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
197 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
198
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
199
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
200 void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
201 ngx_http_file_cache_create_key(ngx_http_request_t *r)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
202 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
203 size_t len;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
204 ngx_str_t *key;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
205 ngx_uint_t i;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
206 ngx_md5_t md5;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
207 ngx_http_cache_t *c;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
208
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
209 c = r->cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
210
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
211 len = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
212
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
213 ngx_crc32_init(c->crc32);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
214 ngx_md5_init(&md5);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
215
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
216 key = c->keys.elts;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
217 for (i = 0; i < c->keys.nelts; i++) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
218 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
219 "http cache key: \"%V\"", &key[i]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
220
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
221 len += key[i].len;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
222
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
223 ngx_crc32_update(&c->crc32, key[i].data, key[i].len);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
224 ngx_md5_update(&md5, key[i].data, key[i].len);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
225 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
226
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
227 c->header_start = sizeof(ngx_http_file_cache_header_t)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
228 + sizeof(ngx_http_file_cache_key) + len + 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
229
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
230 ngx_crc32_final(c->crc32);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
231 ngx_md5_final(c->key, &md5);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
232 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
233
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
234
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
235 ngx_int_t
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
236 ngx_http_file_cache_open(ngx_http_request_t *r)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
237 {
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
238 ngx_int_t rc, rv;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
239 ngx_uint_t cold, test;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
240 ngx_http_cache_t *c;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
241 ngx_pool_cleanup_t *cln;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
242 ngx_open_file_info_t of;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
243 ngx_http_file_cache_t *cache;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
244 ngx_http_core_loc_conf_t *clcf;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
245
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
246 c = r->cache;
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
247
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
248 if (c->buf) {
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
249 return ngx_http_file_cache_read(r, c);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
250 }
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
251
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
252 cache = c->file_cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
253
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
254 cln = ngx_pool_cleanup_add(r->pool, 0);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
255 if (cln == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
256 return NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
257 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
258
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
259 rc = ngx_http_file_cache_exists(cache, c);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
260
498
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
261 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
262 "http file cache exists: %i e:%d", rc, c->exists);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
263
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
264 if (rc == NGX_ERROR) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
265 return rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
266 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
267
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
268 cln->handler = ngx_http_file_cache_cleanup;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
269 cln->data = c;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
270
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
271 if (rc == NGX_AGAIN) {
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
272 return NGX_HTTP_CACHE_SCARCE;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
273 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
274
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
275 cold = cache->sh->cold;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
276
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
277 if (rc == NGX_OK) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
278
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
279 if (c->error) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
280 return c->error;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
281 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
282
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
283 c->temp_file = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
284 test = c->exists ? 1 : 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
285 rv = NGX_DECLINED;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
286
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
287 } else { /* rc == NGX_DECLINED */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
288
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
289 if (c->min_uses > 1) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
290
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
291 if (!cold) {
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
292 return NGX_HTTP_CACHE_SCARCE;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
295 test = 1;
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
296 rv = NGX_HTTP_CACHE_SCARCE;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
297
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
298 } else {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
299 c->temp_file = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
300 test = cold ? 1 : 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
301 rv = NGX_DECLINED;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
305 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
306 return NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
307 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
308
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
309 if (!test) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
310 return NGX_DECLINED;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
311 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
312
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
313 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
314
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
315 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
316
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
317 of.uniq = c->uniq;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
318 of.valid = clcf->open_file_cache_valid;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
319 of.min_uses = clcf->open_file_cache_min_uses;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
320 of.events = clcf->open_file_cache_events;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
321 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF;
532
f7ec98e3caeb nginx 0.8.18
Igor Sysoev <http://sysoev.ru>
parents: 528
diff changeset
322 of.read_ahead = clcf->read_ahead;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
323
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
324 if (ngx_open_cached_file(clcf->open_file_cache, &c->file.name, &of, r->pool)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
325 != NGX_OK)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
326 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
327 switch (of.err) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
328
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
329 case 0:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
330 return NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
331
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
332 case NGX_ENOENT:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
333 case NGX_ENOTDIR:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
334 return rv;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
335
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
336 default:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
337 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
338 ngx_open_file_n " \"%s\" failed", c->file.name.data);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
339 return NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
340 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
341 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
342
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
343 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
344 "http file cache fd: %d", of.fd);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
345
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
346 c->file.fd = of.fd;
466
9eda3153223b nginx 0.7.45
Igor Sysoev <http://sysoev.ru>
parents: 464
diff changeset
347 c->file.log = r->connection->log;
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
348 c->uniq = of.uniq;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
349 c->length = of.size;
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
350 c->fs_size = (of.fs_size + cache->bsize - 1) / cache->bsize;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
351
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
352 c->buf = ngx_create_temp_buf(r->pool, c->body_start);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
353 if (c->buf == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
354 return NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
355 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
356
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
357 return ngx_http_file_cache_read(r, c);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
358 }
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
359
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
360
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
361 static ngx_int_t
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
362 ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
363 {
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
364 time_t now;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
365 ssize_t n;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
366 ngx_int_t rc;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
367 ngx_http_file_cache_t *cache;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
368 ngx_http_file_cache_header_t *h;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
369
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
370 n = ngx_http_file_cache_aio_read(r, c);
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
371
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
372 if (n < 0) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 return n;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375
554
5c576ea5dbd9 nginx 0.8.29
Igor Sysoev <http://sysoev.ru>
parents: 542
diff changeset
376 if ((size_t) n < c->header_start) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
377 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
26
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
378 "cache file \"%s\" is too small", c->file.name.data);
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
379 return NGX_DECLINED;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
381
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
382 h = (ngx_http_file_cache_header_t *) c->buf->pos;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
383
564
da3c99095432 nginx 0.8.34
Igor Sysoev <http://sysoev.ru>
parents: 558
diff changeset
384 if (h->crc32 != c->crc32) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
385 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
386 "cache file \"%s\" has md5 collision", c->file.name.data);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
387 return NGX_DECLINED;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
389
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
390 c->buf->last += n;
26
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
391
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
392 c->valid_sec = h->valid_sec;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
393 c->last_modified = h->last_modified;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
394 c->date = h->date;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
395 c->valid_msec = h->valid_msec;
564
da3c99095432 nginx 0.8.34
Igor Sysoev <http://sysoev.ru>
parents: 558
diff changeset
396 c->header_start = h->header_start;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
397 c->body_start = h->body_start;
26
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
398
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
399 r->cached = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
400
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
401 cache = c->file_cache;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
402
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
403 if (cache->sh->cold) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
404
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
405 ngx_shmtx_lock(&cache->shpool->mutex);
26
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
406
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
407 if (!c->node->exists) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
408 c->node->uses = 1;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
409 c->node->body_start = c->body_start;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
410 c->node->exists = 1;
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
411 c->node->uniq = c->uniq;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
412
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
413 cache->sh->size += c->fs_size;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
414 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
415
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
416 ngx_shmtx_unlock(&cache->shpool->mutex);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
419 now = ngx_time();
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
420
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
421 if (c->valid_sec < now) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
422
498
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
423 ngx_shmtx_lock(&cache->shpool->mutex);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
424
498
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
425 if (c->node->updating) {
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
426 rc = NGX_HTTP_CACHE_UPDATING;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
427
498
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
428 } else {
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
429 c->node->updating = 1;
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
430 c->updating = 1;
498
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
431 rc = NGX_HTTP_CACHE_STALE;
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
432 }
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
433
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
434 ngx_shmtx_unlock(&cache->shpool->mutex);
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
435
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
436 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
437 "http file cache expired: %i %T %T",
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
438 rc, c->valid_sec, now);
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
439
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
440 return rc;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
441 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
443 return NGX_OK;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
444 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
445
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
446
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
447 static ssize_t
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
448 ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c)
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
449 {
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
450 #if (NGX_HAVE_FILE_AIO)
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
451 ssize_t n;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
452 ngx_http_core_loc_conf_t *clcf;
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
453
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
454 if (!ngx_file_aio) {
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
455 goto noaio;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
456 }
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
457
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
458 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
459
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
460 if (!clcf->aio) {
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
461 goto noaio;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
462 }
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
463
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
464 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
465
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
466 if (n != NGX_AGAIN) {
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
467 return n;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
468 }
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
469
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
470 c->file.aio->data = r;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
471 c->file.aio->handler = ngx_http_cache_aio_event_handler;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
472
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
473 r->main->blocked++;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
474 r->aio = 1;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
475
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
476 return NGX_AGAIN;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
477
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
478 noaio:
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
479
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
480 #endif
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
481
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
482 return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
483 }
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
484
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
485
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 536
diff changeset
486 #if (NGX_HAVE_FILE_AIO)
518
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
487
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
488 static void
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
489 ngx_http_cache_aio_event_handler(ngx_event_t *ev)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
490 {
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
491 ngx_event_aio_t *aio;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
492 ngx_http_request_t *r;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
493
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
494 aio = ev->data;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
495 r = aio->data;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
496
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
497 r->main->blocked--;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
498 r->aio = 0;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
499
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
500 r->connection->write->handler(r->connection->write);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
501 }
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
502
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
503 #endif
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
504
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 514
diff changeset
505
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
506 static ngx_int_t
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
507 ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
508 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
509 ngx_int_t rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
510 ngx_http_file_cache_node_t *fcn;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
511
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
512 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
513
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
514 fcn = ngx_http_file_cache_lookup(cache, c->key);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
515
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
516 if (fcn) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
517 ngx_queue_remove(&fcn->queue);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
518
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
519 fcn->uses++;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
520 fcn->count++;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
521
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
522 if (fcn->error) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
523
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
524 if (fcn->valid_sec < ngx_time()) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
525 goto renew;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
526 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
527
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
528 rc = NGX_OK;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
529
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
530 goto done;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
531 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
532
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
533 if (fcn->exists || fcn->uses >= c->min_uses) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
534
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
535 c->exists = fcn->exists;
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
536 if (fcn->body_start) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
537 c->body_start = fcn->body_start;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
538 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
539
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
540 rc = NGX_OK;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
541
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
542 goto done;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
543 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
544
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
545 rc = NGX_AGAIN;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
546
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
547 goto done;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
548 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
549
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
550 fcn = ngx_slab_alloc_locked(cache->shpool,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
551 sizeof(ngx_http_file_cache_node_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
552 if (fcn == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
553 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
554
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
555 (void) ngx_http_file_cache_forced_expire(cache);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
556
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
557 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
558
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
559 fcn = ngx_slab_alloc_locked(cache->shpool,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
560 sizeof(ngx_http_file_cache_node_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
561 if (fcn == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
562 rc = NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
563 goto failed;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
564 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
565 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
566
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
567 ngx_memcpy((u_char *) &fcn->node.key, c->key, sizeof(ngx_rbtree_key_t));
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
568
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
569 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)],
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
570 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
571
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
572 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
573
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
574 fcn->uses = 1;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
575 fcn->count = 1;
594
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
576 fcn->updating = 0;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
577 fcn->deleting = 0;
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
578
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
579 renew:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
580
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
581 rc = NGX_DECLINED;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
582
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
583 fcn->valid_msec = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
584 fcn->error = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
585 fcn->exists = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
586 fcn->valid_sec = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
587 fcn->uniq = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
588 fcn->body_start = 0;
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
589 fcn->fs_size = 0;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
590
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
591 done:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
592
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
593 fcn->expire = ngx_time() + cache->inactive;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
594
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
595 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
596
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
597 c->uniq = fcn->uniq;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
598 c->error = fcn->error;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
599 c->node = fcn;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
600
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
601 failed:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
602
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
603 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
604
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
605 return rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
606 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
607
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
608
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
609 static ngx_int_t
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
610 ngx_http_file_cache_name(ngx_http_request_t *r, ngx_path_t *path)
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
611 {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
612 u_char *p;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
613 ngx_http_cache_t *c;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
614
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
615 c = r->cache;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
616
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
617 c->file.name.len = path->name.len + 1 + path->len
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
618 + 2 * NGX_HTTP_CACHE_KEY_LEN;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
619
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
620 c->file.name.data = ngx_pnalloc(r->pool, c->file.name.len + 1);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
621 if (c->file.name.data == NULL) {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
622 return NGX_ERROR;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
623 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
624
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
625 ngx_memcpy(c->file.name.data, path->name.data, path->name.len);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
626
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
627 p = c->file.name.data + path->name.len + 1 + path->len;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
628 p = ngx_hex_dump(p, c->key, NGX_HTTP_CACHE_KEY_LEN);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
629 *p = '\0';
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
630
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
631 ngx_create_hashed_filename(path, c->file.name.data, c->file.name.len);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
632
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
633 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
634 "cache file: \"%s\"", c->file.name.data);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
635
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
636 return NGX_OK;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
637 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
638
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
639
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
640 static ngx_http_file_cache_node_t *
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
641 ngx_http_file_cache_lookup(ngx_http_file_cache_t *cache, u_char *key)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
642 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
643 ngx_int_t rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
644 ngx_rbtree_key_t node_key;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
645 ngx_rbtree_node_t *node, *sentinel;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
646 ngx_http_file_cache_node_t *fcn;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
647
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
648 ngx_memcpy((u_char *) &node_key, key, sizeof(ngx_rbtree_key_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
649
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
650 node = cache->sh->rbtree.root;
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
651 sentinel = cache->sh->rbtree.sentinel;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
652
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
653 while (node != sentinel) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
654
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
655 if (node_key < node->key) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
656 node = node->left;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
657 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
658 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
659
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
660 if (node_key > node->key) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
661 node = node->right;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
662 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
663 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
664
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
665 /* node_key == node->key */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
666
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
667 do {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
668 fcn = (ngx_http_file_cache_node_t *) node;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
669
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
670 rc = ngx_memcmp(&key[sizeof(ngx_rbtree_key_t)], fcn->key,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
671 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
672
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
673 if (rc == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
674 return fcn;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
675 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
676
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
677 node = (rc < 0) ? node->left : node->right;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
678
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
679 } while (node != sentinel && node_key == node->key);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
680
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
681 break;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
682 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
683
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
684 /* not found */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
685
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
686 return NULL;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
687 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
688
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
689
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
690 static void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
691 ngx_http_file_cache_rbtree_insert_value(ngx_rbtree_node_t *temp,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
692 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
693 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
694 ngx_rbtree_node_t **p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
695 ngx_http_file_cache_node_t *cn, *cnt;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
696
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
697 for ( ;; ) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
698
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
699 if (node->key < temp->key) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
700
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
701 p = &temp->left;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
702
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
703 } else if (node->key > temp->key) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
704
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
705 p = &temp->right;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
706
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
707 } else { /* node->key == temp->key */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
708
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
709 cn = (ngx_http_file_cache_node_t *) node;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
710 cnt = (ngx_http_file_cache_node_t *) temp;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
711
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
712 p = (ngx_memcmp(cn->key, cnt->key,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
713 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t))
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
714 < 0)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
715 ? &temp->left : &temp->right;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
716 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
717
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
718 if (*p == sentinel) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
719 break;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
720 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
721
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
722 temp = *p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
723 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
724
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
725 *p = node;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
726 node->parent = temp;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
727 node->left = sentinel;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
728 node->right = sentinel;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
729 ngx_rbt_red(node);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
730 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
731
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
732
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
733 void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
734 ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
735 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
736 ngx_http_file_cache_header_t *h = (ngx_http_file_cache_header_t *) buf;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
737
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
738 u_char *p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
739 ngx_str_t *key;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
740 ngx_uint_t i;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
741 ngx_http_cache_t *c;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
742
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
743 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
744 "http file cache set header");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
745
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
746 c = r->cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
747
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
748 h->valid_sec = c->valid_sec;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
749 h->last_modified = c->last_modified;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
750 h->date = c->date;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
751 h->crc32 = c->crc32;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
752 h->valid_msec = (u_short) c->valid_msec;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
753 h->header_start = (u_short) c->header_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
754 h->body_start = (u_short) c->body_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
755
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
756 p = buf + sizeof(ngx_http_file_cache_header_t);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
757
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
758 p = ngx_cpymem(p, ngx_http_file_cache_key, sizeof(ngx_http_file_cache_key));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
759
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
760 key = c->keys.elts;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
761 for (i = 0; i < c->keys.nelts; i++) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
762 p = ngx_copy(p, key[i].data, key[i].len);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
763 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
764
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
765 *p = LF;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
766 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
767
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
768
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
769 void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
770 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
771 {
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
772 off_t fs_size;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
773 ngx_int_t rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
774 ngx_file_uniq_t uniq;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
775 ngx_file_info_t fi;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
776 ngx_http_cache_t *c;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
777 ngx_ext_rename_file_t ext;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
778 ngx_http_file_cache_t *cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
779
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
780 c = r->cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
781
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
782 if (c->updated) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
783 return;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
784 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
785
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
786 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
787 "http file cache update");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
788
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
789 c->updated = 1;
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
790 c->updating = 0;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
791
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
792 cache = c->file_cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
793
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
794 uniq = 0;
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
795 fs_size = 0;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
796
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
797 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
798 "http file cache rename: \"%s\" to \"%s\"",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
799 tf->file.name.data, c->file.name.data);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
800
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
801 ext.access = NGX_FILE_OWNER_ACCESS;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
802 ext.path_access = NGX_FILE_OWNER_ACCESS;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
803 ext.time = -1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
804 ext.create_path = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
805 ext.delete_file = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
806 ext.log = r->connection->log;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
807
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
808 rc = ngx_ext_rename_file(&tf->file.name, &c->file.name, &ext);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
809
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
810 if (rc == NGX_OK) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
811
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
812 if (ngx_fd_info(tf->file.fd, &fi) == NGX_FILE_ERROR) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
813 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
814 ngx_fd_info_n " \"%s\" failed", tf->file.name.data);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
815
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
816 rc = NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
817
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
818 } else {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
819 uniq = ngx_file_uniq(&fi);
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
820 fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
821 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
822 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
823
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
824 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
825
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
826 c->node->count--;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
827 c->node->uniq = uniq;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
828 c->node->body_start = c->body_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
829
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
830 cache->sh->size += fs_size - c->node->fs_size;
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
831 c->node->fs_size = fs_size;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
832
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
833 if (rc == NGX_OK) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
834 c->node->exists = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
835 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
836
498
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
837 c->node->updating = 0;
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
838
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
839 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
840 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
841
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
842
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
843 ngx_int_t
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
844 ngx_http_cache_send(ngx_http_request_t *r)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
845 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
846 ngx_int_t rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
847 ngx_buf_t *b;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
848 ngx_chain_t out;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
849 ngx_http_cache_t *c;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
850
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
851 c = r->cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
852
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
853 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
854 "http file cache send: %s", c->file.name.data);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
855
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
856 /* we need to allocate all before the header would be sent */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
857
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
858 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
859 if (b == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
860 return NGX_HTTP_INTERNAL_SERVER_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
861 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
862
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
863 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
864 if (b->file == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
865 return NGX_HTTP_INTERNAL_SERVER_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
866 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
867
558
2da4537168f8 nginx 0.8.31
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
868 r->header_only = (c->length - c->body_start) == 0;
2da4537168f8 nginx 0.8.31
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
869
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
870 rc = ngx_http_send_header(r);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
871
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
872 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
873 return rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
874 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
875
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
876 b->file_pos = c->body_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
877 b->file_last = c->length;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
878
558
2da4537168f8 nginx 0.8.31
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
879 b->in_file = 1;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
880 b->last_buf = (r == r->main) ? 1: 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
881 b->last_in_chain = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
882
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
883 b->file->fd = c->file.fd;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
884 b->file->name = c->file.name;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
885 b->file->log = r->connection->log;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
886
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
887 out.buf = b;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
888 out.next = NULL;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
889
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
890 return ngx_http_output_filter(r, &out);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
891 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
892
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
893
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
894 void
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
895 ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf)
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
896 {
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
897 ngx_http_file_cache_t *cache;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
898 ngx_http_file_cache_node_t *fcn;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
899
626
a7a5fa2e395b nginx 1.0.3
Igor Sysoev <http://sysoev.ru>
parents: 622
diff changeset
900 if (c->updated || c->node == NULL) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
901 return;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
902 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
903
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
904 cache = c->file_cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
905
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
906 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
907 "http file cache free, fd: %d", c->file.fd);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
908
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
909 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
910
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
911 fcn = c->node;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
912 fcn->count--;
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
913
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
914 if (c->updating) {
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
915 fcn->updating = 0;
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
916 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
917
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
918 if (c->error) {
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
919 fcn->error = c->error;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
920
594
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
921 if (c->valid_sec) {
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
922 fcn->valid_sec = c->valid_sec;
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
923 fcn->valid_msec = c->valid_msec;
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
924 }
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
925
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
926 } else if (!fcn->exists && fcn->count == 0 && c->min_uses == 1) {
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
927 ngx_queue_remove(&fcn->queue);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
928 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
929 ngx_slab_free_locked(cache->shpool, fcn);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
930 c->node = NULL;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
931 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
932
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
933 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
934
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
935 c->updated = 1;
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
936 c->updating = 0;
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
937
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
938 if (c->temp_file) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
939 if (tf && tf->file.fd != NGX_INVALID_FILE) {
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
940 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
941 "http file cache incomplete: \"%s\"",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
942 tf->file.name.data);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
943
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
944 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
945 ngx_log_error(NGX_LOG_CRIT, c->file.log, ngx_errno,
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
946 ngx_delete_file_n " \"%s\" failed",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
947 tf->file.name.data);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
948 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
949 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
950 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
951 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
952
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
953
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
954 static void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
955 ngx_http_file_cache_cleanup(void *data)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
956 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
957 ngx_http_cache_t *c = data;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
958
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
959 if (c->updated) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
960 return;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
961 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
962
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
963 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
964 "http file cache cleanup");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
965
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
966 if (c->updating) {
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
967 ngx_log_error(NGX_LOG_ALERT, c->file.log, 0,
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
968 "stalled cache updating, error:%ui", c->error);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
969 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
970
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
971 ngx_http_file_cache_free(c, NULL);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
972 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
973
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
974
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
975 static time_t
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
976 ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache)
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
977 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
978 u_char *name;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
979 size_t len;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
980 time_t wait;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
981 ngx_uint_t tries;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
982 ngx_path_t *path;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
983 ngx_queue_t *q;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
984 ngx_http_file_cache_node_t *fcn;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
985
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
986 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
987 "http file cache forced expire");
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
988
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
989 path = cache->path;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
990 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
991
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
992 name = ngx_alloc(len + 1, ngx_cycle->log);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
993 if (name == NULL) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
994 return 10;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
995 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
996
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
997 ngx_memcpy(name, path->name.data, path->name.len);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
998
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
999 wait = 10;
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1000 tries = 20;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1001
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1002 ngx_shmtx_lock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1003
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1004 for (q = ngx_queue_last(&cache->sh->queue);
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1005 q != ngx_queue_sentinel(&cache->sh->queue);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1006 q = ngx_queue_prev(q))
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1007 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1008 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1009
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1010 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1011 "http file cache forced expire: #%d %d %02xd%02xd%02xd%02xd",
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1012 fcn->count, fcn->exists,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1013 fcn->key[0], fcn->key[1], fcn->key[2], fcn->key[3]);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1014
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1015 if (fcn->count == 0) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1016 ngx_http_file_cache_delete(cache, q, name);
620
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1017 wait = 0;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1018
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1019 } else {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1020 if (--tries) {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1021 continue;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1022 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1023
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1024 wait = 1;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1025 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1026
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1027 break;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1028 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1029
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1030 ngx_shmtx_unlock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1031
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1032 ngx_free(name);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1033
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1034 return wait;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1035 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1036
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1037
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1038 static time_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1039 ngx_http_file_cache_expire(ngx_http_file_cache_t *cache)
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1040 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1041 u_char *name, *p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1042 size_t len;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1043 time_t now, wait;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1044 ngx_path_t *path;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1045 ngx_queue_t *q;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1046 ngx_http_file_cache_node_t *fcn;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1047 u_char key[2 * NGX_HTTP_CACHE_KEY_LEN];
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1048
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1049 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1050 "http file cache expire");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1051
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1052 path = cache->path;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1053 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1054
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1055 name = ngx_alloc(len + 1, ngx_cycle->log);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1056 if (name == NULL) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1057 return 10;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1058 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1059
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1060 ngx_memcpy(name, path->name.data, path->name.len);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1061
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1062 now = ngx_time();
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1063
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1064 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1065
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1066 for ( ;; ) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1067
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1068 if (ngx_queue_empty(&cache->sh->queue)) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1069 wait = 10;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1070 break;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1071 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1072
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1073 q = ngx_queue_last(&cache->sh->queue);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1074
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1075 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1076
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1077 wait = fcn->expire - now;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1078
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1079 if (wait > 0) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1080 wait = wait > 10 ? 10 : wait;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1081 break;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1082 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1083
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1084 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1085 "http file cache expire: #%d %d %02xd%02xd%02xd%02xd",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1086 fcn->count, fcn->exists,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1087 fcn->key[0], fcn->key[1], fcn->key[2], fcn->key[3]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1088
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1089 if (fcn->count == 0) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1090 ngx_http_file_cache_delete(cache, q, name);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1091 continue;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1092 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1093
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1094 if (fcn->deleting) {
630
ad6fee8052d7 nginx 1.0.5
Igor Sysoev <http://sysoev.ru>
parents: 626
diff changeset
1095 wait = 1;
ad6fee8052d7 nginx 1.0.5
Igor Sysoev <http://sysoev.ru>
parents: 626
diff changeset
1096 break;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1097 }
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1098
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1099 p = ngx_hex_dump(key, (u_char *) &fcn->node.key,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1100 sizeof(ngx_rbtree_key_t));
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1101 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1102 (void) ngx_hex_dump(p, fcn->key, len);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1103
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1104 /*
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1105 * abnormally exited workers may leave locked cache entries,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1106 * and although it may be safe to remove them completely,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1107 * we prefer to remove them from inactive queue and rbtree
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1108 * only, and to allow other leaks
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1109 */
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1110
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1111 ngx_queue_remove(q);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1112 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1113
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1114 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1115 "ignore long locked inactive cache entry %*s, count:%d",
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1116 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1117 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1118
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1119 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1120
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1121 ngx_free(name);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1122
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1123 return wait;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1124 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1125
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1126
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1127 static void
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1128 ngx_http_file_cache_delete(ngx_http_file_cache_t *cache, ngx_queue_t *q,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1129 u_char *name)
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1130 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1131 u_char *p;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1132 size_t len;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1133 ngx_path_t *path;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1134 ngx_http_file_cache_node_t *fcn;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1135
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1136 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1137
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1138 if (fcn->exists) {
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
1139 cache->sh->size -= fcn->fs_size;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1140
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1141 path = cache->path;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1142 p = name + path->name.len + 1 + path->len;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1143 p = ngx_hex_dump(p, (u_char *) &fcn->node.key,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1144 sizeof(ngx_rbtree_key_t));
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1145 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1146 p = ngx_hex_dump(p, fcn->key, len);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1147 *p = '\0';
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1148
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1149 fcn->count++;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1150 fcn->deleting = 1;
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1151 ngx_shmtx_unlock(&cache->shpool->mutex);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1152
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1153 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1154 ngx_create_hashed_filename(path, name, len);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1155
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1156 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1157 "http file cache expire: \"%s\"", name);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1158
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1159 if (ngx_delete_file(name) == NGX_FILE_ERROR) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1160 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, ngx_errno,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1161 ngx_delete_file_n " \"%s\" failed", name);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1162 }
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1163
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1164 ngx_shmtx_lock(&cache->shpool->mutex);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1165 fcn->count--;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1166 fcn->deleting = 0;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1167 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1168
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1169 if (fcn->count == 0) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1170 ngx_queue_remove(q);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1171 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1172 ngx_slab_free_locked(cache->shpool, fcn);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1173 }
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1174 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1175
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1176
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1177 static time_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1178 ngx_http_file_cache_manager(void *data)
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1179 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1180 ngx_http_file_cache_t *cache = data;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1181
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1182 off_t size;
620
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1183 time_t next, wait;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1184
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1185 next = ngx_http_file_cache_expire(cache);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1186
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1187 cache->last = ngx_current_msec;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1188 cache->files = 0;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1189
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1190 for ( ;; ) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1191 ngx_shmtx_lock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1192
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1193 size = cache->sh->size;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1194
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1195 ngx_shmtx_unlock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1196
470
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1197 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1198 "http file cache size: %O", size);
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1199
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1200 if (size < cache->max_size) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1201 return next;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1202 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1203
620
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1204 wait = ngx_http_file_cache_forced_expire(cache);
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1205
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1206 if (wait > 0) {
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1207 return wait;
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1208 }
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1209
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1210 if (ngx_quit || ngx_terminate) {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1211 return next;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1212 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1213 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1214 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1215
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1216
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1217 static void
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1218 ngx_http_file_cache_loader(void *data)
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1219 {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1220 ngx_http_file_cache_t *cache = data;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1221
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1222 ngx_tree_ctx_t tree;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1223
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1224 if (!cache->sh->cold || cache->sh->loading) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1225 return;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1226 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1227
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1228 if (!ngx_atomic_cmp_set(&cache->sh->loading, 0, ngx_pid)) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1229 return;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1230 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1231
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1232 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1233 "http file cache loader");
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1234
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1235 tree.init_handler = NULL;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1236 tree.file_handler = ngx_http_file_cache_manage_file;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1237 tree.pre_tree_handler = ngx_http_file_cache_noop;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1238 tree.post_tree_handler = ngx_http_file_cache_noop;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1239 tree.spec_handler = ngx_http_file_cache_delete_file;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1240 tree.data = cache;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1241 tree.alloc = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1242 tree.log = ngx_cycle->log;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1243
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1244 cache->last = ngx_current_msec;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1245 cache->files = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1246
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1247 if (ngx_walk_tree(&tree, &cache->path->name) == NGX_ABORT) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1248 cache->sh->loading = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1249 return;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1250 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1251
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1252 cache->sh->cold = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1253 cache->sh->loading = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1254
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1255 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1256 "http file cache: %V %.3fM, bsize: %uz",
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1257 &cache->path->name,
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1258 ((double) cache->sh->size * cache->bsize) / (1024 * 1024),
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1259 cache->bsize);
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1260 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1261
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1262
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1263 static ngx_int_t
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1264 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache)
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1265 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1266 ngx_msec_t elapsed;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1267
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1268 if (++cache->files >= cache->loader_files) {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1269
566
be4f34123024 nginx 0.8.35
Igor Sysoev <http://sysoev.ru>
parents: 564
diff changeset
1270 ngx_time_update();
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1271
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1272 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1273
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1274 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1275 "http file cache loader time elapsed: %M", elapsed);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1276
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1277 if (elapsed >= cache->loader_threshold) {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1278
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1279 if (cache->loader_files > 1) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1280 cache->loader_files /= 2;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1281 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1282 "cache %V loader_files decreased to %ui",
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1283 &cache->path->name, cache->loader_files);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1284
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1285 } else {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1286 cache->loader_sleep *= 2;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1287 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1288 "cache %V loader_sleep increased to %Mms",
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1289 &cache->path->name, cache->loader_sleep);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1290 }
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1291 }
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1292
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1293 ngx_msleep(cache->loader_sleep);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1294
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1295 ngx_time_update();
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1296
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1297 cache->last = ngx_current_msec;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1298 cache->files = 0;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1299 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1300
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1301 return (ngx_quit || ngx_terminate) ? NGX_ABORT : NGX_OK;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1302 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1303
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1304
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1305 static ngx_int_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1306 ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path)
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1307 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1308 return NGX_OK;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1309 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1310
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1311
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1312 static ngx_int_t
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1313 ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1314 {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1315 ngx_http_file_cache_t *cache;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1316
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1317 cache = ctx->data;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1318
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1319 if (ngx_http_file_cache_add_file(ctx, path) != NGX_OK) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1320 (void) ngx_http_file_cache_delete_file(ctx, path);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1321 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1322
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1323 return ngx_http_file_cache_loader_sleep(cache);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1324 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1325
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1326
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1327 static ngx_int_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1328 ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, ngx_str_t *name)
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1329 {
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1330 u_char *p;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1331 ngx_int_t n;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1332 ngx_uint_t i;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1333 ngx_http_cache_t c;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1334 ngx_http_file_cache_t *cache;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1335
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1336 if (name->len < 2 * NGX_HTTP_CACHE_KEY_LEN) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1337 return NGX_ERROR;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1338 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1339
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1340 if (ctx->size < (off_t) sizeof(ngx_http_file_cache_header_t)) {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1341 ngx_log_error(NGX_LOG_CRIT, ctx->log, 0,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1342 "cache file \"%s\" is too small", name->data);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1343 return NGX_ERROR;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1344 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1345
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1346 ngx_memzero(&c, sizeof(ngx_http_cache_t));
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
1347 cache = ctx->data;
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
1348
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1349 c.length = ctx->size;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1350 c.fs_size = (ctx->fs_size + cache->bsize - 1) / cache->bsize;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1351
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1352 p = &name->data[name->len - 2 * NGX_HTTP_CACHE_KEY_LEN];
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1353
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1354 for (i = 0; i < NGX_HTTP_CACHE_KEY_LEN; i++) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1355 n = ngx_hextoi(p, 2);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1356
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1357 if (n == NGX_ERROR) {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1358 return NGX_ERROR;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1359 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1360
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1361 p += 2;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1362
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1363 c.key[i] = (u_char) n;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1364 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1365
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1366 return ngx_http_file_cache_add(cache, &c);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1367 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1368
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1369
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1370 static ngx_int_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1371 ngx_http_file_cache_add(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1372 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1373 ngx_http_file_cache_node_t *fcn;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1374
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1375 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1376
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1377 fcn = ngx_http_file_cache_lookup(cache, c->key);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1378
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1379 if (fcn == NULL) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1380
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1381 fcn = ngx_slab_alloc_locked(cache->shpool,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1382 sizeof(ngx_http_file_cache_node_t));
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1383 if (fcn == NULL) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1384 ngx_shmtx_unlock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1385 return NGX_ERROR;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1386 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1387
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1388 ngx_memcpy((u_char *) &fcn->node.key, c->key, sizeof(ngx_rbtree_key_t));
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1389
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1390 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)],
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1391 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1392
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1393 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1394
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1395 fcn->uses = 1;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1396 fcn->count = 0;
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1397 fcn->valid_msec = 0;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1398 fcn->error = 0;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1399 fcn->exists = 1;
594
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
1400 fcn->updating = 0;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1401 fcn->deleting = 0;
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1402 fcn->uniq = 0;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1403 fcn->valid_sec = 0;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1404 fcn->body_start = 0;
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
1405 fcn->fs_size = c->fs_size;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1406
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
1407 cache->sh->size += c->fs_size;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1408
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1409 } else {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1410 ngx_queue_remove(&fcn->queue);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1411 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1412
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1413 fcn->expire = ngx_time() + cache->inactive;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1414
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1415 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1416
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1417 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1418
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1419 return NGX_OK;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1420 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1421
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1422
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1423 static ngx_int_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1424 ngx_http_file_cache_delete_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1425 {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1426 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1427 "http file cache delete: \"%s\"", path->data);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1428
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1429 if (ngx_delete_file(path->data) == NGX_FILE_ERROR) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1430 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1431 ngx_delete_file_n " \"%s\" failed", path->data);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1432 }
26
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
1433
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1434 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1435 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1436
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1437
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1438 time_t
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1439 ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1440 {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1441 ngx_uint_t i;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1442 ngx_http_cache_valid_t *valid;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1443
470
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1444 if (cache_valid == NULL) {
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1445 return 0;
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1446 }
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1447
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1448 valid = cache_valid->elts;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1449 for (i = 0; i < cache_valid->nelts; i++) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1450
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1451 if (valid[i].status == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1452 return valid[i].valid;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1453 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1454
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1455 if (valid[i].status == status) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1456 return valid[i].valid;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1457 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1458 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1459
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1460 return 0;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1461 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1462
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1463
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1464 char *
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1465 ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1466 {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1467 off_t max_size;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1468 u_char *last, *p;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1469 time_t inactive;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1470 ssize_t size;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1471 ngx_str_t s, name, *value;
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1472 ngx_int_t loader_files, loader_sleep, loader_threshold;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1473 ngx_uint_t i, n;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1474 ngx_http_file_cache_t *cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1475
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1476 cache = ngx_pcalloc(cf->pool, sizeof(ngx_http_file_cache_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1477 if (cache == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1478 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1479 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1480
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1481 cache->path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1482 if (cache->path == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1483 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1484 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1485
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1486 inactive = 600;
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1487 loader_files = 100;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1488 loader_sleep = 50;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1489 loader_threshold = 200;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1490
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1491 name.len = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1492 size = 0;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1493 max_size = NGX_MAX_OFF_T_VALUE;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1494
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1495 value = cf->args->elts;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1496
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1497 cache->path->name = value[1];
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1498
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1499 if (cache->path->name.data[cache->path->name.len - 1] == '/') {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1500 cache->path->name.len--;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1501 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1502
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1503 if (ngx_conf_full_name(cf->cycle, &cache->path->name, 0) != NGX_OK) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1504 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1505 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1506
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1507 for (i = 2; i < cf->args->nelts; i++) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1508
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1509 if (ngx_strncmp(value[i].data, "levels=", 7) == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1510
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1511 p = value[i].data + 7;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1512 last = value[i].data + value[i].len;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1513
472
09f0ef15d544 nginx 0.7.48
Igor Sysoev <http://sysoev.ru>
parents: 470
diff changeset
1514 for (n = 0; n < 3 && p < last; n++) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1515
472
09f0ef15d544 nginx 0.7.48
Igor Sysoev <http://sysoev.ru>
parents: 470
diff changeset
1516 if (*p > '0' && *p < '3') {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1517
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1518 cache->path->level[n] = *p++ - '0';
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1519 cache->path->len += cache->path->level[n] + 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1520
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1521 if (p == last) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1522 break;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1523 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1524
472
09f0ef15d544 nginx 0.7.48
Igor Sysoev <http://sysoev.ru>
parents: 470
diff changeset
1525 if (*p++ == ':' && n < 2 && p != last) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1526 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1527 }
472
09f0ef15d544 nginx 0.7.48
Igor Sysoev <http://sysoev.ru>
parents: 470
diff changeset
1528
09f0ef15d544 nginx 0.7.48
Igor Sysoev <http://sysoev.ru>
parents: 470
diff changeset
1529 goto invalid_levels;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1530 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1531
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1532 goto invalid_levels;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1533 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1534
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1535 if (cache->path->len < 10 + 3) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1536 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1537 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1538
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1539 invalid_levels:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1540
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1541 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1542 "invalid \"levels\" \"%V\"", &value[i]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1543 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1544 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1545
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1546 if (ngx_strncmp(value[i].data, "keys_zone=", 10) == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1547
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1548 name.data = value[i].data + 10;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1549
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1550 p = (u_char *) ngx_strchr(name.data, ':');
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1551
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1552 if (p) {
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1553 *p = '\0';
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1554
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1555 name.len = p - name.data;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1556
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1557 p++;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1558
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1559 s.len = value[i].data + value[i].len - p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1560 s.data = p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1561
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1562 size = ngx_parse_size(&s);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1563 if (size > 8191) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1564 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1565 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1566 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1567
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1568 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1569 "invalid keys zone size \"%V\"", &value[i]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1570 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1571 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1572
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1573 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1574
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1575 s.len = value[i].len - 9;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1576 s.data = value[i].data + 9;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1577
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1578 inactive = ngx_parse_time(&s, 1);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1579 if (inactive < 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1580 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1581 "invalid inactive value \"%V\"", &value[i]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1582 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1583 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1584
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1585 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1586 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1587
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1588 if (ngx_strncmp(value[i].data, "max_size=", 9) == 0) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1589
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1590 s.len = value[i].len - 9;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1591 s.data = value[i].data + 9;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1592
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1593 max_size = ngx_parse_offset(&s);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1594 if (max_size < 0) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1595 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1596 "invalid max_size value \"%V\"", &value[i]);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1597 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1598 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1599
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1600 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1601 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1602
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1603 if (ngx_strncmp(value[i].data, "loader_files=", 13) == 0) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1604
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1605 loader_files = ngx_atoi(value[i].data + 13, value[i].len - 13);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1606 if (loader_files == NGX_ERROR) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1607 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1608 "invalid loader_files value \"%V\"", &value[i]);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1609 return NGX_CONF_ERROR;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1610 }
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1611
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1612 continue;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1613 }
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1614
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1615 if (ngx_strncmp(value[i].data, "loader_sleep=", 13) == 0) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1616
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1617 s.len = value[i].len - 13;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1618 s.data = value[i].data + 13;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1619
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1620 loader_sleep = ngx_parse_time(&s, 0);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1621 if (loader_sleep < 0) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1622 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1623 "invalid loader_sleep value \"%V\"", &value[i]);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1624 return NGX_CONF_ERROR;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1625 }
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1626
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1627 continue;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1628 }
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1629
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1630 if (ngx_strncmp(value[i].data, "loader_threshold=", 17) == 0) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1631
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1632 s.len = value[i].len - 17;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1633 s.data = value[i].data + 17;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1634
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1635 loader_threshold = ngx_parse_time(&s, 0);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1636 if (loader_threshold < 0) {
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1637 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1638 "invalid loader_threshold value \"%V\"", &value[i]);
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1639 return NGX_CONF_ERROR;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1640 }
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1641
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1642 continue;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1643 }
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1644
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1645 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1646 "invalid parameter \"%V\"", &value[i]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1647 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1648 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1649
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1650 if (name.len == 0 || size == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1651 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1652 "\"%V\" must have \"keys_zone\" parameter",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1653 &cmd->name);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1654 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1655 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1656
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1657 cache->path->manager = ngx_http_file_cache_manager;
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1658 cache->path->loader = ngx_http_file_cache_loader;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1659 cache->path->data = cache;
632
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1660 cache->path->conf_file = cf->conf_file->file.name.data;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1661 cache->path->line = cf->conf_file->line;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1662 cache->loader_files = loader_files;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1663 cache->loader_sleep = (ngx_msec_t) loader_sleep;
5b73504dd4ba nginx 1.1.0
Igor Sysoev <http://sysoev.ru>
parents: 630
diff changeset
1664 cache->loader_threshold = (ngx_msec_t) loader_threshold;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1665
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1666 if (ngx_add_path(cf, &cache->path) != NGX_OK) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1667 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1668 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1669
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1670 cache->shm_zone = ngx_shared_memory_add(cf, &name, size, cmd->post);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1671 if (cache->shm_zone == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1672 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1673 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1674
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1675 if (cache->shm_zone->data) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1676 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1677 "duplicate zone \"%V\"", &name);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1678 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1679 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1680
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1681
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1682 cache->shm_zone->init = ngx_http_file_cache_init;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1683 cache->shm_zone->data = cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1684
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1685 cache->inactive = inactive;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1686 cache->max_size = max_size;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1687
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1688 return NGX_CONF_OK;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1689 }
26
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
1690
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
1691
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1692 char *
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1693 ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1694 void *conf)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1695 {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1696 char *p = conf;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1697
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1698 time_t valid;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1699 ngx_str_t *value;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1700 ngx_uint_t i, n, status;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1701 ngx_array_t **a;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1702 ngx_http_cache_valid_t *v;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1703 static ngx_uint_t statuses[] = { 200, 301, 302 };
26
45fe5b98a9de nginx 0.1.13
Igor Sysoev <http://sysoev.ru>
parents: 18
diff changeset
1704
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1705 a = (ngx_array_t **) (p + cmd->offset);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1706
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1707 if (*a == NGX_CONF_UNSET_PTR) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1708 *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_cache_valid_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1709 if (*a == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1710 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1711 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1712 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1713
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1714 value = cf->args->elts;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1715 n = cf->args->nelts - 1;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1716
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1717 valid = ngx_parse_time(&value[n], 1);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1718 if (valid < 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1719 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1720 "invalid time value \"%V\"", &value[n]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1721 return NGX_CONF_ERROR;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1722 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1723
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1724 if (n == 1) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1725
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1726 for (i = 0; i < 3; i++) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1727 v = ngx_array_push(*a);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1728 if (v == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1729 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1730 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1731
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1732 v->status = statuses[i];
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1733 v->valid = valid;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1734 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1735
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1736 return NGX_CONF_OK;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1737 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1738
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1739 for (i = 1; i < n; i++) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1740
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1741 if (ngx_strcmp(value[i].data, "any") == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1742
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1743 status = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1744
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1745 } else {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1746
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1747 status = ngx_atoi(value[i].data, value[i].len);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1748 if (status < 100) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1749 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1750 "invalid status \"%V\"", &value[i]);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1751 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1752 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1753 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1754
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1755 v = ngx_array_push(*a);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1756 if (v == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1757 return NGX_CONF_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1758 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1759
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1760 v->status = status;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1761 v->valid = valid;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1762 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1763
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1764 return NGX_CONF_OK;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1765 }
572
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1766
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1767
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1768 ngx_int_t
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1769 ngx_http_cache(ngx_http_request_t *r, ngx_array_t *no_cache)
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1770 {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1771 ngx_str_t val;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1772 ngx_uint_t i;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1773 ngx_http_complex_value_t *cv;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1774
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1775 cv = no_cache->elts;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1776
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1777 for (i = 0; i < no_cache->nelts; i++) {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1778 if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1779 return NGX_ERROR;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1780 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1781
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1782 if (val.len && val.data[0] != '0') {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1783 return NGX_DECLINED;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1784 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1785 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1786
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1787 return NGX_OK;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1788 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1789
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1790
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1791 char *
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1792 ngx_http_no_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1793 {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1794 char *p = conf;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1795
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1796 ngx_str_t *value;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1797 ngx_uint_t i;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1798 ngx_array_t **a;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1799 ngx_http_complex_value_t *cv;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1800 ngx_http_compile_complex_value_t ccv;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1801
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1802 a = (ngx_array_t **) (p + cmd->offset);
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1803
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1804 if (*a == NGX_CONF_UNSET_PTR) {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1805 *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_complex_value_t));
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1806 if (*a == NULL) {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1807 return NGX_CONF_ERROR;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1808 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1809 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1810
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1811 value = cf->args->elts;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1812
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1813 for (i = 1; i < cf->args->nelts; i++) {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1814 cv = ngx_array_push(*a);
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1815 if (cv == NULL) {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1816 return NGX_CONF_ERROR;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1817 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1818
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1819 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1820
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1821 ccv.cf = cf;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1822 ccv.value = &value[i];
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1823 ccv.complex_value = cv;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1824
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1825 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1826 return NGX_CONF_ERROR;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1827 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1828 }
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1829
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1830 return NGX_CONF_OK;
ff463db0be31 nginx 0.8.38
Igor Sysoev <http://sysoev.ru>
parents: 566
diff changeset
1831 }