Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 646 lines (521 sloc) 14.757 kb
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
23 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
24
25 #include "common-internal.h"
26 #include "iocache.h"
27
28 #include "buffer.h"
29 #include "server-protected.h"
30 #include "util.h"
a86f167 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1654 5dc97367-9…
alobbs authored
31 #include "bogotime.h"
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
32
33 #ifdef HAVE_SYS_MMAN_H
34 # include <sys/mman.h>
35 #endif
36
37 #ifdef HAVE_FCNTL_H
38 # include <fcntl.h>
39 #endif
40
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <unistd.h>
44 #include <fcntl.h>
45 #include <errno.h>
46
bc29e8c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@830 5dc97367-97…
alobbs authored
47 #define ENTRIES "iocache"
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
48
fd67391 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2198 5dc97367-9…
alobbs authored
49 #define LASTING_MMAP (5 * 60) /* secs */
50 #define LASTING_STAT (5 * 60) /* secs */
51 #define MIN_FILE_SIZE 1 /* bytes */
52 #define MAX_FILE_SIZE SENDFILE_MIN_SIZE /* bytes */
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
53
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
54
55 #ifndef O_BINARY
56 # define O_BINARY 0
57 #endif
58
59 #ifdef MAP_FILE
8f34a86 @alobbs This patch fixes a bug in I/O-cache, and re-enables it in the default
alobbs authored
60 # define MAP_OPTIONS MAP_PRIVATE | MAP_FILE
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
61 #else
8f34a86 @alobbs This patch fixes a bug in I/O-cache, and re-enables it in the default
alobbs authored
62 # define MAP_OPTIONS MAP_PRIVATE
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
63 #endif
64
65
66 typedef struct {
67 cherokee_iocache_entry_t base;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
68 time_t stat_expiration;
69 time_t mmap_expiration;
b45b836 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2101 5dc97367-9…
alobbs authored
70 CHEROKEE_MUTEX_T (parent_lock);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
71 } cherokee_iocache_entry_extension_t;
72
73 #define PUBL(o) ((cherokee_iocache_entry_t *)(o))
74 #define PRIV(o) ((cherokee_iocache_entry_extension_t *)(o))
75
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
76 static ret_t fetch_info_cb (cherokee_cache_entry_t *entry);
77
a957ffd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2119 5dc97367-9…
alobbs authored
78 CHEROKEE_ADD_FUNC_NEW (iocache);
79 CHEROKEE_ADD_FUNC_FREE (iocache);
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
80
eb98dbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1674 5dc97367-9…
alobbs authored
81
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
82 static ret_t
83 clean_info_cb (cherokee_cache_entry_t *entry)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
84 {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
85 cherokee_iocache_entry_t *ioentry = IOCACHE_ENTRY(entry);
86
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
87 TRACE (ENTRIES, "Cleaning cached info: '%s': %s\n",
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
88 entry->key.buf, ioentry->mmaped ? "mmap": "no mmap");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
89
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
90 /* Nothing will be left
91 */
92 ioentry->info = iocache_nothing;
93 ioentry->state_ret = 123456;
94
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
95 /* Free the mmaped info
96 */
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
97 if (ioentry->mmaped != NULL) {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
98 munmap (ioentry->mmaped, ioentry->mmaped_len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
99
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
100 ioentry->mmaped = NULL;
101 ioentry->mmaped_len = 0;
102 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
103
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
104 /* Mark it as expired
105 */
106 PRIV(entry)->mmap_expiration = 0;
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
107 PRIV(entry)->stat_expiration = 0;
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
108
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
109 return ret_ok;
110 }
111
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
112 static ret_t
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
113 free_cb (cherokee_cache_entry_t *entry)
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
114 {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
115 CHEROKEE_MUTEX_DESTROY (&PRIV(entry)->parent_lock);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
116 return ret_ok;
117 }
118
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
119 static ret_t
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
120 get_stats_cb (cherokee_cache_t *cache,
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
121 cherokee_buffer_t *info)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
122 {
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
123 size_t total = 0;
124
125 cherokee_iocache_get_mmaped_size (IOCACHE(cache), &total);
126
127 cherokee_buffer_add_str (info, "IOcache mappped: ");
128 cherokee_buffer_add_fsize (info, total);
129 cherokee_buffer_add_str (info, "\n");
130
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
131 return ret_ok;
132 }
133
134
135 static ret_t
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
136 iocache_entry_new_cb (cherokee_cache_t *cache,
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
137 cherokee_buffer_t *key,
138 void *param,
139 cherokee_cache_entry_t **ret_entry)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
140 {
141 CHEROKEE_NEW_STRUCT(n, iocache_entry_extension);
142
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
143 UNUSED(param);
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
144
fd37d68 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2623 5dc97367-9…
alobbs authored
145 CHEROKEE_MUTEX_INIT (&PRIV(n)->parent_lock, CHEROKEE_MUTEX_FAST);
b45b836 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2101 5dc97367-9…
alobbs authored
146
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
147 /* Init its parent class
148 */
62d31cf @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2193 5dc97367-9…
alobbs authored
149 #ifdef HAVE_PTHREAD
150 cherokee_cache_entry_init (CACHE_ENTRY(n), key, cache, &PRIV(n)->parent_lock);
151 #else
152 cherokee_cache_entry_init (CACHE_ENTRY(n), key, cache, NULL);
153 #endif
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
154
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
155 /* Set the virtual methods
156 */
157 CACHE_ENTRY(n)->clean_cb = clean_info_cb;
158 CACHE_ENTRY(n)->fetch_cb = fetch_info_cb;
159 CACHE_ENTRY(n)->free_cb = free_cb;
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
160
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
161 /* Init its properties
162 */
163 PRIV(n)->stat_expiration = 0;
164 PRIV(n)->mmap_expiration = 0;
165 PUBL(n)->mmaped = NULL;
166 PUBL(n)->mmaped_len = 0;
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
167 PUBL(n)->info = 0;
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
168 PUBL(n)->state_ret = ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
169
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
170 /* Return the new object
171 */
172 *ret_entry = CACHE_ENTRY(n);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
173 return ret_ok;
174 }
175
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
176
177 ret_t
178 cherokee_iocache_configure (cherokee_iocache_t *iocache,
179 cherokee_config_node_t *conf)
180 {
181 ret_t ret;
182 cherokee_list_t *i;
183
184 /* Configure parent class
185 */
186 ret = cherokee_cache_configure (CACHE(iocache), conf);
187 if (ret != ret_ok)
188 return ret;
189
190 /* Configure it own properties
191 */
192 cherokee_config_node_foreach (i, conf) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
193 int val;
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
194 cherokee_config_node_t *subconf = CONFIG_NODE(i);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
195
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
196 if (equal_buf_str (&subconf->key, "max_file_size")) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
197 ret = cherokee_atoi (subconf->val.buf, &val);
198 if (ret != ret_ok) return ret_error;
199 iocache->max_file_size = val;
200
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
201 } else if (equal_buf_str (&subconf->key, "min_file_size")) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
202 ret = cherokee_atoi (subconf->val.buf, &val);
203 if (ret != ret_ok) return ret_error;
204 iocache->min_file_size = val;
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
205
206 } else if (equal_buf_str (&subconf->key, "lasting_stat")) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
207 ret = cherokee_atoi (subconf->val.buf, &val);
208 if (ret != ret_ok) return ret_error;
209 iocache->lasting_stat = val;
210
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
211 } else if (equal_buf_str (&subconf->key, "lasting_mmap")) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
212 ret = cherokee_atoi (subconf->val.buf, &val);
213 if (ret != ret_ok) return ret_error;
214 iocache->lasting_mmap = val;
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
215 }
216 }
217
218 return ret_ok;
219 }
220
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
221
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
222 ret_t
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
223 cherokee_iocache_init (cherokee_iocache_t *iocache)
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
224 {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
225 ret_t ret;
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
226
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
227 /* Init the parent (cache policy) class
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
228 */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
229 ret = cherokee_cache_init (CACHE(iocache));
230 if (ret != ret_ok)
231 return ret;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
232
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
233 /* Init its virtual methods
234 */
235 CACHE(iocache)->new_cb = iocache_entry_new_cb;
236 CACHE(iocache)->new_cb_param = NULL;
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
237 CACHE(iocache)->stats_cb = get_stats_cb;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
238
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
239 iocache->max_file_size = MAX_FILE_SIZE;
240 iocache->min_file_size = MIN_FILE_SIZE;
241 iocache->lasting_stat = LASTING_STAT;
242 iocache->lasting_mmap = LASTING_MMAP;
243
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
244 return ret_ok;
245 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
246
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
247 ret_t
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
248 cherokee_iocache_mrproper (cherokee_iocache_t *iocache)
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
249 {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
250 return cherokee_cache_mrproper (CACHE(iocache));
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
251 }
252
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
253
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
254 /* Cache entry objects
255 */
256
257 ret_t
258 cherokee_iocache_entry_unref (cherokee_iocache_entry_t **entry)
259 {
260 return cherokee_cache_entry_unref ((cherokee_cache_entry_t **)entry);
261 }
262
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
263 static ret_t
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
264 ioentry_update_stat (cherokee_iocache_entry_t *entry)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
265 {
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
266 int re;
267 ret_t ret;
268 cherokee_iocache_t *iocache = IOCACHE(CACHE_ENTRY(entry)->cache);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
269
462db07 @alobbs Three minor, misc code fixes.
alobbs authored
270 /* Returns:
271 * ret_ok - Ok, updated
272 * ret_ok_and_sent - It's still fresh
273 * ret_deny - No info about the file
274 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
275
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
276 if (PRIV(entry)->stat_expiration >= cherokee_bogonow_now) {
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
277 TRACE (ENTRIES, "Update stat: %s: updated - skipped\n",
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
278 CACHE_ENTRY(entry)->key.buf);
21eccb2 @alobbs Fixes a potential issue. There was corner situation on which I/O cache
alobbs authored
279
280 /* Checked, but file didn't exist */
281 if (PUBL(entry)->state_ret != ret_ok) {
282 return ret_deny;
283 }
284
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
285 return ret_ok_and_sent;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
286 }
287
288 /* Update stat
289 */
290 re = cherokee_stat (CACHE_ENTRY(entry)->key.buf, &entry->state);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
291 if (re < 0) {
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
292 TRACE(ENTRIES, "Couldn't update stat: %s: errno=%d\n",
4ecb592 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2178 5dc97367-9…
alobbs authored
293 CACHE_ENTRY(entry)->key.buf, errno);
281d8e6 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@834 5dc97367-97…
alobbs authored
294
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
295 switch (errno) {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
296 case EACCES:
297 ret = ret_deny;
13c898c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1678 5dc97367-9…
alobbs authored
298 break;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
299 case ENOENT:
4ecb592 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2178 5dc97367-9…
alobbs authored
300 case ENOTDIR:
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
301 ret = ret_not_found;
13c898c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1678 5dc97367-9…
alobbs authored
302 break;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
303 default:
13c898c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1678 5dc97367-9…
alobbs authored
304 ret = ret_error;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
305 break;
306 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
307 }
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
308 else {
309 ret = ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
310 }
311
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
312 TRACE (ENTRIES, "Updated stat: %s, ret=%d\n", CACHE_ENTRY(entry)->key.buf, ret);
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
313
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
314 PRIV(entry)->stat_expiration = cherokee_bogonow_now + iocache->lasting_stat;
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
315 PUBL(entry)->state_ret = ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
316
71e2023 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2654 5dc97367-9…
alobbs authored
317 BIT_SET (PUBL(entry)->info, iocache_stat);
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
318 return (ret == ret_ok) ? ret_ok : ret_deny;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
319 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
320
321 static ret_t
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
322 ioentry_update_mmap (cherokee_iocache_entry_t *entry,
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
323 int *fd)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
324 {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
325 ret_t ret;
326 int fd_local = -1;
327 cherokee_buffer_t *filename = &CACHE_ENTRY(entry)->key;
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
328 cherokee_iocache_t *iocache = IOCACHE(CACHE_ENTRY(entry)->cache);
bc29e8c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@830 5dc97367-97…
alobbs authored
329
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
330 /* Short path
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
331 */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
332 if (PRIV(entry)->mmap_expiration >= cherokee_bogonow_now) {
333 TRACE(ENTRIES, "Update mmap: %s: updated - skipped\n", filename->buf);
334 return ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
335 }
336
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
337 /* Check the fd
338 */
339 if (fd != NULL)
340 fd_local = *fd;
341
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
342 /* Only map regular files
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
343 */
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
344 if (unlikely (! S_ISREG(entry->state.st_mode))) {
281d8e6 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@834 5dc97367-97…
alobbs authored
345 TRACE(ENTRIES, "Not a regular file: %s\n", filename->buf);
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
346 ret = ret_deny;
347 goto error;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
348 }
349
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
350 /* Maybe it is already opened
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
351 */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
352 if (fd_local < 0) {
a68f41b @alobbs Merges the Front-Line Cache branch.
alobbs authored
353 fd_local = cherokee_open (filename->buf, (O_RDONLY | O_BINARY), 0);
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
354 if (unlikely (fd_local < 0)) {
6428c5f @alobbs Improves how open() errors are handled at the I/O-cache layer. Thanks
alobbs authored
355 TRACE(ENTRIES, "Couldn't open(%s) = %s\n", filename->buf, strerror(errno));
356
357 switch (errno) {
358 case EACCES:
359 ret = ret_deny;
360 break;
361 case ENOENT:
362 case ENOTDIR:
363 ret = ret_not_found;
364 break;
365 default:
366 ret = ret_error;
367 break;
368 }
369
370 PRIV(entry)->stat_expiration = cherokee_bogonow_now + iocache->lasting_stat;
371 PUBL(entry)->state_ret = ret;
372
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
373 goto error;
281d8e6 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@834 5dc97367-97…
alobbs authored
374 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
375
62ac4c7 @alobbs I/O cache file FDs should not be inherited.
alobbs authored
376 cherokee_fd_set_closexec (fd_local);
377
378 if (fd != NULL) {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
379 *fd = fd_local;
62ac4c7 @alobbs I/O cache file FDs should not be inherited.
alobbs authored
380 }
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
381 }
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
382
383 /* Might need to free the previous mmap
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
384 */
385 if (entry->mmaped != NULL) {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
386 TRACE(ENTRIES, "Cleaning previos mmap: %s\n", filename->buf);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
387 munmap (entry->mmaped, entry->mmaped_len);
388
389 entry->mmaped = NULL;
390 entry->mmaped_len = 0;
391 }
392
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
393 /* Map the file into memory
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
394 */
395 entry->mmaped =
396 mmap (NULL, /* void *start */
397 entry->state.st_size, /* size_t length */
398 PROT_READ, /* int prot */
399 MAP_OPTIONS, /* int flag */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
400 fd_local, /* int fd */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
401 0); /* off_t offset */
402
403 if (entry->mmaped == MAP_FAILED) {
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
404 int err = errno;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
405 TRACE (ENTRIES, "%s mmap() failed: errno=%d\n", filename->buf, err);
281d8e6 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@834 5dc97367-97…
alobbs authored
406
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
407 switch (err) {
408 case EAGAIN:
409 case ENOMEM:
410 case ENFILE:
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
411 ret = ret_eagain;
412 goto error;
413 default:
414 ret = ret_not_found;
415 goto error;
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
416 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
417 }
418
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
419 TRACE(ENTRIES, "Updated mmap: %s\n", filename->buf);
420
421 PUBL(entry)->mmaped_len = entry->state.st_size;
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
422 PRIV(entry)->mmap_expiration = cherokee_bogonow_now + iocache->lasting_mmap;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
423
9a6e161 @alobbs Safer fd closing
alobbs authored
424 if ((fd == NULL) && (fd_local != -1)) {
425 cherokee_fd_close (fd_local);
426 }
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
427
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
428 BIT_SET (PUBL(entry)->info, iocache_mmap);
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
429 return ret_ok;
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
430
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
431 error:
9a6e161 @alobbs Safer fd closing
alobbs authored
432 if ((fd == NULL) && (fd_local != -1)) {
433 cherokee_fd_close (fd_local);
434 }
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
435
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
436 BIT_UNSET (PUBL(entry)->info, iocache_mmap);
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
437 return ret;
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
438 }
439
440
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
441 static ret_t
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
442 entry_update_fd (cherokee_iocache_entry_t *entry,
443 cherokee_iocache_info_t info,
444 int *fd)
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
445 {
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
446 ret_t ret;
447 cherokee_iocache_t *iocache = IOCACHE(CACHE_ENTRY(entry)->cache);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
448
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
449 /* Returns:
450 * ret_ok - Okay
451 * ret_ok_and_sent - Ok but couldn't update it
71e2023 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2654 5dc97367-9…
alobbs authored
452 *
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
453 * ret_deny - Couldn't stat the file
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
454 * ret_not_found - File not found
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
455 * ret_error - Something bad happened
71e2023 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2654 5dc97367-9…
alobbs authored
456 */
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
457
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
458 /* - CACHE_ENTRY(entry)->ref_count > 2:
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
459 * It shouldn't update the object if somebody else
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
460 * is using it.
461 *
462 * - entry->info != iocache_nothing:
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
463 * However, it might happen that a few threads acquired
464 * the object at the 'same' time and they are trying to
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
465 * update it now.
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
466 */
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
467 if ((CACHE_ENTRY(entry)->ref_count > 2) &&
468 (entry->info != iocache_nothing))
469 {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
470 TRACE(ENTRIES, "Cannot update '%s', refs=%d\n",
471 CACHE_ENTRY(entry)->key.buf,
472 CACHE_ENTRY(entry)->ref_count);
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
473
c19da29 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1676 5dc97367-9…
alobbs authored
474 return ret_ok_and_sent;
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
475 }
476
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
477 /* Check the required info
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
478 */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
479 if (info & iocache_stat) {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
480 ioentry_update_stat (entry);
c238f0c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@804 5dc97367-97…
alobbs authored
481 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
482
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
483 if (info & iocache_mmap) {
eb98dbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1674 5dc97367-9…
alobbs authored
484 /* Update mmap
485 */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
486 ret = ioentry_update_stat (entry);
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
487 if ((ret != ret_ok) &&
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
488 (ret != ret_ok_and_sent))
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
489 {
490 /* stat() did not success
491 */
492 return ret_deny;
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
493 }
c238f0c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@804 5dc97367-97…
alobbs authored
494
eb98dbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1674 5dc97367-9…
alobbs authored
495 /* Check the size before mapping it
496 */
d8bf318 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2188 5dc97367-9…
alobbs authored
497 if ((entry->state.st_size < iocache->min_file_size) ||
498 (entry->state.st_size > iocache->max_file_size))
eb98dbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1674 5dc97367-9…
alobbs authored
499 {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
500 return ret_no_sys;
eb98dbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1674 5dc97367-9…
alobbs authored
501 }
502
503 /* Go ahead
504 */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
505 ret = ioentry_update_mmap (entry, fd);
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
506 if (ret != ret_ok) {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
507 return ret;
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
508 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
509 }
510
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
511 return ret_ok;
512 }
a002fd1 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1677 5dc97367-9…
alobbs authored
513
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
514
515 static ret_t
516 entry_update (cherokee_iocache_entry_t *entry,
517 cherokee_iocache_info_t info)
518 {
519 return entry_update_fd (entry, info, NULL);
9db754d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@771 5dc97367-97…
alobbs authored
520 }
521
522
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
523 static ret_t
524 fetch_info_cb (cherokee_cache_entry_t *entry)
b7f7d10 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97…
alobbs authored
525 {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
526 /* cache->priv->mutex is LOCKED
527 * entry->mutex is LOCKED
528 */
529 entry_update (IOCACHE_ENTRY(entry),
530 (iocache_stat | iocache_mmap));
531 return ret_ok;
b7f7d10 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97…
alobbs authored
532 }
533
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
534
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
535 /* I/O cache
536 */
537 static ret_t
538 iocache_get (cherokee_iocache_t *iocache,
539 cherokee_buffer_t *file,
540 cherokee_iocache_info_t info,
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
541 int *fd,
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
542 cherokee_iocache_entry_t **ret_io)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
543 {
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
544 ret_t ret;
545 cherokee_cache_entry_t *entry = NULL;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
546
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
547 /* Request the element to the underlining cache
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
548 */
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
549 ret = cherokee_cache_get (CACHE(iocache), file, &entry);
550 switch (ret) {
551 case ret_ok:
552 case ret_ok_and_sent:
553 *ret_io = IOCACHE_ENTRY(entry);
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
554 break;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
555 default:
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
556 SHOULDNT_HAPPEN;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
557 return ret_error;
281d8e6 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@834 5dc97367-97…
alobbs authored
558 }
559
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
560 /* Update the cached info
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
561 */
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
562 CHEROKEE_MUTEX_LOCK (entry->mutex);
71e2023 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2654 5dc97367-9…
alobbs authored
563 if (fd) {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
564 ret = entry_update_fd (*ret_io, info, fd);
565 } else {
566 ret = entry_update (*ret_io, info);
0e1abd9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2116 5dc97367-9…
alobbs authored
567 }
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
568 CHEROKEE_MUTEX_UNLOCK (entry->mutex);
569
570 if (unlikely (PUBL(entry)->info == 0)) {
571 SHOULDNT_HAPPEN;
572 }
573
574 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
575 }
576
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
577 ret_t
578 cherokee_iocache_autoget_fd (cherokee_iocache_t *iocache,
579 cherokee_buffer_t *file,
580 cherokee_iocache_info_t info,
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
581 int *fd,
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
582 cherokee_iocache_entry_t **ret_io)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
583 {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
584 ret_t ret;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
585 cherokee_iocache_entry_t *entry = *ret_io;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
586
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
587 TRACE (ENTRIES, "file=%s\n", file->buf);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
588
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
589 if (entry) {
590 if (unlikely (cherokee_buffer_cmp_buf (file, &CACHE_ENTRY(entry)->key) != 0))
591 SHOULDNT_HAPPEN;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
592
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
593 CHEROKEE_MUTEX_LOCK (CACHE_ENTRY(entry)->mutex);
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
594 ret = entry_update_fd (entry, info, fd);
595 CHEROKEE_MUTEX_UNLOCK (CACHE_ENTRY(entry)->mutex);
596
597 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
598 }
599
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
600 return iocache_get (iocache, file, info, fd, ret_io);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
601 }
602
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
603 ret_t
604 cherokee_iocache_autoget (cherokee_iocache_t *iocache,
605 cherokee_buffer_t *file,
606 cherokee_iocache_info_t info,
607 cherokee_iocache_entry_t **ret_io)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
608 {
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
609 ret_t ret;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
610 cherokee_iocache_entry_t *entry = *ret_io;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
611
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
612 TRACE (ENTRIES, "file=%s\n", file->buf);
bc29e8c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@830 5dc97367-97…
alobbs authored
613
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
614 if (entry) {
615 if (unlikely (cherokee_buffer_cmp_buf (file, &CACHE_ENTRY(entry)->key) != 0))
616 SHOULDNT_HAPPEN;
b7f7d10 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97…
alobbs authored
617
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
618 CHEROKEE_MUTEX_LOCK (CACHE_ENTRY(entry)->mutex);
619 ret = entry_update (entry, info);
620 CHEROKEE_MUTEX_UNLOCK (CACHE_ENTRY(entry)->mutex);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
621
33c9d33 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2661 5dc97367-9…
alobbs authored
622 return ret;
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
623 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
624
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
625 return iocache_get (iocache, file, info, NULL, ret_io);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
626 }
9a294ab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-9…
alobbs authored
627
12f1ecb @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2107 5dc97367-9…
alobbs authored
628
629 ret_t
630 cherokee_iocache_get_mmaped_size (cherokee_iocache_t *cache, size_t *total)
631 {
632 cuint_t n;
633 cherokee_list_t *i;
634 cherokee_list_t *lists[4] = {&CACHE(cache)->_t1, &CACHE(cache)->_t2};
635
636 *total = 0;
637
638 for (n=0; n<2; n++) {
639 list_for_each (i, lists[n]) {
640 *total += IOCACHE_ENTRY(i)->mmaped_len;
641 }
642 }
643
644 return ret_ok;
645 }
Something went wrong with that request. Please try again.