VirtualBox

Ignore:
Timestamp:
Nov 9, 2010 5:51:38 PM (14 years ago)
Author:
vboxsync
Message:

Main: rework 'save registries' logic to ensure that all media registries get saved, not just the global VirtualBox.xml file

File:
1 edited

Legend:

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

    r33904 r33921  
    33233323    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    33243324
    3325     // if this becomes true then we need to call saveSettings in the end
    3326     // @todo r=dj there is no error handling so far...
    3327     bool fNeedsMachineSaveSettings = false,
    3328          fNeedsGlobalSaveSettings = false;
    3329 
    33303325    // request the host lock first, since might be calling Host methods for getting host drives;
    33313326    // next, protect the media tree all the while we're in here, as well as our member variables
     
    33363331    HRESULT rc = checkStateDependency(MutableStateDep);
    33373332    if (FAILED(rc)) return rc;
     3333
     3334    GuidList llRegistriesThatNeedSaving;
    33383335
    33393336    /// @todo NEWMEDIA implicit machine registration
     
    35963593                        strFullSnapshotFolder.append(RTPATH_SLASH_STR),
    35973594                        medium->getFirstRegistryMachineId(),         // store this diff in the same registry as the parent
    3598                         &fNeedsGlobalSaveSettings);
     3595                        &llRegistriesThatNeedSaving);
    35993596        if (FAILED(rc)) return rc;
    36003597
     
    36283625                                               NULL /* aProgress */,
    36293626                                               true /* aWait */,
    3630                                                &fNeedsGlobalSaveSettings);
     3627                                               &llRegistriesThatNeedSaving);
    36313628
    36323629                alock.enter();
     
    36713668
    36723669        // and decide which medium registry to use now that the medium is attached:
     3670        Guid uuid;
    36733671        if (mData->pMachineConfigFile->canHaveOwnMediaRegistry())
    36743672            // machine XML is VirtualBox 4.0 or higher:
    3675             medium->addRegistry(getId(),         // machine UUID
    3676                                 &fNeedsMachineSaveSettings);
     3673            uuid = getId();     // machine UUID
    36773674        else
    3678             medium->addRegistry(mParent->getGlobalRegistryId(), // VirtualBox global registry UUID
    3679                                 &fNeedsGlobalSaveSettings);
     3675            uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID
     3676
     3677        if (medium->addRegistry(uuid))
     3678            // registry actually changed:
     3679            mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid);
    36803680    }
    36813681
     
    36873687    mediumLock.release();
    36883688    treeLock.leave();
    3689 
    3690     if (fNeedsMachineSaveSettings)
    3691         saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force);
    3692 
    3693     if (fNeedsGlobalSaveSettings)
    3694     {
    3695         // save the global settings; for that we should hold only the VirtualBox lock
    3696         alock.release();
    3697 
    3698         AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
    3699         mParent->saveSettings();
    3700     }
     3689    alock.release();
     3690
     3691    mParent->saveRegistries(llRegistriesThatNeedSaving);
    37013692
    37023693    return rc;
     
    37143705    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    37153706
    3716     bool fNeedsSaveSettings = false;
     3707    GuidList llRegistriesThatNeedSaving;
    37173708
    37183709    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    37373728                        aDevice, aControllerPort, aControllerName);
    37383729
    3739     rc = detachDevice(pAttach, alock, NULL /* pSnapshot */, &fNeedsSaveSettings);
    3740 
    3741     if (fNeedsSaveSettings)
    3742     {
    3743         bool fNeedsGlobalSaveSettings = false;
    3744         saveSettings(&fNeedsGlobalSaveSettings);
    3745 
    3746         if (fNeedsGlobalSaveSettings)
    3747         {
    3748             // save the global settings; for that we should hold only the VirtualBox lock
    3749             alock.release();
    3750             AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS);
    3751             mParent->saveSettings();
    3752         }
    3753     }
    3754 
    3755     return S_OK;
     3730    rc = detachDevice(pAttach, alock, NULL /* pSnapshot */, &llRegistriesThatNeedSaving);
     3731
     3732    alock.release();
     3733
     3734    if (SUCCEEDED(rc))
     3735        rc = mParent->saveRegistries(llRegistriesThatNeedSaving);
     3736
     3737    return rc;
    37563738}
    37573739
     
    38673849    mMediaData.backup();
    38683850
    3869     bool fNeedsMachineSaveSettings = false,
    3870          fNeedsGlobalSaveSettings = false;
     3851    GuidList llRegistriesThatNeedSaving;
    38713852
    38723853    {
     
    38853866
    38863867            // and decide which medium registry to use now that the medium is attached:
     3868            Guid uuid;
    38873869            if (mData->pMachineConfigFile->canHaveOwnMediaRegistry())
    3888                 // machine XML is VirtualBox 4.0 or higher: machine UUID
    3889                 pMedium->addRegistry(getId(),
    3890                                      &fNeedsMachineSaveSettings);
     3870                // machine XML is VirtualBox 4.0 or higher:
     3871                uuid = getId();     // machine UUID
    38913872            else
    3892                 // VirtualBox global registry UUID
    3893                 pMedium->addRegistry(mParent->getGlobalRegistryId(),
    3894                                      &fNeedsGlobalSaveSettings);
     3873                uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID
     3874
     3875            if (pMedium->addRegistry(uuid))
     3876                // registry actually changed:
     3877                mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid);
    38953878        }
    38963879
     
    39273910    multiLock.release();
    39283911
    3929     if (fNeedsMachineSaveSettings)
    3930     {
    3931         AutoWriteLock machineLock(this COMMA_LOCKVAL_SRC_POS);
    3932         saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force);
    3933     }
    3934 
    3935     if (fNeedsGlobalSaveSettings)
    3936     {
    3937         // save the global settings; for that we should hold only the VirtualBox lock
    3938         AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
    3939         mParent->saveSettings();
    3940     }
     3912    mParent->saveRegistries(llRegistriesThatNeedSaving);
    39413913
    39423914    return rc;
     
    43474319    std::list<Utf8Str>          llFilesToDelete;
    43484320    ComObjPtr<Progress>         pProgress;
    4349     bool                        fNeedsGlobalSaveSettings;
     4321    GuidList                    llRegistriesThatNeedSaving;
    43504322};
    43514323
     
    43734345    pTask->llFilesToDelete = mData->llFilesToDelete;            // saved states pushed here by Unregister()
    43744346
    4375     pTask->fNeedsGlobalSaveSettings = false;
    43764347    for (size_t i = 0; i < sfaMedia.size(); ++i)
    43774348    {
     
    43844355        // close the medium now; if that succeeds, then that means the medium is no longer
    43854356        // in use and we can add it to the list of files to delete
    4386         rc = pMedium->close(&pTask->fNeedsGlobalSaveSettings,
     4357        rc = pMedium->close(&pTask->llRegistriesThatNeedSaving,
    43874358                            mediumAutoCaller);
    43884359        if (SUCCEEDED(rc))
     
    45494520    alock.release();
    45504521
    4551     if (task.fNeedsGlobalSaveSettings)
    4552     {
    4553         AutoWriteLock vboxlock(mParent COMMA_LOCKVAL_SRC_POS);
    4554         mParent->saveSettings();
    4555     }
     4522    mParent->saveRegistries(task.llRegistriesThatNeedSaving);
    45564523
    45574524    return S_OK;
     
    74657432            if (puuidRegistry)
    74667433                // caller wants registry ID to be set on all attached media (OVF import case)
    7467                 medium->addRegistry(*puuidRegistry,
    7468                                     NULL /* pfNeedsSaveSettings */);
     7434                medium->addRegistry(*puuidRegistry);
    74697435        }
    74707436
     
    84588424 *                          attached).
    84598425 * @param aOnline           Whether the VM was online prior to this operation.
    8460  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    8461  *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
     8426 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs to receive the registry IDs that need saving
    84628427 *
    84638428 * @note The progress object is not marked as completed, neither on success nor
     
    84698434                                     ULONG aWeight,
    84708435                                     bool aOnline,
    8471                                      bool *pfNeedsSaveSettings)
     8436                                     GuidList *pllRegistriesThatNeedSaving)
    84728437{
    84738438    LogFlowThisFunc(("aOnline=%d\n", aOnline));
     
    85948559                            strFullSnapshotFolder.append(RTPATH_SLASH_STR),
    85958560                            pMedium->getFirstRegistryMachineId(),        // store the diff in the same registry as the parent
    8596                             pfNeedsSaveSettings);
     8561                            pllRegistriesThatNeedSaving);
    85978562            if (FAILED(rc)) throw rc;
    85988563
     
    86188583                                            NULL /* aProgress */,
    86198584                                            true /* aWait */,
    8620                                             pfNeedsSaveSettings);
     8585                                            pllRegistriesThatNeedSaving);
    86218586            alock.enter();
    86228587            if (FAILED(rc)) throw rc;
     
    86658630        MultiResult mrc = rc;
    86668631
    8667         mrc = deleteImplicitDiffs(pfNeedsSaveSettings);
     8632        mrc = deleteImplicitDiffs(pllRegistriesThatNeedSaving);
    86688633    }
    86698634
     
    86838648 * @note Locks this object for writing.
    86848649 */
    8685 HRESULT Machine::deleteImplicitDiffs(bool *pfNeedsSaveSettings)
     8650HRESULT Machine::deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving)
    86868651{
    86878652    AutoCaller autoCaller(this);
     
    87618726
    87628727            rc = hd->deleteStorage(NULL /*aProgress*/, true /*aWait*/,
    8763                                    pfNeedsSaveSettings);
     8728                                   pllRegistriesThatNeedSaving);
    87648729            AssertMsg(SUCCEEDED(rc), ("rc=%Rhrc it=%s hd=%s\n", rc, (*it)->getLogName(), hd->getLocationFull().c_str() ));
    87658730            mrc = rc;
     
    87698734
    87708735        if (mData->mMachineState == MachineState_SettingUp)
    8771         {
    87728736            setMachineState(oldState);
    8773         }
    87748737    }
    87758738
     
    88738836                              AutoWriteLock &writeLock,
    88748837                              Snapshot *pSnapshot,
    8875                               bool *pfNeedsSaveSettings)
     8838                              GuidList *pllRegistriesThatNeedSaving)
    88768839{
    88778840    ComObjPtr<Medium> oldmedium = pAttach->getMedium();
     
    88988861
    88998862        HRESULT rc = oldmedium->deleteStorage(NULL /*aProgress*/, true /*aWait*/,
    8900                                               pfNeedsSaveSettings);
     8863                                              pllRegistriesThatNeedSaving);
    89018864
    89028865        writeLock.acquire();
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