Changeset 35982 in vbox for trunk/src/VBox
- Timestamp:
- Feb 15, 2011 4:02:28 PM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/MediumImpl.h
r35903 r35982 175 175 Utf8Str getName(); 176 176 177 bool addRegistry(const Guid& id); 178 bool removeRegistry(const Guid& id); 177 bool addRegistry(const Guid& id, bool fRecurse); 178 private: 179 void addRegistryImpl(const Guid& id, bool fRecurse); 180 public: 181 bool removeRegistry(const Guid& id, bool fRecurse); 179 182 bool isInRegistry(const Guid& id); 180 183 bool getFirstRegistryMachineId(Guid &uuid) const; … … 187 190 188 191 const Guid* getFirstMachineBackrefId() const; 192 const Guid* getAnyMachineBackref() const; 189 193 const Guid* getFirstMachineBackrefSnapshotId() const; 190 194 -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r35903 r35982 7759 7759 if (puuidRegistry) 7760 7760 // caller wants registry ID to be set on all attached media (OVF import case) 7761 medium->addRegistry(*puuidRegistry );7761 medium->addRegistry(*puuidRegistry, false /* fRecurse */); 7762 7762 } 7763 7763 … … 8784 8784 AutoWriteLock alock(pMedium COMMA_LOCKVAL_SRC_POS); 8785 8785 8786 if (pMedium->addRegistry(uuid ))8786 if (pMedium->addRegistry(uuid, false /* fRecurse */)) 8787 8787 // registry actually changed: 8788 8788 mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid); -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r35915 r35982 3079 3079 * Must have caller + locking! 3080 3080 * 3081 * If fRecurse == true, then additionally the media tree lock must be held for reading. 3082 * 3081 3083 * @param id 3084 * @param fRecurse If true, recurses into child media to make sure the whole tree has registries in sync. 3082 3085 * @return true if the registry was added; false if the given id was already on the list. 3083 3086 */ 3084 bool Medium::addRegistry(const Guid& id )3087 bool Medium::addRegistry(const Guid& id, bool fRecurse) 3085 3088 { 3086 3089 // hard disks cannot be in more than one registry … … 3099 3102 } 3100 3103 3104 addRegistryImpl(id, fRecurse); 3105 3106 return true; 3107 } 3108 3109 /** 3110 * Private implementation for addRegistry() so we can recurse more efficiently. 3111 * @param id 3112 * @param fRecurse 3113 */ 3114 void Medium::addRegistryImpl(const Guid& id, bool fRecurse) 3115 { 3101 3116 m->llRegistryIDs.push_back(id); 3102 return true; 3117 3118 if (fRecurse) 3119 { 3120 for (MediaList::iterator it = m->llChildren.begin(); 3121 it != m->llChildren.end(); 3122 ++it) 3123 { 3124 Medium *pChild = *it; 3125 // recurse! 3126 pChild->addRegistryImpl(id, fRecurse); 3127 } 3128 } 3103 3129 } 3104 3130 … … 3109 3135 * Must have caller + locking! 3110 3136 * 3137 * If fRecurse == true, then additionally the media tree lock must be held for reading. 3138 * 3111 3139 * @param id 3140 * @param fRecurse If true, recurses into child media to make sure the whole tree has registries in sync. 3112 3141 * @return 3113 3142 */ 3114 bool Medium::removeRegistry(const Guid& id )3143 bool Medium::removeRegistry(const Guid& id, bool fRecurse) 3115 3144 { 3116 3145 for (GuidList::iterator it = m->llRegistryIDs.begin(); … … 3121 3150 { 3122 3151 m->llRegistryIDs.erase(it); 3152 3153 if (fRecurse) 3154 { 3155 for (MediaList::iterator it = m->llChildren.begin(); 3156 it != m->llChildren.end(); 3157 ++it) 3158 { 3159 Medium *pChild = *it; 3160 pChild->removeRegistry(id, true); 3161 } 3162 } 3163 3123 3164 return true; 3124 3165 } … … 3359 3400 3360 3401 return &m->backRefs.front().machineId; 3402 } 3403 3404 /** 3405 * Internal method which returns a machine that either this medium or one of its children 3406 * is attached to. This is used for finding a replacement media registry when an existing 3407 * media registry is about to be deleted in VirtualBox::unregisterMachine(). 3408 * 3409 * Must have caller + locking, *and* caller must hold the media tree lock! 3410 * @return 3411 */ 3412 const Guid* Medium::getAnyMachineBackref() const 3413 { 3414 if (m->backRefs.size()) 3415 return &m->backRefs.front().machineId; 3416 3417 for (MediaList::iterator it = m->llChildren.begin(); 3418 it != m->llChildren.end(); 3419 ++it) 3420 { 3421 Medium *pChild = *it; 3422 // recurse for this child 3423 const Guid* puuid; 3424 if ((puuid = pChild->getAnyMachineBackref())) 3425 return puuid; 3426 } 3427 3428 return NULL; 3361 3429 } 3362 3430 -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r35903 r35982 3716 3716 GuidList llRegistriesThatNeedSaving; 3717 3717 { 3718 AutoWriteLock tlock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 3718 AutoReadLock tlock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 3719 // iterate over the list of *base* images 3719 3720 for (MediaOList::iterator it = m->allHardDisks.getList().begin(); 3720 3721 it != m->allHardDisks.getList().end(); … … 3726 3727 AutoWriteLock mlock(pMedium COMMA_LOCKVAL_SRC_POS); 3727 3728 3728 if (pMedium->removeRegistry(id ))3729 if (pMedium->removeRegistry(id, true /* fRecurse */)) 3729 3730 { 3730 // ID was found in medium's registry list: 3731 // add a new one then 3732 const Guid *puuidBetter = pMedium->getFirstMachineBackrefId(); 3731 // machine ID was found in base medium's registry list: 3732 // move this base image and all its children to another registry then 3733 // 1) first, find a better registry to add things to 3734 const Guid *puuidBetter = pMedium->getAnyMachineBackref(); 3733 3735 if (puuidBetter) 3734 3736 { 3735 pMedium->addRegistry(*puuidBetter); 3737 // 2) better registry found: then use that 3738 pMedium->addRegistry(*puuidBetter, true /* fRecurse */); 3739 // 3) and make sure the registry is saved below 3736 3740 addGuidToListUniquely(llRegistriesThatNeedSaving, *puuidBetter); 3737 3741 }
Note:
See TracChangeset
for help on using the changeset viewer.