21 #define NGX_MIN_READ_AHEAD (128 * 1024)
24 static void ngx_open_file_cache_cleanup(
void *data);
38 static void ngx_open_file_cleanup(
void *data);
49 static void ngx_open_file_cache_remove(
ngx_event_t *ev);
64 ngx_open_file_cache_rbtree_insert_value);
77 cln->
handler = ngx_open_file_cache_cleanup;
85 ngx_open_file_cache_cleanup(
void *data)
93 "open file cache cleanup");
112 "delete cached open file: %s", file->
name);
127 "%d items still leave in open file cache",
133 "rbtree still is not empty in open file cache");
159 if (ngx_file_info_wrapper(name, of, &fi, pool->
log)
182 rc = ngx_open_and_stat_file(name, of, pool->
log);
203 hash = ngx_crc32_long(name->
data, name->
len);
205 file = ngx_open_file_lookup(cache, name, hash);
217 rc = ngx_open_and_stat_file(name, of, pool->
log);
227 || (file->
event == NULL
231 && of->disable_symlinks == file->disable_symlinks
232 && of->disable_symlinks_from == file->disable_symlinks_from
236 if (file->
err == 0) {
251 ngx_open_file_add_event(cache, file, of, pool->
log);
256 #if (NGX_HAVE_OPENAT)
257 of->
failed = file->disable_symlinks ? ngx_openat_file_n
268 "retest open file: %s, fd:%d, c:%d, e:%d",
285 rc = ngx_open_and_stat_file(name, of, pool->
log);
299 }
else if (of->
err == 0) {
327 if (file->
count == 0) {
329 ngx_open_file_del_event(file);
350 rc = ngx_open_and_stat_file(name, of, pool->
log);
359 ngx_expire_old_cached_files(cache, 0, pool->
log);
370 if (file->
name == NULL) {
391 ngx_open_file_add_event(cache, file, of, pool->
log);
397 #if (NGX_HAVE_OPENAT)
398 file->disable_symlinks = of->disable_symlinks;
399 file->disable_symlinks_from = of->disable_symlinks_from;
429 "cached open file: %s, fd:%d, c:%d, e:%d, u:%d",
435 cln->
handler = ngx_open_file_cleanup;
438 ofcln->
cache = cache;
456 if (file->
count == 0) {
485 #if (NGX_HAVE_OPENAT)
488 ngx_openat_file_owner(
ngx_fd_t at_fd,
const u_char *name,
507 fd = ngx_openat_file(at_fd, name, mode, create, access);
513 if (ngx_file_at_info(at_fd, name, &atfi, AT_SYMLINK_NOFOLLOW)
525 if (fi.st_uid != atfi.st_uid) {
553 #if !(NGX_HAVE_OPENAT)
567 u_char *p, *cp, *end;
571 if (of->disable_symlinks == NGX_DISABLE_SYMLINKS_OFF) {
588 if (of->disable_symlinks_from) {
590 cp = p + of->disable_symlinks_from;
605 at_name.
len = of->disable_symlinks_from;
608 }
else if (*p ==
'/') {
616 of->
failed = ngx_openat_file_n;
624 at_fd = NGX_AT_FDCWD;
628 cp = ngx_strlchr(p, end,
'/');
640 if (of->disable_symlinks == NGX_DISABLE_SYMLINKS_NOTOWNER) {
641 fd = ngx_openat_file_owner(at_fd, p,
646 fd = ngx_openat_file(at_fd, p,
655 of->
failed = ngx_openat_file_n;
666 at_name.
len = cp - at_name.
data;
682 fd = ngx_openat_file(at_fd,
".", mode, create, access);
686 if (of->disable_symlinks == NGX_DISABLE_SYMLINKS_NOTOWNER
689 fd = ngx_openat_file_owner(at_fd, p, mode, create, access, log);
692 fd = ngx_openat_file(at_fd, p, mode|NGX_FILE_NOFOLLOW, create, access);
699 of->
failed = ngx_openat_file_n;
720 #if !(NGX_HAVE_OPENAT)
736 if (of->disable_symlinks == NGX_DISABLE_SYMLINKS_OFF) {
782 if (ngx_file_info_wrapper(name, of, &fi, log) ==
NGX_FILE_ERROR) {
793 if (ngx_file_info_wrapper(name, of, &fi, log) ==
NGX_FILE_ERROR) {
905 if (file->
event== NULL) {
952 ngx_open_file_cleanup(
void *data)
961 ngx_expire_old_cached_files(c->
cache, 1, c->
log);
970 "close cached open file: %s, fd:%d, c:%d, u:%d, %d",
981 if (file->
uses >= min_uses || file->
count) {
986 ngx_open_file_del_event(file);
1014 if (file->
event == NULL) {
1065 "expire cached open file: %s", file->
name);
1069 ngx_close_cached_file(cache, file, 0, log);
1088 if (node->
key < temp->
key) {
1092 }
else if (node->
key > temp->
key) {
1105 if (*p == sentinel) {
1114 node->
left = sentinel;
1115 node->
right = sentinel;
1131 while (node != sentinel) {
1133 if (hash < node->key) {
1138 if (hash > node->
key) {
1153 node = (rc < 0) ? node->
left : node->
right;
1181 ngx_close_cached_file(fev->
cache, file, 0, ev->
log);