VirtualBox

Changeset 31242 in vbox


Ignore:
Timestamp:
Jul 30, 2010 1:06:39 PM (14 years ago)
Author:
vboxsync
Message:

Main: finish Machine::Unregister(), which can now recursively delete all snapshots and differencing media

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

Legend:

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

    r31239 r31242  
    40704070    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    40714071
    4072     MediaList llMedia;
    40734072    if (mData->mSession.mState != SessionState_Unlocked)
    40744073        return setError(VBOX_E_INVALID_OBJECT_STATE,
    40754074                        tr("Cannot unregister the machine '%ls' while it is locked"),
    4076                            mUserData->mName.raw());
     4075                        mUserData->mName.raw());
    40774076
    40784077    HRESULT rc = S_OK;
    40794078
    40804079    // this list collects the files that should be reported
    4081     // as to be deleted to the caller in aFiles
     4080    // as to be deleted to the caller in aFiles (this includes the
     4081    // media files in llMedia below)
    40824082    std::list<Utf8Str> llFilesForCaller;
    40834083
     
    40964096    }
    40974097
    4098     size_t snapshotCount = 0;
     4098    size_t cSnapshots = 0;
    40994099    if (mData->mFirstSnapshot)
    4100         snapshotCount = mData->mFirstSnapshot->getAllChildrenCount() + 1;
    4101     if (snapshotCount)
    4102     {
    4103         if (fAutoCleanup)
    4104         {
    4105             // caller wants automatic detachment: then do that and report all media to the array
    4106 
    4107             // Snapshot::beginDeletingSnapshot() needs the machine state to be this
    4108             MachineState_T oldState = mData->mMachineState;
    4109             mData->mMachineState = MachineState_DeletingSnapshot;
    4110 
    4111             // make a copy of the first snapshot so the refcount does not drop to 0
    4112             // in beginDeletingSnapshot, which sets pFirstSnapshot to 0 (that hangs
    4113             // because of the AutoCaller voodoo)
    4114             ComObjPtr<Snapshot> pFirstSnapshot = mData->mFirstSnapshot;
    4115 
    4116             // go!
    4117             pFirstSnapshot->uninitRecursively(alock, llMedia, llFilesForCaller);
    4118 
    4119             mData->mMachineState = oldState;
    4120         }
    4121         else
    4122             return setError(VBOX_E_INVALID_OBJECT_STATE,
    4123                             tr("Cannot unregister the machine '%ls' because it has %d snapshots"),
    4124                             mUserData->mName.raw(), snapshotCount);
    4125     }
     4100        cSnapshots = mData->mFirstSnapshot->getAllChildrenCount() + 1;
     4101    if (cSnapshots && !fAutoCleanup)
     4102        // fail now before we start detaching media
     4103        return setError(VBOX_E_INVALID_OBJECT_STATE,
     4104                        tr("Cannot unregister the machine '%ls' because it has %d snapshots"),
     4105                           mUserData->mName.raw(), cSnapshots);
     4106
     4107    // this list collects the medium objects from all medium attachments
     4108    // which got detached from the machine and its snapshots, in the following
     4109    // order:
     4110    // 1) media from machine attachments (these have the "leaf" attachments with snapshots
     4111    //    and must be closed first, or closing the parents will fail because they will
     4112    //    children);
     4113    // 2) media from the youngest snapshots followed those from the parent snapshots until
     4114    //    the root ("first") snapshot of the machine
     4115    // This order allows for closing the media on this list from the beginning to the end
     4116    // without getting "media in use" errors.
     4117    MediaList llMedia;
    41264118
    41274119    if (    !mMediaData.isNull()      // can be NULL if machine is inaccessible
     
    41374129                            mUserData->mName.raw(), mMediaData->mAttachments.size());
    41384130    }
     4131
     4132    if (cSnapshots)
     4133    {
     4134        // autoCleanup must be true here, or we would have failed above
     4135
     4136        // add the media from the medium attachments of the snapshots to llMedia
     4137        // as well, after the "main" machine media; Snapshot::uninitRecursively()
     4138        // calls Machine::detachAllMedia() for the snapshot machine, recursing
     4139        // into the children first
     4140
     4141        // Snapshot::beginDeletingSnapshot() asserts if the machine state is not this
     4142        MachineState_T oldState = mData->mMachineState;
     4143        mData->mMachineState = MachineState_DeletingSnapshot;
     4144
     4145        // make a copy of the first snapshot so the refcount does not drop to 0
     4146        // in beginDeletingSnapshot, which sets pFirstSnapshot to 0 (that hangs
     4147        // because of the AutoCaller voodoo)
     4148        ComObjPtr<Snapshot> pFirstSnapshot = mData->mFirstSnapshot;
     4149
     4150        // GO!
     4151        pFirstSnapshot->uninitRecursively(alock, llMedia, llFilesForCaller);
     4152
     4153        mData->mMachineState = oldState;
     4154    }
     4155
    41394156
    41404157    if (FAILED(rc))
     
    87218738    ComObjPtr<Medium> oldmedium = pAttach->getMedium();
    87228739    DeviceType_T mediumType = pAttach->getType();
     8740
     8741    LogFlowThisFunc(("Entering, medium of attachment is %s\n", oldmedium ? oldmedium->getLocationFull().c_str() : "NULL"));
    87238742
    87248743    if (pAttach->isImplicit())
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r31236 r31242  
    839839    HRESULT rc = S_OK;
    840840
     841    // make a copy of the Guid for logging before we uninit ourselfs
     842#ifdef LOG_ENABLED
     843    Guid uuid = getId();
     844    Utf8Str name = getName();
     845    LogFlowThisFunc(("Entering for snapshot '%s' {%RTuuid}\n", name.c_str(), uuid.raw()));
     846#endif
     847
    841848    // recurse into children first so that the child media appear on
    842849    // the list first; this way caller can close the media from the
     
    869876    this->beginSnapshotDelete();
    870877    this->uninit();
     878
     879#ifdef LOG_ENABLED
     880    LogFlowThisFunc(("Leaving for snapshot '%s' {%RTuuid}\n", name.c_str(), uuid.raw()));
     881#endif
    871882
    872883    return S_OK;
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