aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-04-27 09:55:53 +0000
committerIgor Sysoev <igor@sysoev.ru>2009-04-27 09:55:53 +0000
commitf1cc457d7f562a7c8e7ff9ba28fc143bd175a7dc (patch)
treef3c4ae29d70a5dfd1f42dfe10174a7cbcbb9bdeb
parent0e60e4f73a62bf168dcc0ece770dafa27de35207 (diff)
downloadnginx-f1cc457d7f562a7c8e7ff9ba28fc143bd175a7dc.tar.gz
nginx-f1cc457d7f562a7c8e7ff9ba28fc143bd175a7dc.zip
*) of.test_only to not open file if only stat() is enough
*) of.failed to return exact name of failed syscall
-rw-r--r--src/core/ngx_open_file_cache.c23
-rw-r--r--src/core/ngx_open_file_cache.h3
-rw-r--r--src/http/modules/ngx_http_flv_module.c2
-rw-r--r--src/http/modules/ngx_http_gzip_static_module.c2
-rw-r--r--src/http/modules/ngx_http_index_module.c26
-rw-r--r--src/http/modules/ngx_http_log_module.c4
-rw-r--r--src/http/modules/ngx_http_static_module.c2
-rw-r--r--src/http/modules/perl/nginx.xs2
-rw-r--r--src/http/ngx_http_core_module.c3
-rw-r--r--src/http/ngx_http_script.c3
10 files changed, 51 insertions, 19 deletions
diff --git a/src/core/ngx_open_file_cache.c b/src/core/ngx_open_file_cache.c
index cb7073675..6deb0ce0b 100644
--- a/src/core/ngx_open_file_cache.c
+++ b/src/core/ngx_open_file_cache.c
@@ -130,6 +130,7 @@ ngx_open_cached_file(ngx_open_file_cache_t *cache, ngx_str_t *name,
time_t now;
uint32_t hash;
ngx_int_t rc;
+ ngx_file_info_t fi;
ngx_pool_cleanup_t *cln;
ngx_cached_open_file_t *file;
ngx_pool_cleanup_file_t *clnf;
@@ -140,6 +141,25 @@ ngx_open_cached_file(ngx_open_file_cache_t *cache, ngx_str_t *name,
if (cache == NULL) {
+ if (of->test_only) {
+
+ if (ngx_file_info(name->data, &fi) == -1) {
+ of->err = ngx_errno;
+ of->failed = ngx_file_info_n;
+ return NGX_ERROR;
+ }
+
+ of->uniq = ngx_file_uniq(&fi);
+ of->mtime = ngx_file_mtime(&fi);
+ of->size = ngx_file_size(&fi);
+ of->is_dir = ngx_is_dir(&fi);
+ of->is_file = ngx_is_file(&fi);
+ of->is_link = ngx_is_link(&fi);
+ of->is_exec = ngx_is_exec(&fi);
+
+ return NGX_OK;
+ }
+
cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t));
if (cln == NULL) {
return NGX_ERROR;
@@ -444,6 +464,7 @@ ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log)
if (of->fd != NGX_INVALID_FILE) {
if (ngx_file_info(name, &fi) == -1) {
+ of->failed = ngx_file_info_n;
goto failed;
}
@@ -454,6 +475,7 @@ ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log)
} else if (of->test_dir) {
if (ngx_file_info(name, &fi) == -1) {
+ of->failed = ngx_file_info_n;
goto failed;
}
@@ -471,6 +493,7 @@ ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log)
}
if (fd == NGX_INVALID_FILE) {
+ of->failed = ngx_open_file_n;
goto failed;
}
diff --git a/src/core/ngx_open_file_cache.h b/src/core/ngx_open_file_cache.h
index a8d221b55..f059d6b9a 100644
--- a/src/core/ngx_open_file_cache.h
+++ b/src/core/ngx_open_file_cache.h
@@ -21,13 +21,16 @@ typedef struct {
time_t mtime;
off_t size;
off_t directio;
+
ngx_err_t err;
+ char *failed;
time_t valid;
ngx_uint_t min_uses;
unsigned test_dir:1;
+ unsigned test_only:1;
unsigned log:1;
unsigned errors:1;
unsigned events:1;
diff --git a/src/http/modules/ngx_http_flv_module.c b/src/http/modules/ngx_http_flv_module.c
index b7c18cf57..2afeb2809 100644
--- a/src/http/modules/ngx_http_flv_module.c
+++ b/src/http/modules/ngx_http_flv_module.c
@@ -143,7 +143,7 @@ ngx_http_flv_handler(ngx_http_request_t *r)
if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
ngx_log_error(level, log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
}
return rc;
diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c
index 53ef4ff28..a1848628a 100644
--- a/src/http/modules/ngx_http_gzip_static_module.c
+++ b/src/http/modules/ngx_http_gzip_static_module.c
@@ -152,7 +152,7 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
}
ngx_log_error(level, log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
return NGX_DECLINED;
}
diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c
index da61a954c..f88e599a7 100644
--- a/src/http/modules/ngx_http_index_module.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -83,13 +83,13 @@ ngx_module_t ngx_http_index_module = {
/*
- * Try to open the first index file before the test of the directory existence
- * because the valid requests should be many more than invalid ones.
- * If open() would fail, then stat() should be more quickly because some data
- * is already cached in the kernel.
- * Besides, Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
- * Unix has ENOTDIR error, although it less helpfull - it points only
- * that path contains the usual file in place of the directory.
+ * Try to open/test the first index file before the test of directory
+ * existence because valid requests should be much more than invalid ones.
+ * If the file open()/stat() would fail, then the directory stat() should
+ * be more quickly because some data is already cached in the kernel.
+ * Besides, Win32 may return ERROR_PATH_NOT_FOUND (NGX_ENOTDIR) at once.
+ * Unix has ENOTDIR error, however, it's less helpful than Win32's one:
+ * it only indicates that path contains an usual file in place of directory.
*/
static ngx_int_t
@@ -208,14 +208,15 @@ ngx_http_index_handler(ngx_http_request_t *r)
of.directio = clcf->directio;
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
!= NGX_OK)
{
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err,
+ "%s \"%s\" failed", of.failed, path.data);
if (of.err == 0) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -239,8 +240,8 @@ ngx_http_index_handler(ngx_http_request_t *r)
continue;
}
- ngx_log_error(NGX_LOG_ERR, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
+ "%s \"%s\" failed", of.failed, path.data);
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -291,6 +292,7 @@ ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
ngx_memzero(&of, sizeof(ngx_open_file_info_t));
of.test_dir = 1;
+ of.test_only = 1;
of.valid = clcf->open_file_cache_valid;
of.errors = clcf->open_file_cache_errors;
@@ -318,7 +320,7 @@ ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
}
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", dir.data);
+ "%s \"%s\" failed", of.failed, dir.data);
}
return NGX_HTTP_INTERNAL_SERVER_ERROR;
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index 93ff90568..efe720bf5 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -385,6 +385,8 @@ ngx_http_log_script_write(ngx_http_request_t *r, ngx_http_log_script_t *script,
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_dir = 1;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
@@ -439,7 +441,7 @@ ngx_http_log_script_write(ngx_http_request_t *r, ngx_http_log_script_t *script,
!= NGX_OK)
{
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
- ngx_open_file_n " \"%s\" failed", log.data);
+ "%s \"%s\" failed", of.failed, log.data);
/* simulate successfull logging */
return len;
}
diff --git a/src/http/modules/ngx_http_static_module.c b/src/http/modules/ngx_http_static_module.c
index dce366922..bc46b84a7 100644
--- a/src/http/modules/ngx_http_static_module.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -128,7 +128,7 @@ ngx_http_static_handler(ngx_http_request_t *r)
if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
ngx_log_error(level, log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
}
return rc;
diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
index 57aabecac..66b0f59b2 100644
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -662,7 +662,7 @@ sendfile(r, filename, offset = -1, bytes = 0)
}
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
- ngx_open_file_n " \"%s\" failed", filename);
+ "%s \"%s\" failed", of.failed, filename);
XSRETURN_EMPTY;
}
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 3162d39f8..825c8395c 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1169,6 +1169,7 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
of.directio = clcf->directio;
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
@@ -1177,7 +1178,7 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
{
if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
}
continue;
diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
index 9e09f2d13..f292d5a2e 100644
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -1413,6 +1413,7 @@ ngx_http_script_file_code(ngx_http_script_engine_t *e)
of.directio = clcf->directio;
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
@@ -1421,7 +1422,7 @@ ngx_http_script_file_code(ngx_http_script_engine_t *e)
{
if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
- ngx_file_info_n " \"%s\" failed", value->data);
+ "%s \"%s\" failed", of.failed, value->data);
}
switch (code->op) {