diff src/http/ngx_http_file_cache.c @ 622:8dc007eddbcf NGINX_1_0_1

nginx 1.0.1 *) Change: now the "split_clients" directive uses MurmurHash2 algorithm because of better distribution. Thanks to Oleg Mamontov. *) Change: now long strings starting with zero are not considered as false values. Thanks to Maxim Dounin. *) Change: now nginx uses a default listen backlog value 511 on Linux. *) Feature: the $upstream_... variables may be used in the SSI and perl modules. *) Bugfix: now nginx limits better disk cache size. Thanks to Oleg Mamontov. *) Bugfix: a segmentation fault might occur while parsing incorrect IPv4 address; the bug had appeared in 0.9.3. Thanks to Maxim Dounin. *) Bugfix: nginx could not be built by gcc 4.6 without --with-debug option. *) Bugfix: nginx could not be built on Solaris 9 and earlier; the bug had appeared in 0.9.3. Thanks to Dagobert Michelsen. *) Bugfix: $request_time variable had invalid values if subrequests were used; the bug had appeared in 0.8.47. Thanks to Igor A. Valcov.
author Igor Sysoev <http://sysoev.ru>
date Tue, 03 May 2011 00:00:00 +0400
parents b4dcae568a2a
children a7a5fa2e395b
line wrap: on
line diff
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -349,6 +349,7 @@ ngx_http_file_cache_open(ngx_http_reques
     c->file.log = r->connection->log;
     c->uniq = of.uniq;
     c->length = of.size;
+    c->fs_size = (of.fs_size + cache->bsize - 1) / cache->bsize;
 
     c->buf = ngx_create_temp_buf(r->pool, c->body_start);
     if (c->buf == NULL) {
@@ -411,7 +412,7 @@ ngx_http_file_cache_read(ngx_http_reques
             c->node->exists = 1;
             c->node->uniq = c->uniq;
 
-            cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize;
+            cache->sh->size += c->fs_size;
         }
 
         ngx_shmtx_unlock(&cache->shpool->mutex);
@@ -594,7 +595,7 @@ renew:
     fcn->valid_sec = 0;
     fcn->uniq = 0;
     fcn->body_start = 0;
-    fcn->length = 0;
+    fcn->fs_size = 0;
 
 done:
 
@@ -777,7 +778,7 @@ ngx_http_file_cache_set_header(ngx_http_
 void
 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf)
 {
-    off_t                   size, length;
+    off_t                   fs_size;
     ngx_int_t               rc;
     ngx_file_uniq_t         uniq;
     ngx_file_info_t         fi;
@@ -800,7 +801,7 @@ ngx_http_file_cache_update(ngx_http_requ
     cache = c->file_cache;
 
     uniq = 0;
-    length = 0;
+    fs_size = 0;
 
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http file cache rename: \"%s\" to \"%s\"",
@@ -825,23 +826,18 @@ ngx_http_file_cache_update(ngx_http_requ
 
         } else {
             uniq = ngx_file_uniq(&fi);
-            length = ngx_file_size(&fi);
+            fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize;
         }
     }
 
-    size = (length + cache->bsize - 1) / cache->bsize;
-
     ngx_shmtx_lock(&cache->shpool->mutex);
 
     c->node->count--;
     c->node->uniq = uniq;
     c->node->body_start = c->body_start;
 
-    size = size - (c->node->length + cache->bsize - 1) / cache->bsize;
-
-    c->node->length = length;
-
-    cache->sh->size += size;
+    cache->sh->size += fs_size - c->node->fs_size;
+    c->node->fs_size = fs_size;
 
     if (rc == NGX_OK) {
         c->node->exists = 1;
@@ -1148,7 +1144,7 @@ ngx_http_file_cache_delete(ngx_http_file
     fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
 
     if (fcn->exists) {
-        cache->sh->size -= (fcn->length + cache->bsize - 1) / cache->bsize;
+        cache->sh->size -= fcn->fs_size;
 
         path = cache->path;
         p = name + path->name.len + 1 + path->len;
@@ -1371,6 +1367,8 @@ ngx_http_file_cache_add_file(ngx_tree_ct
         return NGX_ERROR;
     }
 
+    cache = ctx->data;
+
     if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
         ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
                       ngx_fd_info_n " \"%s\" failed", name->data);
@@ -1381,6 +1379,7 @@ ngx_http_file_cache_add_file(ngx_tree_ct
         c.valid_msec = h.valid_msec;
         c.body_start = h.body_start;
         c.length = ngx_file_size(&fi);
+        c.fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize;
     }
 
     if (ngx_close_file(fd) == NGX_FILE_ERROR) {
@@ -1406,8 +1405,6 @@ ngx_http_file_cache_add_file(ngx_tree_ct
         c.key[i] = (u_char) n;
     }
 
-    cache = ctx->data;
-
     return ngx_http_file_cache_add(cache, &c);
 }
 
@@ -1447,9 +1444,9 @@ ngx_http_file_cache_add(ngx_http_file_ca
         fcn->uniq = c->uniq;
         fcn->valid_sec = c->valid_sec;
         fcn->body_start = c->body_start;
-        fcn->length = c->length;
+        fcn->fs_size = c->fs_size;
 
-        cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize;
+        cache->sh->size += c->fs_size;
 
     } else {
         ngx_queue_remove(&fcn->queue);