Changeset 76240 in vbox for trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
- Timestamp:
- Dec 14, 2018 8:34:20 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 127510
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r76239 r76240 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 #include <set>19 #include <map>20 17 21 18 #include "Logging.h" … … 1640 1637 BOOL fSuspendedBySave = FALSE; 1641 1638 1642 std::set<ComObjPtr<Medium> > pMediumsForNotify;1643 std::map<Guid, DeviceType_T> uIdsForNotify;1644 1645 1639 try 1646 1640 { … … 1779 1773 if (FAILED(rc)) 1780 1774 throw rc; 1781 }1782 1783 // store parent of newly created diffs before commit for notify1784 {1785 MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData();1786 for (MediumAttachmentList::const_iterator1787 it = mMediumAttachments->begin();1788 it != mMediumAttachments->end();1789 ++it)1790 {1791 MediumAttachment *pAttach = *it;1792 Medium *pMedium = pAttach->i_getMedium();1793 if (!pMedium)1794 continue;1795 1796 bool fFound = false;1797 /* was this medium attached before? */1798 for (MediumAttachmentList::iterator1799 oldIt = oldAtts.begin();1800 oldIt != oldAtts.end();1801 ++oldIt)1802 {1803 MediumAttachment *pOldAttach = *oldIt;1804 if (pOldAttach->i_getMedium() == pMedium)1805 {1806 fFound = true;1807 break;1808 }1809 }1810 if (!fFound)1811 {1812 pMediumsForNotify.insert(pMedium->i_getParent());1813 uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType();1814 }1815 }1816 1775 } 1817 1776 … … 1917 1876 if (SUCCEEDED(rc)) 1918 1877 mParent->i_onSnapshotTaken(mData->mUuid, task.m_uuidSnapshot); 1919 1920 if (SUCCEEDED(rc))1921 {1922 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin();1923 it != uIdsForNotify.end();1924 ++it)1925 {1926 mParent->i_onMediumRegistered(it->first, it->second, TRUE);1927 }1928 1929 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin();1930 it != pMediumsForNotify.end();1931 ++it)1932 {1933 if (it->isNotNull())1934 mParent->i_onMediumConfigChanged(*it);1935 }1936 }1937 1878 LogFlowThisFuncLeave(); 1938 1879 } … … 2179 2120 HRESULT rc = S_OK; 2180 2121 Guid snapshotId; 2181 std::set<ComObjPtr<Medium> > pMediumsForNotify;2182 std::map<Guid, DeviceType_T> uIdsForNotify;2183 2122 2184 2123 try … … 2275 2214 /* make the snapshot we restored from the current snapshot */ 2276 2215 mData->mCurrentSnapshot = task.m_pSnapshot; 2277 }2278 2279 // store parent of newly created diffs for notify2280 {2281 MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData();2282 for (MediumAttachmentList::const_iterator2283 it = mMediumAttachments->begin();2284 it != mMediumAttachments->end();2285 ++it)2286 {2287 MediumAttachment *pAttach = *it;2288 Medium *pMedium = pAttach->i_getMedium();2289 if (!pMedium)2290 continue;2291 2292 bool fFound = false;2293 /* was this medium attached before? */2294 for (MediumAttachmentList::iterator2295 oldIt = oldAtts.begin();2296 oldIt != oldAtts.end();2297 ++oldIt)2298 {2299 MediumAttachment *pOldAttach = *oldIt;2300 if (pOldAttach->i_getMedium() == pMedium)2301 {2302 fFound = true;2303 break;2304 }2305 }2306 if (!fFound)2307 {2308 pMediumsForNotify.insert(pMedium->i_getParent());2309 uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType();2310 }2311 }2312 2216 } 2313 2217 … … 2410 2314 LogFlowThisFunc(("Deleting old current state in differencing image '%s'\n", pMedium->i_getName().c_str())); 2411 2315 2412 ComObjPtr<Medium> pParent = pMedium->i_getParent();2413 2316 HRESULT rc2 = pMedium->i_deleteStorage(NULL /* aProgress */, 2414 true /* aWait */, 2415 false /* aNotify */); 2317 true /* aWait */); 2416 2318 // ignore errors here because we cannot roll back after i_saveSettings() above 2417 2319 if (SUCCEEDED(rc2)) 2418 {2419 pMediumsForNotify.insert(pParent);2420 2320 pMedium->uninit(); 2421 }2422 2321 } 2423 2322 } … … 2446 2345 2447 2346 if (SUCCEEDED(rc)) 2448 {2449 2347 mParent->i_onSnapshotRestored(mData->mUuid, snapshotId); 2450 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin();2451 it != uIdsForNotify.end();2452 ++it)2453 {2454 mParent->i_onMediumRegistered(it->first, it->second, TRUE);2455 }2456 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin();2457 it != pMediumsForNotify.end();2458 ++it)2459 {2460 if (it->isNotNull())2461 mParent->i_onMediumConfigChanged(*it);2462 }2463 }2464 2348 2465 2349 LogFlowThisFunc(("Done restoring snapshot (rc=%08X)\n", rc)); … … 2812 2696 MediumDeleteRecList toDelete; 2813 2697 Guid snapshotId; 2814 std::set<ComObjPtr<Medium> > pMediumsForNotify;2815 std::map<Guid,DeviceType_T> uIdsForNotify;2816 2698 2817 2699 try … … 3188 3070 /* No need to hold the lock any longer. */ 3189 3071 mLock.release(); 3190 ComObjPtr<Medium> pParent = pMedium->i_getParent();3191 Guid uMedium = pMedium->i_getId();3192 DeviceType_T uMediumType = pMedium->i_getDeviceType();3193 3072 rc = pMedium->i_deleteStorage(&task.m_pProgress, 3194 true /* aWait */, 3195 false /* aNotify */); 3073 true /* aWait */); 3196 3074 if (FAILED(rc)) 3197 3075 throw rc; 3198 3199 pMediumsForNotify.insert(pParent);3200 uIdsForNotify[uMedium] = uMediumType;3201 3076 3202 3077 // need to uninit the deleted medium … … 3206 3081 else 3207 3082 { 3208 {3209 //store ids before merging for notify3210 pMediumsForNotify.insert(it->mpTarget);3211 if (it->mfMergeForward)3212 pMediumsForNotify.insert(it->mpSource->i_getParent());3213 else3214 {3215 //children which will be reparented to target3216 for (MediaList::const_iterator iit = it->mpSource->i_getChildren().begin();3217 iit != it->mpSource->i_getChildren().end();3218 ++iit)3219 {3220 pMediumsForNotify.insert(*iit);3221 }3222 }3223 if (it->mfMergeForward)3224 {3225 for (ComObjPtr<Medium> pTmpMedium = it->mpTarget->i_getParent();3226 pTmpMedium != it->mpSource;3227 pTmpMedium = pTmpMedium->i_getParent())3228 {3229 uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType();3230 }3231 uIdsForNotify[it->mpSource->i_getId()] = it->mpSource->i_getDeviceType();3232 }3233 else3234 {3235 for (ComObjPtr<Medium> pTmpMedium = it->mpSource->i_getParent();3236 pTmpMedium != it->mpTarget;3237 pTmpMedium = pTmpMedium->i_getParent())3238 {3239 uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType();3240 }3241 }3242 }3243 3244 3083 bool fNeedsSave = false; 3245 3084 if (it->mfNeedsOnlineMerge) … … 3272 3111 it->mpMediumLockList, 3273 3112 &task.m_pProgress, 3274 true /* aWait */, 3275 false /* aNotify */); 3113 true /* aWait */); 3276 3114 } 3277 3115 … … 3440 3278 3441 3279 if (SUCCEEDED(mrc)) 3442 {3443 3280 mParent->i_onSnapshotDeleted(mData->mUuid, snapshotId); 3444 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin();3445 it != uIdsForNotify.end();3446 ++it)3447 {3448 mParent->i_onMediumRegistered(it->first, it->second, FALSE);3449 }3450 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin();3451 it != pMediumsForNotify.end();3452 ++it)3453 {3454 if (it->isNotNull())3455 mParent->i_onMediumConfigChanged(*it);3456 }3457 }3458 3281 3459 3282 LogFlowThisFunc(("Done deleting snapshot (rc=%08X)\n", (HRESULT)mrc));
Note:
See TracChangeset
for help on using the changeset viewer.