VirtualBox

Ignore:
Timestamp:
Jun 2, 2014 6:53:08 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94109
Message:

6813 - MachineImpl use of server side wrappers + misc mods on other classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r50899 r51498  
    66
    77/*
    8  * Copyright (C) 2006-2013 Oracle Corporation
     8 * Copyright (C) 2006-2014 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    329329        m->strName = aName;
    330330        alock.release(); /* Important! (child->parent locks are forbidden) */
    331         rc = m->pMachine->onSnapshotChange(this);
     331        rc = m->pMachine->i_onSnapshotChange(this);
    332332    }
    333333
     
    351351        m->strDescription = aDescription;
    352352        alock.release(); /* Important! (child->parent locks are forbidden) */
    353         rc = m->pMachine->onSnapshotChange(this);
     353        rc = m->pMachine->i_onSnapshotChange(this);
    354354    }
    355355
     
    746746    // state file (only if this snapshot is online)
    747747    if (i_getStateFilePath().isNotEmpty())
    748         m->pMachine->copyPathRelativeToMachine(i_getStateFilePath(), data.strStateFile);
     748        m->pMachine->i_copyPathRelativeToMachine(i_getStateFilePath(), data.strStateFile);
    749749    else
    750750        data.strStateFile.setNull();
    751751
    752     HRESULT rc = m->pMachine->saveHardware(data.hardware, &data.debugging, &data.autostart);
     752    HRESULT rc = m->pMachine->i_saveHardware(data.hardware, &data.debugging, &data.autostart);
    753753    if (FAILED(rc)) return rc;
    754754
    755     rc = m->pMachine->saveStorageControllers(data.storage);
     755    rc = m->pMachine->i_saveStorageControllers(data.storage);
    756756    if (FAILED(rc)) return rc;
    757757
     
    858858
    859859    // now call detachAllMedia on the snapshot machine
    860     rc = m->pMachine->detachAllMedia(writeLock,
    861                                      this /* pSnapshot */,
    862                                      cleanupMode,
    863                                      llMedia);
     860    rc = m->pMachine->i_detachAllMedia(writeLock,
     861                                       this /* pSnapshot */,
     862                                       cleanupMode,
     863                                       llMedia);
    864864    if (FAILED(rc))
    865865        return rc;
     
    11681168    /* load hardware and harddisk settings */
    11691169
    1170     HRESULT rc = loadHardware(hardware, pDbg, pAutostart);
     1170    HRESULT rc = i_loadHardware(hardware, pDbg, pAutostart);
    11711171    if (SUCCEEDED(rc))
    1172         rc = loadStorageControllers(storage,
    1173                                     NULL, /* puuidRegistry */
    1174                                     &mSnapshotId);
     1172        rc = i_loadStorageControllers(storage,
     1173                                      NULL, /* puuidRegistry */
     1174                                      &mSnapshotId);
    11751175
    11761176    if (SUCCEEDED(rc))
    11771177        /* commit all changes made during the initialization */
    1178         commit();   /// @todo r=dj why do we need a commit in init?!? this is very expensive
     1178        i_commit();   /// @todo r=dj why do we need a commit in init?!? this is very expensive
    11791179        /// @todo r=klaus for some reason the settings loading logic backs up
    11801180        // the settings, and therefore a commit is needed. Should probably be changed.
     
    12341234 *  @warning Caller must hold no locks when calling this.
    12351235 */
    1236 HRESULT SnapshotMachine::onSnapshotChange(Snapshot *aSnapshot)
     1236HRESULT SnapshotMachine::i_onSnapshotChange(Snapshot *aSnapshot)
    12371237{
    12381238    AutoMultiWriteLock2 mlock(this, aSnapshot COMMA_LOCKVAL_SRC_POS);
     
    12441244     * modification of the current state flag, cause this snapshot data isn't
    12451245     * related to the current state. */
    1246     mMachine->setModified(Machine::IsModified_Snapshots, false /* fAllowStateModification */);
    1247     HRESULT rc = mMachine->saveSettings(&fNeedsGlobalSaveSettings,
    1248                                         SaveS_Force);        // we know we need saving, no need to check
     1246    mMachine->i_setModified(Machine::IsModified_Snapshots, false /* fAllowStateModification */);
     1247    HRESULT rc = mMachine->i_saveSettings(&fNeedsGlobalSaveSettings,
     1248                                          SaveS_Force);        // we know we need saving, no need to check
    12491249    mlock.release();
    12501250
     
    13121312    void handler()
    13131313    {
    1314         pMachine->restoreSnapshotHandler(*this);
     1314        pMachine->i_restoreSnapshotHandler(*this);
    13151315    }
    13161316};
     
    13301330    void handler()
    13311331    {
    1332         pMachine->deleteSnapshotHandler(*this);
     1332        pMachine->i_deleteSnapshotHandler(*this);
    13331333    }
    13341334
     
    14341434        /* save all current settings to ensure current changes are committed and
    14351435         * hard disks are fixed up */
    1436         HRESULT rc = saveSettings(NULL);
     1436        HRESULT rc = i_saveSettings(NULL);
    14371437                // no need to check for whether VirtualBox.xml needs changing since
    14381438                // we can't have a machine XML rename pending at this point
     
    14541454        {
    14551455            // creating a new online snapshot: we need a fresh saved state file
    1456             composeSavedStateFilename(strStateFilePath);
     1456            i_composeSavedStateFilename(strStateFilePath);
    14571457        }
    14581458    }
     
    15021502        // backup the media data so we can recover if things goes wrong along the day;
    15031503        // the matching commit() is in fixupMedia() during endSnapshot()
    1504         setModified(IsModified_Storage);
     1504        i_setModified(IsModified_Storage);
    15051505        mMediaData.backup();
    15061506
    15071507        /* Console::fntTakeSnapshotWorker and friends expects this. */
    15081508        if (mConsoleTaskData.mLastState == MachineState_Running)
    1509             setMachineState(MachineState_LiveSnapshotting);
     1509            i_setMachineState(MachineState_LiveSnapshotting);
    15101510        else
    1511             setMachineState(MachineState_Saving); /** @todo Confusing! Saving is used for both online and offline snapshots. */
     1511            i_setMachineState(MachineState_Saving); /** @todo Confusing! Saving is used for both online and offline snapshots. */
    15121512
    15131513        alock.release();
    15141514        /* create new differencing hard disks and attach them to this machine */
    1515         rc = createImplicitDiffs(aConsoleProgress,
    1516                                  1,            // operation weight; must be the same as in Console::TakeSnapshot()
    1517                                  !!fTakingSnapshotOnline);
     1515        rc = i_createImplicitDiffs(aConsoleProgress,
     1516                                   1,            // operation weight; must be the same as in Console::TakeSnapshot()
     1517                                   !!fTakingSnapshotOnline);
    15181518        if (FAILED(rc))
    15191519            throw rc;
     
    15311531                  : mData->mMachineState == MachineState_Saving)
    15321532           )
    1533             setMachineState(mConsoleTaskData.mLastState);
     1533               i_setMachineState(mConsoleTaskData.mLastState);
    15341534
    15351535        pSnapshot->uninit();
     
    15921592         && mConsoleTaskData.mLastState != MachineState_Running
    15931593       )
    1594         setMachineState(mConsoleTaskData.mLastState);
     1594           i_setMachineState(mConsoleTaskData.mLastState);
    15951595
    15961596    ComObjPtr<Snapshot> pOldFirstSnap = mData->mFirstSnapshot;
     
    16171617            flSaveSettings |= SaveS_ResetCurStateModified;
    16181618
    1619         rc = saveSettings(NULL, flSaveSettings);
     1619        rc = i_saveSettings(NULL, flSaveSettings);
    16201620    }
    16211621
     
    16231623    {
    16241624        /* associate old hard disks with the snapshot and do locking/unlocking*/
    1625         commitMedia(fOnline);
     1625        i_commitMedia(fOnline);
    16261626
    16271627        /* inform callbacks */
     
    16361636        machineLock.release();
    16371637
    1638         rollbackMedia();
     1638        i_rollbackMedia();
    16391639
    16401640        mData->mFirstSnapshot = pOldFirstSnap;      // might have been changed above
     
    17661766
    17671767    /* set the proper machine state (note: after creating a Task instance) */
    1768     setMachineState(MachineState_RestoringSnapshot);
     1768    i_setMachineState(MachineState_RestoringSnapshot);
    17691769
    17701770    /* return the progress to the caller */
     
    17911791 * @param aTask Task data.
    17921792 */
    1793 void SessionMachine::restoreSnapshotHandler(RestoreSnapshotTask &aTask)
     1793void SessionMachine::i_restoreSnapshotHandler(RestoreSnapshotTask &aTask)
    17941794{
    17951795    LogFlowThisFuncEnter();
     
    18231823         * the direct session. */
    18241824        if (mData->flModifications)
    1825             rollback(false /* aNotify */);
     1825            i_rollback(false /* aNotify */);
    18261826
    18271827        /* Delete the saved state file if the machine was Saved prior to this
     
    18351835            Utf8Str strStateFile(mSSData->strStateFilePath);
    18361836            mSSData->strStateFilePath.setNull();
    1837             releaseSavedStateFile(strStateFile, NULL /* pSnapshotToIgnore */ );
     1837            i_releaseSavedStateFile(strStateFile, NULL /* pSnapshotToIgnore */ );
    18381838
    18391839            aTask.modifyBackedUpState(MachineState_PoweredOff);
    18401840
    1841             rc = saveStateSettings(SaveSTS_StateFilePath);
     1841            rc = i_saveStateSettings(SaveSTS_StateFilePath);
    18421842            if (FAILED(rc))
    18431843                throw rc;
     
    18561856
    18571857            /* copy all hardware data from the snapshot */
    1858             copyFrom(pSnapshotMachine);
     1858            i_copyFrom(pSnapshotMachine);
    18591859
    18601860            LogFlowThisFunc(("Restoring hard disks from the snapshot...\n"));
    18611861
    18621862            // restore the attachments from the snapshot
    1863             setModified(IsModified_Storage);
     1863            i_setModified(IsModified_Storage);
    18641864            mMediaData.backup();
    18651865            mMediaData->mAttachments.clear();
     
    18781878            alock.release();
    18791879
    1880             rc = createImplicitDiffs(aTask.pProgress,
    1881                                      1,
    1882                                      false /* aOnline */);
     1880            rc = i_createImplicitDiffs(aTask.pProgress,
     1881                                       1,
     1882                                       false /* aOnline */);
    18831883            if (FAILED(rc))
    18841884                throw rc;
     
    19341934         * state accordingly no matter of the delete snapshot result */
    19351935        if (mSSData->strStateFilePath.isNotEmpty())
    1936             setMachineState(MachineState_Saved);
     1936            i_setMachineState(MachineState_Saved);
    19371937        else
    1938             setMachineState(MachineState_PoweredOff);
    1939 
    1940         updateMachineStateOnClient();
     1938            i_setMachineState(MachineState_PoweredOff);
     1939
     1940        i_updateMachineStateOnClient();
    19411941        stateRestored = true;
    19421942
     
    19861986        // save machine settings, reset the modified flag and commit;
    19871987        bool fNeedsGlobalSaveSettings = false;
    1988         rc = saveSettings(&fNeedsGlobalSaveSettings,
    1989                           SaveS_ResetCurStateModified);
     1988        rc = i_saveSettings(&fNeedsGlobalSaveSettings,
     1989                            SaveS_ResetCurStateModified);
    19901990        if (FAILED(rc))
    19911991            throw rc;
     
    20252025
    20262026        /* undo all changes on failure */
    2027         rollback(false /* aNotify */);
     2027        i_rollback(false /* aNotify */);
    20282028
    20292029        if (!stateRestored)
    20302030        {
    20312031            /* restore the machine state */
    2032             setMachineState(aTask.machineStateBackup);
    2033             updateMachineStateOnClient();
     2032            i_setMachineState(aTask.machineStateBackup);
     2033            i_updateMachineStateOnClient();
    20342034        }
    20352035    }
     
    21082108
    21092109    ComObjPtr<Snapshot> pSnapshot;
    2110     HRESULT rc = findSnapshotById(startId, pSnapshot, true /* aSetError */);
     2110    HRESULT rc = i_findSnapshotById(startId, pSnapshot, true /* aSetError */);
    21112111    if (FAILED(rc)) return rc;
    21122112
     
    21352135        if (mData->flModifications)
    21362136        {
    2137             rc = saveSettings(NULL);
     2137            rc = i_saveSettings(NULL);
    21382138                // no need to change for whether VirtualBox.xml needs saving since
    21392139                // we can't have a machine XML rename pending at this point
     
    22192219    // set the proper machine state here now (note: after creating a Task instance)
    22202220    if (mData->mMachineState == MachineState_Running)
    2221         setMachineState(MachineState_DeletingSnapshotOnline);
     2221        i_setMachineState(MachineState_DeletingSnapshotOnline);
    22222222    else if (mData->mMachineState == MachineState_Paused)
    2223         setMachineState(MachineState_DeletingSnapshotPaused);
     2223        i_setMachineState(MachineState_DeletingSnapshotPaused);
    22242224    else
    2225         setMachineState(MachineState_DeletingSnapshot);
     2225        i_setMachineState(MachineState_DeletingSnapshot);
    22262226
    22272227    /* return the progress to the caller */
     
    23322332 */
    23332333
    2334 void SessionMachine::deleteSnapshotHandler(DeleteSnapshotTask &aTask)
     2334void SessionMachine::i_deleteSnapshotHandler(DeleteSnapshotTask &aTask)
    23352335{
    23362336    LogFlowThisFuncEnter();
     
    23692369        ComObjPtr<SnapshotMachine> pSnapMachine = aTask.pSnapshot->i_getSnapshotMachine();
    23702370        // no need to lock the snapshot machine since it is const by definition
    2371         Guid machineId = pSnapMachine->getId();
     2371        Guid machineId = pSnapMachine->i_getId();
    23722372
    23732373        // save the snapshot ID (for callbacks)
     
    24292429                // prevent online merging in general.
    24302430                pOnlineMediumAttachment =
    2431                     findAttachment(mMediaData->mAttachments,
    2432                                    pAttach->i_getControllerName().raw(),
    2433                                    pAttach->i_getPort(),
    2434                                    pAttach->i_getDevice());
     2431                    i_findAttachment(mMediaData->mAttachments,
     2432                                     pAttach->i_getControllerName().raw(),
     2433                                     pAttach->i_getPort(),
     2434                                     pAttach->i_getDevice());
    24352435                if (pOnlineMediumAttachment)
    24362436                {
     
    24482448
    24492449            treeLock.release();
    2450             rc = prepareDeleteSnapshotMedium(pHD, machineId, snapshotId,
    2451                                              fOnlineMergePossible,
    2452                                              pVMMALockList, pSource, pTarget,
    2453                                              fMergeForward, pParentForTarget,
    2454                                              pChildrenToReparent,
    2455                                              fNeedsOnlineMerge,
    2456                                              pMediumLockList,
    2457                                              pHDLockToken);
     2450            rc = i_prepareDeleteSnapshotMedium(pHD, machineId, snapshotId,
     2451                                               fOnlineMergePossible,
     2452                                               pVMMALockList, pSource, pTarget,
     2453                                               fMergeForward, pParentForTarget,
     2454                                               pChildrenToReparent,
     2455                                               fNeedsOnlineMerge,
     2456                                               pMediumLockList,
     2457                                               pHDLockToken);
    24582458            treeLock.acquire();
    24592459            if (FAILED(rc))
     
    26602660                                                  1);        // weight
    26612661
    2662                 releaseSavedStateFile(stateFilePath, aTask.pSnapshot /* pSnapshotToIgnore */);
     2662                i_releaseSavedStateFile(stateFilePath, aTask.pSnapshot /* pSnapshotToIgnore */);
    26632663
    26642664                // machine will need saving now
    26652665                machineLock.release();
    2666                 mParent->i_markRegistryModified(getId());
     2666                mParent->i_markRegistryModified(i_getId());
    26672667            }
    26682668        }
     
    27302730                    mConsoleTaskData.mDeleteSnapshotInfo = (void *)&(*it);
    27312731                    // online medium merge, in the direction decided earlier
    2732                     rc = onlineMergeMedium(it->mpOnlineMediumAttachment,
    2733                                            it->mpSource,
    2734                                            it->mpTarget,
    2735                                            it->mfMergeForward,
    2736                                            it->mpParentForTarget,
    2737                                            it->mpChildrenToReparent,
    2738                                            it->mpMediumLockList,
    2739                                            aTask.pProgress,
    2740                                            &fNeedsSave);
     2732                    rc = i_onlineMergeMedium(it->mpOnlineMediumAttachment,
     2733                                             it->mpSource,
     2734                                             it->mpTarget,
     2735                                             it->mfMergeForward,
     2736                                             it->mpParentForTarget,
     2737                                             it->mpChildrenToReparent,
     2738                                             it->mpMediumLockList,
     2739                                             aTask.pProgress,
     2740                                             &fNeedsSave);
    27412741                    mConsoleTaskData.mDeleteSnapshotInfo = NULL;
    27422742                }
     
    27992799            if (fReparentTarget)
    28002800            {
    2801                 pAtt = findAttachment(pSnapMachine->mMediaData->mAttachments,
    2802                                       it->mpTarget);
     2801                pAtt = i_findAttachment(pSnapMachine->mMediaData->mAttachments,
     2802                                        it->mpTarget);
    28032803                it->mpTarget->i_removeBackReference(machineId, snapshotId);
    28042804            }
    28052805            else
    2806                 pAtt = findAttachment(pSnapMachine->mMediaData->mAttachments,
    2807                                       it->mpSource);
     2806                pAtt = i_findAttachment(pSnapMachine->mMediaData->mAttachments,
     2807                                        it->mpSource);
    28082808            pSnapMachine->mMediaData->mAttachments.remove(pAtt);
    28092809
     
    28202820                    childSnapshotId = pChildSnapshot->i_getId();
    28212821                }
    2822                 pAtt = findAttachment(pMachine->mMediaData->mAttachments, it->mpSource);
     2822                pAtt = i_findAttachment(pMachine->mMediaData->mAttachments, it->mpSource);
    28232823                if (pAtt)
    28242824                {
     
    28432843
    28442844            // One attachment is merged, must save the settings
    2845             mParent->i_markRegistryModified(getId());
     2845            mParent->i_markRegistryModified(i_getId());
    28462846
    28472847            // prevent calling cancelDeleteSnapshotMedium() for this attachment
     
    28632863
    28642864            machineLock.release();
    2865             mParent->i_markRegistryModified(getId());
     2865            mParent->i_markRegistryModified(i_getId());
    28662866        }
    28672867    }
     
    28842884             it != toDelete.end();
    28852885             ++it)
    2886         {
    2887             cancelDeleteSnapshotMedium(it->mpHD, it->mpSource,
    2888                                        it->mpChildrenToReparent,
    2889                                        it->mfNeedsOnlineMerge,
    2890                                        it->mpMediumLockList, it->mpHDLockToken,
    2891                                        it->mMachineId, it->mSnapshotId);
    2892         }
     2886            i_cancelDeleteSnapshotMedium(it->mpHD, it->mpSource,
     2887                                         it->mpChildrenToReparent,
     2888                                         it->mfNeedsOnlineMerge,
     2889                                         it->mpMediumLockList, it->mpHDLockToken,
     2890                                         it->mMachineId, it->mSnapshotId);
    28932891    }
    28942892
     
    29022900        // restore the machine state that was saved when the
    29032901        // task was started
    2904         setMachineState(aTask.machineStateBackup);
    2905         updateMachineStateOnClient();
     2902        i_setMachineState(aTask.machineStateBackup);
     2903        i_updateMachineStateOnClient();
    29062904
    29072905        mParent->i_saveModifiedRegistries();
     
    29542952 *       and every medium object on the merge chain for writing.
    29552953 */
    2956 HRESULT SessionMachine::prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
    2957                                                     const Guid &aMachineId,
    2958                                                     const Guid &aSnapshotId,
    2959                                                     bool fOnlineMergePossible,
    2960                                                     MediumLockList *aVMMALockList,
    2961                                                     ComObjPtr<Medium> &aSource,
    2962                                                     ComObjPtr<Medium> &aTarget,
    2963                                                     bool &aMergeForward,
    2964                                                     ComObjPtr<Medium> &aParentForTarget,
    2965                                                     MediumLockList * &aChildrenToReparent,
    2966                                                     bool &fNeedsOnlineMerge,
    2967                                                     MediumLockList * &aMediumLockList,
    2968                                                     ComPtr<IToken> &aHDLockToken)
     2954HRESULT SessionMachine::i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
     2955                                                      const Guid &aMachineId,
     2956                                                      const Guid &aSnapshotId,
     2957                                                      bool fOnlineMergePossible,
     2958                                                      MediumLockList *aVMMALockList,
     2959                                                      ComObjPtr<Medium> &aSource,
     2960                                                      ComObjPtr<Medium> &aTarget,
     2961                                                      bool &aMergeForward,
     2962                                                      ComObjPtr<Medium> &aParentForTarget,
     2963                                                      MediumLockList * &aChildrenToReparent,
     2964                                                      bool &fNeedsOnlineMerge,
     2965                                                      MediumLockList * &aMediumLockList,
     2966                                                      ComPtr<IToken> &aHDLockToken)
    29692967{
    29702968    Assert(!mParent->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     
    32473245 * @note Locks the medium tree and the hard disks in the chain for writing.
    32483246 */
    3249 void SessionMachine::cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
    3250                                                 const ComObjPtr<Medium> &aSource,
    3251                                                 MediumLockList *aChildrenToReparent,
    3252                                                 bool fNeedsOnlineMerge,
    3253                                                 MediumLockList *aMediumLockList,
    3254                                                 const ComPtr<IToken> &aHDLockToken,
    3255                                                 const Guid &aMachineId,
    3256                                                 const Guid &aSnapshotId)
     3247void SessionMachine::i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
     3248                                                  const ComObjPtr<Medium> &aSource,
     3249                                                  MediumLockList *aChildrenToReparent,
     3250                                                  bool fNeedsOnlineMerge,
     3251                                                  MediumLockList *aMediumLockList,
     3252                                                  const ComPtr<IToken> &aHDLockToken,
     3253                                                  const Guid &aMachineId,
     3254                                                  const Guid &aSnapshotId)
    32573255{
    32583256    if (aMediumLockList == NULL)
     
    33433341 * @param pfNeedsMachineSaveSettings Whether the VM settings need to be saved (out).
    33443342 */
    3345 HRESULT SessionMachine::onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
    3346                                           const ComObjPtr<Medium> &aSource,
    3347                                           const ComObjPtr<Medium> &aTarget,
    3348                                           bool fMergeForward,
    3349                                           const ComObjPtr<Medium> &aParentForTarget,
    3350                                           MediumLockList *aChildrenToReparent,
    3351                                           MediumLockList *aMediumLockList,
    3352                                           ComObjPtr<Progress> &aProgress,
    3353                                           bool *pfNeedsMachineSaveSettings)
     3343HRESULT SessionMachine::i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
     3344                                            const ComObjPtr<Medium> &aSource,
     3345                                            const ComObjPtr<Medium> &aTarget,
     3346                                            bool fMergeForward,
     3347                                            const ComObjPtr<Medium> &aParentForTarget,
     3348                                            MediumLockList *aChildrenToReparent,
     3349                                            MediumLockList *aMediumLockList,
     3350                                            ComObjPtr<Progress> &aProgress,
     3351                                            bool *pfNeedsMachineSaveSettings)
    33543352{
    33553353    AssertReturn(aSource != NULL, E_FAIL);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette