VirtualBox

Changeset 31218 in vbox


Ignore:
Timestamp:
Jul 29, 2010 3:07:48 PM (14 years ago)
Author:
vboxsync
Message:

Main: extend Machine::unregister() to no longer fail with machines in 'saved' states, but delete the saved state automatically; remove boolean parameter from IConsole::forgetSavedState() which had to be true for the function to do anything useful anyway; remove corresponding internal sessionmachine method

Location:
trunk/src/VBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r31070 r31218  
    160160    {
    161161        SafeArray<BSTR> abstrFiles;
    162         CHECK_ERROR(machine, Unregister(false /* fDetachMedia */,
     162        CHECK_ERROR(machine, Unregister(fDelete /* fAutoCleanup */,
    163163                                        ComSafeArrayAsOutParam(abstrFiles)));
    164         if (SUCCEEDED(rc) && fDelete)
    165             CHECK_ERROR(machine, Delete());
     164        if (SUCCEEDED(rc))
     165        {
     166            for (size_t u = 0;
     167                 u < abstrFiles.size();
     168                 ++u)
     169            {
     170                Utf8Str strFile(abstrFiles[u]);
     171                if (fDelete)
     172                {
     173                    RTPrintf("Deleting '%s'\n", strFile.c_str());
     174                    RTFileDelete(strFile.c_str());
     175                }
     176                else
     177                    RTPrintf("File '%s' is now obsolete and can be deleted\n", strFile.c_str());
     178            }
     179
     180            if (fDelete)
     181            {
     182                CHECK_ERROR(machine, Delete());
     183            }
     184        }
    166185    }
    167186    return SUCCEEDED(rc) ? 0 : 1;
     
    423442                ComPtr<IConsole> console;
    424443                CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
    425                 CHECK_ERROR_BREAK(console, ForgetSavedState(true));
     444                CHECK_ERROR_BREAK(console, ForgetSavedState());
    426445            } while (0);
    427446            CHECK_ERROR_BREAK(a->session, UnlockMachine());
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r31070 r31218  
    16521652        if (machineState == MachineState_Saved)
    16531653        {
    1654             CHECK_ERROR(gConsole, ForgetSavedState(true));
     1654            CHECK_ERROR(gConsole, ForgetSavedState());
    16551655        }
    16561656        /*
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp

    r31070 r31218  
    805805
    806806    CConsole console = session.GetConsole();
    807     console.ForgetSavedState(true);
     807    console.ForgetSavedState();
    808808    if (!console.isOk())
    809809        vboxProblem().cannotDiscardSavedState (console);
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r31008 r31218  
    23872387}
    23882388
    2389 STDMETHODIMP Console::ForgetSavedState(BOOL aRemove)
     2389STDMETHODIMP Console::ForgetSavedState()
    23902390{
    23912391    AutoCaller autoCaller(this);
     
    24002400
    24012401    HRESULT rc = S_OK;
    2402 
    2403     rc = mControl->SetRemoveSavedState(aRemove);
    2404     if (FAILED(rc)) return rc;
    24052402
    24062403    /*
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31070 r31218  
    40624062
    40634063/** @note Locks objects! */
    4064 STDMETHODIMP Machine::Unregister(BOOL fCloseMedia,
     4064STDMETHODIMP Machine::Unregister(BOOL fAutoCleanup,
    40654065                                 ComSafeArrayOut(BSTR, aFiles))
    40664066{
     
    40764076                           mUserData->mName.raw());
    40774077
    4078     // @todo optionally discard saved state
     4078    // this list collects the files that should be reported
     4079    // as to be deleted to the caller in aFiles
     4080    std::list<Bstr> llFilesForCaller;
     4081
     4082    // discard saved state
    40794083    if (mData->mMachineState == MachineState_Saved)
    4080         return setError(VBOX_E_INVALID_VM_STATE,
    4081                         tr("Cannot unregister the machine '%ls' because it is in the Saved state"),
    4082                            mUserData->mName.raw());
     4084    {
     4085        // add the saved state file to the list of files the caller should delete
     4086        Assert(!mSSData->mStateFilePath.isEmpty());
     4087        llFilesForCaller.push_back(Bstr(mSSData->mStateFilePath));
     4088
     4089        mSSData->mStateFilePath.setNull();
     4090
     4091        // unconditionally set the machine state to powered off, we now
     4092        // know no session has locked the machine
     4093        mData->mMachineState = MachineState_PoweredOff;
     4094    }
    40834095
    40844096    // @todo optionally nuke snapshots
     
    40894101        return setError(VBOX_E_INVALID_OBJECT_STATE,
    40904102                        tr("Cannot unregister the machine '%ls' because it has %d snapshots"),
    4091                            mUserData->mName.raw(), snapshotCount);
     4103                        mUserData->mName.raw(), snapshotCount);
    40924104
    40934105    if (    !mMediaData.isNull()      // can be NULL if machine is inaccessible
     
    40964108    {
    40974109        // we have media attachments:
    4098         if (fCloseMedia)
     4110        if (fAutoCleanup)
    40994111        {
    41004112            // caller wants automatic detachment: then do that and report all media to the array
     
    41224134            return setError(VBOX_E_INVALID_OBJECT_STATE,
    41234135                            tr("Cannot unregister the machine '%ls' because it has %d media attachments"),
    4124                               mMediaData->mAttachments.size());
     4136                            mUserData->mName.raw(), mMediaData->mAttachments.size());
    41254137    }
    41264138
     
    41334145    alock.release();
    41344146
    4135     if (fCloseMedia)
     4147    if (fAutoCleanup)
    41364148    {
    41374149        // now go thru the list of attached media reported by prepareUnregister() and close them all
    4138         SafeArray<BSTR> sfaFiles(llMedia.size());
    41394150        size_t u = 0;
    41404151        for (MediaList::const_iterator it = llMedia.begin();
     
    41534164
    41544165            // report the path to the caller
    4155             bstrFile.detachTo(&sfaFiles[u]);
     4166            llFilesForCaller.push_back(bstrFile);
    41564167            ++u;
    41574168        }
    4158         // report all paths to the caller
    4159         sfaFiles.detachTo(ComSafeArrayOutArg(aFiles));
    4160     }
     4169    }
     4170
     4171    // report all paths to the caller
     4172    SafeArray<BSTR> sfaFiles(llFilesForCaller.size());
     4173    size_t i = 0;
     4174    for (std::list<Bstr>::iterator it = llFilesForCaller.begin();
     4175         it != llFilesForCaller.end();
     4176         ++it)
     4177        it->detachTo(&sfaFiles[i++]);
     4178    sfaFiles.detachTo(ComSafeArrayOutArg(aFiles));
    41614179
    41624180    mParent->unregisterMachine(this);
     4181            // calls VirtualBox::saveSettings()
    41634182
    41644183    return S_OK;
     
    96379656    }
    96389657
    9639     /* default is to delete saved state on Saved -> PoweredOff transition */
    9640     mRemoveSavedState = true;
    9641 
    96429658    /* Confirm a successful initialization when it's the case */
    96439659    autoInitSpan.setSucceeded();
     
    99339949
    99349950/**
    9935  *  @note Locks this object for writing.
    9936  */
    9937 STDMETHODIMP SessionMachine::SetRemoveSavedState(BOOL aRemove)
    9938 {
    9939     AutoCaller autoCaller(this);
    9940     AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    9941 
    9942     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    9943 
    9944     mRemoveSavedState = aRemove;
    9945 
    9946     return S_OK;
    9947 }
    9948 
    9949 /**
    99509951 *  @note Locks the same as #setMachineState() does.
    99519952 */
     
    1123611237    if (deleteSavedState)
    1123711238    {
    11238         if (mRemoveSavedState)
    11239         {
    11240             Assert(!mSSData->mStateFilePath.isEmpty());
    11241             RTFileDelete(mSSData->mStateFilePath.c_str());
    11242         }
     11239        Assert(!mSSData->mStateFilePath.isEmpty());
     11240        RTFileDelete(mSSData->mStateFilePath.c_str());
    1124311241        mSSData->mStateFilePath.setNull();
    1124411242        stsFlags |= SaveSTS_StateFilePath;
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31217 r31218  
    31923192  <interface
    31933193     name="IInternalMachineControl" extends="$unknown"
    3194      uuid="26604a54-8628-491b-a0ea-e1392a16d13b"
     3194     uuid="e2da8b1a-2ad1-490e-b29e-c33a144791b6"
    31953195     internal="yes"
    31963196     wsmap="suppress"
    31973197     >
    3198     <method name="setRemoveSavedState">
    3199       <desc>
    3200         Updates the flag whether saved state is removed on a machine state
    3201         change from Saved to PoweredOff.
    3202       </desc>
    3203       <param name="aRemove" type="boolean" dir="in"/>
    3204     </method>
    3205 
    32063198    <method name="updateState">
    32073199      <desc>
     
    51905182      <desc>
    51915183        Unregisters the machine, which must have been previously registered using
    5192         <link to="IVirtualBox::registerMachine"/>. After successful method invocation,
     5184        <link to="IVirtualBox::registerMachine"/>.
     5185
     5186        This method will succeed even if the machine currently has media attachments or
     5187        is in the <link to="MachineState::Saved">Saved</link> state. In those cases,
     5188        the caller receives the names of all files that have been made obsolete by the
     5189        call in the @a aFiles array parameter. This list will consist of the saved
     5190        state file and all storage files by media that were detached from the machine.
     5191
     5192        <note>
     5193          The @a fAutoCleanup parameter is temporary to avoid substantial changes to the
     5194          frontends in SVN trunk.It will go away before the 3.3 release and
     5195          always be true then. If fAutoCleanup is false, the API currently behaves like
     5196          the old VirtualBox::UnregisterMachine API. Cleaning up snapshots does not work
     5197          yet, so the method will still fail if the machine has snapshots.
     5198        </note>
     5199
     5200        The settings XML file of the machine object itself will not be included in that
     5201        list; call <link to="#delete" /> for that.
     5202
     5203        The call will fail if the machine is currently locked (see <link to="ISession" />).
     5204        It implicitly calls <link to="#saveSettings"/> to save all current machine settings
     5205        before unregistering it.
     5206
     5207        After successful method invocation,
    51935208        the <link to="IMachineRegisteredEvent"/> event is fired.
    5194 
    5195         <note>
    5196           The specified machine must not be in the Saved state nor have an open
    5197           (or a spawning) direct session associated with it.
    5198         </note>
    5199 
    5200         <note>
    5201           This method implicitly calls <link to="#saveSettings"/> to
    5202           save all current machine settings before unregistering it.
    5203         </note>
    52045209
    52055210        <note>
     
    52105215        </note>
    52115216
    5212         <result name="VBOX_E_OBJECT_NOT_FOUND">
    5213           Could not find registered machine matching @a id.
    5214         </result>
    5215         <result name="VBOX_E_INVALID_VM_STATE">
    5216           Machine is in Saved state.
    5217         </result>
    52185217        <result name="VBOX_E_INVALID_OBJECT_STATE">
    5219           Machine has snapshot or open session or medium attached.
    5220         </result>
    5221       </desc>
    5222 
    5223       <param name="fCloseMedia" type="boolean" dir="in">
     5218          Machine has snapshot or is locked.
     5219        </result>
     5220      </desc>
     5221
     5222      <param name="fAutoCleanup" type="boolean" dir="in">
    52245223        <desc>If true, the method will automatically detach all media from the
    52255224          machine and its snapshots, call <link to="IMedium::close" /> on each
     
    52275226          the caller in the @a aFiles array so the caller can then delete the
    52285227          image files.
    5229           If false, the method will fail if media attachments are present.</desc>
     5228          If false, the method will fail if media attachments are present.
     5229        </desc>
    52305230      </param>
    52315231      <param name="aFiles" type="wstring" safearray="yes" dir="return">
     
    59335933  <interface
    59345934     name="IConsole" extends="$unknown"
    5935      uuid="9e467cff-98fc-4f5b-83aa-048d903694c9"
     5935     uuid="3a7bb20e-bbee-47f2-a5ee-b158555f2c79"
    59365936     wsmap="managed"
    59375937     >
     
    63016301    <method name="forgetSavedState">
    63026302      <desc>
    6303         Forgets the saved state of the virtual machine previously created
    6304         by <link to="#saveState"/>. Next time the machine is powered up, a
    6305         clean boot will occur. If @a remove is @c true the saved state file
    6306         is deleted.
     6303        Forgets the saved state of the virtual machine if it is currently
     6304        in the "Saved" state (previously created by <link to="#saveState"/>)
     6305        and deletes the file into which the machine state was saved.
     6306        Next time the machine is powered up, a clean boot will occur.
    63076307        <note>
    63086308          This operation is equivalent to resetting or powering off
     
    63136313        </result>
    63146314      </desc>
    6315       <param name="removeFile" type="boolean" dir="in">
    6316         <desc>If @c true remove the saved state file.</desc>
    6317       </param>
    63186315    </method>
    63196316
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r31002 r31218  
    138138    STDMETHOD(SaveState)(IProgress **aProgress);
    139139    STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
    140     STDMETHOD(ForgetSavedState)(BOOL aRemove);
     140    STDMETHOD(ForgetSavedState)();
    141141    STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
    142142                                DeviceActivity_T *aDeviceActivity);
  • trunk/src/VBox/Main/include/MachineImpl.h

    r31019 r31218  
    484484    STDMETHOD(SaveSettings)();
    485485    STDMETHOD(DiscardSettings)();
    486     STDMETHOD(Unregister) (BOOL fCloseMedia, ComSafeArrayOut(BSTR, aFiles));
     486    STDMETHOD(Unregister) (BOOL fAutoCleanup, ComSafeArrayOut(BSTR, aFiles));
    487487    STDMETHOD(Delete)();
    488488    STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
     
    888888
    889889    // IInternalMachineControl methods
    890     STDMETHOD(SetRemoveSavedState)(BOOL aRemove);
    891890    STDMETHOD(UpdateState)(MachineState_T machineState);
    892891    STDMETHOD(GetIPCId)(BSTR *id);
     
    10251024    HRESULT updateMachineStateOnClient();
    10261025
    1027     HRESULT mRemoveSavedState;
    1028 
    10291026    SnapshotData mSnapshotData;
    10301027
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