Changeset 2904 for box/trunk/bin
- Timestamp:
- 08/04/2011 21:01:01 (14 months ago)
- Location:
- box/trunk/bin/bbackupd
- Files:
-
- 2 edited
-
BackupDaemon.cpp (modified) (17 diffs)
-
BackupDaemon.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupd/BackupDaemon.cpp
r2902 r2904 120 120 { 121 121 char* pStr = ConvertFromWideString(buf, CP_UTF8); 122 123 if(pStr == NULL) 124 { 125 return "conversion failed"; 126 } 127 122 128 std::string result(pStr); 123 129 free(pStr); … … 132 138 } 133 139 134 std:: ostream& operator<< (std::ostream& o,const BSTR arg)140 std::string BstrToString(const BSTR arg) 135 141 { 136 142 if(arg == NULL) 137 143 { 138 o << "(null)";144 return std::string("(null)"); 139 145 } 140 146 else 141 147 { 142 148 // Extract the *long* before where the arg points to 143 long len = ((long *)arg)[-1] ;149 long len = ((long *)arg)[-1] / 2; 144 150 std::wstring wstr((WCHAR *)arg, len); 145 151 std::string str; … … 148 154 throw std::exception("string conversion failed"); 149 155 } 150 o << str; 151 } 152 153 return o; 156 return str; 157 } 154 158 } 155 159 # endif … … 1069 1073 } 1070 1074 1075 #define CALL_MEMBER_FN(object, method) ((object).*(method)) 1076 1077 bool BackupDaemon::CallAndWaitForAsync(AsyncMethod method, 1078 const std::string& description) 1079 { 1080 IVssAsync *pAsync; 1081 HRESULT result = CALL_MEMBER_FN(*mpVssBackupComponents, method)(&pAsync); 1082 if(result != S_OK) 1083 { 1084 BOX_ERROR("VSS: " << description << " failed: " << 1085 GetMsgForHresult(result)); 1086 return false; 1087 } 1088 1089 return WaitForAsync(pAsync, description); 1090 } 1091 1071 1092 void BackupDaemon::CreateVssBackupComponents() 1072 1093 { … … 1131 1152 } 1132 1153 1133 { 1134 IVssAsync *pAsync; 1135 result = mpVssBackupComponents->GatherWriterMetadata(&pAsync); 1136 if(result != S_OK) 1137 { 1138 BOX_ERROR("VSS: Failed to set backup state: " << 1139 GetMsgForHresult(result)); 1140 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1141 } 1142 1143 if(!WaitForAsync(pAsync, "GatherWriterMetadata()")) 1144 { 1145 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1146 } 1154 if(!CallAndWaitForAsync(&IVssBackupComponents::GatherWriterMetadata, 1155 "GatherWriterMetadata()")) 1156 { 1157 goto CreateVssBackupComponents_cleanup_WriterMetadata; 1147 1158 } 1148 1159 … … 1153 1164 BOX_ERROR("VSS: Failed to get writer count: " << 1154 1165 GetMsgForHresult(result)); 1155 goto CreateVssBackupComponents_cleanup_ mpVssBackupComponents;1166 goto CreateVssBackupComponents_cleanup_WriterMetadata; 1156 1167 } 1157 1168 … … 1167 1178 BOX_ERROR("Failed to get VSS metadata from writer " << iWriter << 1168 1179 ": " << GetMsgForHresult(result)); 1169 goto CreateVssBackupComponents_cleanup_ mpVssBackupComponents;1180 goto CreateVssBackupComponents_cleanup_WriterMetadata; 1170 1181 } 1171 1182 … … 1175 1186 if(result != S_OK) 1176 1187 { 1177 BOX_ERROR(" Failed to get VSSmetadata file counts from "1188 BOX_ERROR("VSS: Failed to get metadata file counts from " 1178 1189 "writer " << iWriter << ": " << 1179 1190 GetMsgForHresult(result)); … … 1188 1199 if(result != S_OK) 1189 1200 { 1190 BOX_ERROR(" Failed to get VSSmetadata component " <<1201 BOX_ERROR("VSS: Failed to get metadata component " << 1191 1202 iComponent << " from writer " << iWriter << ": " << 1192 1203 GetMsgForHresult(result)); … … 1198 1209 if(result != S_OK) 1199 1210 { 1200 BOX_ERROR(" Failed to get VSSmetadata component " <<1211 BOX_ERROR("VSS: Failed to get metadata component " << 1201 1212 iComponent << " info from writer " << iWriter << ": " << 1202 1213 GetMsgForHresult(result)); … … 1217 1228 1218 1229 BOX_INFO("VSS: logical path: " << 1219 pComponentInfo->bstrLogicalPath);1230 BstrToString(pComponentInfo->bstrLogicalPath)); 1220 1231 BOX_INFO("VSS: component name: " << 1221 pComponentInfo->bstrComponentName);1232 BstrToString(pComponentInfo->bstrComponentName)); 1222 1233 BOX_INFO("VSS: caption: " << 1223 pComponentInfo->bstrCaption);1234 BstrToString(pComponentInfo->bstrCaption)); 1224 1235 BOX_INFO("VSS: restore metadata: " << 1225 1236 pComponentInfo->bRestoreMetadata); … … 1254 1265 BOX_ERROR("VSS: Failed to start snapshot set: " << 1255 1266 GetMsgForHresult(result)); 1256 goto CreateVssBackupComponents_cleanup_ mpVssBackupComponents;1267 goto CreateVssBackupComponents_cleanup_WriterMetadata; 1257 1268 } 1258 1269 … … 1293 1304 volumeRoot << " to snapshot set: " << 1294 1305 GetMsgForHresult(result)); 1295 goto CreateVssBackupComponents_cleanup_ mpVssBackupComponents;1306 goto CreateVssBackupComponents_cleanup_WriterMetadata; 1296 1307 } 1297 1308 } … … 1309 1320 } 1310 1321 1311 { 1312 IVssAsync *pAsync; 1313 result = mpVssBackupComponents->PrepareForBackup(&pAsync); 1322 if(!CallAndWaitForAsync(&IVssBackupComponents::PrepareForBackup, 1323 "PrepareForBackup()")) 1324 { 1325 goto CreateVssBackupComponents_cleanup_WriterMetadata; 1326 } 1327 1328 if(!CallAndWaitForAsync(&IVssBackupComponents::DoSnapshotSet, 1329 "DoSnapshotSet()")) 1330 { 1331 goto CreateVssBackupComponents_cleanup_WriterMetadata; 1332 } 1333 1334 if(!CallAndWaitForAsync(&IVssBackupComponents::GatherWriterStatus, 1335 "GatherWriterStatus()")) 1336 { 1337 goto CreateVssBackupComponents_cleanup_WriterStatus; 1338 } 1339 1340 result = mpVssBackupComponents->GetWriterStatusCount(&writerCount); 1341 if(result != S_OK) 1342 { 1343 BOX_ERROR("VSS: Failed to get writer status count: " << 1344 GetMsgForHresult(result)); 1345 goto CreateVssBackupComponents_cleanup_WriterStatus; 1346 } 1347 1348 for(UINT iWriter = 0; iWriter < writerCount; iWriter++) 1349 { 1350 VSS_ID instance, writer; 1351 BSTR writerNameBstr; 1352 VSS_WRITER_STATE writerState; 1353 HRESULT writerResult; 1354 1355 result = mpVssBackupComponents->GetWriterStatus(iWriter, 1356 &instance, &writer, &writerNameBstr, &writerState, 1357 &writerResult); 1314 1358 if(result != S_OK) 1315 1359 { 1316 BOX_ERROR("VSS: Failed to prepare for backup: " << 1317 GetMsgForHresult(result)); 1318 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1319 } 1320 1321 if(!WaitForAsync(pAsync, "PrepareForBackup()")) 1322 { 1323 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1324 } 1360 BOX_ERROR("VSS: Failed to query writer " << iWriter << 1361 " status: " << GetMsgForHresult(result)); 1362 goto CreateVssBackupComponents_cleanup_WriterStatus; 1363 } 1364 1365 std::string writerName = BstrToString(writerNameBstr); 1366 ::SysFreeString(writerNameBstr); 1367 1368 if(writerResult != S_OK) 1369 { 1370 BOX_ERROR("VSS: Writer " << iWriter << " (" << 1371 writerName << ") failed: " << 1372 GetMsgForHresult(writerResult)); 1373 continue; 1374 } 1375 1376 std::string stateName; 1377 1378 switch(writerState) 1379 { 1380 #define WRITER_STATE(code) \ 1381 case code: stateName = #code; break; 1382 WRITER_STATE(VSS_WS_UNKNOWN); 1383 WRITER_STATE(VSS_WS_STABLE); 1384 WRITER_STATE(VSS_WS_WAITING_FOR_FREEZE); 1385 WRITER_STATE(VSS_WS_WAITING_FOR_THAW); 1386 WRITER_STATE(VSS_WS_WAITING_FOR_POST_SNAPSHOT); 1387 WRITER_STATE(VSS_WS_WAITING_FOR_BACKUP_COMPLETE); 1388 WRITER_STATE(VSS_WS_FAILED_AT_IDENTIFY); 1389 WRITER_STATE(VSS_WS_FAILED_AT_PREPARE_BACKUP); 1390 WRITER_STATE(VSS_WS_FAILED_AT_PREPARE_SNAPSHOT); 1391 WRITER_STATE(VSS_WS_FAILED_AT_FREEZE); 1392 WRITER_STATE(VSS_WS_FAILED_AT_THAW); 1393 WRITER_STATE(VSS_WS_FAILED_AT_POST_SNAPSHOT); 1394 WRITER_STATE(VSS_WS_FAILED_AT_BACKUP_COMPLETE); 1395 WRITER_STATE(VSS_WS_FAILED_AT_PRE_RESTORE); 1396 WRITER_STATE(VSS_WS_FAILED_AT_POST_RESTORE); 1397 WRITER_STATE(VSS_WS_FAILED_AT_BACKUPSHUTDOWN); 1398 #undef WRITER_STATE 1399 default: 1400 std::ostringstream o; 1401 o << "unknown (" << writerState << ")"; 1402 stateName = o.str(); 1403 } 1404 1405 BOX_INFO("VSS: Writer " << iWriter << " (" << 1406 writerName << ") is in state " << stateName); 1325 1407 } 1326 1408 … … 1330 1412 if(result != S_OK) 1331 1413 { 1332 BOX_ERROR(" Failed to query VSSsnapshot list: " <<1414 BOX_ERROR("VSS: Failed to query snapshot list: " << 1333 1415 GetMsgForHresult(result)); 1334 goto CreateVssBackupComponents_cleanup_ mpVssBackupComponents;1416 goto CreateVssBackupComponents_cleanup_WriterStatus; 1335 1417 } 1336 1418 … … 1343 1425 if(result != S_OK && result != S_FALSE) 1344 1426 { 1345 BOX_ERROR(" Failed to enumerate VSSsnapshot: " <<1427 BOX_ERROR("VSS: Failed to enumerate snapshot: " << 1346 1428 GetMsgForHresult(result)); 1347 1429 } 1348 1430 else if(count != 1) 1349 1431 { 1350 BOX_ERROR(" Failed to enumerate VSSsnapshot: " <<1432 BOX_ERROR("VSS: Failed to enumerate snapshot: " << 1351 1433 "Next() returned " << count << " objects instead of 1"); 1352 1434 } 1353 1435 else if(rgelt.Type != VSS_OBJECT_SNAPSHOT) 1354 1436 { 1355 BOX_ERROR(" Failed to enumerate VSSsnapshot: " <<1437 BOX_ERROR("VSS: Failed to enumerate snapshot: " << 1356 1438 "Next() returned a type " << rgelt.Type << " object " 1357 1439 "instead of VSS_OBJECT_SNAPSHOT"); … … 1422 1504 1423 1505 pEnum->Release(); 1506 1507 CreateVssBackupComponents_cleanup_WriterStatus: 1508 result = mpVssBackupComponents->FreeWriterStatus(); 1509 if(result != S_OK) 1510 { 1511 BOX_ERROR("VSS: Failed to free writer status: " << 1512 GetMsgForHresult(result)); 1513 } 1514 1515 CreateVssBackupComponents_cleanup_WriterMetadata: 1516 result = mpVssBackupComponents->FreeWriterMetadata(); 1517 if(result != S_OK) 1518 { 1519 BOX_ERROR("VSS: Failed to free writer metadata: " << 1520 GetMsgForHresult(result)); 1521 } 1424 1522 1425 1523 CreateVssBackupComponents_cleanup_mpVssBackupComponents: -
box/trunk/bin/bbackupd/BackupDaemon.h
r2901 r2904 533 533 void CreateVssBackupComponents(); 534 534 bool WaitForAsync(IVssAsync *pAsync, const std::string& description); 535 typedef HRESULT (__stdcall IVssBackupComponents::*AsyncMethod)(IVssAsync**); 536 bool CallAndWaitForAsync(AsyncMethod method, 537 const std::string& description); 535 538 #endif 536 539 };
Note: See TracChangeset
for help on using the changeset viewer.
