VirtualBox

Changeset 31615 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 12, 2010 6:12:39 PM (14 years ago)
Author:
vboxsync
Message:

Main: Implemenation of per-machine media registries; VirtualBox::openMedium() no longer adds media to the global registry, instead a media are stored in a machine XML registry after Machine::AttachDevice() has been called; Machine::AttachDevice() now takes an IMedium object instead of a UUID; also make Machine::Unregister() work again for inaccessible machines

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

Legend:

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

    r31562 r31615  
    15041504            // create a new hard disk interface for the destination disk image
    15051505            Log(("Creating target disk \"%s\"\n", strTargetFilePath.c_str()));
    1506             rc = mVirtualBox->CreateHardDisk(bstrSrcFormat, Bstr(strTargetFilePath), pTargetDisk.asOutParam());
     1506            rc = mVirtualBox->CreateHardDisk(bstrSrcFormat,
     1507                                             Bstr(strTargetFilePath),
     1508                                             pTargetDisk.asOutParam());
    15071509            if (FAILED(rc)) throw rc;
    15081510
  • trunk/src/VBox/Main/ApplianceImplImport.cpp

    r31568 r31615  
    13161316                srcFormat = L"VMDK";
    13171317            // create an empty hard disk
    1318             rc = mVirtualBox->CreateHardDisk(srcFormat, Bstr(strTargetPath), pTargetHD.asOutParam());
     1318            rc = mVirtualBox->CreateHardDisk(srcFormat,
     1319                                             Bstr(strTargetPath),
     1320                                             pTargetHD.asOutParam());
    13191321            if (FAILED(rc)) DebugBreakThrow(rc);
    13201322
     
    13541356            if (FAILED(rc)) DebugBreakThrow(rc);
    13551357            /* Create a new hard disk interface for the destination disk image */
    1356             rc = mVirtualBox->CreateHardDisk(srcFormat, Bstr(strTargetPath), pTargetHD.asOutParam());
     1358            rc = mVirtualBox->CreateHardDisk(srcFormat,
     1359                                             Bstr(strTargetPath),
     1360                                             pTargetHD.asOutParam());
    13571361            if (FAILED(rc)) DebugBreakThrow(rc);
    13581362            /* Clone the source disk image */
     
    17071711    rc = pNewMachine->COMGETTER(Id)(bstrNewMachineId.asOutParam());
    17081712    if (FAILED(rc)) DebugBreakThrow(rc);
    1709     m->llGuidsMachinesCreated.push_back(Guid(bstrNewMachineId));
     1713    Guid uuidNewMachine(bstrNewMachineId);
     1714    m->llGuidsMachinesCreated.push_back(uuidNewMachine);
    17101715
    17111716    // Add floppies and CD-ROMs to the appropriate controllers.
     
    18741879                rc = stack.pSession->COMGETTER(Machine)(sMachine.asOutParam());
    18751880                if (FAILED(rc)) DebugBreakThrow(rc);
    1876                 Bstr hdId;
    1877                 rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam());
    1878                 if (FAILED(rc)) DebugBreakThrow(rc);
    18791881
    18801882                // find the hard disk controller to which we should attach
     
    18971899                                            mhda.lDevice,           // long device
    18981900                                            DeviceType_HardDisk,    // DeviceType_T type
    1899                                             hdId);                  // uuid id
     1901                                            pTargetHD);
    19001902                if (FAILED(rc)) DebugBreakThrow(rc);
    19011903
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31574 r31615  
    30973097                                   LONG aDevice,
    30983098                                   DeviceType_T aType,
    3099                                    IN_BSTR aId)
     3099                                   IMedium *aMedium)
    31003100{
    31013101    LogFlowThisFunc(("aControllerName=\"%ls\" aControllerPort=%d aDevice=%d aType=%d aId=\"%ls\"\n",
    3102                      aControllerName, aControllerPort, aDevice, aType, aId));
     3102                     aControllerName, aControllerPort, aDevice, aType, aMedium));
    31033103
    31043104    CheckComArgStrNotEmptyOrNull(aControllerName);
     
    31093109    // if this becomes true then we need to call saveSettings in the end
    31103110    // @todo r=dj there is no error handling so far...
    3111     bool fNeedsSaveSettings = false;
     3111    bool fNeedsGlobalSaveSettings = false;
    31123112
    31133113    // request the host lock first, since might be calling Host methods for getting host drives;
     
    31653165    }
    31663166
    3167     Guid uuid(aId);
    3168 
    3169     ComObjPtr<Medium> medium;
    3170 
    3171     switch (aType)
    3172     {
    3173         case DeviceType_HardDisk:
    3174             /* find a hard disk by UUID */
    3175             rc = mParent->findHardDisk(&uuid, Utf8Str::Empty, true /* aSetError */, &medium);
    3176             if (FAILED(rc)) return rc;
    3177             break;
    3178 
    3179         case DeviceType_DVD:
    3180         case DeviceType_Floppy:
    3181             rc = mParent->findRemoveableMedium(aType, uuid, true /* fRefresh */, medium);
    3182         break;
    3183 
    3184         default:
    3185             return setError(E_INVALIDARG,
    3186                             tr("The device type %d is not recognized"),
    3187                             (int)aType);
    3188     }
     3167    ComObjPtr<Medium> medium = static_cast<Medium*>(aMedium);
     3168    if (aMedium && medium.isNull())
     3169        return setError(E_INVALIDARG, "The given medium pointer is invalid");
    31893170
    31903171    AutoCaller mediumCaller(medium);
     
    32233204                {
    32243205                    /* the simplest case: restore the whole attachment
    3225                     * and return, nothing else to do */
     3206                     * and return, nothing else to do */
    32263207                    mMediaData->mAttachments.push_back(pAttachTemp);
    32273208                    return S_OK;
     
    32293210
    32303211                /* bus/channel/device differ; we need a new attachment object,
    3231                     * but don't try to associate it again */
     3212                 * but don't try to associate it again */
    32323213                associate = false;
    32333214                break;
     
    33943375                        medium->getPreferredDiffFormat(),
    33953376                        Utf8Str(mUserData->m_strSnapshotFolderFull).append(RTPATH_SLASH_STR),
    3396                         &fNeedsSaveSettings);
     3377                        medium->getRegistryMachineId(),         // store this diff in the same registry as the parent
     3378                        &fNeedsGlobalSaveSettings);
    33973379        if (FAILED(rc)) return rc;
    33983380
     
    34263408                                               NULL /* aProgress */,
    34273409                                               true /* aWait */,
    3428                                                &fNeedsSaveSettings);
     3410                                               &fNeedsGlobalSaveSettings);
    34293411
    34303412                alock.enter();
     
    34633445    if (associate && !medium.isNull())
    34643446    {
    3465         /* as the last step, associate the medium to the VM */
     3447        // as the last step, associate the medium to the VM
    34663448        rc = medium->addBackReference(mData->mUuid);
    3467         /* here we can fail because of Deleting, or being in process of
    3468          * creating a Diff */
     3449        // here we can fail because of Deleting, or being in process of creating a Diff
    34693450        if (FAILED(rc)) return rc;
     3451
     3452        // and decide which medium registry to use now that the medium is attached:
     3453        if (mData->pMachineConfigFile->canHaveOwnMediaRegistry())
     3454            medium->setRegistryIdIfFirst(getId());        // machine UUID
     3455        else
     3456            medium->setRegistryIdIfFirst(mParent->getGlobalRegistryId()); // VirtualBox global registry UUID
    34703457    }
    34713458
     
    34753462    mMediaData->mAttachments.push_back(attachment);
    34763463
    3477     if (fNeedsSaveSettings)
     3464    if (fNeedsGlobalSaveSettings)
    34783465    {
    34793466        // save the global settings; for that we should hold only the VirtualBox lock
     
    39533940                                 ComSafeArrayOut(IMedium*, aMedia))
    39543941{
    3955     AutoCaller autoCaller(this);
    3956     if (FAILED(autoCaller.rc())) return autoCaller.rc();
     3942    // use AutoLimitedCaller because this call is valid on inaccessible machines as well
     3943    AutoLimitedCaller autoCaller(this);
     3944    AssertComRCReturnRC(autoCaller.rc());
    39573945
    39583946    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     3947
     3948    Guid id(getId());
    39593949
    39603950    if (mData->mSession.mState != SessionState_Unlocked)
     
    39623952                        tr("Cannot unregister the machine '%s' while it is locked"),
    39633953                        mUserData->s.strName.c_str());
     3954
     3955    // wait for state dependants to drop to zero
     3956    ensureNoStateDependencies();
     3957
     3958    if (!mData->mAccessible)
     3959    {
     3960        // inaccessible maschines can only be unregistered; uninitialize ourselves
     3961        // here because currently there may be no unregistered that are inaccessible
     3962        // (this state combination is not supported). Note releasing the caller and
     3963        // leaving the lock before alling uninit()
     3964        alock.leave();
     3965        autoCaller.release();
     3966
     3967        uninit();
     3968
     3969        mParent->unregisterMachine(this, id);
     3970            // calls VirtualBox::saveSettings()
     3971
     3972        return S_OK;
     3973    }
    39643974
    39653975    HRESULT rc = S_OK;
     
    40554065    sfaMedia.detachTo(ComSafeArrayOutArg(aMedia));
    40564066
    4057     mParent->unregisterMachine(this);
     4067    mParent->unregisterMachine(this, id);
    40584068            // calls VirtualBox::saveSettings()
    40594069
     
    66816691    mUserData.commitCopy();
    66826692
     6693    // machine registry, if present (must be loaded before snapshots)
     6694    if (config.canHaveOwnMediaRegistry())
     6695    {
     6696        rc = mParent->initMedia(getId(),         // media registry ID == machine UUID
     6697                                config.mediaRegistry);
     6698        if (FAILED(rc)) return rc;
     6699    }
     6700
    66836701    /* Snapshot node (optional) */
    66846702    size_t cRootSnapshots;
     
    66966714    }
    66976715
    6698     /* Hardware node (required) */
     6716    // hardware data
    66996717    rc = loadHardware(config.hardwareMachine);
    67006718    if (FAILED(rc)) return rc;
    67016719
    6702     /* Load storage controllers */
     6720    // load storage controllers
    67036721    rc = loadStorageControllers(config.storageMachine);
    67046722    if (FAILED(rc)) return rc;
     
    77797797    if (FAILED(rc)) throw rc;
    77807798
     7799    // save machine's media registry if this is VirtualBox 3.3 or later
     7800    if (config.canHaveOwnMediaRegistry())
     7801        mParent->saveMediaRegistry(config.mediaRegistry,
     7802                                   getId());            // only media with registry ID == machine UUID
     7803            // this throws HRESULT
     7804
    77817805    // save snapshots
    77827806    rc = saveAllSnapshots(config);
     
    83578381                            pMedium->getPreferredDiffFormat(),
    83588382                            Utf8Str(mUserData->m_strSnapshotFolderFull).append(RTPATH_SLASH_STR),
     8383                            pMedium->getRegistryMachineId(),        // store the diff in the same registry as the parent
    83598384                            pfNeedsSaveSettings);
    83608385            if (FAILED(rc)) throw rc;
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31571 r31615  
    191191    Task(Medium *aMedium, Progress *aProgress)
    192192        : mVDOperationIfaces(NULL),
    193           m_pfNeedsSaveSettings(NULL),
     193          m_pfNeedsGlobalSaveSettings(NULL),
    194194          mMedium(aMedium),
    195195          mMediumCaller(aMedium),
     
    234234    // the task function returns. Only used in synchronous (wait) mode;
    235235    // otherwise the task will save the settings itself.
    236     bool *m_pfNeedsSaveSettings;
     236    bool *m_pfNeedsGlobalSaveSettings;
    237237
    238238    const ComObjPtr<Medium> mMedium;
     
    728728 * storage unit.
    729729 *
    730  * This gets called by VirtualBox::CreateHardDisk().
     730 * This gets called by VirtualBox::CreateHardDisk() in which case uuidMachineRegistry
     731 * is empty since starting with VirtualBox 3.3, we no longer add opened media to a
     732 * registry automatically (this is deferred until the medium is attached to a machine).
     733 *
     734 * This also gets called when VirtualBox creates diff images; in this case uuidMachineRegistry
     735 * is set to the registry of the parent image to make sure they all end up in the same
     736 * file.
    731737 *
    732738 * For hard disks that don't have the VD_CAP_CREATE_FIXED or
     
    736742 *
    737743 * @param aVirtualBox   VirtualBox object.
     744 * @param aFormat
    738745 * @param aLocation     Storage unit location.
    739  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     746 * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUI or medium UUID or empty if none).
     747 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    740748 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    741749 */
     
    743751                     const Utf8Str &aFormat,
    744752                     const Utf8Str &aLocation,
    745                      bool *pfNeedsSaveSettings)
     753                     const Guid &uuidMachineRegistry,
     754                     bool *pfNeedsGlobalSaveSettings)
    746755{
    747756    AssertReturn(aVirtualBox != NULL, E_FAIL);
     
    754763    HRESULT rc = S_OK;
    755764
    756     /* share VirtualBox weakly (parent remains NULL so far) */
    757765    unconst(m->pVirtualBox) = aVirtualBox;
     766    m->uuidRegistryMachine = uuidMachineRegistry;
    758767
    759768    /* no storage yet */
     
    791800
    792801        AutoWriteLock treeLock(m->pVirtualBox->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    793         rc = m->pVirtualBox->registerHardDisk(this, pfNeedsSaveSettings);
     802        rc = m->pVirtualBox->registerHardDisk(this, pfNeedsGlobalSaveSettings);
    794803    }
    795804
     
    809818 * Machine::AttachDevice() and createImplicitDiffs() when new diff
    810819 * images are created.
     820 *
     821 * There is no registry for this case since starting with VirtualBox 3.3, we
     822 * no longer add opened media to a registry automatically (this is deferred
     823 * until the medium is attached to a machine).
    811824 *
    812825 * For hard disks, the UUID, format and the parent of this medium will be
     
    835848    HRESULT rc = S_OK;
    836849
    837     /* share VirtualBox weakly (parent remains NULL so far) */
    838850    unconst(m->pVirtualBox) = aVirtualBox;
    839851
     
    893905 * node. In this mode, the medium will always be opened read/write.
    894906 *
     907 * In this case, since we're loading from a registry, uuidMachineRegistry is
     908 * always set: it's either the global registry UUID or a machine UUID when
     909 * loading from a per-machine registry.
     910 *
    895911 * @param aVirtualBox   VirtualBox object.
    896912 * @param aParent       Parent medium disk or NULL for a root (base) medium.
    897913 * @param aDeviceType   Device type of the medium.
     914 * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUI or medium UUID).
    898915 * @param aNode         Configuration settings.
    899916 *
     
    903920                     Medium *aParent,
    904921                     DeviceType_T aDeviceType,
     922                     const Guid &uuidMachineRegistry,
    905923                     const settings::Medium &data)
    906924{
     
    915933    HRESULT rc = S_OK;
    916934
    917     /* share VirtualBox and parent weakly */
    918935    unconst(m->pVirtualBox) = aVirtualBox;
     936    m->uuidRegistryMachine = uuidMachineRegistry;
    919937
    920938    /* register with VirtualBox/parent early, since uninit() will
     
    10201038                       this,            // parent
    10211039                       aDeviceType,
     1040                       uuidMachineRegistry,
    10221041                       med);              // child data
    10231042        if (FAILED(rc)) break;
    10241043
    1025         rc = m->pVirtualBox->registerHardDisk(pHD, NULL /*pfNeedsSaveSettings*/);
     1044        rc = m->pVirtualBox->registerHardDisk(pHD, NULL /*pfNeedsGlobalSaveSettings*/);
    10261045        if (FAILED(rc)) break;
    10271046    }
     
    10371056 * Initializes the medium object by providing the host drive information.
    10381057 * Not used for anything but the host floppy/host DVD case.
     1058 *
     1059 * There is no registry for this case.
    10391060 *
    10401061 * @param aVirtualBox   VirtualBox object.
     
    10571078    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    10581079
    1059     /* share VirtualBox weakly (parent remains NULL so far) */
    10601080    unconst(m->pVirtualBox) = aVirtualBox;
    10611081
     
    19621982    ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox);
    19631983
    1964     bool fNeedsSaveSettings = false;
    1965     HRESULT rc = close(&fNeedsSaveSettings, autoCaller);
    1966 
    1967     if (fNeedsSaveSettings)
     1984    bool fNeedsGlobalSaveSettings = false;
     1985    HRESULT rc = close(&fNeedsGlobalSaveSettings, autoCaller);
     1986
     1987    if (fNeedsGlobalSaveSettings)
    19681988    {
    19691989        AutoWriteLock vboxlock(pVirtualBox COMMA_LOCKVAL_SRC_POS);
     
    21802200    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    21812201
    2182     bool fNeedsSaveSettings = false;
     2202    bool fNeedsGlobalSaveSettings = false;
    21832203    ComObjPtr<Progress> pProgress;
    21842204
    21852205    HRESULT rc = deleteStorage(&pProgress,
    21862206                               false /* aWait */,
    2187                                &fNeedsSaveSettings);
    2188     if (fNeedsSaveSettings)
     2207                               &fNeedsGlobalSaveSettings);
     2208    if (fNeedsGlobalSaveSettings)
    21892209    {
    21902210        AutoWriteLock vboxlock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
     
    22362256
    22372257    rc = createDiffStorage(diff, aVariant, pMediumLockList, &pProgress,
    2238                            false /* aWait */, NULL /* pfNeedsSaveSettings*/);
     2258                           false /* aWait */, NULL /* pfNeedsGlobalSaveSettings*/);
    22392259    if (FAILED(rc))
    22402260        delete pMediumLockList;
     
    22712291    rc = mergeTo(pTarget, fMergeForward, pParentForTarget, childrenToReparent,
    22722292                 pMediumLockList, &pProgress, false /* aWait */,
    2273                  NULL /* pfNeedsSaveSettings */);
     2293                 NULL /* pfNeedsGlobalSaveSettings */);
    22742294    if (FAILED(rc))
    22752295        cancelMergeTo(childrenToReparent, pMediumLockList);
     
    32653285    Utf8Str name = RTPathFilename(m->strLocationFull.c_str());
    32663286    return name;
     3287}
     3288
     3289/**
     3290 * This sets the UUID of the machine in whose registry this medium should
     3291 * be registered, or the UUID of the global VirtualBox.xml registry, but
     3292 * only if no registry ID had been previously set.
     3293 * @param id
     3294 */
     3295void Medium::setRegistryIdIfFirst(const Guid& id)
     3296{
     3297    if (m->uuidRegistryMachine.isEmpty())
     3298        m->uuidRegistryMachine = id;
     3299}
     3300
     3301/**
     3302 * Returns the UUID of the machine in whose registry this medium is registered,
     3303 * or the UUID of the global VirtualBox.xml registry.
     3304 * @return
     3305 */
     3306const Guid& Medium::getRegistryId() const
     3307{
     3308    return m->uuidRegistryMachine;
    32673309}
    32683310
     
    38513893 * the object is no longer usable ("not ready" state).
    38523894 *
    3853  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     3895 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    38543896 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    38553897 *                This only works in "wait" mode; otherwise saveSettings gets called automatically by the thread that was created,
     
    38593901 * @return
    38603902 */
    3861 HRESULT Medium::close(bool *pfNeedsSaveSettings, AutoCaller &autoCaller)
     3903HRESULT Medium::close(bool *pfNeedsGlobalSaveSettings, AutoCaller &autoCaller)
    38623904{
    38633905    // we're accessing parent/child and backrefs, so lock the tree first, then ourselves
     
    38963938        // uninitialization (to keep the media registry consistent on
    38973939        // failure to do so)
    3898         rc = unregisterWithVirtualBox(pfNeedsSaveSettings);
     3940        rc = unregisterWithVirtualBox(pfNeedsGlobalSaveSettings);
    38993941        if (FAILED(rc)) return rc;
    39003942    }
     
    39303972 * @param aWait         @c true if this method should block instead of creating
    39313973 *                      an asynchronous thread.
    3932  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     3974 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    39333975 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    39343976 *                This only works in "wait" mode; otherwise saveSettings gets called automatically by the thread that was created,
     
    39403982HRESULT Medium::deleteStorage(ComObjPtr<Progress> *aProgress,
    39413983                              bool aWait,
    3942                               bool *pfNeedsSaveSettings)
     3984                              bool *pfNeedsGlobalSaveSettings)
    39433985{
    39443986    AssertReturn(aProgress != NULL || aWait == true, E_FAIL);
     
    40424084         * which would have been broken if unregisterWithVirtualBox() failed
    40434085         * after we successfully deleted the storage) */
    4044         rc = unregisterWithVirtualBox(pfNeedsSaveSettings);
     4086        rc = unregisterWithVirtualBox(pfNeedsGlobalSaveSettings);
    40454087        if (FAILED(rc))
    40464088            throw rc;
     
    40784120    {
    40794121        if (aWait)
    4080             rc = runNow(pTask, NULL /* pfNeedsSaveSettings*/);
     4122            rc = runNow(pTask, NULL /* pfNeedsGlobalSaveSettings*/);
    40814123        else
    40824124            rc = startThread(pTask);
     
    42014243 * @param aWait             @c true if this method should block instead of
    42024244 *                          creating an asynchronous thread.
    4203  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been
     4245 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been
    42044246 *                          initialized to false and that will be set to true
    42054247 *                          by this function if the caller should invoke
     
    42174259                                  ComObjPtr<Progress> *aProgress,
    42184260                                  bool aWait,
    4219                                   bool *pfNeedsSaveSettings)
     4261                                  bool *pfNeedsGlobalSaveSettings)
    42204262{
    42214263    AssertReturn(!aTarget.isNull(), E_FAIL);
     
    43074349    {
    43084350        if (aWait)
    4309             rc = runNow(pTask, pfNeedsSaveSettings);
     4351            rc = runNow(pTask, pfNeedsGlobalSaveSettings);
    43104352        else
    43114353            rc = startThread(pTask);
     
    46854727 * @param aWait         @c true if this method should block instead of creating
    46864728 *                      an asynchronous thread.
    4687  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     4729 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    46884730 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    46894731 *                This only works in "wait" mode; otherwise saveSettings gets called automatically by the thread that was created,
     
    47004742                        ComObjPtr <Progress> *aProgress,
    47014743                        bool aWait,
    4702                         bool *pfNeedsSaveSettings)
     4744                        bool *pfNeedsGlobalSaveSettings)
    47034745{
    47044746    AssertReturn(pTarget != NULL, E_FAIL);
     
    47624804    {
    47634805        if (aWait)
    4764             rc = runNow(pTask, pfNeedsSaveSettings);
     4806            rc = runNow(pTask, pfNeedsGlobalSaveSettings);
    47654807        else
    47664808            rc = startThread(pTask);
     
    48634905 * on the device type of this medium.
    48644906 *
    4865  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     4907 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    48664908 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    48674909 *
    48684910 * @note Caller must have locked the media tree lock for writing!
    48694911 */
    4870 HRESULT Medium::unregisterWithVirtualBox(bool *pfNeedsSaveSettings)
     4912HRESULT Medium::unregisterWithVirtualBox(bool *pfNeedsGlobalSaveSettings)
    48714913{
    48724914    /* Note that we need to de-associate ourselves from the parent to let
     
    48854927    {
    48864928        case DeviceType_DVD:
    4887             rc = m->pVirtualBox->unregisterImage(this, DeviceType_DVD, pfNeedsSaveSettings);
     4929            rc = m->pVirtualBox->unregisterImage(this, DeviceType_DVD, pfNeedsGlobalSaveSettings);
    48884930        break;
    48894931
    48904932        case DeviceType_Floppy:
    4891             rc = m->pVirtualBox->unregisterImage(this, DeviceType_Floppy, pfNeedsSaveSettings);
     4933            rc = m->pVirtualBox->unregisterImage(this, DeviceType_Floppy, pfNeedsGlobalSaveSettings);
    48924934        break;
    48934935
    48944936        case DeviceType_HardDisk:
    4895             rc = m->pVirtualBox->unregisterHardDisk(this, pfNeedsSaveSettings);
     4937            rc = m->pVirtualBox->unregisterHardDisk(this, pfNeedsGlobalSaveSettings);
    48964938        break;
    48974939
     
    53205362 */
    53215363HRESULT Medium::runNow(Medium::Task *pTask,
    5322                        bool *pfNeedsSaveSettings)
     5364                       bool *pfNeedsGlobalSaveSettings)
    53235365{
    53245366#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     
    53305372#endif
    53315373
    5332     pTask->m_pfNeedsSaveSettings = pfNeedsSaveSettings;
     5374    pTask->m_pfNeedsGlobalSaveSettings = pfNeedsGlobalSaveSettings;
    53335375
    53345376    /* NIL_RTTHREAD indicates synchronous call. */
     
    54285470         * Created state only on success (leaving an orphan file is
    54295471         * better than breaking media registry consistency) */
    5430         bool fNeedsSaveSettings = false;
     5472        bool fNeedsGlobalSaveSettings = false;
    54315473        AutoWriteLock treeLock(m->pVirtualBox->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    5432         rc = m->pVirtualBox->registerHardDisk(this, &fNeedsSaveSettings);
     5474        rc = m->pVirtualBox->registerHardDisk(this, &fNeedsGlobalSaveSettings);
    54335475        treeLock.release();
    54345476
    5435         if (fNeedsSaveSettings)
     5477        if (fNeedsGlobalSaveSettings)
    54365478        {
    54375479            AutoWriteLock vboxlock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
     
    54705512 * synchronously or asynchronously depending on the "wait" parameter passed to
    54715513 * that function. If we run synchronously, the caller expects the bool
    5472  * *pfNeedsSaveSettings to be set before returning; otherwise (in asynchronous
     5514 * *pfNeedsGlobalSaveSettings to be set before returning; otherwise (in asynchronous
    54735515 * mode), we save the settings ourselves.
    54745516 *
     
    54805522    HRESULT rc = S_OK;
    54815523
    5482     bool fNeedsSaveSettings = false;
     5524    bool fNeedsGlobalSaveSettings = false;
    54835525
    54845526    const ComObjPtr<Medium> &pTarget = task.mTarget;
     
    56095651         * Created state only on success (leaving an orphan file is
    56105652         * better than breaking media registry consistency) */
    5611         rc = m->pVirtualBox->registerHardDisk(pTarget, &fNeedsSaveSettings);
     5653        rc = m->pVirtualBox->registerHardDisk(pTarget, &fNeedsGlobalSaveSettings);
    56125654
    56135655        if (FAILED(rc))
     
    56445686    if (task.isAsync())
    56455687    {
    5646         if (fNeedsSaveSettings)
     5688        if (fNeedsGlobalSaveSettings)
    56475689        {
    56485690            // save the global settings; for that we should hold only the VirtualBox lock
     
    56545696    else
    56555697        // synchronous mode: report save settings result to caller
    5656         if (task.m_pfNeedsSaveSettings)
    5657             *task.m_pfNeedsSaveSettings = fNeedsSaveSettings;
     5698        if (task.m_pfNeedsGlobalSaveSettings)
     5699            *task.m_pfNeedsGlobalSaveSettings = fNeedsGlobalSaveSettings;
    56585700
    56595701    /* Note that in sync mode, it's the caller's responsibility to
     
    56695711 * synchronously or asynchrously depending on the "wait" parameter passed to
    56705712 * that function. If we run synchronously, the caller expects the bool
    5671  * *pfNeedsSaveSettings to be set before returning; otherwise (in asynchronous
     5713 * *pfNeedsGlobalSaveSettings to be set before returning; otherwise (in asynchronous
    56725714 * mode), we save the settings ourselves.
    56735715 *
     
    58315873            /* first, unregister the target since it may become a base
    58325874             * medium which needs re-registration */
    5833             rc2 = m->pVirtualBox->unregisterHardDisk(pTarget, NULL /*&fNeedsSaveSettings*/);
     5875            rc2 = m->pVirtualBox->unregisterHardDisk(pTarget, NULL /*&fNeedsGlobalSaveSettings*/);
    58345876            AssertComRC(rc2);
    58355877
     
    58455887
    58465888            /* then, register again */
    5847             rc2 = m->pVirtualBox->registerHardDisk(pTarget, NULL /*&fNeedsSaveSettings*/);
     5889            rc2 = m->pVirtualBox->registerHardDisk(pTarget, NULL /*&fNeedsGlobalSaveSettings*/);
    58485890            AssertComRC(rc2);
    58495891        }
     
    58995941
    59005942            rc2 = pMedium->m->pVirtualBox->unregisterHardDisk(pMedium,
    5901                                                               NULL /*pfNeedsSaveSettings*/);
     5943                                                              NULL /*pfNeedsGlobalSaveSettings*/);
    59025944            AssertComRC(rc2);
    59035945
     
    59415983    else
    59425984        // synchronous mode: report save settings result to caller
    5943         if (task.m_pfNeedsSaveSettings)
    5944             *task.m_pfNeedsSaveSettings = true;
     5985        if (task.m_pfNeedsGlobalSaveSettings)
     5986            *task.m_pfNeedsGlobalSaveSettings = true;
    59455987
    59465988    if (FAILED(rc))
     
    61606202             * Created state only on success (leaving an orphan file is
    61616203             * better than breaking media registry consistency) */
    6162             rc = pParent->m->pVirtualBox->registerHardDisk(pTarget, NULL /* pfNeedsSaveSettings */);
     6204            rc = pParent->m->pVirtualBox->registerHardDisk(pTarget, NULL /* pfNeedsGlobalSaveSettings */);
    61636205
    61646206            if (FAILED(rc))
     
    61696211        {
    61706212            /* just register  */
    6171             rc = m->pVirtualBox->registerHardDisk(pTarget, NULL /* pfNeedsSaveSettings */);
     6213            rc = m->pVirtualBox->registerHardDisk(pTarget, NULL /* pfNeedsGlobalSaveSettings */);
    61726214        }
    61736215    }
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r31539 r31615  
    13571357
    13581358    // if this becomes true, we need to call VirtualBox::saveSettings() in the end
    1359     bool fNeedsSaveSettings = false;
     1359    bool fNeedsGlobalSaveSettings = false;
    13601360
    13611361    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    14401440                                 1,            // operation weight; must be the same as in Console::TakeSnapshot()
    14411441                                 !!fTakingSnapshotOnline,
    1442                                  &fNeedsSaveSettings);
     1442                                 &fNeedsGlobalSaveSettings);
    14431443        if (FAILED(rc))
    14441444            throw rc;
     
    15011501        *aStateFilePath = NULL;
    15021502
    1503     // @todo r=dj normally we would need to save the settings if fNeedsSaveSettings was set to true,
     1503    // @todo r=dj normally we would need to save the settings if fNeedsGlobalSaveSettings was set to true,
    15041504    // but since we have no error handling that cleans up the diff image that might have gotten created,
    15051505    // there's no point in saving the disk registry at this point either... this needs fixing.
     
    23202320
    23212321    bool fMachineSettingsChanged = false;       // Machine
    2322     bool fNeedsSaveSettings = false;            // VirtualBox.xml
     2322    bool fNeedsGlobalSaveSettings = false;            // VirtualBox.xml
    23232323
    23242324    Guid snapshotId;
     
    25642564                                                true /* aWait */,
    25652565                                                &fNeedsSave);
    2566                     fNeedsSaveSettings |= fNeedsSave;
     2566                    fNeedsGlobalSaveSettings |= fNeedsSave;
    25672567                    if (FAILED(rc))
    25682568                        throw rc;
     
    26072607                                               &fNeedsSave);
    26082608                }
    2609                 fNeedsSaveSettings |= fNeedsSave;
     2609                fNeedsGlobalSaveSettings |= fNeedsSave;
    26102610
    26112611                // If the merge failed, we need to do our best to have a usable
     
    27542754        updateMachineStateOnClient();
    27552755
    2756         if (fMachineSettingsChanged || fNeedsSaveSettings)
     2756        if (fMachineSettingsChanged || fNeedsGlobalSaveSettings)
    27572757        {
    27582758            if (fMachineSettingsChanged)
     
    27652765                // then, as it avoids a rather costly config equality check
    27662766                // when we know that it is changed.
    2767                 saveSettings(&fNeedsSaveSettings, SaveS_Force | SaveS_InformCallbacksAnyway);
     2767                saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force | SaveS_InformCallbacksAnyway);
    27682768            }
    27692769
    2770             if (fNeedsSaveSettings)
     2770            if (fNeedsGlobalSaveSettings)
    27712771            {
    27722772                AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
     
    31373137 *                      return NULL if no real merge is necessary).
    31383138 * @param aProgress     Progress indicator.
    3139  * @param pfNeedsSaveSettings Whether the VM settings need to be saved (out).
     3139 * @param pfNeedsMachineSaveSettings Whether the VM settings need to be saved (out).
    31403140 */
    31413141HRESULT SessionMachine::onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
     
    31473147                                          MediumLockList *aMediumLockList,
    31483148                                          ComObjPtr<Progress> &aProgress,
    3149                                           bool *pfNeedsSaveSettings)
     3149                                          bool *pfNeedsMachineSaveSettings)
    31503150{
    31513151    AssertReturn(aSource != NULL, E_FAIL);
     
    32253225    // The callback mentioned above takes care of update the medium state
    32263226
    3227     if (pfNeedsSaveSettings)
    3228         *pfNeedsSaveSettings = true;
     3227    if (pfNeedsMachineSaveSettings)
     3228        *pfNeedsMachineSaveSettings = true;
    32293229
    32303230    return rc;
     
    32603260    if (aMergeForward)
    32613261    {
     3262        Guid uuidRegistry = pTarget->getRegistryId();
     3263
    32623264        // first, unregister the target since it may become a base
    32633265        // hard disk which needs re-registration
    3264         rc = mParent->unregisterHardDisk(pTarget, NULL /*&fNeedsSaveSettings*/);
     3266        rc = mParent->unregisterHardDisk(pTarget, NULL /*&fNeedsGlobalSaveSettings*/);
    32653267        AssertComRC(rc);
    32663268
     
    32733275
    32743276        // then, register again
    3275         rc = mParent->registerHardDisk(pTarget, NULL /*&fNeedsSaveSettings*/);
     3277        rc = mParent->registerHardDisk(pTarget, NULL /*&fNeedsGlobalSaveSettings*/);
    32763278        AssertComRC(rc);
    32773279    }
     
    33443346        {
    33453347            rc = mParent->unregisterHardDisk(pMedium,
    3346                                              NULL /*pfNeedsSaveSettings*/);
     3348                                             NULL /*pfNeedsGlobalSaveSettings*/);
    33473349            AssertComRC(rc);
    33483350
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31595 r31615  
    240240          threadAsyncEvent(NIL_RTTHREAD),
    241241          pAsyncEventQ(NULL)
    242     {}
     242    {
     243        unconst(uuidMediaRegistry).create();
     244    }
    243245
    244246    ~Data()
     
    257259    const Utf8Str                       strSettingsFilePath;
    258260    settings::MainConfigFile            *pMainConfigFile;
     261
     262    // pseudo machine ID for global media registry (recreated on every startup)
     263    const Guid                          uuidMediaRegistry;
    259264
    260265    // const objects not requiring locking
     
    465470
    466471        /* all registered media, needed by machines */
    467         if (FAILED(rc = initMedia()))
     472        if (FAILED(rc = initMedia(m->uuidMediaRegistry,
     473                                  m->pMainConfigFile->mediaRegistry)))
    468474            throw rc;
    469475
     
    593599}
    594600
    595 HRESULT VirtualBox::initMedia()
    596 {
     601/**
     602 * Loads a media registry from XML and adds the media contained therein to
     603 * the global lists of known media.
     604 *
     605 * This now (3.3) gets called from two locations:
     606 *
     607 *  --  VirtualBox::init(), to load the global media registry from VirtualBox.xml;
     608 *
     609 *  --  Machine::loadMachineDataFromSettings(), to load the per-machine registry
     610 *      from machine XML, for machines created with VirtualBox 3.3 or later.
     611 *
     612 * In both cases, the media found are added to the global lists so the
     613 * global arrays of media (including the GUI's virtual media manager)
     614 * continue to work as before.
     615 *
     616 * @param uuidMachineRegistry The UUID of the media registry. This is either the
     617 *       transient UUID created at VirtualBox startup for the global registry or
     618 *       a machine ID.
     619 * @param mediaRegistry The XML settings structure to load, either from VirtualBox.xml
     620 *       or a machine XML.
     621 * @return
     622 */
     623HRESULT VirtualBox::initMedia(const Guid &uuidRegistry,
     624                              const settings::MediaRegistry mediaRegistry)
     625{
     626    LogFlow(("VirtualBox::initMedia ENTERING, uuidRegistry=%s\n", uuidRegistry.toString().c_str()));
     627
    597628    AutoWriteLock treeLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    598629
    599630    HRESULT rc = S_OK;
    600631    settings::MediaList::const_iterator it;
    601     for (it = m->pMainConfigFile->mediaRegistry.llHardDisks.begin();
    602          it != m->pMainConfigFile->mediaRegistry.llHardDisks.end();
     632    for (it = mediaRegistry.llHardDisks.begin();
     633         it != mediaRegistry.llHardDisks.end();
    603634         ++it)
    604635    {
     
    608639        if (SUCCEEDED(rc = pHardDisk.createObject()))
    609640            rc = pHardDisk->init(this,
    610                                  NULL,           // parent
     641                                 NULL,          // parent
    611642                                 DeviceType_HardDisk,
    612                                  xmlHD);         // XML data; this recurses to processes the children
     643                                 uuidRegistry,
     644                                 xmlHD);        // XML data; this recurses to processes the children
    613645        if (FAILED(rc)) return rc;
    614646
    615         rc = registerHardDisk(pHardDisk, NULL /*pfNeedsSaveSettings*/ );
     647        rc = registerHardDisk(pHardDisk,
     648                              NULL /*pfNeedsGlobalSaveSettings*/ );
    616649        if (FAILED(rc)) return rc;
    617650    }
    618651
    619     for (it = m->pMainConfigFile->mediaRegistry.llDvdImages.begin();
    620          it != m->pMainConfigFile->mediaRegistry.llDvdImages.end();
     652    for (it = mediaRegistry.llDvdImages.begin();
     653         it != mediaRegistry.llDvdImages.end();
    621654         ++it)
    622655    {
     
    625658        ComObjPtr<Medium> pImage;
    626659        if (SUCCEEDED(pImage.createObject()))
    627             rc = pImage->init(this, NULL, DeviceType_DVD, xmlDvd);
     660            rc = pImage->init(this,
     661                              NULL,
     662                              DeviceType_DVD,
     663                              uuidRegistry,
     664                              xmlDvd);
    628665        if (FAILED(rc)) return rc;
    629666
    630         rc = registerImage(pImage, DeviceType_DVD, NULL /*pfNeedsSaveSettings*/ );
     667        rc = registerImage(pImage,
     668                           DeviceType_DVD,
     669                           NULL /*pfNeedsGlobalSaveSettings*/ );
    631670        if (FAILED(rc)) return rc;
    632671    }
    633672
    634     for (it = m->pMainConfigFile->mediaRegistry.llFloppyImages.begin();
    635          it != m->pMainConfigFile->mediaRegistry.llFloppyImages.end();
     673    for (it = mediaRegistry.llFloppyImages.begin();
     674         it != mediaRegistry.llFloppyImages.end();
    636675         ++it)
    637676    {
     
    640679        ComObjPtr<Medium> pImage;
    641680        if (SUCCEEDED(pImage.createObject()))
    642             rc = pImage->init(this, NULL, DeviceType_Floppy, xmlFloppy);
     681            rc = pImage->init(this,
     682                              NULL,
     683                              DeviceType_Floppy,
     684                              uuidRegistry,
     685                              xmlFloppy);
    643686        if (FAILED(rc)) return rc;
    644687
    645         rc = registerImage(pImage, DeviceType_Floppy, NULL /*pfNeedsSaveSettings*/ );
     688        rc = registerImage(pImage,
     689                           DeviceType_Floppy,
     690                           NULL /*pfNeedsGlobalSaveSettings*/ );
    646691        if (FAILED(rc)) return rc;
    647692    }
     693
     694    LogFlow(("VirtualBox::initMedia LEAVING\n"));
    648695
    649696    return S_OK;
     
    13281375        getDefaultHardDiskFormat(format);
    13291376
    1330     HRESULT rc = E_FAIL;
    1331 
    1332     bool fNeedsSaveSettings = false;
     1377    bool fNeedsGlobalSaveSettings = false;
    13331378
    13341379    ComObjPtr<Medium> hardDisk;
    13351380    hardDisk.createObject();
    1336     rc = hardDisk->init(this,
    1337                         format,
    1338                         aLocation,
    1339                         &fNeedsSaveSettings);
     1381    HRESULT rc = hardDisk->init(this,
     1382                                format,
     1383                                aLocation,
     1384                                Guid::Empty,        // media registry
     1385                                &fNeedsGlobalSaveSettings);
    13401386
    13411387    if (SUCCEEDED(rc))
    13421388        hardDisk.queryInterfaceTo(aHardDisk);
    13431389
    1344     if (fNeedsSaveSettings)
     1390    if (fNeedsGlobalSaveSettings)
    13451391    {
    13461392        AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS);
     
    13621408    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    13631409
     1410    bool fNeedsGlobalSaveSettings = false;
     1411    ComObjPtr<Medium> pMedium;
     1412
    13641413    /* we don't access non-const data members so no need to lock */
    1365     HRESULT rc = E_FAIL;
    13661414
    13671415    switch (deviceType)
     
    13791427    }
    13801428
    1381     ComObjPtr<Medium> pMedium;
    13821429    pMedium.createObject();
    1383     rc = pMedium->init(this,
    1384                        aLocation,
    1385                        (accessMode == AccessMode_ReadWrite) ? Medium::OpenReadWrite : Medium::OpenReadOnly,
    1386                        deviceType);
     1430    HRESULT rc = pMedium->init(this,
     1431                               aLocation,
     1432                               (accessMode == AccessMode_ReadWrite) ? Medium::OpenReadWrite : Medium::OpenReadOnly,
     1433                               deviceType);
    13871434
    13881435    if (SUCCEEDED(rc))
    13891436    {
    1390         bool fNeedsGlobalSaveSettings = false;
    1391 
    13921437        AutoWriteLock treeLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    13931438
     
    13951440        {
    13961441            case DeviceType_HardDisk:
    1397                 rc = registerHardDisk(pMedium, &fNeedsGlobalSaveSettings);
     1442                rc = registerHardDisk(pMedium,
     1443                                      &fNeedsGlobalSaveSettings);
    13981444            break;
    13991445
    14001446            case DeviceType_DVD:
    14011447            case DeviceType_Floppy:
    1402                 rc = registerImage(pMedium, deviceType, &fNeedsGlobalSaveSettings);
     1448                rc = registerImage(pMedium,
     1449                                   deviceType,
     1450                                   &fNeedsGlobalSaveSettings);
    14031451            break;
    14041452        }
     
    14101458         * with the parent and this association needs to be broken. */
    14111459
    1412         if (SUCCEEDED(rc))
    1413             pMedium.queryInterfaceTo(aMedium);
    1414         else
     1460        if (FAILED(rc))
    14151461            pMedium->uninit();
    1416 
    1417         if (fNeedsGlobalSaveSettings)
    1418         {
    1419             AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS);
    1420             saveSettings();
    1421         }
     1462    }
     1463
     1464    if (SUCCEEDED(rc))
     1465        pMedium.queryInterfaceTo(aMedium);
     1466
     1467    if (fNeedsGlobalSaveSettings)
     1468    {
     1469        AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS);
     1470        saveSettings();
    14221471    }
    14231472
     
    27492798}
    27502799
     2800/**
     2801 * Returns the pseudo-machine UUID that is created on each VirtualBox startup
     2802 * and that is used to identify the global media registry.
     2803 *
     2804 * Starting with VirtualBox 3.3 each medium remembers in its instance data
     2805 * in which media registry it is saved (if any): this can either be a machine
     2806 * UUID, if it's in a per-machine media registry, or this global ID.
     2807 *
     2808 * This UUID is only used to identify the VirtualBox object while VirtualBox
     2809 * is running. It is not saved anywhere and thus gets recreated with every
     2810 * VirtualBox startup.
     2811 *
     2812 * @return
     2813 */
     2814const Guid& VirtualBox::getGlobalRegistryId() const
     2815{
     2816    return m->uuidMediaRegistry;
     2817}
     2818
    27512819const ComObjPtr<Host>& VirtualBox::host() const
    27522820{
     
    28572925// private methods
    28582926/////////////////////////////////////////////////////////////////////////////
     2927
     2928Utf8Str VirtualBox::getRegistryPath(Medium *pMedium)
     2929{
     2930    const Guid &rid = pMedium->getRegistryId();
     2931
     2932    if (!rid.isEmpty())
     2933    {
     2934        if (rid == getGlobalRegistryId())
     2935            return settingsFilePath();
     2936
     2937        return rid.toString();
     2938    }
     2939    return "[null]";
     2940}
    28592941
    28602942/**
     
    29573039
    29583040/**
     3041 * Goes through all known media (hard disks, floppies and DVDs) and saves
     3042 * those into the given settings::MediaRegistry structures whose registry
     3043 * ID match the given UUID.
     3044 *
     3045 * This gets called from two contexts:
     3046 *
     3047 *  -- VirtualBox::saveSettings() with the UUID of the global registry
     3048 *     (VirtualBox::Data.uuidRegistry); this will save those media
     3049 *     which had been loaded from the global registry or have been
     3050 *     attached to a "legacy" machine which can't save its own registry;
     3051 *
     3052 *  -- Machine::saveSettings() with the UUID of a machine, if a medium
     3053 *     has been attached to a machine created with VirtualBox 3.3 or later.
     3054 *
     3055 * Media which have only been temporarily opened without having been
     3056 * attached to a machine have a NULL registry UUID and therefore don't
     3057 * get saved.
     3058 *
     3059 * This throws HRESULT on errors!
     3060 *
     3061 * @param mediaRegistry
     3062 * @param uuidRegistry
     3063 * @return
     3064 */
     3065void VirtualBox::saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
     3066                                   const Guid &uuidRegistry)
     3067{
     3068    HRESULT rc;
     3069    // hard disks
     3070    mediaRegistry.llHardDisks.clear();
     3071    for (MediaList::const_iterator it = m->allHardDisks.begin();
     3072         it != m->allHardDisks.end();
     3073         ++it)
     3074    {
     3075        Medium *pMedium = *it;
     3076        // is medium in global registry:?
     3077        if (pMedium->getRegistryId() == uuidRegistry)
     3078        {
     3079            settings::Medium med;
     3080            rc = pMedium->saveSettings(med);     // this recurses into its children
     3081            if (FAILED(rc)) throw rc;
     3082            mediaRegistry.llHardDisks.push_back(med);
     3083        }
     3084    }
     3085
     3086    // CD/DVD images
     3087    mediaRegistry.llDvdImages.clear();
     3088    for (MediaList::const_iterator it = m->allDVDImages.begin();
     3089         it != m->allDVDImages.end();
     3090         ++it)
     3091    {
     3092        Medium *pMedium = *it;
     3093        // is medium in global registry:?
     3094        if (pMedium->getRegistryId() == uuidRegistry)
     3095        {
     3096            settings::Medium med;
     3097            rc = pMedium->saveSettings(med);
     3098            if (FAILED(rc)) throw rc;
     3099            mediaRegistry.llDvdImages.push_back(med);
     3100        }
     3101    }
     3102
     3103    // floppy images
     3104    mediaRegistry.llFloppyImages.clear();
     3105    for (MediaList::const_iterator it = m->allFloppyImages.begin();
     3106         it != m->allFloppyImages.end();
     3107         ++it)
     3108    {
     3109        Medium *pMedium = *it;
     3110        // is medium in global registry:?
     3111        if (pMedium->getRegistryId() == uuidRegistry)
     3112        {
     3113            settings::Medium med;
     3114            rc = pMedium->saveSettings(med);
     3115            if (FAILED(rc)) throw rc;
     3116            mediaRegistry.llFloppyImages.push_back(med);
     3117        }
     3118    }
     3119}
     3120
     3121/**
    29593122 *  Helper function which actually writes out VirtualBox.xml, the main configuration file.
    29603123 *  Gets called from the public VirtualBox::SaveSettings() as well as from various other
     
    30193182                     ++it2)
    30203183                {
    3021                     const Data::PendingMachineRename &pmr = *it2;
    3022                     pMedium->updatePath(pmr.strConfigDirOld,
    3023                                         pmr.strConfigDirNew);
     3184                    // is medium in global registry:?
     3185                    if (pMedium->getRegistryId() == m->uuidMediaRegistry)
     3186                    {
     3187                        const Data::PendingMachineRename &pmr = *it2;
     3188                        pMedium->updatePath(pmr.strConfigDirOld,
     3189                                            pmr.strConfigDirNew);
     3190                    }
    30243191                }
    30253192            }
     
    30283195        }
    30293196
    3030         // hard disks
    3031         m->pMainConfigFile->mediaRegistry.llHardDisks.clear();
    3032         for (MediaList::const_iterator it = m->allHardDisks.begin();
    3033              it != m->allHardDisks.end();
    3034              ++it)
    3035         {
    3036             settings::Medium med;
    3037             rc = (*it)->saveSettings(med);     // this recurses into its children
    3038             if (FAILED(rc)) throw rc;
    3039             m->pMainConfigFile->mediaRegistry.llHardDisks.push_back(med);
    3040         }
    3041 
    3042         /* CD/DVD images */
    3043         m->pMainConfigFile->mediaRegistry.llDvdImages.clear();
    3044         for (MediaList::const_iterator it = m->allDVDImages.begin();
    3045              it != m->allDVDImages.end();
    3046              ++it)
    3047         {
    3048             settings::Medium med;
    3049             rc = (*it)->saveSettings(med);
    3050             if (FAILED(rc)) throw rc;
    3051             m->pMainConfigFile->mediaRegistry.llDvdImages.push_back(med);
    3052         }
    3053 
    3054         /* floppy images */
    3055         m->pMainConfigFile->mediaRegistry.llFloppyImages.clear();
    3056         for (MediaList::const_iterator it = m->allFloppyImages.begin();
    3057              it != m->allFloppyImages.end();
    3058              ++it)
    3059         {
    3060             settings::Medium med;
    3061             rc = (*it)->saveSettings(med);
    3062             if (FAILED(rc)) throw rc;
    3063             m->pMainConfigFile->mediaRegistry.llFloppyImages.push_back(med);
    3064         }
     3197        saveMediaRegistry(m->pMainConfigFile->mediaRegistry,
     3198                          m->uuidMediaRegistry);
    30653199
    30663200        mediaLock.release();
     
    31693303
    31703304/**
    3171  * Remembers the given hard disk by storing it in the hard disk registry.
    3172  *
    3173  * @param aHardDisk     Hard disk object to remember.
    3174  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     3305 * Remembers the given hard disk by storing it in either the global hard disk registry
     3306 * or a machine one.
     3307 *
     3308 * @note Caller must hold the media tree lock for writing; in addition, this locks @a aHardDisk for reading
     3309 *
     3310 * @param aHardDisk Hard disk object to remember.
     3311 * @param uuidMachineRegistry UUID of machine whose registry should be used, or a NULL UUID for the global registry.
     3312 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    31753313 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    3176  *
    3177  * @note Caller must hold the media tree lock for writing; in addition, this locks @a aHardDisk for reading
    3178  */
    3179 HRESULT VirtualBox::registerHardDisk(Medium *aHardDisk,
    3180                                      bool *pfNeedsSaveSettings)
    3181 {
    3182     AssertReturn(aHardDisk != NULL, E_INVALIDARG);
     3314 * @return
     3315 */
     3316HRESULT VirtualBox::registerHardDisk(Medium *pMedium,
     3317                                     bool *pfNeedsGlobalSaveSettings)
     3318{
     3319    AssertReturn(pMedium != NULL, E_INVALIDARG);
    31833320
    31843321    AutoCaller autoCaller(this);
    31853322    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    31863323
    3187     AutoCaller hardDiskCaller(aHardDisk);
     3324    AutoCaller hardDiskCaller(pMedium);
    31883325    AssertComRCReturn(hardDiskCaller.rc(), hardDiskCaller.rc());
    31893326
     
    31953332    ComObjPtr<Medium> pParent;
    31963333    {
    3197         AutoReadLock hardDiskLock(aHardDisk COMMA_LOCKVAL_SRC_POS);
    3198         id = aHardDisk->getId();
    3199         strLocationFull = aHardDisk->getLocationFull();
    3200         pParent = aHardDisk->getParent();
     3334        AutoReadLock hardDiskLock(pMedium COMMA_LOCKVAL_SRC_POS);
     3335        id = pMedium->getId();
     3336        strLocationFull = pMedium->getLocationFull();
     3337        pParent = pMedium->getParent();
    32013338    }
    32023339
     
    32103347
    32113348    if (strConflict.length())
     3349    {
    32123350        return setError(E_INVALIDARG,
    3213                         tr("Cannot register the hard disk '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
     3351                        tr("Cannot register the hard disk '%s' {%RTuuid} because a %s already exists"),
    32143352                        strLocationFull.c_str(),
    32153353                        id.raw(),
    32163354                        strConflict.c_str(),
    32173355                        m->strSettingsFilePath.c_str());
     3356    }
    32183357
    32193358    // store base (root) hard disks in the list
    32203359    if (pParent.isNull())
    3221         m->allHardDisks.getList().push_back(aHardDisk);
     3360        m->allHardDisks.getList().push_back(pMedium);
    32223361                // access the list directly because we already locked the list above
    32233362
    32243363    // store all hard disks (even differencing images) in the map
    3225     m->mapHardDisks[id] = aHardDisk;
    3226 
    3227     if (pfNeedsSaveSettings)
    3228         *pfNeedsSaveSettings = true;
     3364    m->mapHardDisks[id] = pMedium;
     3365
     3366    if (pfNeedsGlobalSaveSettings)
     3367        // global settings need saving only if the medium is to be saved in the global registry
     3368        if (pMedium->getRegistryId() == m->uuidMediaRegistry)
     3369            *pfNeedsGlobalSaveSettings = true;
    32293370
    32303371    return rc;
     
    32353376 *
    32363377 * @param aHardDisk     Hard disk object to remove.
    3237  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     3378 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    32383379 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    32393380 *
     
    32413382 */
    32423383HRESULT VirtualBox::unregisterHardDisk(Medium *aHardDisk,
    3243                                        bool *pfNeedsSaveSettings)
     3384                                       bool *pfNeedsGlobalSaveSettings)
    32443385{
    32453386    AssertReturn(aHardDisk != NULL, E_INVALIDARG);
     
    32723413    NOREF(cnt);
    32733414
    3274     if (pfNeedsSaveSettings)
    3275         *pfNeedsSaveSettings = true;
     3415    if (pfNeedsGlobalSaveSettings)
     3416        // global settings need saving only if the medium is to be saved in the global registry
     3417        if (aHardDisk->getRegistryId() == m->uuidMediaRegistry)
     3418            *pfNeedsGlobalSaveSettings = true;
    32763419
    32773420    return S_OK;
     
    32833426 * @param argImage      Image object to remember.
    32843427 * @param argType       Either DeviceType_DVD or DeviceType_Floppy.
    3285  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     3428 * @param uuidMachineRegistry UUID of machine whose registry should be used, or a NULL UUID for the global registry.
     3429 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    32863430 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    32873431 *
    32883432 * @note Caller must hold the media tree lock for writing; in addition, this locks @a argImage for reading
    32893433 */
    3290 HRESULT VirtualBox::registerImage(Medium *argImage,
     3434HRESULT VirtualBox::registerImage(Medium *pMedium,
    32913435                                  DeviceType_T argType,
    3292                                   bool *pfNeedsSaveSettings)
    3293 {
    3294     AssertReturn(argImage != NULL, E_INVALIDARG);
     3436                                  bool *pfNeedsGlobalSaveSettings)
     3437{
     3438    AssertReturn(pMedium != NULL, E_INVALIDARG);
    32953439
    32963440    AutoCaller autoCaller(this);
    32973441    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    32983442
    3299     AutoCaller imageCaller(argImage);
     3443    AutoCaller imageCaller(pMedium);
    33003444    AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
    33013445
     
    33073451    ComObjPtr<Medium> pParent;
    33083452    {
    3309         AutoReadLock al(argImage COMMA_LOCKVAL_SRC_POS);
    3310         id = argImage->getId();
    3311         strLocationFull = argImage->getLocationFull();
    3312         pParent = argImage->getParent();
     3453        AutoReadLock al(pMedium COMMA_LOCKVAL_SRC_POS);
     3454        id = pMedium->getId();
     3455        strLocationFull = pMedium->getLocationFull();
     3456        pParent = pMedium->getParent();
    33133457    }
    33143458
     
    33223466    Utf8Str strConflict;
    33233467    rc = checkMediaForConflicts2(id,
    3324                                     strLocationFull,
    3325                                     strConflict);
     3468                                 strLocationFull,
     3469                                 strConflict);
    33263470    if (FAILED(rc)) return rc;
    33273471
    33283472    if (strConflict.length())
    33293473        return setError(VBOX_E_INVALID_OBJECT_STATE,
    3330                         tr("Cannot register the image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
     3474                        tr("Cannot register the image '%s' with UUID {%RTuuid} from '%s' because a %s already exists"),
    33313475                        strLocationFull.c_str(),
    33323476                        id.raw(),
    3333                         strConflict.c_str(),
    3334                         m->strSettingsFilePath.c_str());
     3477                        getRegistryPath(pMedium).c_str(),
     3478                        strConflict.c_str());
    33353479
    33363480    // add to the collection
    3337     all.getList().push_back(argImage);
     3481    all.getList().push_back(pMedium);
    33383482            // access the list directly because we already locked the list above
    33393483
    3340     if (pfNeedsSaveSettings)
    3341         *pfNeedsSaveSettings = true;
     3484    if (pfNeedsGlobalSaveSettings)
     3485        // global settings need saving only if the medium is to be saved in the global registry
     3486        if (pMedium->getRegistryId() == m->uuidMediaRegistry)
     3487            *pfNeedsGlobalSaveSettings = true;
    33423488
    33433489    return rc;
     
    33493495 * @param argImage        Image object to remove.
    33503496 * @param argType         Either DeviceType_DVD or DeviceType_Floppy.
    3351  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     3497 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    33523498 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    33533499 *
     
    33563502HRESULT VirtualBox::unregisterImage(Medium *argImage,
    33573503                                    DeviceType_T argType,
    3358                                     bool *pfNeedsSaveSettings)
     3504                                    bool *pfNeedsGlobalSaveSettings)
    33593505{
    33603506    AssertReturn(argImage != NULL, E_INVALIDARG);
     
    33853531    HRESULT rc = S_OK;
    33863532
    3387     if (pfNeedsSaveSettings)
    3388         *pfNeedsSaveSettings = true;
     3533    if (pfNeedsGlobalSaveSettings)
     3534        // global settings need saving only if the medium is to be saved in the global registry
     3535        if (argImage->getRegistryId() == m->uuidMediaRegistry)
     3536            *pfNeedsGlobalSaveSettings = true;
    33893537
    33903538    return rc;
     
    33953543 * Called from Machine::Unregister().
    33963544 * @param pMachine
     3545 * @param id  UUID of the machine. Must be passed by caller because machine may be dead by this time.
    33973546 * @return
    33983547 */
    3399 HRESULT VirtualBox::unregisterMachine(Machine *pMachine)
    3400 {
    3401     const Guid &id = pMachine->getId();
    3402 
     3548HRESULT VirtualBox::unregisterMachine(Machine *pMachine,
     3549                                      const Guid &id)
     3550{
    34033551    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    34043552
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31596 r31615  
    14371437    <attribute name="DVDImages" type="IMedium" readonly="yes" safearray="yes">
    14381438      <desc>
    1439         Array of CD/DVD image objects registered with this VirtualBox instance.
     1439        Array of CD/DVD image objects currently in use by this VirtualBox instance.
    14401440      </desc>
    14411441    </attribute>
     
    14431443    <attribute name="floppyImages" type="IMedium" readonly="yes" safearray="yes">
    14441444      <desc>
    1445         Array of floppy image objects registered with this VirtualBox instance.
     1445        Array of floppy image objects currently in use by this VirtualBox instance.
    14461446      </desc>
    14471447    </attribute>
     
    17051705        created by one of the above methods.
    17061706
    1707         After the storage unit is successfully created, the medium gets
    1708         remembered by this VirtualBox installation and will be accessible
    1709         through the <link to="#findMedium"/> method. Remembered base medium
    1710         are also returned as part of the <link to="#hardDisks"/> array.
    1711         See <link to="IMedium" /> for more details.
     1707        After the storage unit is successfully created, it will be
     1708        accessible through the <link to="#findMedium"/> method and can
     1709        be found in the <link to="#hardDisks"/> array.
    17121710
    17131711        The list of all storage formats supported by this VirtualBox
     
    17491747        Opens a medium from an existing storage location.
    17501748
    1751         Once a medium has been opened, VirtualBox saves the medium in a media
    1752         registry. Prior to VirtualBox 3.3, this registry had to be the global
    1753         media registry in the VirtualBox.xml file, which was shared between
    1754         all machines and made transporting machines from one host to another
    1755         difficult. Now you can optionally specify an <link to="IMachine" />
    1756         instance, in which case the medium will be remembered in that machine's
    1757         registry. This is the recommended procedure for machines created with
    1758         VirtualBox 3.3 or later. <i>(not yet implemented)</i>
     1749        Once a medium has been opened, it can be passed to other VirtualBox
     1750        methods, in particular to <link to="IMachine::AttachDevice" />.
    17591751
    17601752        Depending on the given device type, the file at the storage location
     
    18061798        <link to="IMedium::location"/>, IMedium and
    18071799        <link to="ISystemProperties::defaultHardDiskFolder"/> for more details.
     1800
     1801        Prior to VirtualBox 3.3, opening a medium added it to a global media
     1802        registry in the VirtualBox.xml file, which was shared between
     1803        all machines and made transporting machines and their media from one
     1804        host to another difficult.
     1805
     1806        Starting with VirtualBox 3.3, media are only added to a registry when
     1807        they are attached to a machine. Machines created with VirtualBox 3.3
     1808        or later can have their own media registry. As a result, a medium attached
     1809        to such a machine will be remembered in that machine's XML settings file.
     1810        Media attached to older machines will continue to be added to the global
     1811        registry.
    18081812
    18091813        <result name="VBOX_E_FILE_ERROR">
     
    27512755        hard disk image. This means that on import the image will be copied and converted from the
    27522756        "ovf" location to the "vbox" location; on export, this will be handled the other way round.
    2753         On import, the target image will also be registered with VirtualBox.
    27542757
    27552758        The matching item in the @a aExtraConfigValues[] array must contain a string of the following
     
    42254228        This method is intended for managing storage devices in general while a
    42264229        machine is powered off. It can be used to attach and detach fixed
    4227         and removeable media.
    4228 
    4229         Starting with VirtualBox 3.3, media no longer have to be globally
    4230         registered before they can be attached to a virtual machine. For
    4231         compatibility with machines created by older versions of VirtualBox
    4232         and for greater flexibility with managing removable media, media
    4233         can still be registered globally. As a result, there are now
    4234         several variants of attaching media:
     4230        and removeable media. The following kind of media can be attached
     4231        to a machine:
    42354232
    42364233        <ul>
    4237           <li>To directly attach a medium without first registering it
    4238             globally, simply pass the file name of its storage unit in the
    4239             @a medium string parameter. This works for all media formats
    4240             supported by the <li to="VirtualBox::openMedium" /> method.
    4241             The difference is that the medium will not be saved in the
    4242             global media registry, but only with the machine settings
    4243             XML file. For better portability of the machine as a whole,
    4244             it is recommended to place the storage unit in the machine's
    4245             folder as well.
     4234          <li>For fixed and removable media, you can pass in a medium that was
     4235            previously opened using <link to="VirtualBox::openMedium" />.
    42464236          </li>
    42474237
    4248           <li>To attach a medium that has been globally registered using
    4249             <li to="VirtualBox::openMedium" />, call that method with the
    4250             full path of a storage unit. Then, retrieve the UUID of that
    4251             medium from its <link to="IMedium::id" /> attribute and pass
    4252             that UUID into this method. This way, the medium will be
    4253             saved in the global media registry in the VirtualBox.xml
    4254             settings file. This is still the recommended way to manage
    4255             removable media such as ISO and RAW files if they are to be
    4256             used by several virtual machines and the storage unit is not
    4257             located in the machine's directory.
    4258           </li>
    4259 
    42604238          <li>Only for storage devices supporting removable media (such as
    4261             DVDs and floppies), you can also specify an empty string to
    4262             indicate an empty drive or the UUID of a host DVD or floppy
    4263             drive; those UUIDs can be obtained from <link to="IHost::DVDDrives" />
    4264             and <link to="IHost::floppyDrives"/>.
     4239            DVDs and floppies), you can also specify a null pointer to
     4240            indicate an empty drive or one of the medium objects listed
     4241            in the <link to="IHost::DVDDrives" /> and <link to="IHost::floppyDrives"/>
     4242            arrays to indicate a host drive.
    42654243            For removeable devices, you can also use <link to="IMachine::mountMedium"/>
    42664244            to change the media while the machine is running.
     
    43264304      </param>
    43274305      <param name="type" type="DeviceType" dir="in">
    4328         <desc>Device type of the attached device.</desc>
    4329       </param>
    4330       <param name="medium" type="wstring" dir="in">
    4331         <desc>Path of the storage unit or UUID of the medium or the UUID of a
    4332           host drive to mount, or an empty string for an empty drive.</desc>
     4306        <desc>Device type of the attached device. For media opened by
     4307        <link to="IVirtualBox::openMedium" />, this must match the device type
     4308        specified there.</desc>
     4309      </param>
     4310      <param name="medium" type="IMedium" dir="in">
     4311        <desc>Medium to mount or NULL for an empty drive.</desc>
    43334312      </param>
    43344313    </method>
  • trunk/src/VBox/Main/include/MachineImpl.h

    r31574 r31615  
    452452    STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
    453453    STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
    454                             LONG aDevice, DeviceType_T aType, IN_BSTR aId);
     454                            LONG aDevice, DeviceType_T aType, IMedium *aMedium);
    455455    STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
    456456    STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
     
    10181018                              MediumLockList *aMediumLockList,
    10191019                              ComObjPtr<Progress> &aProgress,
    1020                               bool *pfNeedsSaveSettings);
     1020                              bool *pfNeedsMachineSaveSettings);
    10211021
    10221022    HRESULT lockMedia();
  • trunk/src/VBox/Main/include/MediumImpl.h

    r31568 r31615  
    7272                 const Utf8Str &aFormat,
    7373                 const Utf8Str &aLocation,
    74                  bool *pfNeedsSaveSettings);
     74                 const Guid &uuidMachineRegistry,
     75                 bool *pfNeedsGlobalSaveSettings);
    7576
    7677    // initializer for opening existing media
    77     // (VirtualBox::OpenHardDisk/DVD(); Machine::AttachDevice())
     78    // (VirtualBox::OpenMedium(); Machine::AttachDevice())
    7879    HRESULT init(VirtualBox *aVirtualBox,
    7980                 const Utf8Str &aLocation,
     
    8586                 Medium *aParent,
    8687                 DeviceType_T aDeviceType,
     88                 const Guid &uuidMachineRegistry,
    8789                 const settings::Medium &data);
    8890
     
    176178    Utf8Str getName();
    177179
     180    void setRegistryIdIfFirst(const Guid& id);
     181    const Guid& getRegistryId() const;
     182
    178183    HRESULT addBackReference(const Guid &aMachineId,
    179184                             const Guid &aSnapshotId = Guid::Empty);
     
    208213                              ComObjPtr<Progress> *aProgress,
    209214                              bool aWait,
    210                               bool *pfNeedsSaveSettings);
    211 
    212     HRESULT close(bool *pfNeedsSaveSettings, AutoCaller &autoCaller);
    213     HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
     215                              bool *pfNeedsGlobalSaveSettings);
     216
     217    HRESULT close(bool *pfNeedsGlobalSaveSettings, AutoCaller &autoCaller);
     218    HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsGlobalSaveSettings);
    214219    HRESULT markForDeletion();
    215220    HRESULT unmarkForDeletion();
     
    232237                    ComObjPtr<Progress> *aProgress,
    233238                    bool aWait,
    234                     bool *pfNeedsSaveSettings);
     239                    bool *pfNeedsGlobalSaveSettings);
    235240    void cancelMergeTo(const MediaList &aChildrenToReparent,
    236241                       MediumLockList *aMediumLockList);
     
    246251
    247252    HRESULT canClose();
    248     HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
     253    HRESULT unregisterWithVirtualBox(bool *pfNeedsGlobalSaveSettings);
    249254
    250255    HRESULT setStateError();
     
    297302
    298303    HRESULT startThread(Medium::Task *pTask);
    299     HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
     304    HRESULT runNow(Medium::Task *pTask, bool *pfNeedsGlobalSaveSettings);
    300305
    301306    HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31595 r31615  
    5454{
    5555    class MainConfigFile;
     56    class MediaRegistry;
    5657}
    5758
     
    9697    HRESULT init();
    9798    HRESULT initMachines();
    98     HRESULT initMedia();
     99    HRESULT initMedia(const Guid &uuidMachineRegistry,
     100                      const settings::MediaRegistry mediaRegistry);
    99101    void uninit();
    100102
     
    127129    STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
    128130
    129     STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
    130                                IMedium **aHardDisk);
     131    STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
     132                              IN_BSTR aLocation,
     133                              IMedium **aHardDisk);
    131134    STDMETHOD(OpenMedium)(IN_BSTR aLocation,
    132135                          DeviceType_T deviceType,
     
    204207                           InternalControlList *aControls = NULL);
    205208
    206     HRESULT findMachine (const Guid &aId,
    207                          bool fPermitInaccessible,
    208                          bool aSetError,
    209                          ComObjPtr<Machine> *machine = NULL);
     209    HRESULT findMachine(const Guid &aId,
     210                        bool fPermitInaccessible,
     211                        bool aSetError,
     212                        ComObjPtr<Machine> *machine = NULL);
    210213
    211214    HRESULT findHardDisk(const Guid *aId,
     
    226229                            GuestOSType*& pGuestOSType);
    227230
     231    const Guid& getGlobalRegistryId() const;
     232
    228233    const ComObjPtr<Host>& host() const;
    229234    SystemProperties* getSystemProperties() const;
     
    242247    void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
    243248
    244     HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
    245     HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
    246 
    247     HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
    248     HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
    249 
    250     HRESULT unregisterMachine(Machine *pMachine);
     249    HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
     250    HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
     251
     252    HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
     253    HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
     254
     255    HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
    251256
    252257    void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
    253258                                           const Utf8Str &strNewConfigDir);
    254259
     260    void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
     261                           const Guid &uuidRegistry);
    255262    HRESULT saveSettings();
    256263
     
    271278    }
    272279
     280    Utf8Str getRegistryPath(Medium *pMedium);
     281
    273282    HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
    274283                                    Utf8Str &aConflictType);
  • trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp

    r31568 r31615  
    330330            {
    331331                /*
    332                  * Now that it's created, we can assign it to the VM. This is done
    333                  * by UUID, so query that one fist. The UUID has been assigned automatically
    334                  * when we've created the image.
     332                 * Now that it's created, we can assign it to the VM.
    335333                 */
    336                 nsXPIDLString vdiUUID;
    337                 hardDisk->GetId(getter_Copies(vdiUUID));
    338334                rc = machine->AttachDevice(NS_LITERAL_STRING("IDE Controller").get(), // controller identifier
    339335                                           0,                              // channel number on the controller
    340336                                           0,                              // device number on the controller
    341337                                           DeviceType_HardDisk,
    342                                            vdiUUID);
     338                                           hardDisk);
    343339                if (NS_FAILED(rc))
    344340                {
  • trunk/src/VBox/Main/xml/Settings.cpp

    r31539 r31615  
    17421742
    17431743/**
     1744 * Public routine which returns true if this machine config file can have its
     1745 * own media registry (which is true for settings version v1.11 and higher,
     1746 * i.e. files created by VirtualBox 3.3 and higher).
     1747 * @return
     1748 */
     1749bool MachineConfigFile::canHaveOwnMediaRegistry() const
     1750{
     1751    return (m->sv >= SettingsVersion_v1_11);
     1752}
     1753
     1754/**
    17441755 * Public routine which allows for importing machine XML from an external DOM tree.
    17451756 * Use this after having called the constructor with a NULL argument.
     
    30973108                pelmMachineChild->getAttributeValue("password", machineUserData.strTeleporterPassword);
    30983109            }
     3110            else if (pelmMachineChild->nameEquals("MediaRegistry"))
     3111                readMediaRegistry(*pelmMachineChild, mediaRegistry);
    30993112        }
    31003113
     
    39984011    }
    39994012
     4013    if (    (fl & BuildMachineXML_MediaRegistry)
     4014         && (m->sv >= SettingsVersion_v1_11)
     4015       )
     4016        buildMediaRegistry(elmMachine, mediaRegistry);
     4017
    40004018    buildExtraData(elmMachine, mapExtraDataItems);
    40014019
     
    40094027                               !!(fl & BuildMachineXML_SkipRemovableMedia),
    40104028                               pllElementsWithUuidAttributes);
    4011 
    4012     if (    (fl & BuildMachineXML_MediaRegistry)
    4013          && (m->sv >= SettingsVersion_v1_11)
    4014        )
    4015         buildMediaRegistry(elmMachine, mediaRegistry);
    40164029}
    40174030
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