- Timestamp:
- May 29, 2019 7:03:20 AM (6 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/MachineImplMoveVM.h
r78761 r78836 80 80 }; 81 81 82 /** @todo r=bird: Why no m_ prefixes here? */ 83 RTCList<MEDIUMTASKCHAINMOVE> llMedias; 84 RTCList<SAVESTATETASKMOVE> llSaveStateFiles; 85 std::map<Utf8Str, MEDIUMTASKMOVE> finalMediumsMap; 86 std::map<Utf8Str, SAVESTATETASKMOVE> finalSaveStateFilesMap; 87 std::map<VBoxFolder_t, Utf8Str> vmFolders; 88 std::list<ErrorInfoItem> errorsList; 82 RTCList<MEDIUMTASKCHAINMOVE> m_llMedias; 83 RTCList<SAVESTATETASKMOVE> m_llSaveStateFiles; 84 std::map<Utf8Str, MEDIUMTASKMOVE> m_finalMediumsMap; 85 std::map<Utf8Str, SAVESTATETASKMOVE> m_finalSaveStateFilesMap; 86 std::map<VBoxFolder_t, Utf8Str> m_vmFolders; 87 std::list<ErrorInfoItem> m_errorsList; 89 88 90 89 ComObjPtr<Machine> m_pMachine; … … 95 94 Utf8Str m_targetPath; 96 95 Utf8Str m_type; 97 HRESULT result; /**< @todo r=bird: Why no m_ prefix here? */96 HRESULT m_result; 98 97 99 98 public: … … 107 106 , m_targetPath(aTargetPath) 108 107 , m_type(aType.isEmpty() ? "basic" : aType) 109 , result(S_OK)108 , m_result(S_OK) 110 109 { 111 110 } -
trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp
r78765 r78836 30 30 #include "LoggingNew.h" 31 31 32 /** @todo r=klaus this file is abusing the release log by putting pretty much33 * everything there. Should be adjusted to use debug logging where appropriate34 * and if really necessary some LogRel2 and the like. */35 36 37 32 /* This variable is global and used in the different places so it must be cleared each time before usage to avoid failure */ 38 33 std::vector< ComObjPtr<Machine> > machineList; … … 137 132 if (fLog) 138 133 { 139 Log RelFunc(("(The error code is %Rrc): %s\n",m_code, m_description.c_str()));134 Log2(("(The error code is %Rrc): %s\n",m_code, m_description.c_str())); 140 135 } 141 136 else … … 145 140 HRESULT MachineMoveVM::init() 146 141 { 147 HRESULT rc = S_OK;148 149 errorsList.clear();142 HRESULT hrc = S_OK; 143 144 m_errorsList.clear(); 150 145 151 146 Utf8Str strTargetFolder; … … 155 150 if (len >= RTPATH_MAX) 156 151 { 157 /** @todo r=bird: Why the leading space in errorDesc? */ 158 /** @todo "The destination path exceeds the maximum length" should 159 * suffice here, I think. */ 160 /** @todo r=bird: missing tr(). */ 161 /** @todo r=bird: Actually, why bother with these error strings here? Nobody 162 * will ever see them, given that the caller deletes the task when 163 * init() fails. */ 164 Utf8Str errorDesc(" The destination path isn't correct. The length of path exceeded the maximum value."); 165 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 166 /** @todo r=bird: What on earth is this? It will cause the caller to leak the 167 * task structure, unless it's catching exception (which it wasn't, but 168 * I made it is now). I sure hope this wasn't intentional... */ 169 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 152 return m_pMachine->setError(VBOX_E_IPRT_ERROR, 153 m_pMachine->tr(Utf8Str("The destination path exceeds " 154 "the maximum value.").c_str())); 170 155 } 171 156 … … 199 184 if (FAILED(vrc)) 200 185 { 201 /** @todo r=bird: What's this RTPrint doing here?!? */ 202 RTPrintf("strTargetFolder is %s\n", strTargetFolder.c_str()); 203 Utf8StrFmt errorDesc("Unable to move machine. Can't get the destination storage size (%s)", 204 strTargetFolder.c_str()); 205 errorsList.push_back(ErrorInfoItem(E_FAIL, errorDesc.c_str())); 206 rc = m_pMachine->setErrorBoth(E_FAIL, vrc, m_pMachine->tr(errorDesc.c_str())); 207 throw rc; 186 return m_pMachine->setErrorBoth(E_FAIL, vrc, 187 m_pMachine->tr(Utf8StrFmt("Unable to move machine. Can't get " 188 "the destination storage size (%s)", 189 strTargetFolder.c_str()).c_str())); 208 190 } 209 191 … … 211 193 Utf8Str strTempFile = strTargetFolder + "test.txt"; 212 194 vrc = RTDirOpen(&hDir, strTargetFolder.c_str()); 213 if ( FAILED(vrc))214 throw rc = vrc; /** @todo r=bird: RTDirOpen returns a VBox status code. That is _not_ the same as a COM HRESULT! */195 if (RT_FAILURE(vrc)) 196 return m_pMachine->setErrorVrc(vrc); 215 197 else 216 198 { 217 199 RTFILE hFile; 218 200 vrc = RTFileOpen(&hFile, strTempFile.c_str(), RTFILE_O_OPEN_CREATE | RTFILE_O_READWRITE | RTFILE_O_DENY_NONE); 219 if ( FAILED(vrc))220 { 221 LogRelFunc(("Can't create a test file %s (The error is %Rrc)\n", strTempFile.c_str(), vrc));222 Utf8StrFmt errorDesc("Can't create a test file test.txt in the %s. Check the access rights of"223 "the destination folder.", strTargetFolder.c_str());224 errorsList.push_back(ErrorInfoItem(HRESULT(vrc), errorDesc.c_str()));225 rc = m_pMachine->setErrorBoth(VBOX_E_FILE_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));226 /** @todo r=bird: What happens to this error and 'rc'? Should it be ignored? */ 227 }228 229 RTFileClose(hFile); /** @todo r=bird: Whey close if opening fail? */201 if (RT_FAILURE(vrc)) 202 { 203 return m_pMachine->setErrorVrc(vrc, 204 m_pMachine->tr(Utf8StrFmt("Can't create a test file test.txt in the %s. " 205 "Check the access rights of the destination " 206 "folder.", strTargetFolder.c_str()).c_str())); 207 } 208 209 /** @todo r=vvp: Do we need to check each return result here? Looks excessively. 210 * And it's not so important for the test file. */ 211 RTFileClose(hFile); 230 212 RTFileDelete(strTempFile.c_str()); 231 213 RTDirClose(hDir); 232 214 } 233 215 234 /** @todo r=bird: Why the need for 'info' here? LogRelFunc can do the exact 235 * same thing without touching the heap. I don't get what this is 236 * about... There is also excessive log duplication here as well as 237 * seemingly unnecessary trailing whitespace. */ 238 Utf8Str info = Utf8StrFmt("blocks: total %RTfoff, free %RTfoff ", cbTotal, cbFree); 239 LogRelFunc(("%s \n", info.c_str())); 240 LogRelFunc(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G)); 241 LogRelFunc(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G)); 216 Log2(("blocks: total %RTfoff, free %RTfoff ", cbTotal, cbFree)); 217 Log2(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G)); 218 Log2(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G)); 242 219 243 220 RTFSPROPERTIES properties; 244 221 vrc = RTFsQueryProperties(strTargetFolder.c_str(), &properties); 245 if (FAILED(vrc)) throw vrc; 246 info = Utf8StrFmt("disk properties:\n" 247 "remote: %s \n" 248 "read only: %s \n" 249 "compressed: %s \n", 250 properties.fRemote == true ? "true":"false", 251 properties.fReadOnly == true ? "true":"false", 252 properties.fCompressed == true ? "true":"false"); 253 254 LogRelFunc(("%s \n", info.c_str())); 222 if (FAILED(vrc)) 223 return m_pMachine->setErrorVrc(vrc); 224 225 Utf8StrFmt info ("disk properties:\n" 226 "remote: %s \n" 227 "read only: %s \n" 228 "compressed: %s \n", 229 properties.fRemote == true ? "true":"false", 230 properties.fReadOnly == true ? "true":"false", 231 properties.fCompressed == true ? "true":"false"); 232 233 Log2(("%s \n", info.c_str())); 255 234 256 235 /* Get the original VM path */ 257 236 Utf8Str strSettingsFilePath; 258 237 Bstr bstr_settingsFilePath; 259 m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam()); /** @todo r=bird: check the status code. */ 238 hrc = m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam()); 239 if (FAILED(hrc)) 240 return hrc; 241 260 242 strSettingsFilePath = bstr_settingsFilePath; 261 243 strSettingsFilePath.stripFilename(); 262 244 263 vmFolders.insert(std::make_pair(VBox_SettingFolder, strSettingsFilePath));245 m_vmFolders.insert(std::make_pair(VBox_SettingFolder, strSettingsFilePath)); 264 246 265 247 /* Collect all files from the VM's folder */ 266 248 fileList_t fullFileList; 267 rc = getFilesList(strSettingsFilePath, fullFileList); 268 if (FAILED(rc)) throw rc; 249 hrc = getFilesList(strSettingsFilePath, fullFileList); 250 if (FAILED(hrc)) 251 return hrc; 269 252 270 253 /* … … 276 259 Utf8Str strLogFolder; 277 260 Bstr bstr_logFolder; 278 m_pMachine->COMGETTER(LogFolder)(bstr_logFolder.asOutParam()); 261 hrc = m_pMachine->COMGETTER(LogFolder)(bstr_logFolder.asOutParam()); 262 if (FAILED(hrc)) 263 return hrc; 264 279 265 strLogFolder = bstr_logFolder; 280 266 if ( m_type.equals("basic") 281 267 && strLogFolder.contains(strSettingsFilePath)) 282 268 { 283 vmFolders.insert(std::make_pair(VBox_LogFolder, strLogFolder));269 m_vmFolders.insert(std::make_pair(VBox_LogFolder, strLogFolder)); 284 270 } 285 271 … … 287 273 Bstr bstr_stateFilePath; 288 274 MachineState_T machineState; 289 rc = m_pMachine->COMGETTER(State)(&machineState); 290 if (FAILED(rc)) throw rc; 275 hrc = m_pMachine->COMGETTER(State)(&machineState); 276 if (FAILED(hrc)) 277 return hrc; 278 291 279 if (machineState == MachineState_Saved) 292 280 { … … 296 284 if ( m_type.equals("basic") 297 285 && strStateFilePath.contains(strSettingsFilePath)) 298 vmFolders.insert(std::make_pair(VBox_StateFolder, strStateFilePath));//Utf8Str(bstr_stateFilePath)));286 m_vmFolders.insert(std::make_pair(VBox_StateFolder, strStateFilePath)); 299 287 } 300 288 301 289 Utf8Str strSnapshotFolder; 302 290 Bstr bstr_snapshotFolder; 303 m_pMachine->COMGETTER(SnapshotFolder)(bstr_snapshotFolder.asOutParam()); 291 hrc = m_pMachine->COMGETTER(SnapshotFolder)(bstr_snapshotFolder.asOutParam()); 292 if (FAILED(hrc)) 293 return hrc; 294 304 295 strSnapshotFolder = bstr_snapshotFolder; 305 296 if ( m_type.equals("basic") 306 297 && strSnapshotFolder.contains(strSettingsFilePath)) 307 vmFolders.insert(std::make_pair(VBox_SnapshotFolder, strSnapshotFolder));298 m_vmFolders.insert(std::make_pair(VBox_SnapshotFolder, strSnapshotFolder)); 308 299 309 300 if (m_pMachine->i_isSnapshotMachine()) 310 301 { 311 302 Bstr bstrSrcMachineId; 312 rc = m_pMachine->COMGETTER(Id)(bstrSrcMachineId.asOutParam()); 313 if (FAILED(rc)) throw rc; 303 hrc = m_pMachine->COMGETTER(Id)(bstrSrcMachineId.asOutParam()); 304 if (FAILED(hrc)) 305 return hrc; 306 314 307 ComPtr<IMachine> newSrcMachine; 315 rc = m_pMachine->i_getVirtualBox()->FindMachine(bstrSrcMachineId.raw(), newSrcMachine.asOutParam()); 316 if (FAILED(rc)) throw rc; 308 hrc = m_pMachine->i_getVirtualBox()->FindMachine(bstrSrcMachineId.raw(), newSrcMachine.asOutParam()); 309 if (FAILED(hrc)) 310 return hrc; 317 311 } 318 312 … … 333 327 { 334 328 ULONG cSnapshots = 0; 335 rc = m_pMachine->COMGETTER(SnapshotCount)(&cSnapshots); 336 if (FAILED(rc)) throw rc; 329 hrc = m_pMachine->COMGETTER(SnapshotCount)(&cSnapshots); 330 if (FAILED(hrc)) 331 return hrc; 332 337 333 if (cSnapshots > 0) 338 334 { … … 341 337 id = m_pMachine->i_getSnapshotId().toString(); 342 338 ComPtr<ISnapshot> pSnapshot; 343 rc = m_pMachine->FindSnapshot(Bstr(id).raw(), pSnapshot.asOutParam()); 344 if (FAILED(rc)) throw rc; 345 rc = createMachineList(pSnapshot, machineList); 346 if (FAILED(rc)) throw rc; 339 hrc = m_pMachine->FindSnapshot(Bstr(id).raw(), pSnapshot.asOutParam()); 340 if (FAILED(hrc)) 341 return hrc; 342 hrc = createMachineList(pSnapshot, machineList); 343 if (FAILED(hrc)) 344 return hrc; 347 345 } 348 346 } … … 351 349 ULONG uTotalWeight = 1; 352 350 353 /* The lists llMedias and llSaveStateFiles are filled in the queryMediasForAllStates() */ 354 queryMediasForAllStates(machineList); /** @todo r=bird: As a rule status codes needs checking every time. */ 351 /* The lists m_llMedias and m_llSaveStateFiles are filled in the queryMediasForAllStates() */ 352 hrc = queryMediasForAllStates(machineList); 353 if (FAILED(hrc)) 354 return hrc; 355 355 356 356 { 357 357 uint64_t totalMediumsSize = 0; 358 358 359 for (size_t i = 0; i < llMedias.size(); ++i)359 for (size_t i = 0; i < m_llMedias.size(); ++i) 360 360 { 361 361 LONG64 cbSize = 0; 362 MEDIUMTASKCHAINMOVE &mtc = llMedias.at(i);362 MEDIUMTASKCHAINMOVE &mtc = m_llMedias.at(i); 363 363 for (size_t a = mtc.chain.size(); a > 0; --a) 364 364 { … … 367 367 Utf8Str name = mtc.chain[a - 1].strBaseName; 368 368 ComPtr<IMedium> plMedium = mtc.chain[a - 1].pMedium; 369 rc = plMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 370 if (FAILED(rc)) throw rc; 371 strLocation = bstrLocation; 369 hrc = plMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 370 if (FAILED(hrc)) 371 return hrc; 372 373 strLocation = bstrLocation; 372 374 373 375 /*if an image is located in the actual VM folder it will be added to the actual list */ 374 376 if (strLocation.contains(strSettingsFilePath)) 375 377 { 376 rc = plMedium->COMGETTER(Size)(&cbSize); 377 if (FAILED(rc)) throw rc; 378 hrc = plMedium->COMGETTER(Size)(&cbSize); 379 if (FAILED(hrc)) 380 return hrc; 378 381 379 382 std::pair<std::map<Utf8Str, MEDIUMTASKMOVE>::iterator,bool> ret; 380 ret = finalMediumsMap.insert(std::make_pair(name, mtc.chain[a - 1]));383 ret = m_finalMediumsMap.insert(std::make_pair(name, mtc.chain[a - 1])); 381 384 if (ret.second == true) 382 385 { … … 385 388 uTotalWeight += mtc.chain[a - 1].uWeight; 386 389 totalMediumsSize += cbSize; 387 Log RelFunc(("Image %s was added into the moved list\n", name.c_str()));390 Log2(("Image %s was added into the moved list\n", name.c_str())); 388 391 } 389 392 } … … 391 394 } 392 395 393 Log RelFunc(("Total Size of images is %lld bytes\n", totalMediumsSize));396 Log2(("Total Size of images is %lld bytes\n", totalMediumsSize)); 394 397 neededFreeSpace += totalMediumsSize; 395 398 } … … 399 402 uint64_t totalStateSize = 0; 400 403 401 for (size_t i = 0; i < llSaveStateFiles.size(); ++i)404 for (size_t i = 0; i < m_llSaveStateFiles.size(); ++i) 402 405 { 403 406 uint64_t cbFile = 0; 404 SAVESTATETASKMOVE &sst = llSaveStateFiles.at(i);407 SAVESTATETASKMOVE &sst = m_llSaveStateFiles.at(i); 405 408 406 409 Utf8Str name = sst.strSaveStateFile; … … 412 415 { 413 416 std::pair<std::map<Utf8Str, SAVESTATETASKMOVE>::iterator,bool> ret; 414 ret = finalSaveStateFilesMap.insert(std::make_pair(name, sst));417 ret = m_finalSaveStateFilesMap.insert(std::make_pair(name, sst)); 415 418 if (ret.second == true) 416 419 { … … 418 421 ++uCount; 419 422 uTotalWeight += sst.uWeight; 420 Log RelFunc(("The state file %s was added into the moved list\n", name.c_str()));423 Log2(("The state file %s was added into the moved list\n", name.c_str())); 421 424 } 422 425 } 423 426 else 424 LogRelFunc(("The state file %s wasn't added into the moved list. Couldn't get the file size.\n", 425 name.c_str())); 427 { 428 Log2(("The state file %s wasn't added into the moved list. Couldn't get the file size.\n", 429 name.c_str())); 430 return m_pMachine->setErrorVrc(vrc); 431 } 426 432 } 427 433 } … … 432 438 /* Prepare data for moving the log files */ 433 439 { 434 Utf8Str strFolder = vmFolders[VBox_LogFolder];440 Utf8Str strFolder = m_vmFolders[VBox_LogFolder]; 435 441 436 442 if (RTPathExists(strFolder.c_str())) 437 443 { 438 444 uint64_t totalLogSize = 0; 439 rc = getFolderSize(strFolder, totalLogSize);440 if (SUCCEEDED( rc))445 hrc = getFolderSize(strFolder, totalLogSize); 446 if (SUCCEEDED(hrc)) 441 447 { 442 448 neededFreeSpace += totalLogSize; 443 449 if (cbFree - neededFreeSpace <= _1M) 444 450 { 445 throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location 451 return m_pMachine->setError(VBOX_E_IPRT_ERROR, 452 m_pMachine->tr(Utf8StrFmt("There is lack of disk space " 453 "(%Rrc)", VERR_OUT_OF_RESOURCES).c_str())); 446 454 } 447 455 448 456 fileList_t filesList; 449 getFilesList(strFolder, filesList); /** @todo r=bird: return code check */ 457 hrc = getFilesList(strFolder, filesList); 458 if (FAILED(hrc)) 459 return hrc; 460 450 461 cit_t it = filesList.m_list.begin(); 451 462 while (it != filesList.m_list.end()) … … 461 472 uTotalWeight += (ULONG)((cbFile + _1M - 1) / _1M); 462 473 actualFileList.add(strFile); 463 Log RelFunc(("The log file %s added into the moved list\n", strFile.c_str()));474 Log2(("The log file %s added into the moved list\n", strFile.c_str())); 464 475 } 465 476 else 466 Log RelFunc(("The log file %s wasn't added into the moved list. Couldn't get the file size."467 "\n", strFile.c_str()));477 Log2(("The log file %s wasn't added into the moved list. " 478 "Couldn't get the file size.\n", strFile.c_str())); 468 479 ++it; 469 480 } 470 481 } 482 else 483 return hrc; 471 484 } 472 485 else 473 486 { 474 Log RelFunc(("Information: The original log folder %s doesn't exist\n", strFolder.c_str()));475 rc = S_OK;//it's not error in this case if there isn't an original log folder476 } 477 } 478 479 LogRel Func(("Total space needed is %lld bytes\n", neededFreeSpace));487 Log2(("Information: The original log folder %s doesn't exist\n", strFolder.c_str())); 488 hrc = S_OK;//it's not error in this case if there isn't an original log folder 489 } 490 } 491 492 LogRel(("Total space needed is %lld bytes\n", neededFreeSpace)); 480 493 /* Check a target location on enough room */ 481 494 if (cbFree - neededFreeSpace <= _1M) 482 495 { 483 LogRelFunc(("but free space on destination is %RTfoff\n", cbFree)); 484 /** @todo r=bird: You're throwing a VBox status code here, but only catching 485 * HRESULT. So, this will go to the caller or someone else up the 486 * stack, which is unacceptable throw behaviour. */ 487 throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location 496 LogRel(("but free space on destination is %RTfoff\n", cbFree)); 497 return m_pMachine->setError(VBOX_E_IPRT_ERROR, 498 m_pMachine->tr(Utf8StrFmt ("There is lack of disk space" 499 " (%Rrc)", VERR_OUT_OF_RESOURCES).c_str())); 488 500 } 489 501 490 502 /* Add step for .vbox machine setting file */ 491 { /** @todo what's the scoping for? */ 492 ++uCount; 493 uTotalWeight += 1; 494 } 503 ++uCount; 504 uTotalWeight += 1; 495 505 496 506 /* Reserve additional steps in case of failure and rollback all changes */ 497 { 498 uTotalWeight += uCount;//just add 1 for each possible rollback operation 499 uCount += uCount;//and increase the steps twice 500 } 507 uTotalWeight += uCount;//just add 1 for each possible rollback operation 508 uCount += uCount;//and increase the steps twice 501 509 502 510 /* Init Progress instance */ 503 511 { 504 rc = m_pProgress->init(m_pMachine->i_getVirtualBox(), 505 static_cast<IMachine*>(m_pMachine) /* aInitiator */, 506 Utf8Str(m_pMachine->tr("Moving Machine")), 507 true /* fCancellable */, 508 uCount, 509 uTotalWeight, 510 Utf8Str(m_pMachine->tr("Initialize Moving")), 511 1); 512 if (FAILED(rc)) 513 { 514 Utf8StrFmt errorDesc("Couldn't correctly setup the progress object for moving VM operation (%Rrc)", rc); 515 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 516 517 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 512 hrc = m_pProgress->init(m_pMachine->i_getVirtualBox(), 513 static_cast<IMachine*>(m_pMachine) /* aInitiator */, 514 Utf8Str(m_pMachine->tr("Moving Machine")), 515 true /* fCancellable */, 516 uCount, 517 uTotalWeight, 518 Utf8Str(m_pMachine->tr("Initialize Moving")), 519 1); 520 if (FAILED(hrc)) 521 { 522 return m_pMachine->setError(VBOX_E_IPRT_ERROR, 523 m_pMachine->tr(Utf8StrFmt("Couldn't correctly setup the progress " 524 "object for moving VM operation (%Rrc)", hrc).c_str())); 518 525 } 519 526 } … … 521 528 /* save all VM data */ 522 529 m_pMachine->i_setModified(Machine::IsModified_MachineData); 523 rc = m_pMachine->SaveSettings(); 524 } 525 catch(HRESULT hrc) 526 { 527 /** @todo r=bird: Seriously, why throw any error when you can just return 528 * them. This is just copying the thrown message and passing it onto 529 * the return statemnt a few lines later. (The log statemnt doesn't 530 * really count as it doesn't log the status.) */ 531 rc = hrc; 530 hrc = m_pMachine->SaveSettings(); 531 if (FAILED(hrc)) 532 return hrc; 533 } 534 catch(HRESULT aRc) 535 { 536 hrc = aRc; 532 537 } 533 538 534 539 LogFlowFuncLeave(); 535 540 536 return rc;541 return hrc; 537 542 } 538 543 … … 545 550 { 546 551 settings::Snapshot snap = (settings::Snapshot)(*it); 547 Log RelFunc(("snap.uuid = %s\n", snap.uuid.toStringCurly().c_str()));548 Log RelFunc(("snap.strStateFile = %s\n", snap.strStateFile.c_str()));552 Log2(("snap.uuid = %s\n", snap.uuid.toStringCurly().c_str())); 553 Log2(("snap.strStateFile = %s\n", snap.strStateFile.c_str())); 549 554 } 550 555 … … 593 598 { 594 599 LogFlowFuncEnter(); 595 HRESULT rc = S_OK;600 HRESULT hrc = S_OK; 596 601 597 602 MachineMoveVM* taskMoveVM = task; … … 604 609 { 605 610 Bstr bstrMachineName; 606 machine->COMGETTER(Name)(bstrMachineName.asOutParam()); 611 hrc = machine->COMGETTER(Name)(bstrMachineName.asOutParam()); 612 if (FAILED(hrc)) 613 { 614 taskMoveVM->m_result = hrc; 615 if (!taskMoveVM->m_pProgress.isNull()) 616 taskMoveVM->m_pProgress->i_notifyComplete(taskMoveVM->m_result); 617 return; 618 } 607 619 strTargetFolder.append(Utf8Str(bstrMachineName)); 608 620 } … … 652 664 { 653 665 /* Move all disks */ 654 rc = taskMoveVM->moveAllDisks(taskMoveVM->finalMediumsMap, &strTargetFolder);655 if (FAILED( rc))656 throw rc;666 hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap, &strTargetFolder); 667 if (FAILED(hrc)) 668 throw hrc; 657 669 658 670 /* Get Machine::Data here because moveAllDisks() change it */ … … 675 687 /* Check if a snapshot folder is necessary and if so doesn't already 676 688 * exists. */ 677 if ( taskMoveVM-> finalSaveStateFilesMap.size() != 0689 if ( taskMoveVM->m_finalSaveStateFilesMap.size() != 0 678 690 && !RTDirExists(strTrgSnapshotFolder.c_str())) 679 691 { … … 682 694 { 683 695 Utf8StrFmt errorDesc("Could not create snapshots folder '%s' (%Rrc)", strTrgSnapshotFolder.c_str(), vrc); 684 taskMoveVM-> errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));696 taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 685 697 686 698 throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str())); … … 688 700 } 689 701 690 std::map<Utf8Str, SAVESTATETASKMOVE>::iterator itState = taskMoveVM-> finalSaveStateFilesMap.begin();691 while (itState != taskMoveVM-> finalSaveStateFilesMap.end())702 std::map<Utf8Str, SAVESTATETASKMOVE>::iterator itState = taskMoveVM->m_finalSaveStateFilesMap.begin(); 703 while (itState != taskMoveVM->m_finalSaveStateFilesMap.end()) 692 704 { 693 705 const SAVESTATETASKMOVE &sst = itState->second; … … 696 708 697 709 /* Move to next sub-operation. */ 698 rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy the save state file '%s' ..."),710 hrc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy the save state file '%s' ..."), 699 711 RTPathFilename(sst.strSaveStateFile.c_str())).raw(), sst.uWeight); 700 if (FAILED(rc)) throw rc; 712 if (FAILED(hrc)) 713 throw hrc; 701 714 702 715 int vrc = RTFileCopyEx(sst.strSaveStateFile.c_str(), strTrgSaveState.c_str(), 0, … … 706 719 Utf8StrFmt errorDesc("Could not copy state file '%s' to '%s' (%Rrc)", 707 720 sst.strSaveStateFile.c_str(), strTrgSaveState.c_str(), vrc); 708 taskMoveVM-> errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));721 taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 709 722 710 723 throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str())); … … 725 738 */ 726 739 { 727 Log RelFunc(("Update state file path\n"));728 rc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->finalSaveStateFilesMap,729 taskMoveVM-> vmFolders[VBox_SettingFolder],740 Log2(("Update state file path\n")); 741 hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap, 742 taskMoveVM->m_vmFolders[VBox_SettingFolder], 730 743 strTargetFolder); 731 if (FAILED( rc))732 throw rc;744 if (FAILED(hrc)) 745 throw hrc; 733 746 } 734 747 … … 739 752 */ 740 753 { 741 Log RelFunc(("Copy Machine settings file \n"));742 743 rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy Machine settings file '%s' ..."),754 Log2(("Copy Machine settings file \n")); 755 756 hrc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy Machine settings file '%s' ..."), 744 757 (*machineConfFile).machineUserData.strName.c_str()).raw(), 1); 745 if (FAILED(rc)) throw rc; 758 if (FAILED(hrc)) 759 throw hrc; 746 760 747 761 Utf8Str strTargetSettingsFilePath = strTargetFolder; … … 755 769 Utf8StrFmt errorDesc("Could not create a home machine folder '%s' (%Rrc)", 756 770 strTargetSettingsFilePath.c_str(), vrc); 757 taskMoveVM-> errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));771 taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 758 772 759 773 throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str())); 760 774 } 761 Log RelFunc(("Created a home machine folder %s\n", strTargetSettingsFilePath.c_str()));775 Log2(("Created a home machine folder %s\n", strTargetSettingsFilePath.c_str())); 762 776 } 763 777 … … 765 779 Bstr bstrMachineName; 766 780 machine->COMGETTER(Name)(bstrMachineName.asOutParam()); 781 if (FAILED(hrc)) 782 throw hrc; 767 783 strTargetSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName)); 768 784 strTargetSettingsFilePath.append(".vbox"); … … 771 787 Bstr bstr_settingsFilePath; 772 788 machine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam()); 789 if (FAILED(hrc)) 790 throw hrc; 773 791 strSettingsFilePath = bstr_settingsFilePath; 774 792 … … 779 797 Utf8StrFmt errorDesc("Could not copy the setting file '%s' to '%s' (%Rrc)", 780 798 strSettingsFilePath.c_str(), strTargetSettingsFilePath.stripFilename().c_str(), vrc); 781 taskMoveVM-> errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));799 taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 782 800 783 801 throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str())); 784 802 } 785 803 786 Log RelFunc(("The setting file %s has been copied into the folder %s\n", strSettingsFilePath.c_str(),804 Log2(("The setting file %s has been copied into the folder %s\n", strSettingsFilePath.c_str(), 787 805 strTargetSettingsFilePath.stripFilename().c_str())); 788 806 … … 795 813 /* Moving Machine log files */ 796 814 { 797 Log RelFunc(("Copy machine log files \n"));798 799 if (taskMoveVM-> vmFolders[VBox_LogFolder].isNotEmpty())815 Log2(("Copy machine log files \n")); 816 817 if (taskMoveVM->m_vmFolders[VBox_LogFolder].isNotEmpty()) 800 818 { 801 819 /* Check an original log folder existence */ 802 if (RTDirExists(taskMoveVM-> vmFolders[VBox_LogFolder].c_str()))820 if (RTDirExists(taskMoveVM->m_vmFolders[VBox_LogFolder].c_str())) 803 821 { 804 822 Utf8Str strTargetLogFolderPath = strTargetFolder; … … 813 831 Utf8StrFmt errorDesc("Could not create log folder '%s' (%Rrc)", 814 832 strTargetLogFolderPath.c_str(), vrc); 815 taskMoveVM-> errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));833 taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 816 834 817 835 throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str())); 818 836 } 819 Log RelFunc(("Created a log machine folder %s\n", strTargetLogFolderPath.c_str()));837 Log2(("Created a log machine folder %s\n", strTargetLogFolderPath.c_str())); 820 838 } 821 839 822 840 fileList_t filesList; 823 taskMoveVM->getFilesList(taskMoveVM-> vmFolders[VBox_LogFolder], filesList);841 taskMoveVM->getFilesList(taskMoveVM->m_vmFolders[VBox_LogFolder], filesList); 824 842 cit_t it = filesList.m_list.begin(); 825 843 while(it != filesList.m_list.end()) … … 832 850 833 851 /* Move to next sub-operation. */ 834 rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copying the log file '%s' ..."),852 hrc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copying the log file '%s' ..."), 835 853 RTPathFilename(strFullSourceFilePath.c_str())).raw(), 836 854 1); 837 if (FAILED(rc)) throw rc; 855 if (FAILED(hrc)) 856 throw hrc; 838 857 839 858 int vrc = RTFileCopyEx(strFullSourceFilePath.c_str(), strFullTargetFilePath.c_str(), 0, … … 845 864 strFullTargetFilePath.stripFilename().c_str(), 846 865 vrc); 847 taskMoveVM-> errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));866 taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 848 867 849 868 throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str())); 850 869 } 851 870 852 Log RelFunc(("The log file %s has been copied into the folder %s\n", strFullSourceFilePath.c_str(),853 871 Log2(("The log file %s has been copied into the folder %s\n", strFullSourceFilePath.c_str(), 872 strFullTargetFilePath.stripFilename().c_str())); 854 873 855 874 /* save new file in case of restoring */ … … 865 884 866 885 /* save all VM data */ 867 {868 rc = machine->SaveSettings();869 }870 871 { 872 Log RelFunc(("Update path to XML setting file\n"));886 hrc = machine->SaveSettings(); 887 if (FAILED(hrc)) 888 throw hrc; 889 890 { 891 Log2(("Update path to XML setting file\n")); 873 892 Utf8Str strTargetSettingsFilePath = strTargetFolder; 874 893 Bstr bstrMachineName; 875 machine->COMGETTER(Name)(bstrMachineName.asOutParam()); 894 hrc = machine->COMGETTER(Name)(bstrMachineName.asOutParam()); 895 if (FAILED(hrc)) 896 throw hrc; 876 897 strTargetSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName)).append(".vbox"); 877 898 machineData->m_strConfigFileFull = strTargetSettingsFilePath; … … 888 909 AutoWriteLock vboxLock(machine->mParent COMMA_LOCKVAL_SRC_POS); 889 910 890 rc = machine->mParent->i_saveSettings(); 891 } 892 } 893 catch(HRESULT hrc) 894 { 895 LogRelFunc(("Moving machine to a new destination was failed. Check original and destination places.\n")); 896 rc = hrc; 897 taskMoveVM->result = rc; 911 hrc = machine->mParent->i_saveSettings(); 912 if (FAILED(hrc)) 913 throw hrc; 914 } 915 } 916 catch(HRESULT aRc) 917 { 918 hrc = aRc; 919 taskMoveVM->m_result = hrc; 898 920 } 899 921 catch (...) 900 922 { 901 Log RelFunc(("Moving machine to a new destination was failed. Check original and destination places.\n"));902 rc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS);903 taskMoveVM-> result =rc;923 Log2(("Moving machine to a new destination was failed. Check original and destination places.\n")); 924 hrc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS); 925 taskMoveVM->m_result = hrc; 904 926 } 905 927 906 928 /* Cleanup on failure */ 907 if (FAILED( rc))929 if (FAILED(hrc)) 908 930 { 909 931 Machine::Data *machineData = machine->mData.data(); 910 911 /* ! Apparently we should update the Progress object !*/912 ULONG operationCount = 0;913 rc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount);914 ULONG operation = 0;915 rc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation);916 Bstr bstrOperationDescription;917 rc = taskMoveVM->m_pProgress->COMGETTER(OperationDescription)(bstrOperationDescription.asOutParam());918 Utf8Str strOperationDescription = bstrOperationDescription;919 ULONG operationPercent = 0;920 rc = taskMoveVM->m_pProgress->COMGETTER(OperationPercent)(&operationPercent);921 922 Bstr bstrMachineName;923 machine->COMGETTER(Name)(bstrMachineName.asOutParam());924 LogRelFunc(("Moving machine %s was failed on operation %s\n",925 Utf8Str(bstrMachineName.raw()).c_str(), Utf8Str(bstrOperationDescription.raw()).c_str()));926 932 927 933 /* Restoring the original mediums */ … … 940 946 * Thus we start from "operation + 1" and finish when "i < operationCount - operation". 941 947 */ 948 949 /** @todo r=vvp: Do we need to check each return result here? Looks excessively 950 * and what to do with any failure here? We are already in the rollback action. 951 * Throw only the important errors? 952 * We MUST finish this action anyway to avoid garbage and get the original VM state. */ 953 /* ! Apparently we should update the Progress object !*/ 954 ULONG operationCount = 0; 955 hrc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount); 956 if (FAILED(hrc)) 957 throw hrc; 958 ULONG operation = 0; 959 hrc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation); 960 if (FAILED(hrc)) 961 throw hrc; 962 Bstr bstrOperationDescription; 963 hrc = taskMoveVM->m_pProgress->COMGETTER(OperationDescription)(bstrOperationDescription.asOutParam()); 964 if (FAILED(hrc)) 965 throw hrc; 966 Utf8Str strOperationDescription = bstrOperationDescription; 967 ULONG operationPercent = 0; 968 hrc = taskMoveVM->m_pProgress->COMGETTER(OperationPercent)(&operationPercent); 969 if (FAILED(hrc)) 970 throw hrc; 971 Bstr bstrMachineName; 972 hrc = machine->COMGETTER(Name)(bstrMachineName.asOutParam()); 973 if (FAILED(hrc)) 974 throw hrc; 975 976 Log2(("Moving machine %s was failed on operation %s\n", 977 Utf8Str(bstrMachineName.raw()).c_str(), Utf8Str(bstrOperationDescription.raw()).c_str())); 978 942 979 for (ULONG i = operation + 1; i < operationCount - operation; ++i) 943 { 944 rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i + 1).raw(), 1); 945 if (FAILED(rc)) throw rc; 946 } 947 948 rc = taskMoveVM->moveAllDisks(taskMoveVM->finalMediumsMap); 949 if (FAILED(rc)) 950 throw rc; 951 } 952 catch(HRESULT hrc) 953 { 954 LogRelFunc(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n")); 955 taskMoveVM->result = hrc; 980 taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i + 1).raw(), 1); 981 982 hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap); 983 if (FAILED(hrc)) 984 throw hrc; 985 986 /* Revert original paths to the state files */ 987 { 988 hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap, 989 strTargetFolder, 990 taskMoveVM->m_vmFolders[VBox_SettingFolder]); 991 if (FAILED(hrc)) 992 { 993 Log2(("Rollback scenario: can't restore the original paths to the state files. " 994 "Machine settings %s can be corrupted.\n", machineData->m_strConfigFileFull.c_str())); 995 throw hrc; 996 } 997 } 998 999 /* Delete all created files. Here we update progress object */ 1000 hrc = taskMoveVM->deleteFiles(newFiles); 1001 if (FAILED(hrc)) 1002 { 1003 Log2(("Rollback scenario: can't delete new created files. Check the destination folder.")); 1004 throw hrc; 1005 } 1006 1007 /* Delete destination folder */ 1008 int vrc = RTDirRemove(strTargetFolder.c_str()); 1009 if (RT_FAILURE(vrc)) 1010 { 1011 Log2(("Rollback scenario: can't delete new destination folder.")); 1012 throw machine->setErrorVrc(vrc, "Rollback scenario: can't delete new destination folder."); 1013 } 1014 1015 /* save all VM data */ 1016 { 1017 AutoWriteLock srcLock(machine COMMA_LOCKVAL_SRC_POS); 1018 srcLock.release(); 1019 hrc = machine->SaveSettings(); 1020 if (FAILED(hrc)) 1021 { 1022 Log2(("Rollback scenario: can't save machine settings.")); 1023 throw hrc; 1024 } 1025 srcLock.acquire(); 1026 } 1027 1028 /* Restore an original path to XML setting file */ 1029 { 1030 Log2(("Rollback scenario: restoration of the original path to XML setting file\n")); 1031 Utf8Str strOriginalSettingsFilePath = taskMoveVM->m_vmFolders[VBox_SettingFolder]; 1032 strOriginalSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName)).append(".vbox"); 1033 machineData->m_strConfigFileFull = strOriginalSettingsFilePath; 1034 machine->mParent->i_copyPathRelativeToConfig(strOriginalSettingsFilePath, machineData->m_strConfigFile); 1035 } 1036 1037 /* Marks the global registry for uuid as modified */ 1038 { 1039 AutoWriteLock srcLock(machine COMMA_LOCKVAL_SRC_POS); 1040 srcLock.release(); 1041 Guid uuid = machine->mData->mUuid; 1042 machine->mParent->i_markRegistryModified(uuid); 1043 srcLock.acquire(); 1044 } 1045 1046 /* save the global settings; for that we should hold only the VirtualBox lock */ 1047 { 1048 AutoWriteLock vboxLock(machine->mParent COMMA_LOCKVAL_SRC_POS); 1049 hrc = machine->mParent->i_saveSettings(); 1050 if (FAILED(hrc)) 1051 { 1052 Log2(("Rollback scenario: can't save global settings.")); 1053 throw hrc; 1054 } 1055 } 1056 } 1057 catch(HRESULT aRc) 1058 { 1059 Log2(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n")); 1060 taskMoveVM->m_result = aRc; 956 1061 } 957 1062 catch (...) 958 1063 { 959 LogRelFunc(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n")); 960 rc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS); 961 taskMoveVM->result = rc; 962 } 963 964 /* Revert original paths to the state files */ 965 rc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->finalSaveStateFilesMap, 966 strTargetFolder, 967 taskMoveVM->vmFolders[VBox_SettingFolder]); 968 if (FAILED(rc)) 969 { 970 LogRelFunc(("Rollback scenario: can't restore the original paths to the state files. " 971 "Machine settings %s can be corrupted.\n", machineData->m_strConfigFileFull.c_str())); 972 } 973 974 /* Delete all created files. Here we update progress object */ 975 rc = taskMoveVM->deleteFiles(newFiles); 976 if (FAILED(rc)) 977 LogRelFunc(("Rollback scenario: can't delete new created files. Check the destination folder.")); 978 979 /* Delete destination folder */ 980 RTDirRemove(strTargetFolder.c_str()); 981 982 /* save all VM data */ 983 { 984 AutoWriteLock srcLock(machine COMMA_LOCKVAL_SRC_POS); 985 srcLock.release(); 986 rc = machine->SaveSettings(); 987 srcLock.acquire(); 988 } 989 990 /* Restore an original path to XML setting file */ 991 { 992 LogRelFunc(("Rollback scenario: restoration of the original path to XML setting file\n")); 993 Utf8Str strOriginalSettingsFilePath = taskMoveVM->vmFolders[VBox_SettingFolder]; 994 strOriginalSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName)).append(".vbox"); 995 machineData->m_strConfigFileFull = strOriginalSettingsFilePath; 996 machine->mParent->i_copyPathRelativeToConfig(strOriginalSettingsFilePath, machineData->m_strConfigFile); 997 } 998 999 /* Marks the global registry for uuid as modified */ 1000 { 1001 AutoWriteLock srcLock(machine COMMA_LOCKVAL_SRC_POS); 1002 srcLock.release(); 1003 Guid uuid = machine->mData->mUuid; 1004 machine->mParent->i_markRegistryModified(uuid); 1005 srcLock.acquire(); 1006 } 1007 1008 /* save the global settings; for that we should hold only the VirtualBox lock */ 1009 { 1010 AutoWriteLock vboxLock(machine->mParent COMMA_LOCKVAL_SRC_POS); 1011 rc = machine->mParent->i_saveSettings(); 1012 } 1013 1064 Log2(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n")); 1065 hrc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS); 1066 taskMoveVM->m_result = hrc; 1067 } 1014 1068 /* In case of failure the progress object on the other side (user side) get notification about operation 1015 1069 completion but the operation percentage may not be set to 100% */ … … 1022 1076 * because we doubled the number of operations for rollback case. 1023 1077 * But if we want to update the progress object corectly it's needed to add all medium moved by standard 1024 * "move medium" logic (for us it's taskMoveVM-> finalMediumsMap) to the current number of operation.1078 * "move medium" logic (for us it's taskMoveVM->m_finalMediumsMap) to the current number of operation. 1025 1079 */ 1026 1080 1027 1081 ULONG operationCount = 0; 1028 rc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount);1082 hrc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount); 1029 1083 ULONG operation = 0; 1030 rc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation); 1031 1032 for (ULONG i = operation; i < operation + taskMoveVM->finalMediumsMap.size() - 1; ++i) 1033 { 1034 rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i).raw(), 1); 1035 if (FAILED(rc)) throw rc; /** @todo r=bird: Who exactly should be catching this? Our caller is 1036 * ThreadTask::taskHandlerThreadProc and it doesn't catch anything, nor does the 1037 * IPRT. */ 1038 } 1039 1040 rc = taskMoveVM->deleteFiles(originalFiles); 1041 if (FAILED(rc)) 1042 LogRelFunc(("Forward scenario: can't delete all original files.\n")); 1084 hrc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation); 1085 1086 for (ULONG i = operation; i < operation + taskMoveVM->m_finalMediumsMap.size() - 1; ++i) 1087 taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i).raw(), 1); 1088 1089 hrc = taskMoveVM->deleteFiles(originalFiles); 1090 if (FAILED(hrc)) 1091 Log2(("Forward scenario: can't delete all original files.\n")); 1043 1092 } 1044 1093 … … 1046 1095 { 1047 1096 /* Set the first error happened */ 1048 if (!taskMoveVM-> errorsList.empty())1049 { 1050 ErrorInfoItem ei = taskMoveVM-> errorsList.front();1097 if (!taskMoveVM->m_errorsList.empty()) 1098 { 1099 ErrorInfoItem ei = taskMoveVM->m_errorsList.front(); 1051 1100 machine->setError(ei.m_code, machine->tr(ei.m_description.c_str())); 1052 1101 } 1053 1102 1054 taskMoveVM->m_pProgress->i_notifyComplete(taskMoveVM-> result);1103 taskMoveVM->m_pProgress->i_notifyComplete(taskMoveVM->m_result); 1055 1104 } 1056 1105 … … 1088 1137 1089 1138 if (mt.fSnapshot == true) 1090 {1091 1139 strLocation.stripFilename().stripPath().append(RTPATH_DELIMITER).append(Utf8Str(bstrSrcName)); 1092 }1093 1140 else 1094 {1095 1141 strLocation.stripPath(); 1096 }1097 1142 1098 1143 strTargetImageName.append(RTPATH_DELIMITER).append(strLocation); … … 1148 1193 com::ErrorInfoKeeper eik; 1149 1194 Utf8Str errorDesc(eik.getText().raw()); 1150 errorsList.push_back(ErrorInfoItem(eik.getResultCode(), errorDesc.c_str()));1195 m_errorsList.push_back(ErrorInfoItem(eik.getResultCode(), errorDesc.c_str())); 1151 1196 } 1152 1197 1153 1198 if (FAILED(rc)) throw rc; 1154 1199 1155 Log RelFunc(("Moving %s has been finished\n", strTargetImageName.c_str()));1200 Log2(("Moving %s has been finished\n", strTargetImageName.c_str())); 1156 1201 1157 1202 ++itMedium; … … 1162 1207 catch(HRESULT hrc) 1163 1208 { 1164 Log RelFunc(("\nException during moving the disk %s\n", strLocation.c_str()));1209 Log2(("\nException during moving the disk %s\n", strLocation.c_str())); 1165 1210 rc = hrc; 1166 1211 machineLock.release(); … … 1168 1213 catch (...) 1169 1214 { 1170 Log RelFunc(("\nException during moving the disk %s\n", strLocation.c_str()));1215 Log2(("\nException during moving the disk %s\n", strLocation.c_str())); 1171 1216 rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS); 1172 1217 machineLock.release(); … … 1176 1221 { 1177 1222 Utf8StrFmt errorDesc("Exception during moving the disk %s\n", strLocation.c_str()); 1178 errorsList.push_back(ErrorInfoItem(rc, errorDesc.c_str()));1223 m_errorsList.push_back(ErrorInfoItem(rc, errorDesc.c_str())); 1179 1224 } 1180 1225 … … 1228 1273 { 1229 1274 RTDIR hDir; 1230 HRESULT rc = S_OK;1275 HRESULT hrc = S_OK; 1231 1276 int vrc = RTDirOpen(&hDir, strRootFolder.c_str()); 1232 1277 if (RT_SUCCESS(vrc)) … … 1247 1292 Utf8Str strNextFolder(strRootFolder); 1248 1293 strNextFolder.append(RTPATH_DELIMITER).append(DirEntry.szName); 1249 rc = getFilesList(strNextFolder, filesList);1250 if (FAILED( rc))1294 hrc = getFilesList(strNextFolder, filesList); 1295 if (FAILED(hrc)) 1251 1296 break; 1252 1297 } … … 1259 1304 { 1260 1305 Utf8StrFmt errorDesc("Folder '%s' doesn't exist (%Rrc)", strRootFolder.c_str(), vrc); 1261 errorsList.push_back(ErrorInfoItem(VERR_FILE_NOT_FOUND, errorDesc.c_str()));1262 1263 rc = m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));1306 m_errorsList.push_back(ErrorInfoItem(VERR_FILE_NOT_FOUND, errorDesc.c_str())); 1307 1308 hrc = m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str())); 1264 1309 } 1265 1310 else 1266 1311 { 1267 1312 Utf8StrFmt errorDesc("Could not open folder '%s' (%Rrc)", strRootFolder.c_str(), vrc); 1268 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1269 1270 /** @todo r=bird: document this throwing business, please! Error handling is 1271 * a bit fishy here. See also */ 1272 throw m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str())); 1273 } 1274 1275 return rc; 1313 m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1314 1315 hrc = m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str())); 1316 } 1317 1318 return hrc; 1276 1319 } 1277 1320 1278 1321 HRESULT MachineMoveVM::deleteFiles(const RTCList<Utf8Str>& listOfFiles) 1279 1322 { 1280 HRESULT rc = S_OK;1323 HRESULT hrc = S_OK; 1281 1324 /* Delete all created files. */ 1282 1325 try … … 1284 1327 for (size_t i = 0; i < listOfFiles.size(); ++i) 1285 1328 { 1286 Log RelFunc(("Deleting file %s ...\n", listOfFiles.at(i).c_str()));1287 rc = m_pProgress->SetNextOperation(BstrFmt("Deleting file %s...", listOfFiles.at(i).c_str()).raw(), 1);1288 if (FAILED( rc)) throwrc;1329 Log2(("Deleting file %s ...\n", listOfFiles.at(i).c_str())); 1330 hrc = m_pProgress->SetNextOperation(BstrFmt("Deleting file %s...", listOfFiles.at(i).c_str()).raw(), 1); 1331 if (FAILED(hrc)) throw hrc; 1289 1332 1290 1333 int vrc = RTFileDelete(listOfFiles.at(i).c_str()); 1291 1334 if (RT_FAILURE(vrc)) 1292 1335 { 1293 Utf8StrFmt errorDesc("Could not delete file '%s' (%Rrc)", listOfFiles.at(i).c_str(), rc);1294 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));1295 1296 rc =m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));1336 Utf8StrFmt errorDesc("Could not delete file '%s' (%Rrc)", listOfFiles.at(i).c_str(), hrc); 1337 m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1338 1339 throw m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str())); 1297 1340 } 1298 1341 else 1299 Log RelFunc(("File %s has been deleted\n", listOfFiles.at(i).c_str()));1300 } 1301 } 1302 catch(HRESULT hrc)1303 { 1304 rc = hrc;1342 Log2(("File %s has been deleted\n", listOfFiles.at(i).c_str())); 1343 } 1344 } 1345 catch(HRESULT aRc) 1346 { 1347 hrc = aRc; 1305 1348 } 1306 1349 catch (...) 1307 1350 { 1308 rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS);1309 } 1310 1311 return rc;1351 hrc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS); 1352 } 1353 1354 return hrc; 1312 1355 } 1313 1356 1314 1357 HRESULT MachineMoveVM::getFolderSize(const Utf8Str& strRootFolder, uint64_t& size) 1315 1358 { 1316 HRESULT rc = S_OK;1359 HRESULT hrc = S_OK; 1317 1360 int vrc = 0; 1318 1361 uint64_t totalFolderSize = 0; … … 1322 1365 if (ex == true) 1323 1366 { 1324 rc = getFilesList(strRootFolder, filesList);1325 if (SUCCEEDED( rc))1367 hrc = getFilesList(strRootFolder, filesList); 1368 if (SUCCEEDED(hrc)) 1326 1369 { 1327 1370 cit_t it = filesList.m_list.begin(); … … 1339 1382 { 1340 1383 Utf8StrFmt errorDesc("Could not get the size of file '%s' (%Rrc)", fullPath.c_str(), vrc); 1341 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));1342 1343 throwm_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));1384 m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1385 1386 return m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str())); 1344 1387 } 1345 1388 ++it; … … 1348 1391 size = totalFolderSize; 1349 1392 } 1350 else1351 {1352 /** @todo r=bird: This only happens if RTDirOpen fails. So, I'm not sure1353 * what you're going for here... See not about throwing in getFilesList(). */1354 Utf8StrFmt errorDesc("Could not calculate the size of folder '%s'", strRootFolder.c_str());1355 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));1356 1357 m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str()));1358 }1359 1393 } 1360 1394 else 1361 1395 size = 0; 1362 1396 1363 return rc;1397 return hrc; 1364 1398 } 1365 1399 … … 1433 1467 Bstr bstrLocation; 1434 1468 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 1435 if (FAILED(rc)) throwrc;1469 if (FAILED(rc)) return rc; 1436 1470 1437 1471 /* Cast to ComObjPtr<Medium> */ … … 1439 1473 1440 1474 /*Check for "read-only" medium in terms that VBox can't create this one */ 1441 bool fPass = isMediumTypeSupportedForMoving(pMedium); 1442 if(!fPass) 1443 { 1444 LogRelFunc(("Skipping file %s because of this medium type hasn't been supported for moving.\n", 1445 Utf8Str(bstrLocation.raw()).c_str())); 1446 continue; 1475 try 1476 { 1477 bool fPass = isMediumTypeSupportedForMoving(pMedium); 1478 if(!fPass) 1479 { 1480 Log2(("Skipping file %s because of this medium type hasn't been supported for moving.\n", 1481 Utf8Str(bstrLocation.raw()).c_str())); 1482 continue; 1483 } 1484 } catch (HRESULT aRc) 1485 { 1486 return aRc; 1447 1487 } 1448 1488 … … 1465 1505 MediumType_T mediumType;//immutable, shared, passthrough 1466 1506 rc = pMedium->COMGETTER(Type)(&mediumType); 1467 if (FAILED(rc)) throwrc;1507 if (FAILED(rc)) return rc; 1468 1508 1469 1509 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 1470 if (FAILED(rc)) throwrc;1510 if (FAILED(rc)) return rc; 1471 1511 1472 1512 MEDIUMTASKMOVE mt;// = {false, "basename", NULL, 0, 0}; 1473 1513 mt.strBaseName = bstrLocation; 1474 Utf8Str strFolder = vmFolders[VBox_SnapshotFolder];1514 Utf8Str strFolder = m_vmFolders[VBox_SnapshotFolder]; 1475 1515 if (strFolder.isNotEmpty() && mt.strBaseName.contains(strFolder)) 1476 1516 { … … 1490 1530 } 1491 1531 1492 llMedias.append(mtc);1532 m_llMedias.append(mtc); 1493 1533 } 1494 1534 /* Add the save state files of this machine if there is one. */ … … 1500 1540 * that in the previous loop, cause there we go from child -> parent and 1501 1541 * didn't know how many are between. */ 1502 for (size_t i = 0; i < llMedias.size(); ++i)1542 for (size_t i = 0; i < m_llMedias.size(); ++i) 1503 1543 { 1504 1544 uint32_t uIdx = 0; 1505 MEDIUMTASKCHAINMOVE &mtc = llMedias.at(i);1545 MEDIUMTASKCHAINMOVE &mtc = m_llMedias.at(i); 1506 1546 for (size_t a = mtc.chain.size(); a > 0; --a) 1507 1547 mtc.chain[a - 1].uIdx = uIdx++; … … 1528 1568 { 1529 1569 Utf8StrFmt errorDesc("Could not get file size of '%s' (%Rrc)", sst.strSaveStateFile.c_str(), vrc); 1530 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));1570 m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1531 1571 1532 1572 return m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str())); … … 1535 1575 * be read and written */ 1536 1576 sst.uWeight = (ULONG)(2 * (cbSize + _1M - 1) / _1M); 1537 llSaveStateFiles.append(sst);1577 m_llSaveStateFiles.append(sst); 1538 1578 } 1539 1579 return S_OK; … … 1605 1645 if (formatName.compare("VHDX", Utf8Str::CaseInsensitive) == 0) 1606 1646 { 1607 Log RelFunc(("Skipping medium %s. VHDX format is supported in \"read-only\" mode only. \n",1608 1647 Log2(("Skipping medium %s. VHDX format is supported in \"read-only\" mode only. \n", 1648 Utf8Str(bstrLocation.raw()).c_str())); 1609 1649 fSupported = false; 1610 1650 } … … 1617 1657 if (!fSupported) 1618 1658 { 1619 Log RelFunc(("Skipping medium %s because it's not a real file on the disk.\n",1620 1659 Log2(("Skipping medium %s because it's not a real file on the disk.\n", 1660 Utf8Str(bstrLocation.raw()).c_str())); 1621 1661 } 1622 1662 } … … 1631 1671 if (fIso == false) 1632 1672 { 1633 Log RelFunc(("Skipping file %s. Only ISO images are supported for now.\n",1634 1673 Log2(("Skipping file %s. Only ISO images are supported for now.\n", 1674 Utf8Str(bstrLocation.raw()).c_str())); 1635 1675 fSupported = false; 1636 1676 }
Note:
See TracChangeset
for help on using the changeset viewer.