| 444 | } |
| 445 | |
| 446 | static inline int |
| 447 | cache_op(AIOCallback *op) |
| 448 | { |
| 449 | bool read = (op->aiocb.aio_lio_opcode == LIO_READ); |
| 450 | for (; op; op = op->then) { |
| 451 | ink_aiocb *a = &op->aiocb; |
| 452 | ssize_t err, res = 0; |
| 453 | |
| 454 | while (a->aio_nbytes - res > 0) { |
| 455 | do { |
| 456 | if (read) { |
| 457 | #ifdef AIO_FAULT_INJECTION |
| 458 | err = aioFaultInjection.pread(a->aio_fildes, (static_cast<char *>(a->aio_buf)) + res, a->aio_nbytes - res, |
| 459 | a->aio_offset + res); |
| 460 | #else |
| 461 | err = pread(a->aio_fildes, (static_cast<char *>(a->aio_buf)) + res, a->aio_nbytes - res, a->aio_offset + res); |
| 462 | #endif |
| 463 | } else { |
| 464 | #ifdef AIO_FAULT_INJECTION |
| 465 | err = aioFaultInjection.pwrite(a->aio_fildes, (static_cast<char *>(a->aio_buf)) + res, a->aio_nbytes - res, |
| 466 | a->aio_offset + res); |
| 467 | #else |
| 468 | err = pwrite(a->aio_fildes, (static_cast<char *>(a->aio_buf)) + res, a->aio_nbytes - res, a->aio_offset + res); |
| 469 | #endif |
| 470 | } |
| 471 | } while ((err < 0) && (errno == EINTR || errno == ENOBUFS || errno == ENOMEM)); |
| 472 | if (err <= 0) { |
| 473 | Warning("cache disk operation failed %s %zd %d\n", (a->aio_lio_opcode == LIO_READ) ? "READ" : "WRITE", err, errno); |
| 474 | op->aio_result = -errno; |
| 475 | return (err); |
| 476 | } |
| 477 | res += err; |
| 478 | } |
| 479 | op->aio_result = res; |
| 480 | ink_assert(op->ok()); |
| 481 | } |
| 482 | return 1; |
| 483 | } |
| 484 | |
| 485 | bool |
| 486 | ink_aio_thread_num_set(int thread_num) |
no test coverage detected