[Box Backup-commit] COMMIT r2850 - box/trunk/lib/raidfile

subversion at boxbackup.org subversion at boxbackup.org
Wed Jan 12 00:14:06 GMT 2011


Author: chris
Date: 2011-01-12 00:14:06 +0000 (Wed, 12 Jan 2011)
New Revision: 2850

Modified:
   box/trunk/lib/raidfile/RaidFileRead.cpp
Log:
Improve error messages on failure to open a RaidFile for reading.


Modified: box/trunk/lib/raidfile/RaidFileRead.cpp
===================================================================
--- box/trunk/lib/raidfile/RaidFileRead.cpp	2011-01-12 00:13:48 UTC (rev 2849)
+++ box/trunk/lib/raidfile/RaidFileRead.cpp	2011-01-12 00:14:06 UTC (rev 2850)
@@ -1086,10 +1086,20 @@
 			{
 				stripe2errno = errno;
 			}
-			if(stripe1errno != 0 || stripe2errno != 0)
+
+			if(stripe1errno != 0)
 			{
-				THROW_EXCEPTION(RaidFileException, ErrorOpeningFileForRead)
+				THROW_SYS_FILE_ERRNO("Failed to open RaidFile",
+					stripe1Filename, stripe1errno,
+					RaidFileException, ErrorOpeningFileForRead);
 			}
+
+			if(stripe2errno != 0)
+			{
+				THROW_SYS_FILE_ERRNO("Failed to open RaidFile",
+					stripe2Filename, stripe2errno,
+					RaidFileException, ErrorOpeningFileForRead);
+			}
 			
 			// stat stripe 1 to find ('half' of) length...
 			struct stat st;
@@ -1107,11 +1117,20 @@
 			length += st.st_size;
 			
 			// Handle errors
-			if(stripe1errno != 0 || stripe2errno != 0)
+			if(stripe1errno != 0)
 			{
-				THROW_EXCEPTION(RaidFileException, OSError)
+				THROW_SYS_FILE_ERRNO("Failed to stat RaidFile",
+					stripe1Filename, stripe1errno,
+					RaidFileException, OSError);
 			}
-			
+
+			if(stripe2errno != 0)
+			{
+				THROW_SYS_FILE_ERRNO("Failed to stat RaidFile",
+					stripe2Filename, stripe2errno,
+					RaidFileException, OSError);
+			}
+	
 			// Make a nice object to represent this file
 			return std::auto_ptr<RaidFileRead>(new RaidFileRead_Raid(SetNumber, Filename, stripe1, stripe2, -1, length, rdiscSet.GetBlockSize(), false /* actually we don't know */));
 		}
@@ -1238,17 +1257,27 @@
 				ASSERT(sizeof(FileSizeType) == 8); // compiler bug (I think) prevents from using 0 - sizeof(FileSizeType)...
 				if(::lseek(parity, -8 /*(0 - sizeof(FileSizeType))*/, SEEK_END) == -1)
 				{
-					THROW_EXCEPTION(RaidFileException, OSError)
+					THROW_SYS_FILE_ERROR("Failed to seek "
+						"in parity RaidFile",
+						parityFilename, 
+						RaidFileException, OSError);
 				}
 				// Read it in
 				if(::read(parity, &parityLastData, sizeof(parityLastData)) != sizeof(parityLastData))
 				{
-					THROW_EXCEPTION(RaidFileException, OSError)
+					THROW_SYS_FILE_ERROR("Failed to read "
+						"parity RaidFile",
+						parityFilename, 
+						RaidFileException, OSError);
 				}
+
 				// Set back to beginning of file
 				if(::lseek(parity, 0, SEEK_SET) == -1)
 				{
-					THROW_EXCEPTION(RaidFileException, OSError)
+					THROW_SYS_FILE_ERROR("Failed to seek "
+						"in parity RaidFile",
+						parityFilename, 
+						RaidFileException, OSError);
 				}
 			}
 			
@@ -1271,7 +1300,10 @@
 					//  to get the size from the FileSizeType value at end of the file.
 					if(::fstat(stripe1, &st) != 0)
 					{
-						THROW_EXCEPTION(RaidFileException, OSError)
+						THROW_SYS_FILE_ERROR("Failed to "
+							"stat RaidFile stripe 1",
+							stripe1Filename,
+							RaidFileException, OSError);
 					}
 					pos_type stripe1Size = st.st_size;
 					// Is size integral?
@@ -1305,17 +1337,26 @@
 							ASSERT(btr <= (int)sizeof(FileSizeType));
 							if(::lseek(stripe1, 0 - btr, SEEK_END) == -1)
 							{
-								THROW_EXCEPTION(RaidFileException, OSError)
+								THROW_SYS_FILE_ERROR("Failed to "
+									"seek in RaidFile stripe 1",
+									stripe1Filename,
+									RaidFileException, OSError);
 							}
 							// Read it in
 							if(::read(stripe1, &stripe1LastData, btr) != btr)
 							{
-								THROW_EXCEPTION(RaidFileException, OSError)
+								THROW_SYS_FILE_ERROR("Failed to "
+									"read RaidFile stripe 1",
+									stripe1Filename,
+									RaidFileException, OSError);
 							}
 							// Set back to beginning of file
 							if(::lseek(stripe1, 0, SEEK_SET) == -1)
 							{
-								THROW_EXCEPTION(RaidFileException, OSError)
+								THROW_SYS_FILE_ERROR("Failed to "
+									"seek in RaidFile stripe 1",
+									stripe1Filename,
+									RaidFileException, OSError);
 							}
 						}
 						// Lovely!
@@ -1337,7 +1378,10 @@
 					// Get size of stripe2 file
 					if(::fstat(stripe2, &st) != 0)
 					{
-						THROW_EXCEPTION(RaidFileException, OSError)
+						THROW_SYS_FILE_ERROR("Failed to "
+							"stat RaidFile stripe 2",
+							stripe2Filename,
+							RaidFileException, OSError);
 					}
 					pos_type stripe2Size = st.st_size;
 					
@@ -1406,7 +1450,8 @@
 		}
 	}
 	
-	THROW_EXCEPTION(RaidFileException, FileIsDamagedNotRecoverable)
+	THROW_FILE_ERROR("Failed to recover RaidFile", Filename,
+		RaidFileException, FileIsDamagedNotRecoverable);
 	
 	// Avoid compiler warning -- it'll never get here...
 	return std::auto_ptr<RaidFileRead>();




More information about the Boxbackup-commit mailing list