VirtualBox

Changeset 24298 in vbox


Ignore:
Timestamp:
Nov 3, 2009 5:20:02 PM (15 years ago)
Author:
vboxsync
Message:

Main: snapshots code cleanup, renames, documentation, coding style

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

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

    r24291 r24298  
    10551055////////////////////////////////////////////////////////////////////////////////
    10561056
    1057 /** Task structure for asynchronous VM operations */
    1058 struct SessionMachine::Task
    1059 {
    1060     Task (SessionMachine *m, Progress *p)
    1061         : machine (m), progress (p)
    1062         , state (m->mData->mMachineState) // save the current machine state
    1063         , subTask (false)
     1057/**
     1058 * Abstract base class for SessionMachine::DeleteSnapshotTask and
     1059 * SessionMachine::RestoreSnapshotTask. This is necessary since
     1060 * RTThreadCreate cannot call a method as its thread function, so
     1061 * instead we have it call the static SessionMachine::taskHandler,
     1062 * which can then call the handler() method in here (implemented
     1063 * by the children).
     1064 */
     1065struct SessionMachine::SnapshotTask
     1066{
     1067    SnapshotTask(SessionMachine *m,
     1068                 Progress *p,
     1069                 Snapshot *s)
     1070        : pMachine(m),
     1071          pProgress(p),
     1072          machineStateBackup(m->mData->mMachineState), // save the current machine state
     1073          pSnapshot(s)
    10641074    {}
    10651075
    1066     void modifyLastState (MachineState_T s)
    1067     {
    1068         *const_cast <MachineState_T *> (&state) = s;
     1076    void modifyBackedUpState(MachineState_T s)
     1077    {
     1078        *const_cast<MachineState_T*>(&machineStateBackup) = s;
    10691079    }
    10701080
    10711081    virtual void handler() = 0;
    10721082
    1073     ComObjPtr<SessionMachine> machine;
    1074     ComObjPtr<Progress> progress;
    1075     const MachineState_T state;
    1076 
    1077     bool subTask : 1;
     1083    ComObjPtr<SessionMachine>       pMachine;
     1084    ComObjPtr<Progress>             pProgress;
     1085    const MachineState_T            machineStateBackup;
     1086    ComObjPtr<Snapshot>             pSnapshot;
    10781087};
    10791088
    10801089/** Discard snapshot task */
    10811090struct SessionMachine::DeleteSnapshotTask
    1082     : public SessionMachine::Task
    1083 {
    1084     DeleteSnapshotTask(SessionMachine *m, Progress *p, Snapshot *s)
    1085         : Task(m, p),
    1086           snapshot(s)
     1091    : public SessionMachine::SnapshotTask
     1092{
     1093    DeleteSnapshotTask(SessionMachine *m,
     1094                       Progress *p,
     1095                       Snapshot *s)
     1096        : SnapshotTask(m, p, s)
    10871097    {}
    10881098
    1089     DeleteSnapshotTask (const Task &task, Snapshot *s)
    1090         : Task(task)
    1091         , snapshot(s)
     1099    void handler()
     1100    {
     1101        pMachine->deleteSnapshotHandler(*this);
     1102    }
     1103
     1104private:
     1105    DeleteSnapshotTask(const SnapshotTask &task)
     1106        : SnapshotTask(task)
    10921107    {}
    1093 
    1094     void handler()
    1095     {
    1096         machine->deleteSnapshotHandler(*this);
    1097     }
    1098 
    1099     ComObjPtr<Snapshot> snapshot;
    11001108};
    11011109
    11021110/** Restore snapshot state task */
    11031111struct SessionMachine::RestoreSnapshotTask
    1104     : public SessionMachine::Task
     1112    : public SessionMachine::SnapshotTask
    11051113{
    11061114    RestoreSnapshotTask(SessionMachine *m,
    1107                         ComObjPtr<Snapshot> &aSnapshot,
    11081115                        Progress *p,
     1116                        Snapshot *s,
    11091117                        ULONG ulStateFileSizeMB)
    1110         : Task(m, p),
    1111           m_pSnapshot(aSnapshot),
     1118        : SnapshotTask(m, p, s),
    11121119          m_ulStateFileSizeMB(ulStateFileSizeMB)
    11131120    {}
     
    11151122    void handler()
    11161123    {
    1117         machine->restoreSnapshotHandler(*this);
    1118     }
    1119 
    1120     ComObjPtr<Snapshot> m_pSnapshot;
    1121     ULONG m_ulStateFileSizeMB;
     1124        pMachine->restoreSnapshotHandler(*this);
     1125    }
     1126
     1127    ULONG       m_ulStateFileSizeMB;
    11221128};
    11231129
     
    14741480    /* create and start the task on a separate thread (note that it will not
    14751481     * start working until we release alock) */
    1476     RestoreSnapshotTask *task = new RestoreSnapshotTask(this, pSnapshot, progress, ulStateFileSizeMB);
     1482    RestoreSnapshotTask *task = new RestoreSnapshotTask(this,
     1483                                                        progress,
     1484                                                        pSnapshot,
     1485                                                        ulStateFileSizeMB);
    14771486    int vrc = RTThreadCreate(NULL,
    14781487                             taskHandler,
     
    15091518
    15101519/* static */
    1511 DECLCALLBACK(int) SessionMachine::taskHandler (RTTHREAD /* thread */, void *pvUser)
     1520DECLCALLBACK(int) SessionMachine::taskHandler(RTTHREAD /* thread */, void *pvUser)
    15121521{
    15131522    AssertReturn(pvUser, VERR_INVALID_POINTER);
    15141523
    1515     Task *task = static_cast <Task *> (pvUser);
     1524    SnapshotTask *task = static_cast<SnapshotTask*>(pvUser);
    15161525    task->handler();
    15171526
     
    16091618struct MediumDiscardRec
    16101619{
    1611     MediumDiscardRec() : chain (NULL) {}
    1612 
    1613     MediumDiscardRec (const ComObjPtr<Medium> &aHd,
    1614                       Medium::MergeChain *aChain = NULL)
    1615         : hd (aHd), chain (aChain) {}
    1616 
    1617     MediumDiscardRec (const ComObjPtr<Medium> &aHd,
    1618                       Medium::MergeChain *aChain,
    1619                       const ComObjPtr<Medium> &aReplaceHd,
    1620                       const ComObjPtr<MediumAttachment> &aReplaceHda,
    1621                       const Guid &aSnapshotId)
    1622         : hd (aHd), chain (aChain)
    1623         , replaceHd (aReplaceHd), replaceHda (aReplaceHda)
    1624         , snapshotId (aSnapshotId) {}
     1620    MediumDiscardRec()
     1621        : chain(NULL)
     1622    {}
     1623
     1624    MediumDiscardRec(const ComObjPtr<Medium> &aHd,
     1625                     Medium::MergeChain *aChain = NULL)
     1626        : hd(aHd),
     1627          chain(aChain)
     1628    {}
     1629
     1630    MediumDiscardRec(const ComObjPtr<Medium> &aHd,
     1631                     Medium::MergeChain *aChain,
     1632                     const ComObjPtr<Medium> &aReplaceHd,
     1633                     const ComObjPtr<MediumAttachment> &aReplaceHda,
     1634                     const Guid &aSnapshotId)
     1635        : hd(aHd),
     1636          chain (aChain),
     1637          replaceHd(aReplaceHd),
     1638          replaceHda(aReplaceHda),
     1639          snapshotId(aSnapshotId)
     1640    {}
    16251641
    16261642    ComObjPtr<Medium> hd;
     
    16551671        /* we might have been uninitialized because the session was accidentally
    16561672         * closed by the client, so don't assert */
    1657         aTask.progress->notifyComplete(E_FAIL,
    1658                                        COM_IIDOF(IMachine),
    1659                                        getComponentName(),
    1660                                        tr("The session has been accidentally closed"));
     1673        aTask.pProgress->notifyComplete(E_FAIL,
     1674                                        COM_IIDOF(IMachine),
     1675                                        getComponentName(),
     1676                                        tr("The session has been accidentally closed"));
    16611677        LogFlowThisFuncLeave();
    16621678        return;
     
    16661682    AutoMultiWriteLock3 alock(this->lockHandle(),
    16671683                              this->snapshotsTreeLockHandle(),
    1668                               aTask.snapshot->lockHandle());
    1669 
    1670     ComPtr<SnapshotMachine> sm = aTask.snapshot->getSnapshotMachine();
     1684                              aTask.pSnapshot->lockHandle());
     1685
     1686    ComPtr<SnapshotMachine> sm = aTask.pSnapshot->getSnapshotMachine();
    16711687    /* no need to lock the snapshot machine since it is const by definiton */
    16721688
     
    16741690
    16751691    /* save the snapshot ID (for callbacks) */
    1676     Guid snapshotId = aTask.snapshot->getId();
     1692    Guid snapshotId = aTask.pSnapshot->getId();
    16771693
    16781694    MediumDiscardRecList toDiscard;
     
    17051721                /* skip writethrough hard disks */
    17061722                Assert(hd->type() == MediumType_Writethrough);
    1707                 rc = aTask.progress->SetNextOperation(BstrFmt(tr("Skipping writethrough hard disk '%s'"),
    1708                                                               hd->base()->name().raw()),
    1709                                                       1); // weight
     1723                rc = aTask.pProgress->SetNextOperation(BstrFmt(tr("Skipping writethrough hard disk '%s'"),
     1724                                                               hd->base()->name().raw()),
     1725                                                       1); // weight
    17101726                CheckComRCThrowRC(rc);
    17111727                continue;
     
    17961812
    17971813        {
    1798             ComObjPtr<Snapshot> parentSnapshot = aTask.snapshot->parent();
    1799             Utf8Str stateFilePath = aTask.snapshot->stateFilePath();
     1814            ComObjPtr<Snapshot> parentSnapshot = aTask.pSnapshot->parent();
     1815            Utf8Str stateFilePath = aTask.pSnapshot->stateFilePath();
    18001816
    18011817            /* Note that discarding the snapshot will deassociate it from the
    18021818             * hard disks which will allow the merge+delete operation for them*/
    1803             aTask.snapshot->beginDiscard();
    1804             aTask.snapshot->uninit();
     1819            aTask.pSnapshot->beginDiscard();
     1820            aTask.pSnapshot->uninit();
    18051821
    18061822            rc = saveAllSnapshots();
     
    18121828            if (!stateFilePath.isEmpty())
    18131829            {
    1814                 aTask.progress->SetNextOperation(Bstr(tr("Discarding the execution state")),
    1815                                                  1);        // weight
     1830                aTask.pProgress->SetNextOperation(Bstr(tr("Discarding the execution state")),
     1831                                                  1);        // weight
    18161832
    18171833                RTFileDelete(stateFilePath.c_str());
     
    18461862             it != toDiscard.end();)
    18471863        {
    1848             rc = it->hd->discard (aTask.progress, it->chain);
     1864            rc = it->hd->discard(aTask.pProgress, it->chain);
    18491865            CheckComRCBreakRC(rc);
    18501866
     
    18851901    }
    18861902
    1887     if (!aTask.subTask || FAILED(rc))
    1888     {
    1889         if (!aTask.subTask)
    1890         {
    1891             /* saveSettings() below needs a VirtualBox write lock and we need to
    1892              * leave this object's lock to do this to follow the {parent-child}
    1893              * locking rule. This is the last chance to do that while we are
    1894              * still in a protective state which allows us to temporarily leave
    1895              * the lock */
    1896             alock.unlock();
    1897             AutoWriteLock vboxLock(mParent);
    1898             alock.lock();
    1899 
    1900             /* preserve existing error info */
    1901             ErrorInfoKeeper eik;
    1902 
    1903             /* restore the machine state */
    1904             setMachineState(aTask.state);
    1905             updateMachineStateOnClient();
    1906 
    1907             if (settingsChanged)
    1908                 saveSettings(SaveS_InformCallbacksAnyway);
    1909         }
     1903    if (FAILED(rc))
     1904    {
     1905        /* saveSettings() below needs a VirtualBox write lock and we need to
     1906         * leave this object's lock to do this to follow the {parent-child}
     1907         * locking rule. This is the last chance to do that while we are
     1908         * still in a protective state which allows us to temporarily leave
     1909         * the lock */
     1910        alock.unlock();
     1911        AutoWriteLock vboxLock(mParent);
     1912        alock.lock();
     1913
     1914        /* preserve existing error info */
     1915        ErrorInfoKeeper eik;
     1916
     1917        /* restore the machine state */
     1918        setMachineState(aTask.machineStateBackup);
     1919        updateMachineStateOnClient();
     1920
     1921        if (settingsChanged)
     1922            saveSettings(SaveS_InformCallbacksAnyway);
    19101923
    19111924        /* set the result (this will try to fetch current error info on failure) */
    1912         aTask.progress->notifyComplete (rc);
     1925        aTask.pProgress->notifyComplete(rc);
    19131926    }
    19141927
    19151928    if (SUCCEEDED(rc))
    1916         mParent->onSnapshotDiscarded (mData->mUuid, snapshotId);
    1917 
    1918     LogFlowThisFunc(("Done discarding snapshot (rc=%08X)\n", rc));
     1929        mParent->onSnapshotDeleted(mData->mUuid, snapshotId);
     1930
     1931    LogFlowThisFunc(("Done deleting snapshot (rc=%08X)\n", rc));
    19191932    LogFlowThisFuncLeave();
    19201933}
     
    19371950        /* we might have been uninitialized because the session was accidentally
    19381951         * closed by the client, so don't assert */
    1939         aTask.progress->notifyComplete(E_FAIL,
    1940                                        COM_IIDOF(IMachine),
    1941                                        getComponentName(),
    1942                                        tr("The session has been accidentally closed"));
     1952        aTask.pProgress->notifyComplete(E_FAIL,
     1953                                        COM_IIDOF(IMachine),
     1954                                        getComponentName(),
     1955                                        tr("The session has been accidentally closed"));
    19431956
    19441957        LogFlowThisFuncLeave();
     
    19701983        /* discard the saved state file if the machine was Saved prior to this
    19711984         * operation */
    1972         if (aTask.state == MachineState_Saved)
     1985        if (aTask.machineStateBackup == MachineState_Saved)
    19731986        {
    19741987            Assert(!mSSData->mStateFilePath.isEmpty());
    19751988            RTFileDelete(mSSData->mStateFilePath.c_str());
    19761989            mSSData->mStateFilePath.setNull();
    1977             aTask.modifyLastState(MachineState_PoweredOff);
     1990            aTask.modifyBackedUpState(MachineState_PoweredOff);
    19781991            rc = saveStateSettings(SaveSTS_StateFilePath);
    19791992            CheckComRCThrowRC(rc);
     
    19841997
    19851998        {
    1986             AutoReadLock snapshotLock(aTask.m_pSnapshot);
     1999            AutoReadLock snapshotLock(aTask.pSnapshot);
    19872000
    19882001            /* remember the timestamp of the snapshot we're restoring from */
    1989             snapshotTimeStamp = aTask.m_pSnapshot->getTimeStamp();
    1990 
    1991             ComPtr<SnapshotMachine> pSnapshotMachine(aTask.m_pSnapshot->getSnapshotMachine());
     2002            snapshotTimeStamp = aTask.pSnapshot->getTimeStamp();
     2003
     2004            ComPtr<SnapshotMachine> pSnapshotMachine(aTask.pSnapshot->getSnapshotMachine());
    19922005
    19932006            /* copy all hardware data from the snapshot */
     
    20052018
    20062019            rc = createImplicitDiffs(mUserData->mSnapshotFolderFull,
    2007                                      aTask.progress,
     2020                                     aTask.pProgress,
    20082021                                     1,
    20092022                                     false /* aOnline */);
     
    20222035            Assert(mSSData->mStateFilePath.isEmpty());
    20232036
    2024             if (!aTask.m_pSnapshot->stateFilePath().isEmpty())
     2037            if (!aTask.pSnapshot->stateFilePath().isEmpty())
    20252038            {
    2026                 Utf8Str snapStateFilePath = aTask.m_pSnapshot->stateFilePath();
     2039                Utf8Str snapStateFilePath = aTask.pSnapshot->stateFilePath();
    20272040
    20282041                Utf8Str stateFilePath = Utf8StrFmt("%ls%c{%RTuuid}.sav",
     
    20342047                                  snapStateFilePath.raw(), stateFilePath.raw()));
    20352048
    2036                 aTask.progress->SetNextOperation(Bstr(tr("Restoring the execution state")),
    2037                                                  aTask.m_ulStateFileSizeMB);        // weight
     2049                aTask.pProgress->SetNextOperation(Bstr(tr("Restoring the execution state")),
     2050                                                  aTask.m_ulStateFileSizeMB);        // weight
    20382051
    20392052                /* leave the lock before the potentially lengthy operation */
     
    20462059                                       0,
    20472060                                       progressCallback,
    2048                                        aTask.progress);
     2061                                       aTask.pProgress);
    20492062
    20502063                alock.enter();
     
    20612074            }
    20622075
    2063             LogFlowThisFunc(("Setting new current snapshot {%RTuuid}\n", aTask.m_pSnapshot->getId().raw()));
     2076            LogFlowThisFunc(("Setting new current snapshot {%RTuuid}\n", aTask.pSnapshot->getId().raw()));
    20642077            /* make the snapshot we restored from the current snapshot */
    2065             mData->mCurrentSnapshot = aTask.m_pSnapshot;
     2078            mData->mCurrentSnapshot = aTask.pSnapshot;
    20662079        }
    20672080
     
    21722185        {
    21732186            /* restore the machine state */
    2174             setMachineState(aTask.state);
     2187            setMachineState(aTask.machineStateBackup);
    21752188            updateMachineStateOnClient();
    21762189        }
     
    21782191
    21792192    /* set the result (this will try to fetch current error info on failure) */
    2180     aTask.progress->notifyComplete(rc);
     2193    aTask.pProgress->notifyComplete(rc);
    21812194
    21822195    if (SUCCEEDED(rc))
    2183         mParent->onSnapshotDiscarded(mData->mUuid, Guid());
     2196        mParent->onSnapshotDeleted(mData->mUuid, Guid());
    21842197
    21852198    LogFlowThisFunc(("Done restoring snapshot (rc=%08X)\n", rc));
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r24273 r24298  
    24912491void VirtualBox::onSnapshotTaken (const Guid &aMachineId, const Guid &aSnapshotId)
    24922492{
    2493     postEvent (new SnapshotEvent (this, aMachineId, aSnapshotId, SnapshotEvent::Taken));
     2493    postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId, SnapshotEvent::Taken));
    24942494}
    24952495
     
    24972497 *  @note Doesn't lock any object.
    24982498 */
    2499 void VirtualBox::onSnapshotDiscarded (const Guid &aMachineId, const Guid &aSnapshotId)
    2500 {
    2501     postEvent (new SnapshotEvent (this, aMachineId, aSnapshotId, SnapshotEvent::Discarded));
     2499void VirtualBox::onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId)
     2500{
     2501    postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId, SnapshotEvent::Discarded));
    25022502}
    25032503
     
    25052505 *  @note Doesn't lock any object.
    25062506 */
    2507 void VirtualBox::onSnapshotChange (const Guid &aMachineId, const Guid &aSnapshotId)
    2508 {
    2509     postEvent (new SnapshotEvent (this, aMachineId, aSnapshotId, SnapshotEvent::Changed));
     2507void VirtualBox::onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId)
     2508{
     2509    postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId, SnapshotEvent::Changed));
    25102510}
    25112511
     
    25132513struct GuestPropertyEvent : public VirtualBox::CallbackEvent
    25142514{
    2515     GuestPropertyEvent (VirtualBox *aVBox, const Guid &aMachineId,
    2516                         IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags)
    2517         : CallbackEvent (aVBox), machineId (aMachineId)
    2518         , name (aName), value (aValue), flags(aFlags)
    2519         {}
    2520 
    2521     void handleCallback (const ComPtr<IVirtualBoxCallback> &aCallback)
    2522     {
    2523         LogFlow (("OnGuestPropertyChange: machineId={%RTuuid}, name='%ls', value='%ls', flags='%ls'\n",
    2524                   machineId.ptr(), name.raw(), value.raw(), flags.raw()));
     2515    GuestPropertyEvent(VirtualBox *aVBox, const Guid &aMachineId,
     2516                       IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags)
     2517        : CallbackEvent(aVBox),
     2518          machineId(aMachineId),
     2519          name(aName),
     2520          value(aValue),
     2521          flags(aFlags)
     2522    {}
     2523
     2524    void handleCallback(const ComPtr<IVirtualBoxCallback> &aCallback)
     2525    {
     2526        LogFlow(("OnGuestPropertyChange: machineId={%RTuuid}, name='%ls', value='%ls', flags='%ls'\n",
     2527                 machineId.ptr(), name.raw(), value.raw(), flags.raw()));
    25252528        aCallback->OnGuestPropertyChange (machineId.toUtf16(), name, value, flags);
    25262529    }
     
    25332536 *  @note Doesn't lock any object.
    25342537 */
    2535 void VirtualBox::onGuestPropertyChange (const Guid &aMachineId, IN_BSTR aName,
    2536                                         IN_BSTR aValue, IN_BSTR aFlags)
    2537 {
    2538     postEvent (new GuestPropertyEvent (this, aMachineId, aName, aValue, aFlags));
     2538void VirtualBox::onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName,
     2539                                       IN_BSTR aValue, IN_BSTR aFlags)
     2540{
     2541    postEvent(new GuestPropertyEvent(this, aMachineId, aName, aValue, aFlags));
    25392542}
    25402543
  • trunk/src/VBox/Main/include/MachineImpl.h

    r24295 r24298  
    10341034    };
    10351035
    1036     struct Task;
     1036    struct SnapshotTask;
    10371037    struct DeleteSnapshotTask;
    10381038    struct RestoreSnapshotTask;
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r24273 r24298  
    196196    void updateClientWatcher();
    197197
    198     void onMachineStateChange (const Guid &aId, MachineState_T aState);
    199     void onMachineDataChange (const Guid &aId);
     198    void onMachineStateChange(const Guid &aId, MachineState_T aState);
     199    void onMachineDataChange(const Guid &aId);
    200200    BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
    201201                              Bstr &aError);
    202202    void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
    203     void onMachineRegistered (const Guid &aId, BOOL aRegistered);
    204     void onSessionStateChange (const Guid &aId, SessionState_T aState);
    205 
    206     void onSnapshotTaken (const Guid &aMachineId, const Guid &aSnapshotId);
    207     void onSnapshotDiscarded (const Guid &aMachineId, const Guid &aSnapshotId);
    208     void onSnapshotChange (const Guid &aMachineId, const Guid &aSnapshotId);
    209     void onGuestPropertyChange (const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
    210                                 IN_BSTR aFlags);
     203    void onMachineRegistered(const Guid &aId, BOOL aRegistered);
     204    void onSessionStateChange(const Guid &aId, SessionState_T aState);
     205
     206    void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
     207    void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
     208    void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
     209    void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
     210                               IN_BSTR aFlags);
    211211
    212212    ComObjPtr<GuestOSType> getUnknownOSType();
Note: See TracChangeset for help on using the changeset viewer.

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