VirtualBox

Changeset 31814 in vbox


Ignore:
Timestamp:
Aug 20, 2010 12:38:56 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
65012
Message:

Main: cleanup medium objects from media registry when machine object is uninitialized (fixes totally misleading error reports when machine XML cannot be loaded because the actually relevant error gets overwritten)

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

Legend:

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

    r31746 r31814  
    755755    }
    756756
     757    // uninit media from this machine's media registry
     758    mParent->unregisterMachineMedia(getId());
     759
    757760    /* the lock is no more necessary (SessionMachine is uninitialized) */
    758761    alock.leave();
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31615 r31814  
    33473347
    33483348    if (strConflict.length())
    3349     {
    33503349        return setError(E_INVALIDARG,
    33513350                        tr("Cannot register the hard disk '%s' {%RTuuid} because a %s already exists"),
     
    33543353                        strConflict.c_str(),
    33553354                        m->strSettingsFilePath.c_str());
    3356     }
    33573355
    33583356    // store base (root) hard disks in the list
     
    35373535
    35383536    return rc;
     3537}
     3538
     3539/**
     3540 * Little helper called from unregisterMachineMedia() to recursively add media to the given list,
     3541 * with children appearing before their parents.
     3542 * @param llMedia
     3543 * @param pMedium
     3544 */
     3545void VirtualBox::pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium)
     3546{
     3547    // recurse first, then add ourselves; this way children end up on the
     3548    // list before their parents
     3549
     3550    const MediaList &llChildren = pMedium->getChildren();
     3551    for (MediaList::const_iterator it = llChildren.begin();
     3552         it != llChildren.end();
     3553         ++it)
     3554    {
     3555        Medium *pChild = *it;
     3556        pushMediumToListWithChildren(llMedia, pChild);
     3557    }
     3558
     3559    Log(("Pushing medium %RTuuid\n", pMedium->getId().raw()));
     3560    llMedia.push_back(pMedium);
     3561}
     3562
     3563/**
     3564 * Unregisters all Medium objects which belong to the given machine registry.
     3565 * Gets called from Machine::uninit() just before the machine object dies
     3566 * and must only be called with a machine UUID as the registry ID.
     3567 *
     3568 * Locks the media tree.
     3569 *
     3570 * @param uuidMachine Medium registry ID (always a machine UUID)
     3571 * @return
     3572 */
     3573HRESULT VirtualBox::unregisterMachineMedia(const Guid &uuidMachine)
     3574{
     3575    Assert(!uuidMachine.isEmpty());
     3576
     3577    LogFlowFuncEnter();
     3578
     3579    AutoCaller autoCaller(this);
     3580    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     3581
     3582    MediaList llMedia2Close;
     3583
     3584    {
     3585        AutoWriteLock mlock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
     3586        for (MediaOList::iterator it = m->allHardDisks.getList().begin();
     3587             it != m->allHardDisks.getList().end();
     3588             ++it)
     3589        {
     3590            ComObjPtr<Medium> pMedium = *it;
     3591
     3592            const Guid &uuidRegistryThis = pMedium->getRegistryId();
     3593            if (    !uuidRegistryThis.isEmpty()
     3594                 && (uuidRegistryThis == uuidMachine)
     3595               )
     3596            {
     3597                // recursively with children first
     3598                pushMediumToListWithChildren(llMedia2Close, pMedium);
     3599            }
     3600        }
     3601    }
     3602
     3603    for (MediaList::iterator it = llMedia2Close.begin();
     3604         it != llMedia2Close.end();
     3605         ++it)
     3606    {
     3607        ComObjPtr<Medium> pMedium = *it;
     3608        Log(("Closing medium %RTuuid\n", pMedium->getId().raw()));
     3609        AutoCaller mac(pMedium);
     3610        pMedium->close(NULL /* pfNeedsGlobalSaveSettings*/, mac);
     3611    }
     3612
     3613    LogFlowFuncLeave();
     3614
     3615    return S_OK;
    35393616}
    35403617
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31725 r31814  
    253253    HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
    254254
     255    void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
     256    HRESULT unregisterMachineMedia(const Guid &id);
     257
    255258    HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
    256259
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