VirtualBox

Ignore:
Timestamp:
Oct 21, 2019 6:19:39 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134142
Message:

Main/Machine+BIOSSettings+Console: Full implementation of NVRAM handling (part of VM delete, rename, clone and move code in combination with taking, deleting and restoring snapshots). Corresponding console update (ripping out old, never really used NVRAM handling).

File:
1 edited

Legend:

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

    r79154 r81425  
    656656
    657657    /* state file may be NULL (for offline snapshots) */
    658     if (    path.length()
     658    if (    path.isNotEmpty()
    659659         && RTPathStartsWith(path.c_str(), strOldPath.c_str())
    660660       )
     
    663663                                                            strNewPath.c_str(),
    664664                                                            path.c_str() + strOldPath.length());
    665         LogFlowThisFunc(("-> updated: {%s}\n", path.c_str()));
     665        LogFlowThisFunc(("-> updated: {%s}\n", m->pMachine->mSSData->strStateFilePath.c_str()));
    666666    }
    667667
     
    673673        pChild->i_updateSavedStatePathsImpl(strOldPath, strNewPath);
    674674    }
     675}
     676
     677/**
     678 *  Checks if the specified path change affects the saved state file path of
     679 *  this snapshot or any of its (grand-)children and updates it accordingly.
     680 *
     681 *  Intended to be called by Machine::openConfigLoader() only.
     682 *
     683 *  @param  strOldPath old path (full)
     684 *  @param  strNewPath new path (full)
     685 *
     686 *  @note Locks the machine (for the snapshots tree) +  this object + children for writing.
     687 */
     688void Snapshot::i_updateSavedStatePaths(const Utf8Str &strOldPath,
     689                                       const Utf8Str &strNewPath)
     690{
     691    LogFlowThisFunc(("aOldPath={%s} aNewPath={%s}\n", strOldPath.c_str(), strNewPath.c_str()));
     692
     693    AutoCaller autoCaller(this);
     694    AssertComRC(autoCaller.rc());
     695
     696    // snapshots tree is protected by machine lock
     697    AutoWriteLock alock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     698
     699    // call the implementation under the tree lock
     700    i_updateSavedStatePathsImpl(strOldPath, strNewPath);
    675701}
    676702
     
    714740
    715741/**
    716  *  Checks if the specified path change affects the saved state file path of
     742 * Internal implementation for Snapshot::updateNVRAMPaths (below).
     743 * @param   strOldPath
     744 * @param   strNewPath
     745 */
     746void Snapshot::i_updateNVRAMPathsImpl(const Utf8Str &strOldPath,
     747                                      const Utf8Str &strNewPath)
     748{
     749    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     750
     751    const Utf8Str path = m->pMachine->mBIOSSettings->i_getNonVolatileStorageFile();
     752    LogFlowThisFunc(("Snap[%s].nvramPath={%s}\n", m->strName.c_str(), path.c_str()));
     753
     754    /* NVRAM filename may be empty */
     755    if (    path.isNotEmpty()
     756         && RTPathStartsWith(path.c_str(), strOldPath.c_str())
     757       )
     758    {
     759        m->pMachine->mBIOSSettings->i_updateNonVolatileStorageFile(Utf8StrFmt("%s%s",
     760                                                                              strNewPath.c_str(),
     761                                                                              path.c_str() + strOldPath.length()));
     762        LogFlowThisFunc(("-> updated: {%s}\n", m->pMachine->mBIOSSettings->i_getNonVolatileStorageFile().c_str()));
     763    }
     764
     765    for (SnapshotsList::const_iterator it = m->llChildren.begin();
     766         it != m->llChildren.end();
     767         ++it)
     768    {
     769        Snapshot *pChild = *it;
     770        pChild->i_updateNVRAMPathsImpl(strOldPath, strNewPath);
     771    }
     772}
     773
     774/**
     775 *  Checks if the specified path change affects the NVRAM file path of
    717776 *  this snapshot or any of its (grand-)children and updates it accordingly.
    718777 *
     
    724783 *  @note Locks the machine (for the snapshots tree) +  this object + children for writing.
    725784 */
    726 void Snapshot::i_updateSavedStatePaths(const Utf8Str &strOldPath,
    727                                        const Utf8Str &strNewPath)
     785void Snapshot::i_updateNVRAMPaths(const Utf8Str &strOldPath,
     786                                  const Utf8Str &strNewPath)
    728787{
    729788    LogFlowThisFunc(("aOldPath={%s} aNewPath={%s}\n", strOldPath.c_str(), strNewPath.c_str()));
     
    844903
    845904    // report the saved state file if it's not on the list yet
    846     if (!m->pMachine->mSSData->strStateFilePath.isEmpty())
     905    if (m->pMachine->mSSData->strStateFilePath.isNotEmpty())
    847906    {
    848907        bool fFound = false;
     
    861920            llFilenames.push_back(m->pMachine->mSSData->strStateFilePath);
    862921    }
     922
     923    Utf8Str strNVRAMFile = m->pMachine->mBIOSSettings->i_getNonVolatileStorageFile();
     924    if (strNVRAMFile.isNotEmpty() && RTFileExists(strNVRAMFile.c_str()))
     925        llFilenames.push_back(strNVRAMFile);
    863926
    864927    i_beginSnapshotDelete();
     
    17821845            if (FAILED(rc))
    17831846                throw rc;
     1847        }
     1848
     1849        // Handle NVRAM file snapshotting
     1850        Utf8Str strNVRAM = mBIOSSettings->i_getNonVolatileStorageFile();
     1851        Utf8Str strNVRAMSnap = pSnapshotMachine->i_getSnapshotNVRAMFilename();
     1852        Utf8Str strNVRAMSnapAbs;
     1853        i_calculateFullPath(strNVRAMSnap, strNVRAMSnapAbs);
     1854        if (strNVRAM.isNotEmpty() && strNVRAMSnap.isNotEmpty() && RTFileExists(strNVRAM.c_str()))
     1855        {
     1856            rc = VirtualBox::i_ensureFilePathExists(strNVRAMSnapAbs, true /* fCreate */);
     1857            if (FAILED(rc))
     1858                throw rc;
     1859            int vrc = RTFileCopy(strNVRAM.c_str(), strNVRAMSnapAbs.c_str());
     1860            if (RT_FAILURE(vrc))
     1861                throw setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
     1862                                   tr("Could not copy NVRAM file '%s' to '%s' (%Rrc)"),
     1863                                   strNVRAM.c_str(), strNVRAMSnapAbs.c_str(), vrc);
     1864            pSnapshotMachine->mBIOSSettings->i_updateNonVolatileStorageFile(strNVRAMSnap);
    17841865        }
    17851866
     
    22762357                mSSData->strStateFilePath = strSnapshotStateFile;
    22772358
     2359            const Utf8Str srcNVRAM(pSnapshotMachine->mBIOSSettings->i_getNonVolatileStorageFile());
     2360            const Utf8Str dstNVRAM(mBIOSSettings->i_getNonVolatileStorageFile());
     2361            if (dstNVRAM.isNotEmpty() && RTFileExists(dstNVRAM.c_str()))
     2362                RTFileDelete(dstNVRAM.c_str());
     2363            if (srcNVRAM.isNotEmpty() && dstNVRAM.isNotEmpty() && RTFileExists(srcNVRAM.c_str()))
     2364                RTFileCopy(srcNVRAM.c_str(), dstNVRAM.c_str());
     2365
    22782366            LogFlowThisFunc(("Setting new current snapshot {%RTuuid}\n", task.m_pSnapshot->i_getId().raw()));
    22792367            /* make the snapshot we restored from the current snapshot */
     
    26212709    ULONG ulTotalWeight = 1;        // one for preparations
    26222710
    2623     if (pSnapshot->i_getStateFilePath().length())
     2711    if (pSnapshot->i_getStateFilePath().isNotEmpty())
    26242712    {
    26252713        ++ulOpCount;
     
    33913479        }
    33923480
     3481        /* 3a: delete NVRAM file if present. */
     3482        {
     3483            Utf8Str NVRAMPath = pSnapMachine->mBIOSSettings->i_getNonVolatileStorageFile();
     3484            if (NVRAMPath.isNotEmpty() && RTFileExists(NVRAMPath.c_str()))
     3485                RTFileDelete(NVRAMPath.c_str());
     3486        }
     3487
     3488        /* third pass: */
    33933489        {
    33943490            // beginSnapshotDelete() needs the machine lock, and the snapshots
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