diff options
author | Tor Egge <Tor.Egge@yahooinc.com> | 2023-07-18 11:36:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-18 11:36:46 +0200 |
commit | c0abdfb4b0dd4141b1a01000eed3e1a8c1900876 (patch) | |
tree | cc15318555fe68564327ae7e2a135a32e58419a5 /vespalib | |
parent | ef723dd9da516f4c3e16e18b83d8d302dd942d17 (diff) | |
parent | 778446173b03842fc60e3714d6c9dde4a2bd719d (diff) |
Merge pull request #27809 from vespa-engine/balder/gc-some-obscure-fastos-file-stdout-stderr-support
GC some obscure support in FastOS_File for stderr and stdout.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/fastos/file.h | 3 | ||||
-rw-r--r-- | vespalib/src/vespa/fastos/linux_file.cpp | 3 | ||||
-rw-r--r-- | vespalib/src/vespa/fastos/unix_file.cpp | 110 |
3 files changed, 38 insertions, 78 deletions
diff --git a/vespalib/src/vespa/fastos/file.h b/vespalib/src/vespa/fastos/file.h index 716af343e21..84b94df5acc 100644 --- a/vespalib/src/vespa/fastos/file.h +++ b/vespalib/src/vespa/fastos/file.h @@ -20,9 +20,6 @@ constexpr int FASTOS_FILE_OPEN_WRITE = (1<<1); constexpr int FASTOS_FILE_OPEN_EXISTING = (1<<2); constexpr int FASTOS_FILE_OPEN_CREATE = (1<<3); constexpr int FASTOS_FILE_OPEN_TRUNCATE = (1<<4); -constexpr int FASTOS_FILE_OPEN_STDOUT = (2<<5); -constexpr int FASTOS_FILE_OPEN_STDERR = (3<<5); -constexpr int FASTOS_FILE_OPEN_STDFLAGS = (3<<5); constexpr int FASTOS_FILE_OPEN_DIRECTIO = (1<<7); constexpr int FASTOS_FILE_OPEN_SYNCWRITES = (1<<9); // synchronous writes diff --git a/vespalib/src/vespa/fastos/linux_file.cpp b/vespalib/src/vespa/fastos/linux_file.cpp index 6fb29782957..dabe84a8f30 100644 --- a/vespalib/src/vespa/fastos/linux_file.cpp +++ b/vespalib/src/vespa/fastos/linux_file.cpp @@ -372,9 +372,6 @@ FastOS_Linux_File::Open(unsigned int openFlags, const char *filename) bool rc; _cachedSize = -1; _filePointer = -1; - if (_directIOEnabled && (_openFlags & FASTOS_FILE_OPEN_STDFLAGS) != 0) { - _directIOEnabled = false; - } if (_syncWritesEnabled) { openFlags |= FASTOS_FILE_OPEN_SYNCWRITES; } diff --git a/vespalib/src/vespa/fastos/unix_file.cpp b/vespalib/src/vespa/fastos/unix_file.cpp index f7dac40efe8..952d9820306 100644 --- a/vespalib/src/vespa/fastos/unix_file.cpp +++ b/vespalib/src/vespa/fastos/unix_file.cpp @@ -207,80 +207,50 @@ FastOS_UNIX_File::Open(unsigned int openFlags, const char *filename) bool rc = false; assert(_filedes == -1); - if ((openFlags & FASTOS_FILE_OPEN_STDFLAGS) != 0) { - FILE *file; - - switch(openFlags & FASTOS_FILE_OPEN_STDFLAGS) { - - case FASTOS_FILE_OPEN_STDOUT: - file = stdout; - SetFileName("stdout"); - break; + if (filename != nullptr) { + SetFileName(filename); + } + unsigned int accessFlags = CalcAccessFlags(openFlags); - case FASTOS_FILE_OPEN_STDERR: - file = stderr; - SetFileName("stderr"); - break; + _filedes = open(_filename.c_str(), accessFlags, 0664); - default: - fprintf(stderr, "Invalid open-flags %08X\n", openFlags); - abort(); - } + rc = (_filedes != -1); -#ifdef __linux__ - _filedes = file->_fileno; -#else - _filedes = fileno(file); -#endif + if (rc) { _openFlags = openFlags; - rc = true; - } else { - if (filename != nullptr) { - SetFileName(filename); - } - unsigned int accessFlags = CalcAccessFlags(openFlags); - - _filedes = open(_filename.c_str(), accessFlags, 0664); - - rc = (_filedes != -1); - - if (rc) { - _openFlags = openFlags; - if (_mmapEnabled) { - int64_t filesize = GetSize(); - auto mlen = static_cast<size_t>(filesize); - if ((static_cast<int64_t>(mlen) == filesize) && (mlen > 0)) { - void *mbase = mmap(nullptr, mlen, PROT_READ, MAP_SHARED | _mmapFlags, _filedes, 0); - if (mbase == MAP_FAILED) { - mbase = mmap(nullptr, mlen, PROT_READ, MAP_SHARED | (_mmapFlags & ALWAYS_SUPPORTED_MMAP_FLAGS), _filedes, 0); - } - if (mbase != MAP_FAILED) { + if (_mmapEnabled) { + int64_t filesize = GetSize(); + auto mlen = static_cast<size_t>(filesize); + if ((static_cast<int64_t>(mlen) == filesize) && (mlen > 0)) { + void *mbase = mmap(nullptr, mlen, PROT_READ, MAP_SHARED | _mmapFlags, _filedes, 0); + if (mbase == MAP_FAILED) { + mbase = mmap(nullptr, mlen, PROT_READ, MAP_SHARED | (_mmapFlags & ALWAYS_SUPPORTED_MMAP_FLAGS), _filedes, 0); + } + if (mbase != MAP_FAILED) { #ifdef __linux__ - int fadviseOptions = getFAdviseOptions(); - int eCode(0); - if (POSIX_FADV_RANDOM == fadviseOptions) { - eCode = posix_madvise(mbase, mlen, POSIX_MADV_RANDOM); - } else if (POSIX_FADV_SEQUENTIAL == fadviseOptions) { - eCode = posix_madvise(mbase, mlen, POSIX_MADV_SEQUENTIAL); - } - if (eCode != 0) { - fprintf(stderr, "Failed: posix_madvise(%p, %ld, %d) = %d\n", mbase, mlen, fadviseOptions, eCode); - } -#endif - _mmapbase = mbase; - _mmaplen = mlen; - } else { - close(_filedes); - _filedes = -1; - std::ostringstream os; - os << "mmap of file '" << GetFileName() << "' with flags '" << std::hex << (MAP_SHARED | _mmapFlags) << std::dec - << "' failed with error :'" << getErrorString(GetLastOSError()) << "'"; - throw std::runtime_error(os.str()); + int fadviseOptions = getFAdviseOptions(); + int eCode(0); + if (POSIX_FADV_RANDOM == fadviseOptions) { + eCode = posix_madvise(mbase, mlen, POSIX_MADV_RANDOM); + } else if (POSIX_FADV_SEQUENTIAL == fadviseOptions) { + eCode = posix_madvise(mbase, mlen, POSIX_MADV_SEQUENTIAL); } + if (eCode != 0) { + fprintf(stderr, "Failed: posix_madvise(%p, %ld, %d) = %d\n", mbase, mlen, fadviseOptions, eCode); + } +#endif + _mmapbase = mbase; + _mmaplen = mlen; + } else { + close(_filedes); + _filedes = -1; + std::ostringstream os; + os << "mmap of file '" << GetFileName() << "' with flags '" << std::hex << (MAP_SHARED | _mmapFlags) << std::dec + << "' failed with error :'" << getErrorString(GetLastOSError()) << "'"; + throw std::runtime_error(os.str()); } } } - } return rc; @@ -300,13 +270,9 @@ FastOS_UNIX_File::Close() bool ok = true; if (_filedes >= 0) { - if ((_openFlags & FASTOS_FILE_OPEN_STDFLAGS) != 0) { - ok = true; - } else { - do { - ok = (close(_filedes) == 0); - } while (!ok && errno == EINTR); - } + do { + ok = (close(_filedes) == 0); + } while (!ok && errno == EINTR); if (_mmapbase != nullptr) { madvise(_mmapbase, _mmaplen, MADV_DONTNEED); |