VirtualBox

Ignore:
Timestamp:
Dec 13, 2018 6:58:16 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
127481
Message:

Main: bugref:6913: Added generation of medium events

File:
1 edited

Legend:

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

    r75373 r76215  
    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
     1794                bool fFound = false;
     1795                /* was this medium attached before? */
     1796                for (MediumAttachmentList::iterator
     1797                     oldIt = oldAtts.begin();
     1798                     oldIt != oldAtts.end();
     1799                     ++oldIt)
     1800                {
     1801                    MediumAttachment *pOldAttach = *oldIt;
     1802                    if (pOldAttach->i_getMedium() == pMedium)
     1803                    {
     1804                        fFound = true;
     1805                        break;
     1806                    }
     1807                }
     1808                if (!fFound)
     1809                {
     1810                    pMediumsForNotify.insert(pMedium->i_getParent());
     1811                    uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType();
     1812                }
     1813            }
    17751814        }
    17761815
     
    18771916        mParent->i_onSnapshotTaken(mData->mUuid, task.m_uuidSnapshot);
    18781917    LogFlowThisFuncLeave();
     1918
     1919    if (SUCCEEDED(rc))
     1920    {
     1921        for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin();
     1922             it != uIdsForNotify.end();
     1923             ++it)
     1924        {
     1925            mParent->i_onMediumRegistered(it->first, it->second, TRUE);
     1926        }
     1927
     1928        for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin();
     1929             it != pMediumsForNotify.end();
     1930             ++it)
     1931        {
     1932            if (it->isNotNull())
     1933                mParent->i_onMediumConfigChanged(*it);
     1934        }
     1935    }
    18791936}
    18801937
     
    21202177    HRESULT rc = S_OK;
    21212178    Guid snapshotId;
     2179    std::set<ComObjPtr<Medium> > pMediumsForNotify;
     2180    std::map<Guid, DeviceType_T> uIdsForNotify;
    21222181
    21232182    try
     
    22142273            /* make the snapshot we restored from the current snapshot */
    22152274            mData->mCurrentSnapshot = task.m_pSnapshot;
     2275        }
     2276
     2277        // store parent of newly created diffs for notify
     2278        {
     2279            MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData();
     2280            for (MediumAttachmentList::const_iterator
     2281                 it = mMediumAttachments->begin();
     2282                 it != mMediumAttachments->end();
     2283                 ++it)
     2284            {
     2285                MediumAttachment *pAttach = *it;
     2286                Medium *pMedium = pAttach->i_getMedium();
     2287
     2288                bool fFound = false;
     2289                /* was this medium attached before? */
     2290                for (MediumAttachmentList::iterator
     2291                     oldIt = oldAtts.begin();
     2292                     oldIt != oldAtts.end();
     2293                     ++oldIt)
     2294                {
     2295                    MediumAttachment *pOldAttach = *oldIt;
     2296                    if (pOldAttach->i_getMedium() == pMedium)
     2297                    {
     2298                        fFound = true;
     2299                        break;
     2300                    }
     2301                }
     2302                if (!fFound)
     2303                {
     2304                    pMediumsForNotify.insert(pMedium->i_getParent());
     2305                    uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType();
     2306                }
     2307            }
    22162308        }
    22172309
     
    23142406            LogFlowThisFunc(("Deleting old current state in differencing image '%s'\n", pMedium->i_getName().c_str()));
    23152407
     2408            ComObjPtr<Medium> pParent = pMedium->i_getParent();
    23162409            HRESULT rc2 = pMedium->i_deleteStorage(NULL /* aProgress */,
    2317                                                    true /* aWait */);
     2410                                                   true /* aWait */,
     2411                                                   false /* aNotify */);
    23182412            // ignore errors here because we cannot roll back after i_saveSettings() above
    23192413            if (SUCCEEDED(rc2))
     2414            {
     2415                pMediumsForNotify.insert(pParent);
    23202416                pMedium->uninit();
     2417            }
    23212418        }
    23222419    }
     
    23452442
    23462443    if (SUCCEEDED(rc))
     2444    {
    23472445        mParent->i_onSnapshotRestored(mData->mUuid, snapshotId);
     2446        for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin();
     2447             it != uIdsForNotify.end();
     2448             ++it)
     2449        {
     2450            mParent->i_onMediumRegistered(it->first, it->second, TRUE);
     2451        }
     2452        for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin();
     2453             it != pMediumsForNotify.end();
     2454             ++it)
     2455        {
     2456            if (it->isNotNull())
     2457                mParent->i_onMediumConfigChanged(*it);
     2458        }
     2459    }
    23482460
    23492461    LogFlowThisFunc(("Done restoring snapshot (rc=%08X)\n", rc));
     
    26962808    MediumDeleteRecList toDelete;
    26972809    Guid snapshotId;
     2810    std::set<ComObjPtr<Medium> > pMediumsForNotify;
     2811    std::map<Guid,DeviceType_T> uIdsForNotify;
    26982812
    26992813    try
     
    30703184                    /* No need to hold the lock any longer. */
    30713185                    mLock.release();
     3186                    ComObjPtr<Medium> pParent = pMedium->i_getParent();
     3187                    Guid uMedium = pMedium->i_getId();
     3188                    DeviceType_T uMediumType = pMedium->i_getDeviceType();
    30723189                    rc = pMedium->i_deleteStorage(&task.m_pProgress,
    3073                                                   true /* aWait */);
     3190                                                  true /* aWait */,
     3191                                                  false /* aNotify */);
    30743192                    if (FAILED(rc))
    30753193                        throw rc;
     3194
     3195                    pMediumsForNotify.insert(pParent);
     3196                    uIdsForNotify[uMedium] = uMediumType;
    30763197
    30773198                    // need to uninit the deleted medium
     
    30813202            else
    30823203            {
     3204                {
     3205                    //store ids before merging for notify
     3206                    pMediumsForNotify.insert(it->mpTarget);
     3207                    if (it->mfMergeForward)
     3208                        pMediumsForNotify.insert(it->mpSource->i_getParent());
     3209                    else
     3210                    {
     3211                        //children which will be reparented to target
     3212                        for (MediaList::const_iterator iit = it->mpSource->i_getChildren().begin();
     3213                             iit != it->mpSource->i_getChildren().end();
     3214                             ++iit)
     3215                        {
     3216                            pMediumsForNotify.insert(*iit);
     3217                        }
     3218                    }
     3219                    if (it->mfMergeForward)
     3220                    {
     3221                        for (ComObjPtr<Medium> pTmpMedium = it->mpTarget->i_getParent();
     3222                             pTmpMedium != it->mpSource;
     3223                             pTmpMedium = pTmpMedium->i_getParent())
     3224                        {
     3225                            uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType();
     3226                        }
     3227                        uIdsForNotify[it->mpSource->i_getId()] = it->mpSource->i_getDeviceType();
     3228                    }
     3229                    else
     3230                    {
     3231                        for (ComObjPtr<Medium> pTmpMedium = it->mpSource->i_getParent();
     3232                             pTmpMedium != it->mpTarget;
     3233                             pTmpMedium = pTmpMedium->i_getParent())
     3234                        {
     3235                            uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType();
     3236                        }
     3237                    }
     3238                }
     3239
    30833240                bool fNeedsSave = false;
    30843241                if (it->mfNeedsOnlineMerge)
     
    31113268                                                 it->mpMediumLockList,
    31123269                                                 &task.m_pProgress,
    3113                                                  true /* aWait */);
     3270                                                 true /* aWait */,
     3271                                                 false /* aNotify */);
    31143272                }
    31153273
     
    32783436
    32793437    if (SUCCEEDED(mrc))
     3438    {
    32803439        mParent->i_onSnapshotDeleted(mData->mUuid, snapshotId);
     3440        for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin();
     3441             it != uIdsForNotify.end();
     3442             ++it)
     3443        {
     3444            mParent->i_onMediumRegistered(it->first, it->second, FALSE);
     3445        }
     3446        for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin();
     3447             it != pMediumsForNotify.end();
     3448             ++it)
     3449        {
     3450            if (it->isNotNull())
     3451                mParent->i_onMediumConfigChanged(*it);
     3452        }
     3453    }
    32813454
    32823455    LogFlowThisFunc(("Done deleting snapshot (rc=%08X)\n", (HRESULT)mrc));
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