annotate src/http/ngx_http_file_cache.c @ 630:ad6fee8052d7 NGINX_1_0_5

nginx 1.0.5 *) Change: now default SSL ciphers are "HIGH:!aNULL:!MD5". Thanks to Rob Stradling. *) Feature: the "referer_hash_max_size" and "referer_hash_bucket_size" directives. Thanks to Witold Filipczyk. *) Feature: $uid_reset variable. *) Bugfix: a segmentation fault might occur in a worker process, if a caching was used. Thanks to Lanshun Zhou. *) Bugfix: worker processes may got caught in an endless loop during reconfiguration, if a caching was used; the bug had appeared in 0.8.48. Thanks to Maxim Dounin. *) Bugfix: "stalled cache updating" alert. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Tue, 19 Jul 2011 00:00:00 +0400
parents a7a5fa2e395b
children 5b73504dd4ba
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
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
34 ngx_http_file_cache_manager_sleep(ngx_http_file_cache_t *cache);
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);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
379 return NGX_ERROR;
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
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
533 if (fcn->exists) {
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;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
536 c->body_start = fcn->body_start;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
537
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
538 rc = NGX_OK;
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 goto done;
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
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
543 if (fcn->uses >= c->min_uses) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
544
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
545 c->exists = fcn->exists;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
546 c->body_start = fcn->body_start;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
547
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
548 rc = NGX_OK;
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 } else {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
551 rc = NGX_AGAIN;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
552 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
553
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
554 goto done;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
555 }
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 fcn = ngx_slab_alloc_locked(cache->shpool,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
558 sizeof(ngx_http_file_cache_node_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
559 if (fcn == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
560 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
561
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
562 (void) ngx_http_file_cache_forced_expire(cache);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
563
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
564 ngx_shmtx_lock(&cache->shpool->mutex);
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 fcn = ngx_slab_alloc_locked(cache->shpool,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
567 sizeof(ngx_http_file_cache_node_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
568 if (fcn == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
569 rc = NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
570 goto failed;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
571 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
572 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
573
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
574 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
575
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
576 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
577 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
578
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
579 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
580
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
581 fcn->uses = 1;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
582 fcn->count = 1;
594
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
583 fcn->updating = 0;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
584 fcn->deleting = 0;
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
585
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
586 renew:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
587
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
588 rc = NGX_DECLINED;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
589
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
590 fcn->valid_msec = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
591 fcn->error = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
592 fcn->exists = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
593 fcn->valid_sec = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
594 fcn->uniq = 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
595 fcn->body_start = 0;
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
596 fcn->fs_size = 0;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
597
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
598 done:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
599
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
600 fcn->expire = ngx_time() + cache->inactive;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
601
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
602 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
603
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
604 c->uniq = fcn->uniq;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
605 c->error = fcn->error;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
606 c->node = fcn;
464
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 failed:
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
609
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
610 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
611
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
612 return rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
613 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
614
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
615
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
616 static ngx_int_t
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
617 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
618 {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
619 u_char *p;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
620 ngx_http_cache_t *c;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
621
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
622 c = r->cache;
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 c->file.name.len = path->name.len + 1 + path->len
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
625 + 2 * NGX_HTTP_CACHE_KEY_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 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
628 if (c->file.name.data == NULL) {
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
629 return NGX_ERROR;
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
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
632 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
633
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
634 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
635 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
636 *p = '\0';
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 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
639
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
640 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
641 "cache file: \"%s\"", c->file.name.data);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
642
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
643 return NGX_OK;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
644 }
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
645
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
646
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
647 static ngx_http_file_cache_node_t *
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
648 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
649 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
650 ngx_int_t rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
651 ngx_rbtree_key_t node_key;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
652 ngx_rbtree_node_t *node, *sentinel;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
653 ngx_http_file_cache_node_t *fcn;
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 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
656
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
657 node = cache->sh->rbtree.root;
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
658 sentinel = cache->sh->rbtree.sentinel;
464
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 while (node != sentinel) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
661
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
662 if (node_key < node->key) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
663 node = node->left;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
664 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
665 }
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 if (node_key > node->key) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
668 node = node->right;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
669 continue;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
670 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
671
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
672 /* node_key == node->key */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
673
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
674 do {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
675 fcn = (ngx_http_file_cache_node_t *) node;
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 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
678 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
679
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
680 if (rc == 0) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
681 return fcn;
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 node = (rc < 0) ? node->left : node->right;
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 } while (node != sentinel && node_key == node->key);
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 break;
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
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
691 /* not found */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
692
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
693 return NULL;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
694 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
695
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 static void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
698 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
699 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
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 ngx_rbtree_node_t **p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
702 ngx_http_file_cache_node_t *cn, *cnt;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
703
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
704 for ( ;; ) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
705
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
706 if (node->key < temp->key) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
707
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
708 p = &temp->left;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
709
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
710 } else if (node->key > temp->key) {
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 = &temp->right;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
713
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
714 } else { /* node->key == temp->key */
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
715
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
716 cn = (ngx_http_file_cache_node_t *) node;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
717 cnt = (ngx_http_file_cache_node_t *) temp;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
718
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
719 p = (ngx_memcmp(cn->key, cnt->key,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
720 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t))
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
721 < 0)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
722 ? &temp->left : &temp->right;
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 if (*p == sentinel) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
726 break;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
727 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
728
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
729 temp = *p;
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 *p = node;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
733 node->parent = temp;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
734 node->left = sentinel;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
735 node->right = sentinel;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
736 ngx_rbt_red(node);
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
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
739
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
740 void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
741 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
742 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
743 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
744
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
745 u_char *p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
746 ngx_str_t *key;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
747 ngx_uint_t i;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
748 ngx_http_cache_t *c;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
749
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
750 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
751 "http file cache set header");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
752
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
753 c = r->cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
754
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
755 h->valid_sec = c->valid_sec;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
756 h->last_modified = c->last_modified;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
757 h->date = c->date;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
758 h->crc32 = c->crc32;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
759 h->valid_msec = (u_short) c->valid_msec;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
760 h->header_start = (u_short) c->header_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
761 h->body_start = (u_short) c->body_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
762
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
763 p = buf + sizeof(ngx_http_file_cache_header_t);
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 = 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
766
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
767 key = c->keys.elts;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
768 for (i = 0; i < c->keys.nelts; i++) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
769 p = ngx_copy(p, key[i].data, key[i].len);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
770 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
771
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
772 *p = LF;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
773 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
774
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
775
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
776 void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
777 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
778 {
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
779 off_t fs_size;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
780 ngx_int_t rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
781 ngx_file_uniq_t uniq;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
782 ngx_file_info_t fi;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
783 ngx_http_cache_t *c;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
784 ngx_ext_rename_file_t ext;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
785 ngx_http_file_cache_t *cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
786
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
787 c = r->cache;
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 if (c->updated) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
790 return;
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
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
793 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
794 "http file cache update");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
795
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
796 c->updated = 1;
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
797 c->updating = 0;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
798
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
799 cache = c->file_cache;
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 uniq = 0;
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
802 fs_size = 0;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
803
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
804 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
805 "http file cache rename: \"%s\" to \"%s\"",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
806 tf->file.name.data, c->file.name.data);
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 ext.access = NGX_FILE_OWNER_ACCESS;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
809 ext.path_access = NGX_FILE_OWNER_ACCESS;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
810 ext.time = -1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
811 ext.create_path = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
812 ext.delete_file = 1;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
813 ext.log = r->connection->log;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
814
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
815 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
816
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
817 if (rc == NGX_OK) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
818
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
819 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
820 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
821 ngx_fd_info_n " \"%s\" failed", tf->file.name.data);
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 rc = NGX_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
824
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
825 } else {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
826 uniq = ngx_file_uniq(&fi);
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
827 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
828 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
829 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
830
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
831 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
832
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
833 c->node->count--;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
834 c->node->uniq = uniq;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
835 c->node->body_start = c->body_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
836
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
837 cache->sh->size += fs_size - c->node->fs_size;
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
838 c->node->fs_size = fs_size;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
839
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
840 if (rc == NGX_OK) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
841 c->node->exists = 1;
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
498
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
844 c->node->updating = 0;
207ae3ff0444 nginx 0.8.1
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
845
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
846 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
847 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
848
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
849
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
850 ngx_int_t
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
851 ngx_http_cache_send(ngx_http_request_t *r)
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_int_t rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
854 ngx_buf_t *b;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
855 ngx_chain_t out;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
856 ngx_http_cache_t *c;
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 c = r->cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
859
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
860 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
861 "http file cache send: %s", c->file.name.data);
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 /* 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
864
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
865 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
866 if (b == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
867 return NGX_HTTP_INTERNAL_SERVER_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
868 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
869
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
870 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
871 if (b->file == NULL) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
872 return NGX_HTTP_INTERNAL_SERVER_ERROR;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
873 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
874
558
2da4537168f8 nginx 0.8.31
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
875 r->header_only = (c->length - c->body_start) == 0;
2da4537168f8 nginx 0.8.31
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
876
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
877 rc = ngx_http_send_header(r);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
878
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
879 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
880 return rc;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
881 }
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_pos = c->body_start;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
884 b->file_last = c->length;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
885
558
2da4537168f8 nginx 0.8.31
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
886 b->in_file = 1;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
887 b->last_buf = (r == r->main) ? 1: 0;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
888 b->last_in_chain = 1;
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 b->file->fd = c->file.fd;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
891 b->file->name = c->file.name;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
892 b->file->log = r->connection->log;
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 out.buf = b;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
895 out.next = NULL;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
896
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
897 return ngx_http_output_filter(r, &out);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
898 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
899
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
900
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
901 void
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
902 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
903 {
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
904 ngx_http_file_cache_t *cache;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
905 ngx_http_file_cache_node_t *fcn;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
906
626
a7a5fa2e395b nginx 1.0.3
Igor Sysoev <http://sysoev.ru>
parents: 622
diff changeset
907 if (c->updated || c->node == NULL) {
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
908 return;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
909 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
910
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
911 cache = c->file_cache;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
912
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
913 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
914 "http file cache free, fd: %d", c->file.fd);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
915
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
916 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
917
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
918 fcn = c->node;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
919 fcn->count--;
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
920
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
921 if (c->updating) {
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
922 fcn->updating = 0;
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
923 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
924
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
925 if (c->error) {
588
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
926 fcn->error = c->error;
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
927
594
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
928 if (c->valid_sec) {
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
929 fcn->valid_sec = c->valid_sec;
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
930 fcn->valid_msec = c->valid_msec;
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
931 }
3436cf38d59e nginx 0.8.49
Igor Sysoev <http://sysoev.ru>
parents: 592
diff changeset
932
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
933 } 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
934 ngx_queue_remove(&fcn->queue);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
935 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
936 ngx_slab_free_locked(cache->shpool, fcn);
b6a5942a4e6a nginx 0.8.46
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
937 c->node = NULL;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
938 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
939
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
940 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
941
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
942 c->updated = 1;
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
943 c->updating = 0;
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
944
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
945 if (c->temp_file) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
946 if (tf && tf->file.fd != NGX_INVALID_FILE) {
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
947 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
948 "http file cache incomplete: \"%s\"",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
949 tf->file.name.data);
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 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
952 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
953 ngx_delete_file_n " \"%s\" failed",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
954 tf->file.name.data);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
955 }
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 }
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
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
960
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
961 static void
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
962 ngx_http_file_cache_cleanup(void *data)
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
963 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
964 ngx_http_cache_t *c = data;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
965
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
966 if (c->updated) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
967 return;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
968 }
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 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
971 "http file cache cleanup");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
972
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
973 if (c->updating) {
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
974 ngx_log_error(NGX_LOG_ALERT, c->file.log, 0,
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
975 "stalled cache updating, error:%ui", c->error);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
976 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
977
590
cde3626b2d0d nginx 0.8.47
Igor Sysoev <http://sysoev.ru>
parents: 588
diff changeset
978 ngx_http_file_cache_free(c, NULL);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
979 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
980
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
981
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
982 static time_t
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
983 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
984 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
985 u_char *name;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
986 size_t len;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
987 time_t wait;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
988 ngx_uint_t tries;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
989 ngx_path_t *path;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
990 ngx_queue_t *q;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
991 ngx_http_file_cache_node_t *fcn;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
992
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
993 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
994 "http file cache forced expire");
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 path = cache->path;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
997 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
998
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
999 name = ngx_alloc(len + 1, ngx_cycle->log);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1000 if (name == NULL) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1001 return 10;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1002 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1003
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1004 ngx_memcpy(name, path->name.data, path->name.len);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1005
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1006 wait = 10;
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1007 tries = 20;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1008
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1009 ngx_shmtx_lock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1010
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1011 for (q = ngx_queue_last(&cache->sh->queue);
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1012 q != ngx_queue_sentinel(&cache->sh->queue);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1013 q = ngx_queue_prev(q))
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1014 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1015 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
1016
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1017 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
1018 "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
1019 fcn->count, fcn->exists,
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1020 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
1021
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1022 if (fcn->count == 0) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1023 ngx_http_file_cache_delete(cache, q, name);
620
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1024 wait = 0;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1025
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1026 } else {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1027 if (--tries) {
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1028 continue;
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
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1031 wait = 1;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1032 }
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 break;
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 ngx_shmtx_unlock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1038
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1039 ngx_free(name);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1040
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1041 return wait;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1042 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1043
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1044
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1045 static time_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1046 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
1047 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1048 u_char *name, *p;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1049 size_t len;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1050 time_t now, wait;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1051 ngx_path_t *path;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1052 ngx_queue_t *q;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1053 ngx_http_file_cache_node_t *fcn;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1054 u_char key[2 * NGX_HTTP_CACHE_KEY_LEN];
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1055
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1056 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
1057 "http file cache expire");
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1058
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1059 path = cache->path;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1060 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
1061
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1062 name = ngx_alloc(len + 1, ngx_cycle->log);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1063 if (name == NULL) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1064 return 10;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1065 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1066
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1067 ngx_memcpy(name, path->name.data, path->name.len);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1068
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1069 now = ngx_time();
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1070
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1071 ngx_shmtx_lock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1072
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1073 for ( ;; ) {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1074
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1075 if (ngx_queue_empty(&cache->sh->queue)) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1076 wait = 10;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1077 break;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1078 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1079
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1080 q = ngx_queue_last(&cache->sh->queue);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1081
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1082 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
1083
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1084 wait = fcn->expire - now;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1085
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1086 if (wait > 0) {
478
f2c6a7373274 nginx 0.7.51
Igor Sysoev <http://sysoev.ru>
parents: 472
diff changeset
1087 wait = wait > 10 ? 10 : wait;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1088 break;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1089 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1090
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1091 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
1092 "http file cache expire: #%d %d %02xd%02xd%02xd%02xd",
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1093 fcn->count, fcn->exists,
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1094 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
1095
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1096 if (fcn->count == 0) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1097 ngx_http_file_cache_delete(cache, q, name);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1098 continue;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1099 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1100
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1101 if (fcn->deleting) {
630
ad6fee8052d7 nginx 1.0.5
Igor Sysoev <http://sysoev.ru>
parents: 626
diff changeset
1102 wait = 1;
ad6fee8052d7 nginx 1.0.5
Igor Sysoev <http://sysoev.ru>
parents: 626
diff changeset
1103 break;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1104 }
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1105
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1106 p = ngx_hex_dump(key, (u_char *) &fcn->node.key,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1107 sizeof(ngx_rbtree_key_t));
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1108 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
1109 (void) ngx_hex_dump(p, fcn->key, len);
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 /*
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1112 * abnormally exited workers may leave locked cache entries,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1113 * and although it may be safe to remove them completely,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1114 * we prefer to remove them from inactive queue and rbtree
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1115 * only, and to allow other leaks
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1116 */
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1117
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1118 ngx_queue_remove(q);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1119 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1120
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1121 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1122 "ignore long locked inactive cache entry %*s, count:%d",
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1123 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count);
464
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 ngx_shmtx_unlock(&cache->shpool->mutex);
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1127
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1128 ngx_free(name);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1129
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1130 return wait;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1131 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1132
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1133
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1134 static void
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1135 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
1136 u_char *name)
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1137 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1138 u_char *p;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1139 size_t len;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1140 ngx_path_t *path;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1141 ngx_http_file_cache_node_t *fcn;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1142
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1143 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
1144
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1145 if (fcn->exists) {
622
8dc007eddbcf nginx 1.0.1
Igor Sysoev <http://sysoev.ru>
parents: 620
diff changeset
1146 cache->sh->size -= fcn->fs_size;
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1147
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1148 path = cache->path;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1149 p = name + path->name.len + 1 + path->len;
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1150 p = ngx_hex_dump(p, (u_char *) &fcn->node.key,
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1151 sizeof(ngx_rbtree_key_t));
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1152 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
1153 p = ngx_hex_dump(p, fcn->key, len);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1154 *p = '\0';
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 fcn->count++;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1157 fcn->deleting = 1;
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1158 ngx_shmtx_unlock(&cache->shpool->mutex);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1159
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1160 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
1161 ngx_create_hashed_filename(path, name, len);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1162
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1163 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
1164 "http file cache expire: \"%s\"", name);
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1165
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1166 if (ngx_delete_file(name) == NGX_FILE_ERROR) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1167 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
1168 ngx_delete_file_n " \"%s\" failed", name);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1169 }
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1170
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1171 ngx_shmtx_lock(&cache->shpool->mutex);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1172 fcn->count--;
596
6c96fdd2dfc3 nginx 0.8.50
Igor Sysoev <http://sysoev.ru>
parents: 594
diff changeset
1173 fcn->deleting = 0;
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
592
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1176 if (fcn->count == 0) {
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1177 ngx_queue_remove(q);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1178 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1179 ngx_slab_free_locked(cache->shpool, fcn);
09d5f308901f nginx 0.8.48
Igor Sysoev <http://sysoev.ru>
parents: 590
diff changeset
1180 }
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1181 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1182
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1183
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1184 static time_t
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1185 ngx_http_file_cache_manager(void *data)
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1186 {
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1187 ngx_http_file_cache_t *cache = data;
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1188
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1189 off_t size;
620
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1190 time_t next, wait;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1191
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1192 next = ngx_http_file_cache_expire(cache);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1193
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1194 cache->last = ngx_current_msec;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1195 cache->files = 0;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1196
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1197 for ( ;; ) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1198 ngx_shmtx_lock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1199
480
549994537f15 nginx 0.7.52
Igor Sysoev <http://sysoev.ru>
parents: 478
diff changeset
1200 size = cache->sh->size;
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1201
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1202 ngx_shmtx_unlock(&cache->shpool->mutex);
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1203
470
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1204 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
1205 "http file cache size: %O", size);
6866b490272e nginx 0.7.47
Igor Sysoev <http://sysoev.ru>
parents: 468
diff changeset
1206
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1207 if (size < cache->max_size) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1208 return next;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1209 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1210
620
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1211 wait = ngx_http_file_cache_forced_expire(cache);
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1212
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1213 if (wait > 0) {
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1214 return wait;
b4dcae568a2a nginx 1.0.0
Igor Sysoev <http://sysoev.ru>
parents: 596
diff changeset
1215 }
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1216
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1217 if (ngx_http_file_cache_manager_sleep(cache) != NGX_OK) {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1218 return next;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1219 }
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1220 }
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1221 }
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1222
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1223
514
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1224 static void
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1225 ngx_http_file_cache_loader(void *data)
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 ngx_http_file_cache_t *cache = data;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1228
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1229 ngx_tree_ctx_t tree;
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 if (!cache->sh->cold || cache->sh->loading) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1232 return;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1233 }
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 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
1236 return;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1237 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1238
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1239 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
1240 "http file cache loader");
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1241
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1242 tree.init_handler = NULL;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1243 tree.file_handler = ngx_http_file_cache_manage_file;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1244 tree.pre_tree_handler = ngx_http_file_cache_noop;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1245 tree.post_tree_handler = ngx_http_file_cache_noop;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1246 tree.spec_handler = ngx_http_file_cache_delete_file;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1247 tree.data = cache;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1248 tree.alloc = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1249 tree.log = ngx_cycle->log;
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 cache->last = ngx_current_msec;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1252 cache->files = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1253
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1254 if (ngx_walk_tree(&tree, &cache->path->name) == NGX_ABORT) {
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1255 cache->sh->loading = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1256 return;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1257 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1258
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1259 cache->sh->cold = 0;
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1260 cache->sh->loading = 0;
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 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1263 "http file cache: %V %.3fM, bsize: %uz",
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1264 &cache->path->name,
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1265 ((double) cache->sh->size * cache->bsize) / (1024 * 1024),
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1266 cache->bsize);
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1267 }
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1268
43cc6f0b77ce nginx 0.8.9
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
1269
464
c8cfb6c462ef nginx 0.7.44
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
1270 static ngx_int_t
468
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1271 ngx_http_file_cache_manager_sleep(ngx_http_file_cache_t *cache)
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1272 {
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset
1273 ngx_msec_t elapsed;
56baf312c1b5 nginx 0.7.46
Igor Sysoev <http://sysoev.ru>
parents: 466
diff changeset