VirtualBox

Changeset 91743 in vbox for trunk


Ignore:
Timestamp:
Oct 14, 2021 8:04:27 PM (3 years ago)
Author:
vboxsync
Message:

Main/Machine: Release lock while waiting in Machine::i_ensureNoStateDependencies. Needs passing the lock from the caller (and a bit of multiple lock untangling). Regression introduced in r76471. bugref:10121

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImpl.h

    r91476 r91743  
    632632    Machine *i_getMachine();
    633633
    634     void i_ensureNoStateDependencies();
     634    void i_ensureNoStateDependencies(AutoWriteLock &alock);
    635635
    636636    virtual HRESULT i_setMachineState(MachineState_T aMachineState);
     
    682682
    683683    HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
    684     HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
     684    HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, AutoWriteLock &alock, int aFlags = 0);
    685685
    686686    void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r91718 r91743  
    829829        {
    830830            AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    831             i_saveSettings(NULL, Machine::SaveS_Force);
     831            i_saveSettings(NULL, alock, Machine::SaveS_Force);
    832832        }
    833833    }
     
    16101610    /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    16111611    if (Global::IsOnline(mData->mMachineState))
    1612         i_saveSettings(NULL);
     1612        i_saveSettings(NULL, alock);
    16131613
    16141614    return S_OK;
     
    26642664    /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    26652665    if (Global::IsOnline(mData->mMachineState))
    2666         i_saveSettings(NULL);
     2666        i_saveSettings(NULL, alock);
    26672667
    26682668    return S_OK;
     
    26952695    /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    26962696    if (Global::IsOnline(mData->mMachineState))
    2697         i_saveSettings(NULL);
     2697        i_saveSettings(NULL, alock);
    26982698
    26992699    return S_OK;
     
    27272727    /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    27282728    if (Global::IsOnline(mData->mMachineState))
    2729         i_saveSettings(NULL);
     2729        i_saveSettings(NULL, alock);
    27302730
    27312731    return S_OK;
     
    48014801        // extradata items at all (unlike all other settings), so the old/new
    48024802        // settings comparison would give a wrong result!
    4803         i_saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force);
     4803        i_saveSettings(&fNeedsGlobalSaveSettings, alock, SaveS_Force);
    48044804
    48054805        if (fNeedsGlobalSaveSettings)
     
    48384838    /* save all VM data excluding snapshots */
    48394839    bool fNeedsGlobalSaveSettings = false;
    4840     rc = i_saveSettings(&fNeedsGlobalSaveSettings);
     4840    rc = i_saveSettings(&fNeedsGlobalSaveSettings, mlock);
    48414841    mlock.release();
    48424842
     
    49314931
    49324932    // wait for state dependents to drop to zero
    4933     i_ensureNoStateDependencies();
     4933    i_ensureNoStateDependencies(alock);
    49344934
    49354935    if (!mData->mAccessible)
     
    64116411    /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    64126412    if (Global::IsOnline(mData->mMachineState))
    6413         i_saveSettings(NULL);
     6413        i_saveSettings(NULL, alock);
    64146414
    64156415    return S_OK;
     
    64486448    /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    64496449    if (Global::IsOnline(mData->mMachineState))
    6450         i_saveSettings(NULL);
     6450        i_saveSettings(NULL, alock);
    64516451
    64526452    return S_OK;
     
    78837883
    78847884    /* wait for state dependents to drop to zero */
    7885     i_ensureNoStateDependencies();
     7885    i_ensureNoStateDependencies(alock);
    78867886
    78877887    if (!mData->mAccessible)
     
    79077907       )
    79087908    {
    7909         rc = i_saveSettings(NULL);
     7909        rc = i_saveSettings(NULL, alock);
    79107910                // no need to check whether VirtualBox.xml needs saving too since
    79117911                // we can't have a machine XML file rename pending
     
    84208420 * control to the caller.
    84218421 *
    8422  * @note Locks this object for writing. The lock will be released while waiting
    8423  *       (if necessary).
     8422 * @note Receives a lock to this object for writing. The lock will be released
     8423 *       while waiting (if necessary).
    84248424 *
    84258425 * @warning To be used only in methods that change the machine state!
    84268426 */
    8427 void Machine::i_ensureNoStateDependencies()
     8427void Machine::i_ensureNoStateDependencies(AutoWriteLock &alock)
    84288428{
    84298429    AssertReturnVoid(isWriteLockOnCurrentThread());
    8430 
    8431     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    84328430
    84338431    /* Wait for all state dependents if necessary */
     
    84778475
    84788476    /* wait for state dependents to drop to zero */
    8479     i_ensureNoStateDependencies();
     8477    i_ensureNoStateDependencies(alock);
    84808478
    84818479    MachineState_T const enmOldState = mData->mMachineState;
     
    98669864 */
    98679865HRESULT Machine::i_saveSettings(bool *pfNeedsGlobalSaveSettings,
     9866                                AutoWriteLock &alock,
    98689867                                int  aFlags /*= 0*/)
    98699868{
     
    98749873    /* make sure child objects are unable to modify the settings while we are
    98759874     * saving them */
    9876     i_ensureNoStateDependencies();
     9875    i_ensureNoStateDependencies(alock);
    98779876
    98789877    AssertReturn(!i_isSnapshotMachine(),
     
    1299912998
    1300012999            /* save all VM settings */
    13001             rc = i_saveSettings(NULL);
     13000            rc = i_saveSettings(NULL, alock);
    1300213001                    // no need to check whether VirtualBox.xml needs saving also since
    1300313002                    // we can't have a name change pending at this point
  • trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp

    r91503 r91743  
    16001600            /* save all VM data */
    16011601            bool fNeedsGlobalSaveSettings = false;
    1602             rc = d->pTrgMachine->i_saveSettings(&fNeedsGlobalSaveSettings, Machine::SaveS_Force);
     1602            rc = d->pTrgMachine->i_saveSettings(&fNeedsGlobalSaveSettings, trgLock, Machine::SaveS_Force);
    16031603            if (FAILED(rc)) throw rc;
    16041604            /* Release all locks */
  • trunk/src/VBox/Main/src-server/RecordingSettingsImpl.cpp

    r82968 r91743  
    239239        else
    240240        {
    241             AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     241            AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // pMachine is const, needs no locking
    242242            m->pMachine->i_setModified(Machine::IsModified_Recording);
    243243
     
    248248            /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    249249            if (Global::IsOnline(m->pMachine->i_getMachineState()))
    250                 rc = m->pMachine->i_saveSettings(NULL);
     250                rc = m->pMachine->i_saveSettings(NULL, mlock);
    251251        }
    252252    }
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r91718 r91743  
    13951395HRESULT SnapshotMachine::i_onSnapshotChange(Snapshot *aSnapshot)
    13961396{
    1397     AutoMultiWriteLock2 mlock(this, aSnapshot COMMA_LOCKVAL_SRC_POS);
     1397    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1398    AutoWriteLock slock(aSnapshot COMMA_LOCKVAL_SRC_POS);
    13981399    Guid uuidMachine(mData->mUuid),
    13991400         uuidSnapshot(aSnapshot->i_getId());
     
    14041405     * related to the current state. */
    14051406    mMachine->i_setModified(Machine::IsModified_Snapshots, false /* fAllowStateModification */);
     1407    slock.release();
    14061408    HRESULT rc = mMachine->i_saveSettings(&fNeedsGlobalSaveSettings,
     1409                                          alock,
    14071410                                          SaveS_Force);        // we know we need saving, no need to check
    1408     mlock.release();
     1411    alock.release();
    14091412
    14101413    if (SUCCEEDED(rc) && fNeedsGlobalSaveSettings)
     
    17541757        /* save settings to ensure current changes are committed and
    17551758         * hard disks are fixed up */
    1756         rc = i_saveSettings(NULL);
     1759        rc = i_saveSettings(NULL, alock);
    17571760            // no need to check for whether VirtualBox.xml needs changing since
    17581761            // we can't have a machine XML rename pending at this point
     
    21092112            flSaveSettings |= SaveS_ResetCurStateModified;
    21102113
    2111         rc = i_saveSettings(NULL, flSaveSettings);
     2114        rc = i_saveSettings(NULL, alock, flSaveSettings);
    21122115    }
    21132116
     
    25082511        // save machine settings, reset the modified flag and commit;
    25092512        bool fNeedsGlobalSaveSettings = false;
    2510         rc = i_saveSettings(&fNeedsGlobalSaveSettings,
     2513        rc = i_saveSettings(&fNeedsGlobalSaveSettings, alock,
    25112514                            SaveS_ResetCurStateModified);
    25122515        if (FAILED(rc))
     
    27202723        if (mData->flModifications)
    27212724        {
    2722             rc = i_saveSettings(NULL);
     2725            snapshotLock.release();
     2726            rc = i_saveSettings(NULL, alock);
     2727            snapshotLock.acquire();
    27232728                // no need to change for whether VirtualBox.xml needs saving since
    27242729                // we can't have a machine XML rename pending at this point
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r91503 r91743  
    54805480                    continue;
    54815481                AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS);
    5482                 rc = pMachine->i_saveSettings(&fNeedsGlobalSettings,
     5482                rc = pMachine->i_saveSettings(&fNeedsGlobalSettings, mlock,
    54835483                                              Machine::SaveS_Force);           // caller said save, so stop arguing
    54845484            }
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