VirtualBox

Ignore:
Timestamp:
Dec 19, 2018 6:17:50 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
127586
Message:

Main: bugref:6913: Added generation of some medium events. Contains some fixes for VBoxSVC crash in the MacOS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r76240 r76298  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
     17
     18#include <set>
     19#include <map>
    1720
    1821#include "Logging.h"
     
    16371640    BOOL fSuspendedBySave     = FALSE;
    16381641
     1642    std::set<ComObjPtr<Medium> > pMediumsForNotify;
     1643    std::map<Guid, DeviceType_T> uIdsForNotify;
     1644
    16391645    try
    16401646    {
     
    17731779            if (FAILED(rc))
    17741780                throw rc;
     1781        }
     1782
     1783        // store parent of newly created diffs before commit for notify
     1784        {
     1785            MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData();
     1786            for (MediumAttachmentList::const_iterator
     1787                 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::iterator
     1799                     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            }
    17751816        }
    17761817
     
    18761917    if (SUCCEEDED(rc))
    18771918        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    }
    18781937    LogFlowThisFuncLeave();
    18791938}
     
    21202179    HRESULT rc = S_OK;
    21212180    Guid snapshotId;
     2181    std::set<ComObjPtr<Medium> > pMediumsForNotify;
     2182    std::map<Guid, DeviceType_T> uIdsForNotify;
    21222183
    21232184    try
     
    22142275            /* make the snapshot we restored from the current snapshot */
    22152276            mData->mCurrentSnapshot = task.m_pSnapshot;
     2277        }
     2278
     2279        // store parent of newly created diffs for notify
     2280        {
     2281            MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData();
     2282            for (MediumAttachmentList::const_iterator
     2283                 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::iterator
     2295                     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            }
    22162312        }
    22172313
     
    23142410            LogFlowThisFunc(("Deleting old current state in differencing image '%s'\n", pMedium->i_getName().c_str()));
    23152411
     2412            ComObjPtr<Medium> pParent = pMedium->i_getParent();
    23162413            HRESULT rc2 = pMedium->i_deleteStorage(NULL /* aProgress */,
    2317                                                    true /* aWait */);
     2414                                                   true /* aWait */,
     2415                                                   false /* aNotify */);
    23182416            // ignore errors here because we cannot roll back after i_saveSettings() above
    23192417            if (SUCCEEDED(rc2))
     2418            {
     2419                pMediumsForNotify.insert(pParent);
    23202420                pMedium->uninit();
     2421            }
    23212422        }
    23222423    }
     
    23452446
    23462447    if (SUCCEEDED(rc))
     2448    {
    23472449        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    }
    23482464
    23492465    LogFlowThisFunc(("Done restoring snapshot (rc=%08X)\n", rc));
     
    26962812    MediumDeleteRecList toDelete;
    26972813    Guid snapshotId;
     2814    std::set<ComObjPtr<Medium> > pMediumsForNotify;
     2815    std::map<Guid,DeviceType_T> uIdsForNotify;
    26982816
    26992817    try
     
    30703188                    /* No need to hold the lock any longer. */
    30713189                    mLock.release();
     3190                    ComObjPtr<Medium> pParent = pMedium->i_getParent();
     3191                    Guid uMedium = pMedium->i_getId();
     3192                    DeviceType_T uMediumType = pMedium->i_getDeviceType();
    30723193                    rc = pMedium->i_deleteStorage(&task.m_pProgress,
    3073                                                   true /* aWait */);
     3194                                                  true /* aWait */,
     3195                                                  false /* aNotify */);
    30743196                    if (FAILED(rc))
    30753197                        throw rc;
     3198
     3199                    pMediumsForNotify.insert(pParent);
     3200                    uIdsForNotify[uMedium] = uMediumType;
    30763201
    30773202                    // need to uninit the deleted medium
     
    30813206            else
    30823207            {
     3208                {
     3209                    //store ids before merging for notify
     3210                    pMediumsForNotify.insert(it->mpTarget);
     3211                    if (it->mfMergeForward)
     3212                        pMediumsForNotify.insert(it->mpSource->i_getParent());
     3213                    else
     3214                    {
     3215                        //children which will be reparented to target
     3216                        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 && 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                    else
     3234                    {
     3235                        for (ComObjPtr<Medium> pTmpMedium = it->mpSource->i_getParent();
     3236                             pTmpMedium && pTmpMedium != it->mpTarget;
     3237                             pTmpMedium = pTmpMedium->i_getParent())
     3238                        {
     3239                            uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType();
     3240                        }
     3241                    }
     3242                }
     3243
    30833244                bool fNeedsSave = false;
    30843245                if (it->mfNeedsOnlineMerge)
     
    31113272                                                 it->mpMediumLockList,
    31123273                                                 &task.m_pProgress,
    3113                                                  true /* aWait */);
     3274                                                 true /* aWait */,
     3275                                                 false /* aNotify */);
    31143276                }
    31153277
     
    32783440
    32793441    if (SUCCEEDED(mrc))
     3442    {
    32803443        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    }
    32813458
    32823459    LogFlowThisFunc(("Done deleting snapshot (rc=%08X)\n", (HRESULT)mrc));
     
    39724149    return S_OK;
    39734150}
    3974 
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette