VirtualBox

Changeset 105382 in vbox for trunk/src/VBox/Main/src-all


Ignore:
Timestamp:
Jul 17, 2024 2:32:41 PM (9 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
164035
Message:

Main/NvramStore: Don't make the NVRAM map part of the backupable data as these get shared between snapshots and the copy is only shallow so references to RTVFSFILE entries are shared. Instead when a new NvramStore object is created and the path is set it will be loaded again when required. Fixes restoring snapshots for VMs which have NVRAM data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp

    r103532 r105382  
    9494    com::Utf8Str            strKeyStore;
    9595#endif
    96     /** The NVRAM store. */
    97     NvramStoreMap           mapNvram;
    9896};
    9997
     
    138136
    139137    Backupable<BackupableNvramStoreData> bd;
     138
     139    /** The NVRAM store. */
     140    NvramStoreMap                        mapNvram;
    140141};
    141142
     
    332333
    333334    /* Delete the NVRAM content. */
    334     NvramStoreIter it = m->bd->mapNvram.begin();
    335     while (it != m->bd->mapNvram.end())
     335    NvramStoreIter it = m->mapNvram.begin();
     336    while (it != m->mapNvram.end())
    336337    {
    337338        RTVfsFileRelease(it->second);
     
    339340    }
    340341
    341     m->bd->mapNvram.clear();
     342    m->mapNvram.clear();
    342343    m->bd.free();
    343344
     
    391392    {
    392393        /* Load the NVRAM file first if it isn't already. */
    393         if (!m->bd->mapNvram.size())
     394        if (!m->mapNvram.size())
    394395        {
    395396            int vrc = i_loadStore(strPath.c_str());
     
    400401        if (SUCCEEDED(hrc))
    401402        {
    402             NvramStoreIter it = m->bd->mapNvram.find("efi/nvram");
    403             if (it != m->bd->mapNvram.end())
     403            NvramStoreIter it = m->mapNvram.find("efi/nvram");
     404            if (it != m->mapNvram.end())
    404405            {
    405406                unconst(m->pUefiVarStore).createObject();
     
    475476    /* Load the NVRAM file first if it isn't already. */
    476477    HRESULT hrc = S_OK;
    477     if (!m->bd->mapNvram.size())
     478    if (!m->mapNvram.size())
    478479    {
    479480        int vrc = i_loadStore(strPath.c_str());
     
    486487        int vrc = VINF_SUCCESS;
    487488        RTVFSFILE hVfsUefiVarStore = NIL_RTVFSFILE;
    488         NvramStoreIter it = m->bd->mapNvram.find("efi/nvram");
    489         if (it != m->bd->mapNvram.end())
     489        NvramStoreIter it = m->mapNvram.find("efi/nvram");
     490        if (it != m->mapNvram.end())
    490491            hVfsUefiVarStore = it->second;
    491492        else
     
    498499                vrc = RTVfsFileSetSize(hVfsUefiVarStore, 540672, RTVFSFILE_SIZE_F_NORMAL);
    499500                if (RT_SUCCESS(vrc))
    500                     m->bd->mapNvram["efi/nvram"] = hVfsUefiVarStore;
     501                    m->mapNvram["efi/nvram"] = hVfsUefiVarStore;
    501502                else
    502503                    RTVfsFileRelease(hVfsUefiVarStore);
     
    582583                    RTVfsIoStrmRelease(hVfsIosEntry);
    583584
    584                     m->bd->mapNvram[Utf8Str(pszName)] = hVfsFileEntry;
     585                    m->mapNvram[Utf8Str(pszName)] = hVfsFileEntry;
    585586                    break;
    586587                }
     
    748749
    749750                                RTVfsFileRetain(hVfsFileNvram); /* Retain a new reference for the map. */
    750                                 m->bd->mapNvram[Utf8Str("efi/nvram")] = hVfsFileNvram;
     751                                m->mapNvram[Utf8Str("efi/nvram")] = hVfsFileNvram;
    751752
    752753                                RTVfsRelease(hVfsEfiVarStore);
     
    840841            if (RT_SUCCESS(vrc))
    841842            {
    842                 NvramStoreIter it = m->bd->mapNvram.begin();
    843 
    844                 while (it != m->bd->mapNvram.end())
     843                NvramStoreIter it = m->mapNvram.begin();
     844
     845                while (it != m->mapNvram.end())
    845846                {
    846847                    RTVFSFILE hVfsFile = it->second;
     
    927928         */
    928929        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    929         if (   m->bd->mapNvram.size() == 1
    930             && m->bd->mapNvram.begin()->first == "efi/nvram")
    931         {
    932             RTVFSFILE hVfsFileNvram = m->bd->mapNvram.begin()->second;
     930        if (   m->mapNvram.size() == 1
     931            && m->mapNvram.begin()->first == "efi/nvram")
     932        {
     933            RTVFSFILE hVfsFileNvram = m->mapNvram.begin()->second;
    933934
    934935            vrc = RTVfsFileSeek(hVfsFileNvram, 0 /*offSeek*/, RTFILE_SEEK_BEGIN, NULL /*poffActual*/);
     
    970971            }
    971972        }
    972         else if (m->bd->mapNvram.size())
     973        else if (m->mapNvram.size())
    973974            vrc = i_saveStoreAsTar(strTmp.c_str());
    974975        /* else: No NVRAM content to store so we are done here. */
     
    10671068
    10681069    HRESULT hrc = S_OK;
    1069     NvramStoreIter it = m->bd->mapNvram.find("efi/nvram");
    1070     if (it != m->bd->mapNvram.end())
     1070    NvramStoreIter it = m->mapNvram.find("efi/nvram");
     1071    if (it != m->mapNvram.end())
    10711072    {
    10721073        RTVFSFILE hVfsFileNvram = it->second;
     
    11091110HRESULT NvramStore::i_loadSettings(const settings::NvramSettings &data)
    11101111{
     1112    LogFlowThisFuncEnter();
     1113    LogFlowThisFunc(("data: %p\n", data));
     1114
    11111115    AutoCaller autoCaller(this);
    11121116    AssertComRCReturnRC(autoCaller.hrc());
     
    11281132        m->bd->strNvramPath.setNull();
    11291133
     1134    LogFlowThisFuncLeave();
    11301135    return S_OK;
    11311136}
     
    12761281
    12771282    AutoReadLock rlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS);
    1278     NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey);
    1279     if (it != pThis->pNvramStore->m->bd->mapNvram.end())
     1283    NvramStoreIter it = pThis->pNvramStore->m->mapNvram.find(strKey);
     1284    if (it != pThis->pNvramStore->m->mapNvram.end())
    12801285    {
    12811286        RTVFSFILE hVfsFile = it->second;
     
    12981303
    12991304    AutoReadLock rlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS);
    1300     NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey);
    1301     if (it != pThis->pNvramStore->m->bd->mapNvram.end())
     1305    NvramStoreIter it = pThis->pNvramStore->m->mapNvram.find(strKey);
     1306    if (it != pThis->pNvramStore->m->mapNvram.end())
    13021307    {
    13031308        RTVFSFILE hVfsFile = it->second;
     
    13251330    AutoWriteLock wlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS);
    13261331
    1327     NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey);
    1328     if (it != pThis->pNvramStore->m->bd->mapNvram.end())
     1332    NvramStoreIter it = pThis->pNvramStore->m->mapNvram.find(strKey);
     1333    if (it != pThis->pNvramStore->m->mapNvram.end())
    13291334    {
    13301335        RTVFSFILE hVfsFile = it->second;
     
    13451350            try
    13461351            {
    1347                 pThis->pNvramStore->m->bd->mapNvram[strKey] = hVfsFile;
     1352                pThis->pNvramStore->m->mapNvram[strKey] = hVfsFile;
    13481353            }
    13491354            catch (...)
     
    13701375
    13711376    AutoWriteLock wlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS);
    1372     NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey);
    1373     if (it != pThis->pNvramStore->m->bd->mapNvram.end())
     1377    NvramStoreIter it = pThis->pNvramStore->m->mapNvram.find(strKey);
     1378    if (it != pThis->pNvramStore->m->mapNvram.end())
    13741379    {
    13751380        RTVFSFILE hVfsFile = it->second;
    1376         pThis->pNvramStore->m->bd->mapNvram.erase(it);
     1381        pThis->pNvramStore->m->mapNvram.erase(it);
    13771382        RTVfsFileRelease(hVfsFile);
    13781383        return VINF_SUCCESS;
     
    13921397    AutoWriteLock wlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS);
    13931398
    1394     size_t cEntries = pThis->pNvramStore->m->bd->mapNvram.size();
     1399    size_t cEntries = pThis->pNvramStore->m->mapNvram.size();
    13951400    AssertReturn(cEntries < 32, VERR_OUT_OF_RANGE); /* Some sanity checking. */
    13961401    pHlp->pfnSSMPutU32(pSSM, (uint32_t)cEntries);
     
    14121417                                   void **ppvData, size_t *pcbDataMax) RT_NOEXCEPT
    14131418{
    1414     for (NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.begin(); it != pThis->pNvramStore->m->bd->mapNvram.end(); ++it)
     1419    for (NvramStoreIter it = pThis->pNvramStore->m->mapNvram.begin(); it != pThis->pNvramStore->m->mapNvram.end(); ++it)
    14151420    {
    14161421        RTVFSFILE hVfsFile = it->second;
     
    14551460
    14561461        /* Clear any content first. */
    1457         NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.begin();
    1458         while (it != pThis->pNvramStore->m->bd->mapNvram.end())
     1462        NvramStoreIter it = pThis->pNvramStore->m->mapNvram.begin();
     1463        while (it != pThis->pNvramStore->m->mapNvram.end())
    14591464        {
    14601465            RTVfsFileRelease(it->second);
     
    14621467        }
    14631468
    1464         pThis->pNvramStore->m->bd->mapNvram.clear();
     1469        pThis->pNvramStore->m->mapNvram.clear();
    14651470
    14661471        uint32_t cEntries = 0;
     
    15191524        try
    15201525        {
    1521             pThis->pNvramStore->m->bd->mapNvram[Utf8Str(szId)] = hVfsFile;
     1526            pThis->pNvramStore->m->mapNvram[Utf8Str(szId)] = hVfsFile;
    15221527        }
    15231528        catch (...)
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