Changeset 24922 in vbox for trunk/src/VBox/Main
- Timestamp:
- Nov 24, 2009 7:33:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r24899 r24922 2579 2579 ULONG ulMemSize; 2580 2580 rc = mMachine->COMGETTER(MemorySize)(&ulMemSize); 2581 if (FAILED(rc)) return rc; 2581 if (FAILED(rc)) 2582 return rc; 2582 2583 2583 2584 for (size_t i = 0; … … 2587 2588 DeviceType_T type; 2588 2589 rc = aMediumAttachments[i]->COMGETTER(Type)(&type); 2589 if (FAILED(rc)) return rc; 2590 if (FAILED(rc)) 2591 return rc; 2590 2592 2591 2593 if (type == DeviceType_HardDisk) … … 2605 2607 2606 2608 if ( fTakingSnapshotOnline 2607 || (mMachineState == MachineState_Saved)2609 || mMachineState == MachineState_Saved 2608 2610 ) 2609 2611 { … … 2624 2626 1); // ulFirstOperationWeight 2625 2627 2626 if (FAILED(rc)) return rc; 2628 if (FAILED(rc)) 2629 return rc; 2627 2630 2628 2631 VMTakeSnapshotTask *pTask; 2629 2632 if (!(pTask = new VMTakeSnapshotTask(this, pProgress, aName, aDescription))) 2630 return VERR_NO_MEMORY;2633 return E_OUTOFMEMORY; 2631 2634 2632 2635 Assert(pTask->mProgress); … … 5271 5274 if (mMachineState != aMachineState) 5272 5275 { 5273 LogFlowThisFunc(("machineState=%d\n", aMachineState)); 5276 LogThisFunc(("machineState=%s -> %s aUpdateServer=%RTbool\n", 5277 Global::stringifyMachineState(mMachineState), Global::stringifyMachineState(aMachineState), aUpdateServer)); 5274 5278 mMachineState = aMachineState; 5275 5279 … … 5627 5631 void *aUser) 5628 5632 { 5629 LogFlowFunc(("Changing state from % d to %d(aVM=%p)\n",5630 aOldState, aState, aVM));5633 LogFlowFunc(("Changing state from %s to %s (aVM=%p)\n", 5634 VMR3GetStateName(aOldState), VMR3GetStateName(aState), aVM)); 5631 5635 5632 5636 Console *that = static_cast<Console *>(aUser); … … 7345 7349 7346 7350 bool fBeganTakingSnapshot = false; 7351 bool fSuspenededBySave = false; 7347 7352 7348 7353 AutoCaller autoCaller(pTask->mConsole); … … 7368 7373 pTask->fTakingSnapshotOnline, 7369 7374 pTask->bstrSavedStateFile.asOutParam()); 7370 if (FAILED(rc)) throw rc; 7375 if (FAILED(rc)) 7376 throw rc; 7371 7377 7372 7378 fBeganTakingSnapshot = true; … … 7381 7387 7382 7388 /* sync the state with the server */ 7383 that->setMachineStateLocally(MachineState_Saving); 7389 if (pTask->lastMachineState == MachineState_Running) 7390 that->setMachineStateLocally(MachineState_LiveSnapshotting); 7391 else 7392 that->setMachineStateLocally(MachineState_Saving); 7384 7393 7385 7394 // STEP 3: save the VM state (if online) … … 7392 7401 7393 7402 alock.leave(); 7394 7403 LogFlowFunc(("VMR3Save...\n")); 7395 7404 int vrc = VMR3Save(that->mpVM, 7396 7405 strSavedStateFile.c_str(), 7397 7406 true /*fContinueAfterwards*/, 7398 7407 Console::stateProgressCallback, 7399 (void*)pTask); 7408 (void*)pTask, 7409 &fSuspenededBySave); 7410 alock.enter(); 7400 7411 if (RT_FAILURE(vrc)) 7401 7412 throw setError(E_FAIL, 7402 tr("Failed to save the machine state to '%s' (%Rrc)"), 7403 strSavedStateFile.c_str(), vrc); 7404 7405 alock.enter(); 7413 tr("Failed to save the machine state to '%s' (%Rrc)"), 7414 strSavedStateFile.c_str(), vrc); 7415 7406 7416 7407 7417 // STEP 4: reattach hard disks … … 7413 7423 com::SafeIfaceArray<IMediumAttachment> atts; 7414 7424 rc = that->mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(atts)); 7415 if (FAILED(rc)) throw rc; 7425 if (FAILED(rc)) 7426 throw rc; 7416 7427 7417 7428 for (size_t i = 0; … … 7431 7442 */ 7432 7443 rc = atts[i]->COMGETTER(Controller)(&controllerName); 7433 if (FAILED(rc)) throw rc; 7444 if (FAILED(rc)) 7445 throw rc; 7434 7446 7435 7447 rc = that->mMachine->GetStorageControllerByName(controllerName, controller.asOutParam()); 7436 if (FAILED(rc)) throw rc; 7448 if (FAILED(rc)) 7449 throw rc; 7437 7450 7438 7451 rc = controller->COMGETTER(ControllerType)(&enmController); 7439 if (FAILED(rc)) throw rc; 7452 if (FAILED(rc)) 7453 throw rc; 7440 7454 rc = controller->COMGETTER(Instance)(&lInstance); 7441 if (FAILED(rc)) throw rc; 7455 if (FAILED(rc)) 7456 throw rc; 7442 7457 rc = controller->COMGETTER(Bus)(&enmBus); 7443 if (FAILED(rc)) throw rc; 7458 if (FAILED(rc)) 7459 throw rc; 7444 7460 7445 7461 /* … … 7459 7475 if (RT_FAILURE(vrc)) 7460 7476 throw setError(E_FAIL, Console::tr("%Rrc"), vrc); 7461 if (FAILED(rc)) throw rc; 7477 if (FAILED(rc)) 7478 throw rc; 7462 7479 } 7463 7480 } … … 7468 7485 * before calling mControl->BeginTakingSnapshot(). 7469 7486 */ 7470 rc = that->mControl->EndTakingSnapshot(TRUE ); // success7487 rc = that->mControl->EndTakingSnapshot(TRUE /*aSuccess*/); 7471 7488 // do not throw rc here because we can't call EndTakingSnapshot() twice 7472 } 7473 catch (HRESULT rc) 7489 LogFlowFunc(("EndTakingSnapshot -> %Rhrc [mMachineState=%s]\n", rc, Global::stringifyMachineState(that->mMachineState))); 7490 } 7491 catch (HRESULT rcThrown) 7474 7492 { 7475 7493 /* preserve existing error info */ … … 7477 7495 7478 7496 if (fBeganTakingSnapshot) 7479 that->mControl->EndTakingSnapshot(FALSE); // failure 7480 } 7481 7482 pTask->mProgress->notifyComplete(rc); 7497 that->mControl->EndTakingSnapshot(FALSE /*aSuccess*/); 7498 7499 rc = rcThrown; 7500 LogFunc(("Caught %Rhrc [mMachineState=%s]\n", rc, Global::stringifyMachineState(that->mMachineState))); 7501 } 7502 Assert(alock.isWriteLockOnCurrentThread()); 7503 7504 if (FAILED(rc)) /* Must come before calling setMachineState. */ 7505 pTask->mProgress->notifyComplete(rc); 7506 7507 /* 7508 * Fix up the machine state. 7509 * 7510 * For live snapshots we do all the work, for the two other variantions we 7511 * just update the local copy. 7512 */ 7513 MachineState_T enmMachineState; 7514 that->mMachine->COMGETTER(State)(&enmMachineState); 7515 if ( that->mMachineState == MachineState_LiveSnapshotting 7516 || that->mMachineState == MachineState_Saving) 7517 { 7518 7519 if (!pTask->fTakingSnapshotOnline) 7520 that->setMachineStateLocally(pTask->lastMachineState); 7521 else if (SUCCEEDED(rc)) 7522 { 7523 Assert( pTask->lastMachineState == MachineState_Running 7524 || pTask->lastMachineState == MachineState_Paused); 7525 Assert(that->mMachineState == MachineState_Saving); 7526 if (pTask->lastMachineState == MachineState_Running) 7527 { 7528 LogFlowFunc(("VMR3Resume...\n")); 7529 alock.leave(); 7530 int vrc = VMR3Resume(that->mpVM); 7531 alock.enter(); 7532 if (RT_FAILURE(vrc)) 7533 { 7534 rc = setError(VBOX_E_VM_ERROR, tr("Could not resume the machine execution (%Rrc)"), vrc); 7535 pTask->mProgress->notifyComplete(rc); 7536 if (that->mMachineState == MachineState_Saving) 7537 that->setMachineStateLocally(MachineState_Paused); 7538 } 7539 } 7540 else 7541 that->setMachineStateLocally(MachineState_Paused); 7542 } 7543 else 7544 { 7545 /** @todo this could probably be made more generic and reused elsewhere. */ 7546 /* paranoid cleanup on for a failed online snapshot. */ 7547 VMSTATE enmVMState = VMR3GetState(that->mpVM); 7548 switch (enmVMState) 7549 { 7550 case VMSTATE_RUNNING: 7551 case VMSTATE_RUNNING_LS: 7552 case VMSTATE_DEBUGGING: 7553 case VMSTATE_DEBUGGING_LS: 7554 case VMSTATE_POWERING_OFF: 7555 case VMSTATE_POWERING_OFF_LS: 7556 case VMSTATE_RESETTING: 7557 case VMSTATE_RESETTING_LS: 7558 Assert(!fSuspenededBySave); 7559 that->setMachineState(MachineState_Running); 7560 break; 7561 7562 case VMSTATE_GURU_MEDITATION: 7563 case VMSTATE_GURU_MEDITATION_LS: 7564 that->setMachineState(MachineState_Stuck); 7565 break; 7566 7567 case VMSTATE_FATAL_ERROR: 7568 case VMSTATE_FATAL_ERROR_LS: 7569 if (pTask->lastMachineState == MachineState_Paused) 7570 that->setMachineStateLocally(pTask->lastMachineState); 7571 else 7572 that->setMachineState(MachineState_Paused); 7573 break; 7574 7575 default: 7576 AssertMsgFailed(("%s\n", VMR3GetStateName(enmVMState))); 7577 case VMSTATE_SUSPENDED: 7578 case VMSTATE_SUSPENDED_LS: 7579 case VMSTATE_SUSPENDING: 7580 case VMSTATE_SUSPENDING_LS: 7581 case VMSTATE_SUSPENDING_EXT_LS: 7582 if (fSuspenededBySave) 7583 { 7584 Assert(pTask->lastMachineState == MachineState_Running); 7585 LogFlowFunc(("VMR3Resume (on failure)...\n")); 7586 alock.leave(); 7587 int vrc = VMR3Resume(that->mpVM); 7588 alock.enter(); 7589 AssertLogRelRC(vrc); 7590 if (RT_FAILURE(vrc)) 7591 that->setMachineState(MachineState_Paused); 7592 } 7593 else if (pTask->lastMachineState == MachineState_Paused) 7594 that->setMachineStateLocally(pTask->lastMachineState); 7595 else 7596 that->setMachineState(MachineState_Paused); 7597 break; 7598 } 7599 7600 } 7601 } 7602 /*else: somebody else has change the state... Leave it. */ 7603 7604 /* check the remote state to see that we got it right. */ 7605 that->mMachine->COMGETTER(State)(&enmMachineState); 7606 AssertLogRelMsg(that->mMachineState == enmMachineState, 7607 ("mMachineState=%s enmMachineState=%s\n", Global::stringifyMachineState(that->mMachineState), 7608 Global::stringifyMachineState(enmMachineState) )); 7609 7610 7611 if (SUCCEEDED(rc)) /* The failure cases are handled above. */ 7612 pTask->mProgress->notifyComplete(rc); 7483 7613 7484 7614 delete pTask; 7485 7486 if (pTask->lastMachineState == MachineState_Running)7487 {7488 /* restore the paused state if appropriate */7489 that->setMachineStateLocally(MachineState_Paused);7490 /* restore the running state if appropriate */7491 that->Resume();7492 }7493 else7494 that->setMachineStateLocally(pTask->lastMachineState);7495 7615 7496 7616 LogFlowFuncLeave(); … … 7524 7644 LogFlowFunc(("Saving the state to '%s'...\n", task->mSavedStateFile.raw())); 7525 7645 7646 bool fSuspenededBySave; 7526 7647 int vrc = VMR3Save(that->mpVM, 7527 7648 task->mSavedStateFile.c_str(), 7528 7649 false, /*fContinueAfterwards*/ 7529 7650 Console::stateProgressCallback, 7530 static_cast<VMProgressTask*>(task.get())); 7651 static_cast<VMProgressTask*>(task.get()), 7652 &fSuspenededBySave); 7531 7653 if (RT_FAILURE(vrc)) 7532 7654 { … … 7535 7657 rc = E_FAIL; 7536 7658 } 7659 Assert(!fSuspenededBySave); 7537 7660 7538 7661 /* lock the console once we're going to access it */
Note:
See TracChangeset
for help on using the changeset viewer.