summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-08-15 13:58:27 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-08-15 14:04:52 +0000
commitf15cba5580e897378fe46adfbfd4ee2776740cd4 (patch)
treec43e911c2a75e108b9d905001fc5a93507379130
parente945442941c923b09ac67b2fcd63a4f115ebd638 (diff)
GC unused direct IO support
-rw-r--r--vespalib/src/tests/io/fileutil/fileutiltest.cpp9
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.cpp58
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.h10
3 files changed, 4 insertions, 73 deletions
diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
index 0289bb376ad..93803c1fe9e 100644
--- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp
+++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
@@ -102,15 +102,6 @@ TEST("require that vespalib::File::open works")
ASSERT_TRUE(fileExists("mydir/myfile"));
f.unlink();
}
- // Opening with direct IO support works.
- {
- File f("mydir/myfile");
- f.open(File::CREATE | File::DIRECTIO, false);
- ASSERT_TRUE(fileExists("mydir/myfile"));
- if (!f.isOpenWithDirectIO()) {
- std::cerr << "This platform does not support direct IO\n";
- }
- }
// Opening plain file works
{
File f("myfile");
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp
index 28455d3dd42..cb478f0f225 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.cpp
+++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp
@@ -54,7 +54,6 @@ safeStrerror(int errnum)
File::File(stringref filename)
: _fd(-1),
- _flags(0),
_filename(filename)
{ }
@@ -97,27 +96,14 @@ File::open(int flags, bool autoCreateDirectories) {
}
int openflags = ((flags & File::READONLY) != 0 ? O_RDONLY : O_RDWR)
| ((flags & File::CREATE) != 0 ? O_CREAT : 0)
-#ifdef __linux__
- | ((flags & File::DIRECTIO) != 0 ? O_DIRECT : 0)
-#endif
| ((flags & File::TRUNC) != 0 ? O_TRUNC: 0);
int fd = openAndCreateDirsIfMissing(_filename, openflags, autoCreateDirectories);
-#ifdef __linux__
- if (fd < 0 && ((flags & File::DIRECTIO) != 0)) {
- openflags = (openflags ^ O_DIRECT);
- flags = (flags ^ DIRECTIO);
- LOG(debug, "open(%s, %d): Retrying without direct IO due to failure opening with errno(%d): %s",
- _filename.c_str(), flags, errno, safeStrerror(errno).c_str());
- fd = openAndCreateDirsIfMissing(_filename, openflags, autoCreateDirectories);
- }
-#endif
if (fd < 0) {
asciistream ost;
ost << "open(" << _filename << ", 0x" << hex << flags << dec
<< "): Failed, errno(" << errno << "): " << safeStrerror(errno);
throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC);
}
- _flags = flags;
if (_fd != -1) close();
_fd = fd;
LOG(debug, "open(%s, %d). File opened with file descriptor %d.", _filename.c_str(), flags, fd);
@@ -135,7 +121,7 @@ File::stat() const
result = processStat(filestats, ::stat(_filename.c_str(), &filestats) == 0, _filename);
// If the file does not exist yet, act like it does. It will
// probably be created when opened.
- if (result.get() == 0) {
+ if ( ! result) {
result = std::make_unique<FileInfo>();
result->_size = 0;
result->_directory = false;
@@ -156,42 +142,12 @@ File::resize(off_t size)
LOG(debug, "resize(%s): Resized to %" PRIu64 " bytes.", _filename.c_str(), size);
}
-void
-File::verifyDirectIO(uint64_t buf, size_t bufsize, off_t offset) const
-{
- if (offset % 512 != 0) {
- LOG(error,
- "Access to file %s failed because offset %" PRIu64 " wasn't 512-byte "
- "aligned. Buffer memory address was %" PRIx64 ", length %zu",
- _filename.c_str(), static_cast<uint64_t>(offset), buf, bufsize);
- assert(false);
- }
- if (buf % 512 != 0) {
- LOG(error,
- "Access to file %s failed because buffer memory address %" PRIx64 " "
- "wasn't 512-byte aligned. Offset was %" PRIu64 ", length %zu",
- _filename.c_str(), buf, static_cast<uint64_t>(offset), bufsize);
- assert(false);
- }
- if (bufsize % 512 != 0) {
- LOG(error,
- "Access to file %s failed because buffer size %zu wasn't 512-byte "
- "aligned. Buffer memory address was %" PRIx64 ", offset %" PRIu64,
- _filename.c_str(), bufsize, buf, static_cast<uint64_t>(offset));
- assert(false);
- }
-}
-
off_t
File::write(const void *buf, size_t bufsize, off_t offset)
{
size_t left = bufsize;
LOG(debug, "write(%s): Writing %zu bytes at offset %" PRIu64 ".", _filename.c_str(), bufsize, offset);
- if (_flags & DIRECTIO) {
- verifyDirectIO((uint64_t)buf, bufsize, offset);
- }
-
while (left > 0) {
ssize_t written = ::pwrite(_fd, buf, left, offset);
if (written > 0) {
@@ -218,10 +174,6 @@ File::read(void *buf, size_t bufsize, off_t offset) const
size_t remaining = bufsize;
LOG(debug, "read(%s): Reading %zu bytes from offset %" PRIu64 ".", _filename.c_str(), bufsize, offset);
- if (_flags & DIRECTIO) {
- verifyDirectIO((uint64_t)buf, bufsize, offset);
- }
-
while (remaining > 0) {
ssize_t bytesread = ::pread(_fd, buf, remaining, offset);
if (bytesread > 0) {
@@ -229,14 +181,8 @@ File::read(void *buf, size_t bufsize, off_t offset) const
remaining -= bytesread;
buf = ((char*) buf) + bytesread;
offset += bytesread;
- if (((_flags & DIRECTIO) != 0) && ((bytesread % 512) != 0) && (offset == getFileSize())) {
- LOG(spam, "read(%s): Found EOF. Directio read to unaligned file end at offset %" PRIu64 ".",
- _filename.c_str(), offset);
- break;
- }
} else if (bytesread == 0) { // EOF
- LOG(spam, "read(%s): Found EOF. Zero bytes read from offset %" PRIu64 ".",
- _filename.c_str(), offset);
+ LOG(spam, "read(%s): Found EOF. Zero bytes read from offset %" PRIu64 ".", _filename.c_str(), offset);
break;
} else if (errno != EINTR && errno != EAGAIN) {
asciistream ost;
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h
index 1d66c026ecf..148317a7edf 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.h
+++ b/vespalib/src/vespa/vespalib/io/fileutil.h
@@ -58,13 +58,8 @@ struct FileInfo {
class File {
private:
int _fd;
- int _flags;
string _filename;
- /**
- * Verify that direct I/O alignment preconditions hold. Triggers assertion
- * failure on violations.
- */
- void verifyDirectIO(uint64_t buf, size_t bufsize, off_t offset) const;
+
void sync();
/**
* Get information about the current file. If file is opened, file descriptor
@@ -78,7 +73,7 @@ public:
/**
* If failing to open file using direct IO it will retry using cached IO.
*/
- enum Flag { READONLY = 1, CREATE = 2, DIRECTIO = 4, TRUNC = 8 };
+ enum Flag { READONLY = 1, CREATE = 2, TRUNC = 8 };
/** Create a file instance, without opening the file. */
File(stringref filename);
@@ -91,7 +86,6 @@ public:
void open(int flags, bool autoCreateDirectories = false);
bool isOpen() const { return (_fd != -1); }
- bool isOpenWithDirectIO() const { return ((_flags & DIRECTIO) != 0); }
int getFileDescriptor() const { return _fd; }