Changeset 38499 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Aug 19, 2011 12:02:55 PM (13 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r38494 r38499 3733 3733 // creating the diff image for the immutable, and the parent is not yet registered); 3734 3734 // put the parent in the machine registry then 3735 mediumLock.release(); 3735 3736 addMediumToRegistry(medium, llRegistriesThatNeedSaving, &uuidRegistryParent); 3737 mediumLock.acquire(); 3736 3738 } 3737 3739 rc = diff->init(mParent, … … 3816 3818 if (FAILED(rc)) return rc; 3817 3819 3820 mediumLock.release(); 3818 3821 addMediumToRegistry(medium, 3819 3822 llRegistriesThatNeedSaving, 3820 3823 NULL /* Guid *puuid */); 3824 mediumLock.acquire(); 3821 3825 } 3822 3826 … … 4190 4194 pMedium->addBackReference(mData->mUuid); 4191 4195 4196 mediumLock.release(); 4192 4197 addMediumToRegistry(pMedium, llRegistriesThatNeedSaving, NULL /* Guid *puuid */ ); 4198 mediumLock.acquire(); 4193 4199 } 4194 4200 … … 9200 9206 * registry. 9201 9207 * 9202 * Caller must hold machine read lock! 9208 * Caller must hold machine read lock and at least media tree read lock! 9209 * Caller must NOT hold any medium locks. 9203 9210 * 9204 9211 * @param pMedium … … 9210 9217 Guid *puuid) 9211 9218 { 9219 ComObjPtr<Medium> pBase = pMedium->getBase(); 9220 /* Paranoia checks: do not hold medium locks. */ 9221 AssertReturnVoid(!pMedium->isWriteLockOnCurrentThread()); 9222 AssertReturnVoid(!pBase->isWriteLockOnCurrentThread()); 9223 9212 9224 // decide which medium registry to use now that the medium is attached: 9213 9225 Guid uuid; … … 9218 9230 uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID 9219 9231 9220 AutoCaller autoCaller(pMedium); 9221 if (FAILED(autoCaller.rc())) return; 9222 AutoWriteLock alock(pMedium COMMA_LOCKVAL_SRC_POS); 9223 9232 bool fAdd = false; 9224 9233 if (pMedium->addRegistry(uuid, false /* fRecurse */)) 9234 { 9225 9235 // registry actually changed: 9226 9236 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving, uuid); 9237 fAdd = true; 9238 } 9239 9240 /* For more complex hard disk structures it can happen that the base 9241 * medium isn't yet associated with any medium registry. Do that now. */ 9242 if (pMedium != pBase) 9243 { 9244 if ( pBase->addRegistry(uuid, true /* fRecurse */) 9245 && !fAdd) 9246 { 9247 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving, uuid); 9248 fAdd = true; 9249 } 9250 } 9227 9251 9228 9252 if (puuid) -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r38475 r38499 3122 3122 * See getFirstRegistryMachineId() for details. 3123 3123 * 3124 * Must have caller + locking! 3125 * 3126 * If fRecurse == true, then additionally the media tree lock must be held for reading. 3124 * If fRecurse == true, then the media tree lock must be held for reading. 3127 3125 * 3128 3126 * @param id … … 3132 3130 bool Medium::addRegistry(const Guid& id, bool fRecurse) 3133 3131 { 3132 AutoCaller autoCaller(this); 3133 if (FAILED(autoCaller.rc())) 3134 return false; 3135 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3136 3137 bool fAdd = true; 3138 3134 3139 // hard disks cannot be in more than one registry 3135 if ( m->devType == DeviceType_HardDisk 3136 && m->llRegistryIDs.size() > 0 3137 ) 3138 return false; 3140 if ( m->devType == DeviceType_HardDisk 3141 && m->llRegistryIDs.size() > 0) 3142 fAdd = false; 3139 3143 3140 3144 // no need to add the UUID twice 3141 for (GuidList::const_iterator it = m->llRegistryIDs.begin(); 3142 it != m->llRegistryIDs.end(); 3143 ++it) 3144 { 3145 if ((*it) == id) 3146 return false; 3147 } 3148 3149 addRegistryImpl(id, fRecurse); 3150 3151 return true; 3152 } 3153 3154 /** 3155 * Private implementation for addRegistry() so we can recurse more efficiently. 3156 * @param id 3157 * @param fRecurse 3158 */ 3159 void Medium::addRegistryImpl(const Guid& id, bool fRecurse) 3160 { 3161 m->llRegistryIDs.push_back(id); 3145 if (fAdd) 3146 { 3147 for (GuidList::const_iterator it = m->llRegistryIDs.begin(); 3148 it != m->llRegistryIDs.end(); 3149 ++it) 3150 { 3151 if ((*it) == id) 3152 { 3153 fAdd = false; 3154 break; 3155 } 3156 } 3157 } 3158 3159 if (fAdd) 3160 m->llRegistryIDs.push_back(id); 3162 3161 3163 3162 if (fRecurse) 3164 3163 { 3165 for (MediaList::iterator it = m->llChildren.begin(); 3166 it != m->llChildren.end(); 3164 // Get private list of children and release medium lock straight away. 3165 MediaList llChildren(m->llChildren); 3166 alock.release(); 3167 3168 for (MediaList::iterator it = llChildren.begin(); 3169 it != llChildren.end(); 3167 3170 ++it) 3168 3171 { 3169 3172 Medium *pChild = *it; 3170 // recurse! 3171 pChild->addRegistryImpl(id, fRecurse); 3172 } 3173 } 3173 fAdd |= pChild->addRegistry(id, true); 3174 } 3175 } 3176 3177 return fAdd; 3174 3178 } 3175 3179 … … 3178 3182 * if found or false if not. 3179 3183 * 3180 * Must have caller + locking! 3181 * 3182 * If fRecurse == true, then additionally the media tree lock must be held for reading. 3184 * If fRecurse == true, then the media tree lock must be held for reading. 3183 3185 * 3184 3186 * @param id … … 3188 3190 bool Medium::removeRegistry(const Guid& id, bool fRecurse) 3189 3191 { 3192 AutoCaller autoCaller(this); 3193 if (FAILED(autoCaller.rc())) 3194 return false; 3195 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3196 3197 bool fRemove = false; 3198 3190 3199 for (GuidList::iterator it = m->llRegistryIDs.begin(); 3191 3200 it != m->llRegistryIDs.end(); … … 3195 3204 { 3196 3205 m->llRegistryIDs.erase(it); 3197 3198 if (fRecurse) 3199 { 3200 for (MediaList::iterator it2 = m->llChildren.begin(); 3201 it2 != m->llChildren.end(); 3202 ++it2) 3203 { 3204 Medium *pChild = *it2; 3205 pChild->removeRegistry(id, true); 3206 } 3207 } 3208 3209 return true; 3210 } 3211 } 3212 3213 return false; 3206 fRemove = true; 3207 break; 3208 } 3209 } 3210 3211 if (fRecurse) 3212 { 3213 // Get private list of children and release medium lock straight away. 3214 MediaList llChildren(m->llChildren); 3215 alock.release(); 3216 3217 for (MediaList::iterator it = llChildren.begin(); 3218 it != llChildren.end(); 3219 ++it) 3220 { 3221 Medium *pChild = *it; 3222 fRemove |= pChild->removeRegistry(id, true); 3223 } 3224 } 3225 3226 return fRemove; 3214 3227 } 3215 3228 … … 3217 3230 * Returns true if id is in the list of media registries for this medium. 3218 3231 * 3219 * Must have caller + locking!3232 * Must have caller + read locking! 3220 3233 * 3221 3234 * @param id … … 3224 3237 bool Medium::isInRegistry(const Guid& id) 3225 3238 { 3226 AutoCaller autoCaller(this);3227 if (FAILED(autoCaller.rc())) return false;3228 3229 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);3230 3231 3239 for (GuidList::const_iterator it = m->llRegistryIDs.begin(); 3232 3240 it != m->llRegistryIDs.end();
Note:
See TracChangeset
for help on using the changeset viewer.