# HG changeset patch # User Igor Sysoev # Date 1221422400 -14400 # Node ID a8e3f1441eec1b608b77f39110e16f0b82b983d5 # Parent f6561f72153214f6e7e8ab19c72cb87357d3738f nginx 0.7.17 *) Feature: now the "directio" directive works on Linux. *) Feature: the $pid variable. *) Bugfix: the "directio" optimization that had appeared in 0.7.15 did not work with open_file_cache. *) Bugfix: the "access_log" with variables did not work on Linux; the bug had appeared in 0.7.7. *) Bugfix: the ngx_http_charset_module did not understand quoted charset name received from backend. diff --git a/CHANGES b/CHANGES --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,20 @@ +Changes with nginx 0.7.17 15 Sep 2008 + + *) Feature: now the "directio" directive works on Linux. + + *) Feature: the $pid variable. + + *) Bugfix: the "directio" optimization that had appeared in 0.7.15 did + not work with open_file_cache. + + *) Bugfix: the "access_log" with variables did not work on Linux; the + bug had appeared in 0.7.7. + + *) Bugfix: the ngx_http_charset_module did not understand quoted + charset name received from backend. + + Changes with nginx 0.7.16 08 Sep 2008 *) Bugfix: nginx could not be built on 64-bit platforms; the bug had diff --git a/CHANGES.ru b/CHANGES.ru --- a/CHANGES.ru +++ b/CHANGES.ru @@ -1,4 +1,20 @@ +Изменения в nginx 0.7.17 15.09.2008 + + *) Добавление: директива directio теперь работает на Linux. + + *) Добавление: переменная $pid. + + *) Исправление: оптимизация directio, появившаяся в 0.7.15, не работала + при использовании open_file_cache. + + *) Исправление: access_log с переменными не работал на Linux; ошибка + появилась в 0.7.7. + + *) Исправление: модуль ngx_http_charset_module не понимал название + кодировки в кавычках, полученное от бэкенда. + + Изменения в nginx 0.7.16 08.09.2008 *) Исправление: nginx не собирался на 64-битных платформах; ошибка diff --git a/auto/os/features b/auto/os/features --- a/auto/os/features +++ b/auto/os/features @@ -182,6 +182,10 @@ ngx_feature_test="fcntl(0, F_SETFL, O_DI . auto/feature +if [ $ngx_found = yes -a "$NGX_SYSTEM" = "Linux" ]; then + have=NGX_HAVE_ALIGNED_DIRECTIO . auto/have +fi + ngx_feature="F_NOCACHE" ngx_feature_name="NGX_HAVE_F_NOCACHE" ngx_feature_run=no diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -8,7 +8,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VERSION "0.7.16" +#define NGINX_VERSION "0.7.17" #define NGINX_VER "nginx/" NGINX_VERSION #define NGINX_VAR "NGINX" diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h --- a/src/core/ngx_buf.h +++ b/src/core/ngx_buf.h @@ -79,6 +79,9 @@ typedef struct { unsigned sendfile; unsigned directio; +#if (NGX_HAVE_ALIGNED_DIRECTIO) + unsigned unaligned; +#endif unsigned need_in_memory; unsigned need_in_temp; diff --git a/src/core/ngx_open_file_cache.c b/src/core/ngx_open_file_cache.c --- a/src/core/ngx_open_file_cache.c +++ b/src/core/ngx_open_file_cache.c @@ -205,6 +205,7 @@ ngx_open_cached_file(ngx_open_file_cache of->is_file = file->is_file; of->is_link = file->is_link; of->is_exec = file->is_exec; + of->is_directio = file->is_directio; if (!file->is_dir) { file->count++; @@ -360,6 +361,7 @@ update: file->is_file = of->is_file; file->is_link = of->is_link; file->is_exec = of->is_exec; + file->is_directio = of->is_directio; if (!of->is_dir) { file->count++; @@ -499,9 +501,9 @@ ngx_open_and_stat_file(u_char *name, ngx of->fd = fd; if (of->directio <= ngx_file_size(&fi)) { - if (ngx_directio(fd) == -1) { + if (ngx_directio_on(fd) == -1) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - ngx_directio_n " \"%s\" failed", name); + ngx_directio_on_n " \"%s\" failed", name); } else { of->is_directio = 1; diff --git a/src/core/ngx_open_file_cache.h b/src/core/ngx_open_file_cache.h --- a/src/core/ngx_open_file_cache.h +++ b/src/core/ngx_open_file_cache.h @@ -63,6 +63,7 @@ struct ngx_cached_open_file_s { unsigned is_file:1; unsigned is_link:1; unsigned is_exec:1; + unsigned is_directio:1; ngx_event_t *event; }; diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -355,6 +355,10 @@ ngx_output_chain_align_file_buf(ngx_outp * to reuse the buf via ctx->free list */ +#if (NGX_HAVE_ALIGNED_DIRECTIO) + ctx->unaligned = 1; +#endif + return NGX_OK; } @@ -491,8 +495,41 @@ ngx_output_chain_copy_buf(ngx_output_cha } } else { + +#if (NGX_HAVE_ALIGNED_DIRECTIO) + + if (ctx->unaligned) { + if (ngx_directio_off(src->file->fd) == -1) { + ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno, + ngx_directio_off_n " \"%s\" failed", + src->file->name.data); + } + } + +#endif + n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos); +#if (NGX_HAVE_ALIGNED_DIRECTIO) + + if (ctx->unaligned) { + ngx_err_t err; + + err = ngx_errno; + + if (ngx_directio_on(src->file->fd) == -1) { + ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno, + ngx_directio_on_n " \"%s\" failed", + src->file->name.data); + } + + ngx_set_errno(err); + + ctx->unaligned = 0; + } + +#endif + if (n == NGX_ERROR) { return (ngx_int_t) n; } @@ -505,8 +542,8 @@ ngx_output_chain_copy_buf(ngx_output_cha if (n != size) { ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, - ngx_read_file_n " read only %z of %O from file", - n, size); + ngx_read_file_n " read only %z of %O from \"%s\"", + n, size, src->file->name.data); if (n == 0) { return NGX_ERROR; } diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c --- a/src/http/modules/ngx_http_log_module.c +++ b/src/http/modules/ngx_http_log_module.c @@ -430,6 +430,7 @@ ngx_http_log_script_write(ngx_http_reque of.log = 1; of.valid = llcf->open_file_cache_valid; of.min_uses = llcf->open_file_cache_min_uses; + of.directio = NGX_MAX_OFF_T_VALUE; if (ngx_open_cached_file(llcf->open_file_cache, &log, &of, r->pool) != NGX_OK) diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm --- a/src/http/modules/perl/nginx.pm +++ b/src/http/modules/perl/nginx.pm @@ -47,7 +47,7 @@ our @EXPORT = qw( HTTP_INSUFFICIENT_STORAGE ); -our $VERSION = '0.7.16'; +our $VERSION = '0.7.17'; require XSLoader; XSLoader::load('nginx', $VERSION); diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1751,6 +1751,9 @@ ngx_http_finalize_request(ngx_http_reque } } + c->read->handler = ngx_http_request_handler; + c->write->handler = ngx_http_request_handler; + ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc)); return; } diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -2632,7 +2632,17 @@ ngx_http_upstream_copy_content_type(ngx_ r->headers_out.content_type_len = last - h->value.data; - r->headers_out.charset.len = h->value.data + h->value.len - p; + if (*p == '"') { + p++; + } + + last = h->value.data + h->value.len; + + if (*(last - 1) == '"') { + last--; + } + + r->headers_out.charset.len = last - p; r->headers_out.charset.data = p; return NGX_OK; diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -78,6 +78,8 @@ static ngx_int_t ngx_http_variable_nginx ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); +static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data); /* * TODO: @@ -227,6 +229,9 @@ static ngx_http_variable_t ngx_http_cor { ngx_string("hostname"), NULL, ngx_http_variable_hostname, 0, 0, 0 }, + { ngx_string("pid"), NULL, ngx_http_variable_pid, + 0, 0, 0 }, + { ngx_null_string, NULL, NULL, 0, 0, 0 } }; @@ -1353,6 +1358,27 @@ ngx_http_variable_hostname(ngx_http_requ } +static ngx_int_t +ngx_http_variable_pid(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data) +{ + u_char *p; + + p = ngx_pnalloc(r->pool, NGX_INT64_LEN); + if (p == NULL) { + return NGX_ERROR; + } + + v->len = ngx_sprintf(p, "%P", ngx_pid) - p; + v->valid = 1; + v->no_cacheable = 0; + v->not_found = 0; + v->data = p; + + return NGX_OK; +} + + ngx_int_t ngx_http_variables_add_core_vars(ngx_conf_t *cf) { diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c --- a/src/os/unix/ngx_files.c +++ b/src/os/unix/ngx_files.c @@ -389,7 +389,7 @@ ngx_unlock_fd(ngx_fd_t fd) #if (NGX_HAVE_O_DIRECT) ngx_int_t -ngx_directio(ngx_fd_t fd) +ngx_directio_on(ngx_fd_t fd) { int flags; @@ -402,4 +402,19 @@ ngx_directio(ngx_fd_t fd) return fcntl(fd, F_SETFL, flags | O_DIRECT); } + +ngx_int_t +ngx_directio_off(ngx_fd_t fd) +{ + int flags; + + flags = fcntl(fd, F_GETFL); + + if (flags == -1) { + return -1; + } + + return fcntl(fd, F_SETFL, flags & ~O_DIRECT); +} + #endif diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h --- a/src/os/unix/ngx_files.h +++ b/src/os/unix/ngx_files.h @@ -222,23 +222,26 @@ ngx_err_t ngx_unlock_fd(ngx_fd_t fd); #if (NGX_HAVE_O_DIRECT) -ngx_int_t ngx_directio(ngx_fd_t fd); -#define ngx_directio_n "fcntl(O_DIRECT)" +ngx_int_t ngx_directio_on(ngx_fd_t fd); +#define ngx_directio_on_n "fcntl(O_DIRECT)" + +ngx_int_t ngx_directio_off(ngx_fd_t fd); +#define ngx_directio_off_n "fcntl(!O_DIRECT)" #elif (NGX_HAVE_F_NOCACHE) -#define ngx_directio(fd) fcntl(fd, F_NOCACHE, 1) -#define ngx_directio_n "fcntl(F_NOCACHE)" +#define ngx_directio_on(fd) fcntl(fd, F_NOCACHE, 1) +#define ngx_directio_on_n "fcntl(F_NOCACHE, 1)" #elif (NGX_HAVE_DIRECTIO) -#define ngx_directio(fd) directio(fd, DIRECTIO_ON) -#define ngx_directio_n "directio(DIRECTIO_ON)" +#define ngx_directio_on(fd) directio(fd, DIRECTIO_ON) +#define ngx_directio_on_n "directio(DIRECTIO_ON)" #else -#define ngx_directio(fd) 0 -#define ngx_directio_n "ngx_directio_n" +#define ngx_directio_on(fd) 0 +#define ngx_directio_on_n "ngx_directio_on_n" #endif