MCPcopy Create free account
hub / github.com/apple/foundationdb / open

Method open

fdbrpc/Net2FileSystem.cpp:43–89  ·  view source on GitHub ↗

Opens a file for asynchronous I/O

Source from the content-addressed store, hash-verified

41
42// Opens a file for asynchronous I/O
43Future<Reference<class IAsyncFile>> Net2FileSystem::open(const std::string& filename, int64_t flags, int64_t mode) {
44#ifdef __linux__
45 if (checkFileSystem) {
46 dev_t fileDeviceId = getDeviceId(filename);
47 if (fileDeviceId != this->fileSystemDeviceId) {
48 TraceEvent(SevError, "DeviceIdMismatched")
49 .detail("FileSystemDeviceId", this->fileSystemDeviceId)
50 .detail("FileDeviceId", fileDeviceId);
51 throw io_error();
52 }
53 }
54#endif
55
56 if ((flags & IAsyncFile::OPEN_EXCLUSIVE))
57 ASSERT(flags & IAsyncFile::OPEN_CREATE);
58 if (!(flags & IAsyncFile::OPEN_UNCACHED))
59 return AsyncFileCached::open(filename, flags, mode);
60
61 Future<Reference<IAsyncFile>> f;
62#ifdef __linux__
63 // In the vast majority of cases, we wish to use Kernel AIO. However, some systems
64 // don’t properly support kernel async I/O without O_DIRECT or AIO at all. In such
65 // cases, DISABLE_POSIX_KERNEL_AIO knob can be enabled to fallback to EIO instead
66 // of Kernel AIO. And EIO_USE_ODIRECT can be used to turn on or off O_DIRECT within
67 // EIO.
68 if ((flags & IAsyncFile::OPEN_UNBUFFERED) && !(flags & IAsyncFile::OPEN_NO_AIO) &&
69 !FLOW_KNOBS->DISABLE_POSIX_KERNEL_AIO)
70 f = AsyncFileKAIO::open(filename, flags, mode, nullptr);
71 else
72#endif
73 f = Net2AsyncFile::open(
74 filename,
75 flags,
76 mode,
77 static_cast<boost::asio::io_service*>((void*)g_network->global(INetwork::enASIOService)));
78 if (FLOW_KNOBS->PAGE_WRITE_CHECKSUM_HISTORY > 0)
79 f = map(f, [=](Reference<IAsyncFile> r) { return Reference<IAsyncFile>(new AsyncFileWriteChecker(r)); });
80 if (FLOW_KNOBS->ENABLE_CHAOS_FEATURES)
81 f = map(f, [=](Reference<IAsyncFile> r) { return Reference<IAsyncFile>(new AsyncFileChaos(r)); });
82 if (flags & IAsyncFile::OPEN_ENCRYPTED)
83 f = map(f, [flags](Reference<IAsyncFile> r) {
84 auto mode = flags & IAsyncFile::OPEN_READWRITE ? AsyncFileEncrypted::Mode::APPEND_ONLY
85 : AsyncFileEncrypted::Mode::READ_ONLY;
86 return Reference<IAsyncFile>(new AsyncFileEncrypted(r, mode));
87 });
88 return f;
89}
90
91// Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power
92// failure.

Callers

nothing calls this directly

Calls 6

getDeviceIdFunction · 0.85
TraceEventClass · 0.85
mapFunction · 0.85
detailMethod · 0.80
openFunction · 0.50
globalMethod · 0.45

Tested by

no test coverage detected