Klaus Demo nginx / fae2c00
disable directio for unaligned reads in Linux Igor Sysoev 13 years ago
7 changed file(s) with 87 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
181181 . auto/feature
182182
183183
184 if [ $ngx_found = yes -a "$NGX_SYSTEM" = "Linux" ]; then
185 have=NGX_HAVE_ALIGNED_DIRECTIO . auto/have
186 fi
187
184188 ngx_feature="F_NOCACHE"
185189 ngx_feature_name="NGX_HAVE_F_NOCACHE"
186190 ngx_feature_run=no
7878
7979 unsigned sendfile;
8080 unsigned directio;
81 #if (NGX_HAVE_ALIGNED_DIRECTIO)
82 unsigned unaligned;
83 #endif
8184 unsigned need_in_memory;
8285 unsigned need_in_temp;
8386
354354 * to reuse the buf via ctx->free list
355355 */
356356
357 #if (NGX_HAVE_ALIGNED_DIRECTIO)
358 ctx->unaligned = 1;
359 #endif
360
357361 return NGX_OK;
358362 }
359363
490494 }
491495
492496 } else {
497
498 #if (NGX_HAVE_ALIGNED_DIRECTIO)
499
500 if (ctx->unaligned) {
501 if (ngx_directio_off(src->file->fd) == -1) {
502 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
503 ngx_directio_off_n " \"%s\" failed",
504 src->file->name.data);
505 }
506 }
507
508 #endif
509
493510 n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos);
511
512 #if (NGX_HAVE_ALIGNED_DIRECTIO)
513
514 if (ctx->unaligned) {
515 ngx_err_t err;
516
517 err = ngx_errno;
518
519 if (ngx_directio_on(src->file->fd) == -1) {
520 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
521 ngx_directio_on_n " \"%s\" failed",
522 src->file->name.data);
523 }
524
525 ngx_set_errno(err);
526
527 ctx->unaligned = 0;
528 }
529
530 #endif
494531
495532 if (n == NGX_ERROR) {
496533 return (ngx_int_t) n;
388388 #if (NGX_HAVE_O_DIRECT)
389389
390390 ngx_int_t
391 ngx_directio(ngx_fd_t fd)
391 ngx_directio_on(ngx_fd_t fd)
392392 {
393393 int flags;
394394
401401 return fcntl(fd, F_SETFL, flags | O_DIRECT);
402402 }
403403
404 #endif
404
405 ngx_int_t
406 ngx_directio_off(ngx_fd_t fd)
407 {
408 int flags;
409
410 flags = fcntl(fd, F_GETFL);
411
412 if (flags == -1) {
413 return -1;
414 }
415
416 return fcntl(fd, F_SETFL, flags & ~O_DIRECT);
417 }
418
419 #endif
221221
222222 #if (NGX_HAVE_O_DIRECT)
223223
224 ngx_int_t ngx_directio(ngx_fd_t fd);
225 #define ngx_directio_n "fcntl(O_DIRECT)"
224 ngx_int_t ngx_directio_on(ngx_fd_t fd);
225 #define ngx_directio_on_n "fcntl(O_DIRECT)"
226
227 ngx_int_t ngx_directio_off(ngx_fd_t fd);
228 #define ngx_directio_off_n "fcntl(!O_DIRECT)"
226229
227230 #elif (NGX_HAVE_F_NOCACHE)
228231
229 #define ngx_directio(fd) fcntl(fd, F_NOCACHE, 1)
230 #define ngx_directio_n "fcntl(F_NOCACHE)"
232 #define ngx_directio_on(fd) fcntl(fd, F_NOCACHE, 1)
233 #define ngx_directio_on_n "fcntl(F_NOCACHE, 1)"
231234
232235 #elif (NGX_HAVE_DIRECTIO)
233236
234 #define ngx_directio(fd) directio(fd, DIRECTIO_ON)
235 #define ngx_directio_n "directio(DIRECTIO_ON)"
236
237 #else
238
239 #define ngx_directio(fd) 0
240 #define ngx_directio_n "ngx_directio_n"
237 #define ngx_directio_on(fd) directio(fd, DIRECTIO_ON)
238 #define ngx_directio_on_n "directio(DIRECTIO_ON)"
239
240 #else
241
242 #define ngx_directio_on(fd) 0
243 #define ngx_directio_on_n "ngx_directio_on_n"
241244
242245 #endif
243246
504504
505505
506506 ngx_int_t
507 ngx_directio(ngx_fd_t fd)
507 ngx_directio_on(ngx_fd_t fd)
508508 {
509509 return 0;
510510 }
511
512 ngx_int_t
513 ngx_directio_off(ngx_fd_t fd)
514 {
515 return 0;
516 }
231231 off_t offset, ngx_pool_t *pool);
232232
233233
234 ngx_int_t ngx_directio(ngx_fd_t fd);
235 #define ngx_directio_n "ngx_directio_n"
234 ngx_int_t ngx_directio_on(ngx_fd_t fd);
235 #define ngx_directio_on_n "ngx_directio_on_n"
236
237 ngx_int_t ngx_directio_off(ngx_fd_t fd);
238 #define ngx_directio_off_n "ngx_directio_off_n"
236239
237240
238241 #endif /* _NGX_FILES_H_INCLUDED_ */