mirror of
https://github.com/nginx/nginx.git
synced 2025-01-23 23:03:18 -06:00
elimination of reading cache files by cache loader
This commit is contained in:
parent
92161bac79
commit
c2cafadfa5
@ -926,6 +926,7 @@ ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree)
|
||||
"tree file \"%s\"", file.data);
|
||||
|
||||
ctx->size = ngx_de_size(&dir);
|
||||
ctx->fs_size = ngx_de_fs_size(&dir);
|
||||
ctx->access = ngx_de_access(&dir);
|
||||
ctx->mtime = ngx_de_mtime(&dir);
|
||||
|
||||
|
@ -104,6 +104,7 @@ typedef ngx_int_t (*ngx_tree_handler_pt) (ngx_tree_ctx_t *ctx, ngx_str_t *name);
|
||||
|
||||
struct ngx_tree_ctx_s {
|
||||
off_t size;
|
||||
off_t fs_size;
|
||||
ngx_uint_t access;
|
||||
time_t mtime;
|
||||
|
||||
|
@ -1320,60 +1320,27 @@ ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
|
||||
static ngx_int_t
|
||||
ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, ngx_str_t *name)
|
||||
{
|
||||
u_char *p;
|
||||
ngx_fd_t fd;
|
||||
ngx_int_t n;
|
||||
ngx_uint_t i;
|
||||
ngx_file_info_t fi;
|
||||
ngx_http_cache_t c;
|
||||
ngx_http_file_cache_t *cache;
|
||||
ngx_http_file_cache_header_t h;
|
||||
u_char *p;
|
||||
ngx_int_t n;
|
||||
ngx_uint_t i;
|
||||
ngx_http_cache_t c;
|
||||
ngx_http_file_cache_t *cache;
|
||||
|
||||
if (name->len < 2 * NGX_HTTP_CACHE_KEY_LEN) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_memzero(&c, sizeof(ngx_http_cache_t));
|
||||
|
||||
fd = ngx_open_file(name->data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
|
||||
|
||||
if (fd == NGX_INVALID_FILE) {
|
||||
ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
|
||||
ngx_open_file_n " \"%s\" failed", name->data);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
c.file.fd = fd;
|
||||
c.file.name = *name;
|
||||
c.file.log = ctx->log;
|
||||
|
||||
n = ngx_read_file(&c.file, (u_char *) &h,
|
||||
sizeof(ngx_http_file_cache_header_t), 0);
|
||||
if (n == NGX_ERROR) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if ((size_t) n < sizeof(ngx_http_file_cache_header_t)) {
|
||||
if (ctx->size < (off_t) sizeof(ngx_http_file_cache_header_t)) {
|
||||
ngx_log_error(NGX_LOG_CRIT, ctx->log, 0,
|
||||
"cache file \"%s\" is too small", name->data);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_memzero(&c, sizeof(ngx_http_cache_t));
|
||||
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);
|
||||
|
||||
} else {
|
||||
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) {
|
||||
ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
|
||||
ngx_close_file_n " \"%s\" failed", name->data);
|
||||
}
|
||||
c.length = ctx->size;
|
||||
c.fs_size = (ctx->fs_size + cache->bsize - 1) / cache->bsize;
|
||||
|
||||
p = &name->data[name->len - 2 * NGX_HTTP_CACHE_KEY_LEN];
|
||||
|
||||
|
@ -253,6 +253,7 @@ ngx_de_info(u_char *name, ngx_dir_t *dir)
|
||||
|
||||
#define ngx_de_access(dir) (((dir)->info.st_mode) & 0777)
|
||||
#define ngx_de_size(dir) (dir)->info.st_size
|
||||
#define ngx_de_fs_size(dir) ((dir)->info.st_blocks * 512)
|
||||
#define ngx_de_mtime(dir) (dir)->info.st_mtime
|
||||
|
||||
|
||||
|
@ -227,6 +227,7 @@ ngx_int_t ngx_de_link_info(u_char *name, ngx_dir_t *dir);
|
||||
#define ngx_de_access(dir) 0
|
||||
#define ngx_de_size(dir) \
|
||||
(((off_t) (dir)->finddata.nFileSizeHigh << 32) | (dir)->finddata.nFileSizeLow)
|
||||
#define ngx_de_fs_size(dir) ngx_de_size(dir)
|
||||
|
||||
/* 116444736000000000 is commented in src/os/win32/ngx_time.c */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user