diff options
Diffstat (limited to 'lib/raidfile/RaidFileRead.cpp')
-rw-r--r-- | lib/raidfile/RaidFileRead.cpp | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/lib/raidfile/RaidFileRead.cpp b/lib/raidfile/RaidFileRead.cpp index bcff54c6..7b755395 100644 --- a/lib/raidfile/RaidFileRead.cpp +++ b/lib/raidfile/RaidFileRead.cpp @@ -44,8 +44,12 @@ #define READ_NUMBER_DISCS_REQUIRED 3 #define READV_MAX_BLOCKS 64 -// We want to use POSIX fstat() for now, not the emulated one -#undef fstat +// We want to use POSIX fstat() for now, not the emulated one, because it's +// difficult to rewrite all this code to use HANDLEs instead of ints. + +const RaidFileReadCategory RaidFileRead::OPEN_IN_RECOVERY("OpenInRecovery"); +const RaidFileReadCategory RaidFileRead::IO_ERROR("IoError"); +const RaidFileReadCategory RaidFileRead::RECOVERING_IO_ERROR("RecoverIoError"); // -------------------------------------------------------------------------- // @@ -548,7 +552,8 @@ void RaidFileRead_Raid::MoveDamagedFileAlertDaemon(int SetNumber, const std::str // -------------------------------------------------------------------------- void RaidFileRead_Raid::AttemptToRecoverFromIOError(bool Stripe1) { - BOX_WARNING("Attempting to recover from I/O error: " << mSetNumber << + BOX_LOG_CATEGORY(Log::WARNING, RaidFileRead::RECOVERING_IO_ERROR, + "Attempting to recover from I/O error: " << mSetNumber << " " << mFilename << ", on stripe " << (Stripe1?1:2)); // Close offending file @@ -740,7 +745,7 @@ int RaidFileRead_Raid::ReadRecovered(void *pBuffer, int NBytes) // Go XORing! unsigned int *b1 = (unsigned int*)mRecoveryBuffer; unsigned int *b2 = (unsigned int *)(mRecoveryBuffer + mBlockSize); - if((mStripe1Handle == -1)) + if(mStripe1Handle == -1) { b1 = b2; b2 = (unsigned int*)mRecoveryBuffer; @@ -861,10 +866,10 @@ void RaidFileRead_Raid::SetPosition(pos_type FilePosition) { if(errno == EIO) { - BOX_ERROR("I/O error when seeking in " << - mSetNumber << " " << mFilename << - " (to " << FilePosition << "), " << - "stripe 1"); + BOX_LOG_CATEGORY(Log::ERROR, RaidFileRead::IO_ERROR, + "I/O error when seeking in set " << mSetNumber << + ": " << mFilename << " (to " << FilePosition << + "), " << "stripe 1"); // Attempt to recover AttemptToRecoverFromIOError(true /* is stripe 1 */); ASSERT(mStripe1Handle == -1); @@ -881,10 +886,10 @@ void RaidFileRead_Raid::SetPosition(pos_type FilePosition) { if(errno == EIO) { - BOX_ERROR("I/O error when seeking in " << - mSetNumber << " " << mFilename << - " (to " << FilePosition << "), " << - "stripe 2"); + BOX_LOG_CATEGORY(Log::ERROR, RaidFileRead::IO_ERROR, + "I/O error when seeking in set " << mSetNumber << + ": " << mFilename << " (to " << FilePosition << + "), " << "stripe 2"); // Attempt to recover AttemptToRecoverFromIOError(false /* is stripe 2 */); ASSERT(mStripe2Handle == -1); @@ -1155,8 +1160,9 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string bool oktotryagain = true; if(stripe1errno == EIO) { - BOX_ERROR("I/O error on opening " << - SetNumber << " " << Filename << + BOX_LOG_CATEGORY(Log::ERROR, + RaidFileRead::RECOVERING_IO_ERROR, "I/O error " + "on opening " << SetNumber << " " << Filename << " stripe 1, trying recovery mode"); RaidFileRead_Raid::MoveDamagedFileAlertDaemon(SetNumber, Filename, true /* is stripe 1 */); @@ -1172,8 +1178,9 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string if(stripe2errno == EIO) { - BOX_ERROR("I/O error on opening " << - SetNumber << " " << Filename << + BOX_LOG_CATEGORY(Log::ERROR, + RaidFileRead::RECOVERING_IO_ERROR, "I/O error " + "on opening " << SetNumber << " " << Filename << " stripe 2, trying recovery mode"); RaidFileRead_Raid::MoveDamagedFileAlertDaemon(SetNumber, Filename, false /* is stripe 2 */); @@ -1196,7 +1203,8 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string if(existance == RaidFileUtil::AsRaidWithMissingReadable) { - BOX_ERROR("Attempting to open RAID file " << SetNumber << + BOX_LOG_CATEGORY(Log::ERROR, RaidFileRead::OPEN_IN_RECOVERY, + "Attempting to open RAID file " << SetNumber << " " << Filename << " in recovery mode (stripe " << ((existingFiles & RaidFileUtil::Stripe1Exists)?1:2) << " present)"); @@ -1498,8 +1506,8 @@ bool RaidFileRead::DirectoryExists(const RaidFileDiscSet &rSet, const std::strin std::string dn(rSet[l] + DIRECTORY_SEPARATOR + rDirName); // check for existence - struct stat st; - if(::stat(dn.c_str(), &st) == 0) + EMU_STRUCT_STAT st; + if(EMU_STAT(dn.c_str(), &st) == 0) { // Directory? if(st.st_mode & S_IFDIR) @@ -1510,7 +1518,10 @@ bool RaidFileRead::DirectoryExists(const RaidFileDiscSet &rSet, const std::strin else { // No. It's a file. Bad! - THROW_EXCEPTION(RaidFileException, UnexpectedFileInDirPlace) + THROW_FILE_ERROR("Expected a directory, " + "found something else", dn, + RaidFileException, + UnexpectedFileInDirPlace); } } else @@ -1519,7 +1530,9 @@ bool RaidFileRead::DirectoryExists(const RaidFileDiscSet &rSet, const std::strin if(errno != ENOENT) { // No. Bad things. - THROW_EXCEPTION(RaidFileException, OSError) + THROW_SYS_FILE_ERROR("Failed to check for " + "existing RaidFile directory", dn, + RaidFileException, OSError); } } } @@ -1617,12 +1630,15 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN #ifdef HAVE_VALID_DIRENT_D_TYPE if(DirReadType == DirReadType_FilesOnly && en->d_type == DT_REG) #else - struct stat st; + EMU_STRUCT_STAT st; std::string fullName(dn + DIRECTORY_SEPARATOR + en->d_name); - if(::lstat(fullName.c_str(), &st) != 0) + if(EMU_LSTAT(fullName.c_str(), &st) != 0) { - THROW_EXCEPTION(RaidFileException, OSError) + THROW_SYS_FILE_ERROR("Failed to stat", + fullName, RaidFileException, + OSError); } + if(DirReadType == DirReadType_FilesOnly && (st.st_mode & S_IFDIR) == 0) #endif { @@ -1721,7 +1737,7 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN // Created: 2003/08/21 // // -------------------------------------------------------------------------- -void RaidFileRead::Write(const void *pBuffer, int NBytes) +void RaidFileRead::Write(const void *pBuffer, int NBytes, int Timeout) { THROW_EXCEPTION(RaidFileException, UnsupportedReadWriteOrClose) } @@ -1767,6 +1783,7 @@ IOStream::pos_type RaidFileRead::GetDiscUsageInBlocks() return RaidFileUtil::DiscUsageInBlocks(GetFileSize(), rdiscSet); } - - - +std::string RaidFileRead::ToString() const +{ + return std::string("RaidFile ") + mFilename; +} |