VirtualBox

Changeset 30929 in vbox


Ignore:
Timestamp:
Jul 20, 2010 2:11:51 PM (14 years ago)
Author:
vboxsync
Message:

Main: add option to UnregisterMachine() to automatically nuke all attached media

Location:
trunk/src/VBox
Files:
12 edited

Legend:

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

    r30681 r30929  
    162162        machine->COMGETTER(Id)(uuid.asOutParam());
    163163        machine = NULL;
    164         CHECK_ERROR(a->virtualBox, UnregisterMachine(uuid, machine.asOutParam()));
     164        SafeArray<BSTR> abstrFiles;
     165        CHECK_ERROR(a->virtualBox, UnregisterMachine(uuid,
     166                                                     false /* fDetachMedia */,
     167                                                     ComSafeArrayAsOutParam(abstrFiles),
     168                                                     machine.asOutParam()));
    165169        if (SUCCEEDED(rc) && machine && fDelete)
    166170            CHECK_ERROR(machine, DeleteSettings());
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp

    r30868 r30929  
    679679        if (ok)
    680680        {
    681             CMachine machine = item->machine();
    682             vbox.UnregisterMachine (id);
     681            QVector<QString> files;
     682            CMachine machine;
     683            vbox.UnregisterMachine(id, false /*fDetachMedia*/, files, machine);
    683684            if (vbox.isOk() && item->accessible())
    684685            {
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp

    r30210 r30929  
    782782        {
    783783            /* Unregister on failure */
    784             vbox.UnregisterMachine(machineId);
     784            QVector<QString> files;
     785            CMachine machine;
     786            vbox.UnregisterMachine(machineId, false /*fDetachMedia*/, files, machine);
    785787            if (vbox.isOk())
    786788                m_Machine.DeleteSettings();
  • trunk/src/VBox/Main/ApplianceImplImport.cpp

    r30881 r30929  
    12281228        HRESULT rc2;
    12291229        // detach all hard disks from all machines we created
    1230         list<MyHardDiskAttachment>::iterator itM;
    1231         for (itM = stack.llHardDiskAttachments.begin();
     1230        for (list<MyHardDiskAttachment>::iterator itM = stack.llHardDiskAttachments.begin();
    12321231             itM != stack.llHardDiskAttachments.end();
    12331232             ++itM)
     
    12501249
    12511250        // now clean up all hard disks we created
    1252         list< ComPtr<IMedium> >::iterator itHD;
    1253         for (itHD = stack.llHardDisksCreated.begin();
     1251        for (list< ComPtr<IMedium> >::iterator itHD = stack.llHardDisksCreated.begin();
    12541252             itHD != stack.llHardDisksCreated.end();
    12551253             ++itHD)
     
    12691267            Bstr bstrGuid = guid.toUtf16();
    12701268            ComPtr<IMachine> failedMachine;
    1271             rc2 = mVirtualBox->UnregisterMachine(bstrGuid, failedMachine.asOutParam());
     1269            SafeArray<BSTR> abstrPaths;
     1270            rc2 = mVirtualBox->UnregisterMachine(bstrGuid, false, ComSafeArrayAsOutParam(abstrPaths), failedMachine.asOutParam());
    12721271            if (SUCCEEDED(rc2))
    12731272                rc2 = failedMachine->DeleteSettings();
  • trunk/src/VBox/Main/MachineImpl.cpp

    r30882 r30929  
    59195919
    59205920/**
    5921  *  Checks that the registered flag of the machine can be set according to
    5922  *  the argument and sets it. On success, commits and saves all settings.
    5923  *
    5924  *  @note When this machine is inaccessible, the only valid value for \a
    5925  *  aRegistered is FALSE (i.e. unregister the machine) because unregistered
    5926  *  inaccessible machines are not currently supported. Note that unregistering
    5927  *  an inaccessible machine will \b uninitialize this machine object. Therefore,
    5928  *  the caller must make sure there are no active Machine::addCaller() calls
    5929  *  on the current thread because this will block Machine::uninit().
     5921 *  Checks whether the machine can be registered. If so, commits and saves
     5922 *  all settings.
    59305923 *
    59315924 *  @note Must be called from mParent's write lock. Locks this object and
    59325925 *  children for writing.
    59335926 */
    5934 HRESULT Machine::trySetRegistered(BOOL argNewRegistered)
     5927HRESULT Machine::prepareRegister()
    59355928{
    59365929    AssertReturn(mParent->isWriteLockOnCurrentThread(), E_FAIL);
     
    59445937    ensureNoStateDependencies();
    59455938
    5946     ComAssertRet(mData->mRegistered != argNewRegistered, E_FAIL);
    5947 
    59485939    if (!mData->mAccessible)
    5949     {
    5950         /* A special case: the machine is not accessible. */
    5951 
    5952         /* inaccessible machines can only be unregistered */
    5953         AssertReturn(!argNewRegistered, E_FAIL);
    5954 
    5955         /* Uninitialize ourselves here because currently there may be no
    5956          * unregistered that are inaccessible (this state combination is not
    5957          * supported). Note releasing the caller and leaving the lock before
    5958          * calling uninit() */
    5959 
    5960         alock.leave();
    5961         autoCaller.release();
    5962 
    5963         uninit();
    5964 
    5965         return S_OK;
    5966     }
     5940        return setError(VBOX_E_INVALID_OBJECT_STATE,
     5941                        tr("The machine '%ls' with UUID {%s} is inaccessible and cannot be registered"),
     5942                        mUserData->mName.raw(),
     5943                        mData->mUuid.toString().raw());
    59675944
    59685945    AssertReturn(autoCaller.state() == Ready, E_FAIL);
    59695946
    5970     if (argNewRegistered)
    5971     {
    5972         if (mData->mRegistered)
    5973             return setError(VBOX_E_INVALID_OBJECT_STATE,
    5974                             tr("The machine '%ls' with UUID {%s} is already registered"),
    5975                             mUserData->mName.raw(),
    5976                             mData->mUuid.toString().raw());
    5977     }
    5978     else
    5979     {
    5980         if (mData->mMachineState == MachineState_Saved)
    5981             return setError(VBOX_E_INVALID_VM_STATE,
    5982                             tr("Cannot unregister the machine '%ls' because it is in the Saved state"),
    5983                             mUserData->mName.raw());
    5984 
    5985         size_t snapshotCount = 0;
    5986         if (mData->mFirstSnapshot)
    5987             snapshotCount = mData->mFirstSnapshot->getAllChildrenCount() + 1;
    5988         if (snapshotCount)
    5989             return setError(VBOX_E_INVALID_OBJECT_STATE,
    5990                             tr("Cannot unregister the machine '%ls' because it has %d snapshots"),
    5991                             mUserData->mName.raw(), snapshotCount);
    5992 
    5993         if (mData->mSession.mState != SessionState_Closed)
    5994             return setError(VBOX_E_INVALID_OBJECT_STATE,
    5995                             tr("Cannot unregister the machine '%ls' because it has an open session"),
    5996                             mUserData->mName.raw());
    5997 
    5998         if (mMediaData->mAttachments.size() != 0)
    5999             return setError(VBOX_E_INVALID_OBJECT_STATE,
    6000                             tr("Cannot unregister the machine '%ls' because it has %d medium attachments"),
    6001                             mUserData->mName.raw(),
    6002                             mMediaData->mAttachments.size());
    6003 
    6004         /* Note that we do not prevent unregistration of a DVD or Floppy image
    6005          * is attached: as opposed to hard disks detaching such an image
    6006          * implicitly in this method (which we will do below) won't have any
    6007          * side effects (like detached orphan base and diff hard disks etc).*/
    6008     }
     5947    if (mData->mRegistered)
     5948        return setError(VBOX_E_INVALID_OBJECT_STATE,
     5949                        tr("The machine '%ls' with UUID {%s} is already registered"),
     5950                        mUserData->mName.raw(),
     5951                        mData->mUuid.toString().raw());
    60095952
    60105953    HRESULT rc = S_OK;
     
    60135956    // no config file exists yet, create it by calling saveSettings() too.
    60145957    if (    (mData->flModifications)
    6015          || (argNewRegistered && !mData->pMachineConfigFile->fileExists())
     5958         || (!mData->pMachineConfigFile->fileExists())
    60165959       )
    60175960    {
     
    60295972        commit();
    60305973
    6031         mData->mRegistered = argNewRegistered;
     5974        mData->mRegistered = true;
    60325975    }
    60335976    else
     
    60385981
    60395982    return rc;
     5983}
     5984
     5985/**
     5986 * Called from VirtualBox::UnregisterMachine() with the flags given there to
     5987 * give the machine a chance to clean up for itself.
     5988 * @param fDetachMedia As passed to VirtualBox::UnregisterMachine(). If true, all
     5989 *                     media are detached from the machine and its snapshots.
     5990 * @param llFiles
     5991 * @return
     5992 */
     5993HRESULT Machine::prepareUnregister(bool fCloseMedia,
     5994                                   MediaList &llMedia)
     5995{
     5996    AutoLimitedCaller autoCaller(this);
     5997    AssertComRCReturnRC(autoCaller.rc());
     5998
     5999    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     6000
     6001    if (mData->mSession.mState != SessionState_Closed)
     6002        return setError(VBOX_E_INVALID_OBJECT_STATE,
     6003                        tr("Cannot unregister the machine '%ls' because it has an open session"),
     6004                        mUserData->mName.raw());
     6005
     6006    // @todo optionally discard saved state
     6007    if (mData->mMachineState == MachineState_Saved)
     6008        return setError(VBOX_E_INVALID_VM_STATE,
     6009                        tr("Cannot unregister the machine '%ls' because it is in the Saved state"),
     6010                        mUserData->mName.raw());
     6011
     6012    // @todo optionally nuke snapshots
     6013    size_t snapshotCount = 0;
     6014    if (mData->mFirstSnapshot)
     6015        snapshotCount = mData->mFirstSnapshot->getAllChildrenCount() + 1;
     6016    if (snapshotCount)
     6017        return setError(VBOX_E_INVALID_OBJECT_STATE,
     6018                        tr("Cannot unregister the machine '%ls' because it has %d snapshots"),
     6019                        mUserData->mName.raw(), snapshotCount);
     6020
     6021    if (fCloseMedia)
     6022    {
     6023        // caller wants automatic detachment: then do that and report all media to the array
     6024        MediaData::AttachmentList::iterator it = mMediaData->mAttachments.begin();
     6025        while (it != mMediaData->mAttachments.end())
     6026        {
     6027            ComObjPtr<MediumAttachment> pAttach = *it;
     6028            ComObjPtr<Medium> pMedium = pAttach->getMedium();
     6029
     6030            if (!pMedium.isNull())
     6031                llMedia.push_back(pMedium);
     6032
     6033            setModified(IsModified_Storage);
     6034            mMediaData.backup();
     6035
     6036            // for non-hard disk media, detach straight away
     6037            // (same logic as in DetachDevice())
     6038            if (!pMedium.isNull())
     6039                pMedium->detachFrom(mData->mUuid);
     6040
     6041            // remove this attachment; erase() returns the iterator of the next element
     6042            it = mMediaData->mAttachments.erase(it);
     6043        }
     6044    }
     6045    else
     6046        // caller wants no automatic detachment: then fail if there are any
     6047        if (mMediaData->mAttachments.size())
     6048            return setError(VBOX_E_INVALID_OBJECT_STATE,
     6049                            tr("Cannot unregister the machine '%ls' because it has %d media attachments"),
     6050                               mMediaData->mAttachments.size());
     6051
     6052    mData->mRegistered = false;
     6053
     6054    return S_OK;
    60406055}
    60416056
  • trunk/src/VBox/Main/MediumImpl.cpp

    r30764 r30929  
    19041904    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    19051905
    1906     // we're accessing parent/child and backrefs, so lock the tree first, then ourselves
    1907     AutoMultiWriteLock2 multilock(&m->pVirtualBox->getMediaTreeLockHandle(),
    1908                                   this->lockHandle()
    1909                                   COMMA_LOCKVAL_SRC_POS);
    1910 
    1911     bool wasCreated = true;
    1912     bool fNeedsSaveSettings = false;
    1913 
    1914     switch (m->state)
    1915     {
    1916         case MediumState_NotCreated:
    1917             wasCreated = false;
    1918             break;
    1919         case MediumState_Created:
    1920         case MediumState_Inaccessible:
    1921             break;
    1922         default:
    1923             return setStateError();
    1924     }
    1925 
    1926     if (m->backRefs.size() != 0)
    1927         return setError(VBOX_E_OBJECT_IN_USE,
    1928                         tr("Medium '%s' is attached to %d virtual machines"),
    1929                         m->strLocationFull.raw(), m->backRefs.size());
    1930 
    1931     /* perform extra media-dependent close checks */
    1932     HRESULT rc = canClose();
    1933     if (FAILED(rc)) return rc;
    1934 
    1935     if (wasCreated)
    1936     {
    1937         /* remove from the list of known media before performing actual
    1938          * uninitialization (to keep the media registry consistent on
    1939          * failure to do so) */
    1940         rc = unregisterWithVirtualBox(&fNeedsSaveSettings);
    1941         if (FAILED(rc)) return rc;
    1942     }
    1943 
    19441906    // make a copy of VirtualBox pointer which gets nulled by uninit()
    19451907    ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox);
    19461908
    1947     // leave the AutoCaller, as otherwise uninit() will simply hang
    1948     autoCaller.release();
    1949 
    1950     /* Keep the locks held until after uninit, as otherwise the consistency
    1951      * of the medium tree cannot be guaranteed. */
    1952     uninit();
    1953 
    1954     multilock.release();
     1909    bool fNeedsSaveSettings = false;
     1910    HRESULT rc = close(&fNeedsSaveSettings, autoCaller);
    19551911
    19561912    if (fNeedsSaveSettings)
     
    19601916    }
    19611917
    1962     return S_OK;
     1918    return rc;
    19631919}
    19641920
     
    38203776        }
    38213777    }
     3778
     3779    return rc;
     3780}
     3781
     3782/**
     3783 * Implementation for the public Medium::Close() with the exception of calling
     3784 * VirtualBox::saveSettings(), in case someone wants to call this for several
     3785 * media.
     3786 *
     3787 * After this returns with success, uninit() has been called on the medium, and
     3788 * the object is no longer usable ("not ready" state).
     3789 *
     3790 * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     3791 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
     3792 *                This only works in "wait" mode; otherwise saveSettings gets called automatically by the thread that was created,
     3793 *                and this parameter is ignored.
     3794 * @param autoCaller AutoCaller instance which must have been created on the caller's stack for this medium. This gets released here
     3795 *                   upon which the Medium instance gets uninitialized.
     3796 * @return
     3797 */
     3798HRESULT Medium::close(bool *pfNeedsSaveSettings, AutoCaller &autoCaller)
     3799{
     3800    // we're accessing parent/child and backrefs, so lock the tree first, then ourselves
     3801    AutoMultiWriteLock2 multilock(&m->pVirtualBox->getMediaTreeLockHandle(),
     3802                                   this->lockHandle()
     3803                                           COMMA_LOCKVAL_SRC_POS);
     3804
     3805    bool wasCreated = true;
     3806
     3807    switch (m->state)
     3808    {
     3809        case MediumState_NotCreated:
     3810            wasCreated = false;
     3811            break;
     3812        case MediumState_Created:
     3813        case MediumState_Inaccessible:
     3814            break;
     3815        default:
     3816            return setStateError();
     3817    }
     3818
     3819    if (m->backRefs.size() != 0)
     3820        return setError(VBOX_E_OBJECT_IN_USE,
     3821                        tr("Medium '%s' is attached to %d virtual machines"),
     3822                           m->strLocationFull.raw(), m->backRefs.size());
     3823
     3824    // perform extra media-dependent close checks
     3825    HRESULT rc = canClose();
     3826    if (FAILED(rc)) return rc;
     3827
     3828    if (wasCreated)
     3829    {
     3830        // remove from the list of known media before performing actual
     3831        // uninitialization (to keep the media registry consistent on
     3832        // failure to do so)
     3833        rc = unregisterWithVirtualBox(pfNeedsSaveSettings);
     3834        if (FAILED(rc)) return rc;
     3835    }
     3836
     3837    // leave the AutoCaller, as otherwise uninit() will simply hang
     3838    autoCaller.release();
     3839
     3840    // Keep the locks held until after uninit, as otherwise the consistency
     3841    // of the medium tree cannot be guaranteed.
     3842    uninit();
    38223843
    38233844    return rc;
     
    47894810
    47904811/**
     4812 * Performs extra checks if the medium can be closed and returns S_OK in
     4813 * this case. Otherwise, returns a respective error message. Called by
     4814 * Close() under the medium tree lock and the medium lock.
     4815 *
    47914816 * @note Also reused by Medium::Reset().
    47924817 *
     
    48064831
    48074832/**
    4808  * Calls either VirtualBox::unregisterImage or VirtualBox::unregisterHardDisk depending
     4833 * Unregisters this medium with mVirtualBox. Called by close() under the medium tree lock.
     4834 *
     4835 * This calls either VirtualBox::unregisterImage or VirtualBox::unregisterHardDisk depending
    48094836 * on the device type of this medium.
    48104837 *
     
    48504877        if (pParentBackup)
    48514878        {
    4852             /* re-associate with the parent as we are still relatives in the
    4853              * registry */
     4879            // re-associate with the parent as we are still relatives in the registry
    48544880            m->pParent = pParentBackup;
    48554881            m->pParent->m->llChildren.push_back(this);
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r30882 r30929  
    13671367
    13681368/** @note Locks objects! */
    1369 STDMETHODIMP VirtualBox::UnregisterMachine(IN_BSTR  aId,
     1369STDMETHODIMP VirtualBox::UnregisterMachine(IN_BSTR aId,
     1370                                           BOOL fCloseMedia,
     1371                                           ComSafeArrayOut(BSTR, aFiles),
    13701372                                           IMachine **aMachine)
    13711373{
     
    13821384    if (FAILED(rc)) return rc;
    13831385
    1384     // trySetRegistered needs VirtualBox object write lock
    13851386    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1386     rc = pMachine->trySetRegistered(FALSE);
     1387
     1388    MediaList llMedia;
     1389    rc = pMachine->prepareUnregister(fCloseMedia, llMedia);
    13871390    if (FAILED(rc)) return rc;
    13881391
    1389     /* remove from the collection of registered machines */
     1392    // remove from the collection of registered machines
    13901393    m->allMachines.removeChild(pMachine);
    13911394
    1392     /* save the global registry */
     1395    if (fCloseMedia)
     1396    {
     1397        // now go thru the list of attached media reported by prepareUnregister() and close them all
     1398        SafeArray<BSTR> sfaFiles(llMedia.size());
     1399        size_t u = 0;
     1400        for (MediaList::const_iterator it = llMedia.begin();
     1401             it != llMedia.end();
     1402             ++it)
     1403        {
     1404            ComObjPtr<Medium> pMedium = *it;
     1405            Bstr bstrFile = pMedium->getLocationFull();
     1406
     1407            AutoCaller autoCaller2(pMedium);
     1408            if (FAILED(autoCaller2.rc())) return autoCaller2.rc();
     1409
     1410            pMedium->close(NULL /*fNeedsSaveSettings*/,     // we'll call saveSettings() in any case below
     1411                           autoCaller2);
     1412                // this uninitializes the medium
     1413
     1414            // report the path to the caller
     1415            bstrFile.detachTo(&sfaFiles[u]);
     1416            ++u;
     1417        }
     1418        // report all paths to the caller
     1419        sfaFiles.detachTo(ComSafeArrayOutArg(aFiles));
     1420    }
     1421
     1422    // save the global registry
    13931423    rc = saveSettings();
    13941424
     
    35443574    if (autoCaller.state() != InInit)
    35453575    {
    3546         rc = aMachine->trySetRegistered(TRUE);
     3576        rc = aMachine->prepareRegister();
    35473577        if (FAILED(rc)) return rc;
    35483578    }
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r30881 r30929  
    17421742          Machine has snapshot or open session or medium attached.
    17431743        </result>
    1744 
    1745       </desc>
     1744      </desc>
     1745
    17461746      <param name="id" type="uuid" mod="string" dir="in">
    17471747        <desc>UUID of the machine to unregister.</desc>
    17481748      </param>
    1749       <param name="machine" type="IMachine" dir="return">
     1749      <param name="fCloseMedia" type="boolean" dir="in">
     1750        <desc>If true, the method will automatically detach all media from the
     1751          machine and its snapshots, call <link to="IMedium::close" /> on each
     1752          medium, and the paths of all media files involved will be reported to
     1753          the caller in the @a aFiles array so the caller can then delete the
     1754          image files.
     1755          If false, the method will fail if media attachments are present.</desc>
     1756      </param>
     1757      <param name="aFiles" type="wstring" safearray="yes" dir="out">
     1758        <desc>
     1759          List of all files detached from medium attachments of the machine, if
     1760          @a fDetachMedia is true.
     1761        </desc>
     1762      </param>
     1763      <param name="machine" type="IMachine" dir="out">
    17501764        <desc>Unregistered machine object.</desc>
    17511765      </param>
  • trunk/src/VBox/Main/include/MachineImpl.h

    r30847 r30929  
    682682    bool checkForSpawnFailure();
    683683
    684     HRESULT trySetRegistered(BOOL aRegistered);
     684    HRESULT prepareRegister();
     685    HRESULT prepareUnregister(bool fDetachMedia, MediaList &llMedia);
    685686
    686687    HRESULT getSharedFolder(CBSTR aName,
  • trunk/src/VBox/Main/include/MediumImpl.h

    r30764 r30929  
    198198                              bool *pfNeedsSaveSettings);
    199199
     200    HRESULT close(bool *pfNeedsSaveSettings, AutoCaller &autoCaller);
    200201    HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
    201202    HRESULT markForDeletion();
     
    232233    HRESULT queryInfo();
    233234
    234     /**
    235      * Performs extra checks if the medium can be closed and returns S_OK in
    236      * this case. Otherwise, returns a respective error message. Called by
    237      * Close() under the medium tree lock and the medium lock.
    238      */
    239235    HRESULT canClose();
    240 
    241     /**
    242      * Unregisters this medium with mVirtualBox. Called by Close() under
    243      * the medium tree lock.
    244      */
    245236    HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
    246237
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r30847 r30929  
    100100
    101101    /* IVirtualBox properties */
    102     STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
    103     STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
    104     STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
    105     STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
    106     STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
    107     STDMETHOD(COMGETTER(Host)) (IHost **aHost);
    108     STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
    109     STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
    110     STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IMedium *, aHardDisks));
    111     STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IMedium *, aDVDImages));
    112     STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IMedium *, aFloppyImages));
    113     STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
    114     STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
    115     STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
    116     STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
    117     STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
    118     STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
     102    STDMETHOD(COMGETTER(Version))               (BSTR *aVersion);
     103    STDMETHOD(COMGETTER(Revision))              (ULONG *aRevision);
     104    STDMETHOD(COMGETTER(PackageType))           (BSTR *aPackageType);
     105    STDMETHOD(COMGETTER(HomeFolder))            (BSTR *aHomeFolder);
     106    STDMETHOD(COMGETTER(SettingsFilePath))      (BSTR *aSettingsFilePath);
     107    STDMETHOD(COMGETTER(Host))                  (IHost **aHost);
     108    STDMETHOD(COMGETTER(SystemProperties))      (ISystemProperties **aSystemProperties);
     109    STDMETHOD(COMGETTER(Machines))              (ComSafeArrayOut(IMachine *, aMachines));
     110    STDMETHOD(COMGETTER(HardDisks))             (ComSafeArrayOut(IMedium *, aHardDisks));
     111    STDMETHOD(COMGETTER(DVDImages))             (ComSafeArrayOut(IMedium *, aDVDImages));
     112    STDMETHOD(COMGETTER(FloppyImages))          (ComSafeArrayOut(IMedium *, aFloppyImages));
     113    STDMETHOD(COMGETTER(ProgressOperations))    (ComSafeArrayOut(IProgress *, aOperations));
     114    STDMETHOD(COMGETTER(GuestOSTypes))          (ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
     115    STDMETHOD(COMGETTER(SharedFolders))         (ComSafeArrayOut(ISharedFolder *, aSharedFolders));
     116    STDMETHOD(COMGETTER(PerformanceCollector))  (IPerformanceCollector **aPerformanceCollector);
     117    STDMETHOD(COMGETTER(DHCPServers))           (ComSafeArrayOut(IDHCPServer *, aDHCPServers));
     118    STDMETHOD(COMGETTER(EventSource))           (IEventSource ** aEventSource);
    119119
    120120    /* IVirtualBox methods */
     
    128128    STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
    129129    STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
    130     STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
     130    STDMETHOD(UnregisterMachine) (IN_BSTR aId, BOOL fCloseMedia, ComSafeArrayOut(BSTR, aFiles), IMachine **aMachine);
    131131    STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
    132132
  • trunk/src/VBox/Main/testcase/tstOVF.cpp

    r30883 r30929  
    238238    if (FAILED(rc)) throw MyError(rc, "Progress::WaitForCompletion() failed\n");
    239239    pProgress->COMGETTER(ResultCode)(&rc2);
    240     if (FAILED(rc2)) throw MyError(rc2, "Progress::GetResultCode() failed\n");
     240    if (FAILED(rc2)) throw MyError(rc2, "Appliance::ImportMachines() failed\n", pProgress);
    241241
    242242    com::SafeArray<BSTR> aMachineUUIDs;
     
    262262 * @param pcszDest Target for dummy VMDK.
    263263 */
    264 void copyDummyDiskImage(std::list<Utf8Str> &llFiles2Delete, const char *pcszDest)
     264void copyDummyDiskImage(const char *pcszPrefix,
     265                        std::list<Utf8Str> &llFiles2Delete,
     266                        const char *pcszDest)
    265267{
     268    RTPrintf("%s: copying ovf-dummy.vmdk to \"%s\"...\n", pcszPrefix, pcszDest);
     269
    266270    int vrc = RTFileCopy("ovf-testcases/ovf-dummy.vmdk", pcszDest);
    267271    if (RT_FAILURE(vrc)) throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str());
     
    306310
    307311        // testcase 1: import ovf-joomla-0.9/joomla-1.1.4-ovf.ovf
    308         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
    309         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
     312        copyDummyDiskImage("joomla-0.9", llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
     313        copyDummyDiskImage("joomla-0.9", llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
    310314        importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf", llMachinesCreated);
    311315
    312316        // testcase 2: import ovf-winxp-vbox-sharedfolders/winxp.ovf
    313         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/Windows 5.1 XP 1 merged.vmdk");
    314         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/smallvdi.vmdk");
     317        copyDummyDiskImage("winxp-vbox-sharedfolders", llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/Windows 5.1 XP 1 merged.vmdk");
     318        copyDummyDiskImage("winxp-vbox-sharedfolders", llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/smallvdi.vmdk");
    315319        importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf", llMachinesCreated);
    316320
     
    330334             ++it)
    331335        {
    332 //             const Guid &uuid = *it;
    333 //             Bstr bstrUUID(uuid.toUtf16());
    334 //             ComPtr<IMachine> pMachine;
    335 //             rc = pVirtualBox->GetMachine(bstrUUID, pMachine.asOutParam());
    336 //             if (FAILED(rc)) throw MyError(rc, "VirtualBox::FindMachine() failed\n");
    337 //
    338 //             SafeIfaceArray<IMediumAttachment> aMediumAttachments;
    339 //             rc = pMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(aMediumAttachments));
    340 //             if (FAILED(rc)) throw MyError(rc, "Machine::MediumAttachments() failed\n");
    341 //
    342 //             for (size_t u2 = 0;
    343 //                  u2 < aMediumAttachments.size();
    344 //                  ++u2)
    345 //             {
    346 //                 ComPtr<IMediumAttachment> pMediumAttachment(aMediumAttachments[u2]);
    347 //                 ComPtr<IMedium> pMedium;
    348 //                 rc = pMediumAttachment->COMGETTER(Medium)(pMedium.asOutParam());
    349 //                 if (FAILED(rc)) throw MyError(rc, "MediumAttachment::GetMedium() failed\n");
    350 //
    351 //                 if (!pMedium.isNull())
    352 //                 {
    353 //                     Bstr bstrLocation;
    354 //                     rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
    355 //                     if (FAILED(rc)) throw MyError(rc, "Medium::GetLocation() failed\n");
    356 //
    357 //                     llFiles2Delete.push_back(bstrLocation);
    358 //                 }
    359 //             }
    360 
    361 //             RTPrintf("  Deleting machine %ls...\n", bstrUUID.raw());
    362 //             pVirtualBox->UnregisterMachine(bstrUUID, pMachine.asOutParam());
    363 //             if (FAILED(rc)) throw MyError(rc, "VirtualBox::UnregisterMachine() failed\n");
    364 //
    365 //             if (!pMachine.isNull())
    366 //             {
    367 //                 rc = pMachine->DeleteSettings();
    368 //                 if (FAILED(rc)) throw MyError(rc, "Machine::DeleteSettings() failed\n");
    369 //             }
     336            const Guid &uuid = *it;
     337            Bstr bstrUUID(uuid.toUtf16());
     338            ComPtr<IMachine> pMachine;
     339            rc = pVirtualBox->GetMachine(bstrUUID, pMachine.asOutParam());
     340            if (FAILED(rc)) throw MyError(rc, "VirtualBox::FindMachine() failed\n");
     341
     342            RTPrintf("  Deleting machine %ls...\n", bstrUUID.raw());
     343            SafeArray<BSTR> sfaFiles;
     344            rc = pVirtualBox->UnregisterMachine(bstrUUID,
     345                                                true /* fDetachMedia */,
     346                                                ComSafeArrayAsOutParam(sfaFiles),
     347                                                pMachine.asOutParam());
     348            if (FAILED(rc)) throw MyError(rc, "VirtualBox::UnregisterMachine() failed\n");
     349
     350            for (size_t u = 0;
     351                 u < sfaFiles.size();
     352                 ++u)
     353            {
     354                RTPrintf("    UnregisterMachine reported disk image %ls\n", sfaFiles[u]);
     355                llFiles2Delete.push_back(sfaFiles[u]);
     356            }
     357
     358            rc = pMachine->DeleteSettings();
     359            if (FAILED(rc)) throw MyError(rc, "Machine::DeleteSettings() failed\n");
    370360        }
    371361    }
     
    382372    {
    383373        const Utf8Str &strFile = *it;
     374        RTPrintf("Deleting file %s...\n", strFile.c_str());
    384375        RTFileDelete(strFile.c_str());
    385376    }
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