VirtualBox

Changeset 35836 in vbox


Ignore:
Timestamp:
Feb 3, 2011 2:55:17 PM (14 years ago)
Author:
vboxsync
Message:

Main: do not return first item from list of registry IDs unconditionally since that list may be empty; this fixes the problem that media registry do not get saved properly if a new immutable image gets attached to a machine

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImpl.h

    r35755 r35836  
    782782    HRESULT saveStateSettings(int aFlags);
    783783
     784    void addMediumToRegistry(ComObjPtr<Medium> &pMedium,
     785                             GuidList &llRegistriesThatNeedSaving,
     786                             Guid *puuid);
     787
    784788    HRESULT createImplicitDiffs(IProgress *aProgress,
    785789                                ULONG aWeight,
  • trunk/src/VBox/Main/include/MediumImpl.h

    r35638 r35836  
    177177    bool addRegistry(const Guid& id);
    178178    bool isInRegistry(const Guid& id);
    179     const Guid& getFirstRegistryMachineId() const;
     179    bool getFirstRegistryMachineId(Guid &uuid) const;
    180180    HRESULT addToRegistryIDList(GuidList &llRegistryIDs);
    181181
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r35757 r35836  
    36243624        ComObjPtr<Medium> diff;
    36253625        diff.createObject();
     3626        // store this diff in the same registry as the parent
     3627        Guid uuidRegistryParent;
     3628        if (!medium->getFirstRegistryMachineId(uuidRegistryParent))
     3629        {
     3630            // parent image has no registry: this can happen if we're attaching a new immutable
     3631            // image that has not yet been attached (medium then points to the base and we're
     3632            // creating the diff image for the immutable, and the parent is not yet registered);
     3633            // put the parent in the machine registry then
     3634            addMediumToRegistry(medium, llRegistriesThatNeedSaving, &uuidRegistryParent);
     3635        }
    36263636        rc = diff->init(mParent,
    36273637                        medium->getPreferredDiffFormat(),
    36283638                        strFullSnapshotFolder.append(RTPATH_SLASH_STR),
    3629                         medium->getFirstRegistryMachineId(),         // store this diff in the same registry as the parent
     3639                        uuidRegistryParent,
    36303640                        &llRegistriesThatNeedSaving);
    36313641        if (FAILED(rc)) return rc;
     
    37023712        if (FAILED(rc)) return rc;
    37033713
    3704         // and decide which medium registry to use now that the medium is attached:
    3705         Guid uuid;
    3706         if (mData->pMachineConfigFile->canHaveOwnMediaRegistry())
    3707             // machine XML is VirtualBox 4.0 or higher:
    3708             uuid = getId();     // machine UUID
    3709         else
    3710             uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID
    3711 
    3712         if (medium->addRegistry(uuid))
    3713             // registry actually changed:
    3714             mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid);
     3714        addMediumToRegistry(medium,
     3715                            llRegistriesThatNeedSaving,
     3716                            NULL /* Guid *puuid */);
    37153717    }
    37163718
     
    39483950            pMedium->addBackReference(mData->mUuid);
    39493951
    3950             // and decide which medium registry to use now that the medium is attached:
    3951             Guid uuid;
    3952             if (mData->pMachineConfigFile->canHaveOwnMediaRegistry())
    3953                 // machine XML is VirtualBox 4.0 or higher:
    3954                 uuid = getId();     // machine UUID
    3955             else
    3956                 uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID
    3957 
    3958             if (pMedium->addRegistry(uuid))
    3959                 // registry actually changed:
    3960                 mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid);
     3952            addMediumToRegistry(pMedium, llRegistriesThatNeedSaving, NULL /* Guid *puuid */ );
    39613953        }
    39623954
     
    87398731
    87408732/**
     8733 * Ensures that the given medium is added to a media registry. If this machine
     8734 * was created with 4.0 or later, then the machine registry is used. Otherwise
     8735 * the global VirtualBox media registry is used. If the medium was actually
     8736 * added to a registry (because it wasn't in the registry yet), the UUID of
     8737 * that registry is added to the given list so that the caller can save the
     8738 * registry.
     8739 *
     8740 * Caller must hold machine read lock!
     8741 *
     8742 * @param pMedium
     8743 * @param llRegistriesThatNeedSaving
     8744 * @param puuid Optional buffer that receives the registry UUID that was used.
     8745 */
     8746void Machine::addMediumToRegistry(ComObjPtr<Medium> &pMedium,
     8747                                  GuidList &llRegistriesThatNeedSaving,
     8748                                  Guid *puuid)
     8749{
     8750    // decide which medium registry to use now that the medium is attached:
     8751    Guid uuid;
     8752    if (mData->pMachineConfigFile->canHaveOwnMediaRegistry())
     8753        // machine XML is VirtualBox 4.0 or higher:
     8754        uuid = getId();     // machine UUID
     8755    else
     8756        uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID
     8757
     8758    if (pMedium->addRegistry(uuid))
     8759        // registry actually changed:
     8760        mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid);
     8761
     8762    if (puuid)
     8763        *puuid = uuid;
     8764}
     8765
     8766/**
    87418767 * Creates differencing hard disks for all normal hard disks attached to this
    87428768 * machine and a new set of attachments to refer to created disks.
     
    88948920            ComObjPtr<Medium> diff;
    88958921            diff.createObject();
     8922            // store the diff in the same registry as the parent
     8923            // (this cannot fail here because we can't create implicit diffs for
     8924            // unregistered images)
     8925            Guid uuidRegistryParent;
     8926            Assert(pMedium->getFirstRegistryMachineId(uuidRegistryParent));
    88968927            rc = diff->init(mParent,
    88978928                            pMedium->getPreferredDiffFormat(),
    88988929                            strFullSnapshotFolder.append(RTPATH_SLASH_STR),
    8899                             pMedium->getFirstRegistryMachineId(),        // store the diff in the same registry as the parent
     8930                            uuidRegistryParent,
    89008931                            pllRegistriesThatNeedSaving);
    89018932            if (FAILED(rc)) throw rc;
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r35803 r35836  
    31313131 * machine XML this medium is listed).
    31323132 *
    3133  * Every medium must now (4.0) reside in at least one media registry, which is identified by
    3134  * a UUID. This is either a machine UUID if the machine is from 4.0 or newer, in which case
     3133 * Every attached medium must now (4.0) reside in at least one media registry, which is identified
     3134 * by a UUID. This is either a machine UUID if the machine is from 4.0 or newer, in which case
    31353135 * machines have their own media registries, or it is the pseudo-UUID of the VirtualBox
    31363136 * object if the machine is old and still needs the global registry in VirtualBox.xml.
     
    31413141 * case, only VM2's registry is used for the disk in question.)
    31423142 *
     3143 * If there is no medium registry, particularly if the medium has not been attached yet, this
     3144 * does not modify uuid and returns false.
     3145 *
    31433146 * ISOs and RAWs, by contrast, can be in more than one repository to make things easier for
    31443147 * the user.
     
    31463149 * Must have caller + locking!
    31473150 *
    3148  * @return
    3149  */
    3150 const Guid& Medium::getFirstRegistryMachineId() const
    3151 {
    3152     return m->llRegistryIDs.front();
     3151 * @param uuid Receives first registry machine UUID, if available.
     3152 * @return true if uuid was set.
     3153 */
     3154bool Medium::getFirstRegistryMachineId(Guid &uuid) const
     3155{
     3156    if (m->llRegistryIDs.size())
     3157    {
     3158        uuid = m->llRegistryIDs.front();
     3159        return true;
     3160    }
     3161    return false;
    31533162}
    31543163
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