| 634 | } |
| 635 | |
| 636 | ACTOR static Future<int> read_impl(SimpleFile* self, void* data, int length, int64_t offset) { |
| 637 | ASSERT((self->flags & IAsyncFile::OPEN_NO_AIO) != 0 || |
| 638 | ((uintptr_t)data % 4096 == 0 && length % 4096 == 0 && offset % 4096 == 0)); // Required by KAIO. |
| 639 | state UID opId = deterministicRandom()->randomUniqueID(); |
| 640 | if (randLog) |
| 641 | fmt::print(randLog, |
| 642 | "SFR1 {0} {1} {2} {3} {4}\n", |
| 643 | self->dbgId.shortString(), |
| 644 | self->filename, |
| 645 | opId.shortString(), |
| 646 | length, |
| 647 | offset); |
| 648 | |
| 649 | wait(waitUntilDiskReady(self->diskParameters, length)); |
| 650 | |
| 651 | if (_lseeki64(self->h, offset, SEEK_SET) == -1) { |
| 652 | TraceEvent(SevWarn, "SimpleFileIOError").detail("Location", 1); |
| 653 | throw io_error(); |
| 654 | } |
| 655 | |
| 656 | unsigned int read_bytes = 0; |
| 657 | if ((read_bytes = _read(self->h, data, (unsigned int)length)) == -1) { |
| 658 | TraceEvent(SevWarn, "SimpleFileIOError").detail("Location", 2); |
| 659 | throw io_error(); |
| 660 | } |
| 661 | |
| 662 | if (randLog) { |
| 663 | uint32_t a = crc32c_append(0, (const uint8_t*)data, read_bytes); |
| 664 | fprintf(randLog, |
| 665 | "SFR2 %s %s %s %d %d\n", |
| 666 | self->dbgId.shortString().c_str(), |
| 667 | self->filename.c_str(), |
| 668 | opId.shortString().c_str(), |
| 669 | read_bytes, |
| 670 | a); |
| 671 | } |
| 672 | |
| 673 | debugFileCheck("SimpleFileRead", self->filename, data, offset, length); |
| 674 | |
| 675 | INJECT_FAULT(io_timeout, "SimpleFile::read"); // SimpleFile::read io_timeout injected |
| 676 | INJECT_FAULT(io_error, "SimpleFile::read"); // SimpleFile::read io_error injected |
| 677 | |
| 678 | return read_bytes; |
| 679 | } |
| 680 | |
| 681 | ACTOR static Future<Void> write_impl(SimpleFile* self, StringRef data, int64_t offset) { |
| 682 | state UID opId = deterministicRandom()->randomUniqueID(); |
nothing calls this directly
no test coverage detected