VirtualBox

Changeset 81393 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Oct 21, 2019 8:33:26 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134106
Message:

Main/MachineImplMoveVM: many cleanups including removal of unused code

File:
1 edited

Legend:

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

    r81362 r81393  
    3131
    3232/* This variable is global and used in the different places so it must be cleared each time before usage to avoid failure */
    33 std::vector< ComObjPtr<Machine> > machineList;
     33std::vector<ComObjPtr<Machine> > machineList;
    3434
    3535typedef std::multimap<Utf8Str, Utf8Str> list_t;
     
    4040struct fileList_t
    4141{
    42     HRESULT add(const Utf8Str& folder, const Utf8Str& file)
     42    HRESULT add(const Utf8Str &folder, const Utf8Str &file)
    4343    {
    4444        HRESULT rc = S_OK;
     
    4747    }
    4848
    49     HRESULT add(const Utf8Str& fullPath)
     49    HRESULT add(const Utf8Str &fullPath)
    5050    {
    5151        HRESULT rc = S_OK;
     
    5858    }
    5959
    60     HRESULT removeFileFromList(const Utf8Str& fullPath)
     60    HRESULT removeFileFromList(const Utf8Str &fullPath)
    6161    {
    6262        HRESULT rc = S_OK;
     
    8181    }
    8282
    83     HRESULT removeFileFromList(const Utf8Str& path, const Utf8Str& fileName)
     83    HRESULT removeFileFromList(const Utf8Str &path, const Utf8Str &fileName)
    8484    {
    8585        HRESULT rc = S_OK;
     
    9999    }
    100100
    101     HRESULT removeFolderFromList(const Utf8Str& path)
     101    HRESULT removeFolderFromList(const Utf8Str &path)
    102102    {
    103103        HRESULT rc = S_OK;
     
    106106    }
    107107
    108     rangeRes_t getFilesInRange(const Utf8Str& path)
     108    rangeRes_t getFilesInRange(const Utf8Str &path)
    109109    {
    110110        rangeRes_t res;
     
    113113    }
    114114
    115     std::list<Utf8Str> getFilesInList(const Utf8Str& path)
     115    std::list<Utf8Str> getFilesInList(const Utf8Str &path)
    116116    {
    117117        std::list<Utf8Str> list_;
     
    128128
    129129
    130 #ifdef DEBUG
    131 void MachineMoveVM::ErrorInfoItem::logItem() const
    132 {
    133     Log2(("(The error code is %Rrc): %s\n", m_code, m_description.c_str()));
    134 }
    135 #endif
    136 
    137130HRESULT MachineMoveVM::init()
    138131{
     
    149142         *        for doing this.  We need this often and code like this doesn't
    150143         *        need to be repeated and re-optimized in each instance... */
    151         char* path = new char [len];
     144        char *path = new char [len];
    152145        RTStrCopy(path, len, m_targetPath.c_str());
    153146        RTPathEnsureTrailingSeparator(path, len);
     
    201194    vrc = RTDirClose(hDir); AssertRC(vrc);
    202195
    203     Log2(("blocks: total %RTfoff, free %RTfoff ", cbTotal, cbFree));
     196    Log2(("blocks: total %RTfoff, free %RTfoff\n", cbTotal, cbFree));
    204197    Log2(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G));
    205198    Log2(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G));
     
    210203        return m_pMachine->setErrorVrc(vrc, "RTFsQueryProperties(%s): %Rrc", strTargetFolder.c_str(), vrc);
    211204
    212     Log2(("disk properties:\n"
    213           "remote: %RTbool\n"
    214           "read only: %RTbool\n"
    215           "compressed: %RTbool\n",
    216           properties.fRemote,
    217           properties.fReadOnly,
    218           properties.fCompressed));
     205    Log2(("disk properties: remote=%RTbool read only=%RTbool compressed=%RTbool\n",
     206          properties.fRemote, properties.fReadOnly, properties.fCompressed));
    219207
    220208    /* Get the original VM path */
     
    493481    {
    494482        hrc = m_pProgress->init(m_pMachine->i_getVirtualBox(),
    495                                 static_cast<IMachine*>(m_pMachine) /* aInitiator */,
     483                                static_cast<IMachine *>(m_pMachine) /* aInitiator */,
    496484                                Utf8Str(m_pMachine->tr("Moving Machine")),
    497485                                true /* fCancellable */,
     
    536524DECLCALLBACK(int) MachineMoveVM::updateProgress(unsigned uPercent, void *pvUser)
    537525{
    538     MachineMoveVM* pTask = *(MachineMoveVM**)pvUser;
     526    MachineMoveVM *pTask = *(MachineMoveVM **)pvUser;
    539527
    540528    if (    pTask
     
    553541DECLCALLBACK(int) MachineMoveVM::copyFileProgress(unsigned uPercentage, void *pvUser)
    554542{
    555     ComObjPtr<Progress> pProgress = *static_cast< ComObjPtr<Progress>* >(pvUser);
     543    ComObjPtr<Progress> pProgress = *static_cast<ComObjPtr<Progress> *>(pvUser);
    556544
    557545    BOOL fCanceled = false;
     
    568556
    569557/* static */
    570 void MachineMoveVM::i_MoveVMThreadTask(MachineMoveVM* task)
     558void MachineMoveVM::i_MoveVMThreadTask(MachineMoveVM *task)
    571559{
    572560    LogFlowFuncEnter();
    573561    HRESULT hrc = S_OK;
    574562
    575     MachineMoveVM* taskMoveVM = task;
     563    MachineMoveVM *taskMoveVM = task;
    576564    ComObjPtr<Machine> &machine = taskMoveVM->m_pMachine;
    577565
     
    637625    {
    638626        /* Move all disks */
    639         hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap, &strTargetFolder);
     627        hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap, strTargetFolder);
    640628        if (FAILED(hrc))
    641629            throw hrc;
     
    650638            /* When the current snapshot folder is absolute we reset it to the
    651639             * default relative folder. */
    652             if (RTPathStartsWithRoot((*machineConfFile).machineUserData.strSnapshotFolder.c_str()))
    653                 (*machineConfFile).machineUserData.strSnapshotFolder = "Snapshots";
    654             (*machineConfFile).strStateFile = "";
     640            if (RTPathStartsWithRoot(machineConfFile->machineUserData.strSnapshotFolder.c_str()))
     641                machineConfFile->machineUserData.strSnapshotFolder = "Snapshots";
     642            machineConfFile->strStateFile = "";
    655643
    656644            /* The absolute name of the snapshot folder. */
    657645            strTrgSnapshotFolder = Utf8StrFmt("%s%c%s", strTargetFolder.c_str(), RTPATH_DELIMITER,
    658                                               (*machineConfFile).machineUserData.strSnapshotFolder.c_str());
     646                                              machineConfFile->machineUserData.strSnapshotFolder.c_str());
    659647
    660648            /* Check if a snapshot folder is necessary and if so doesn't already
     
    709697            Log2(("Update state file path\n"));
    710698            hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap,
    711                                                      taskMoveVM->m_vmFolders[VBox_SettingFolder],
    712                                                      strTargetFolder);
     699                                                      taskMoveVM->m_vmFolders[VBox_SettingFolder],
     700                                                      strTargetFolder);
    713701            if (FAILED(hrc))
    714702                throw hrc;
     
    721709         */
    722710        {
    723             Log2(("Copy Machine settings file \n"));
     711            Log2(("Copy Machine settings file\n"));
    724712
    725713            hrc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy Machine settings file '%s' ..."),
    726                                                                     (*machineConfFile).machineUserData.strName.c_str()).raw(),
     714                                                                    machineConfFile->machineUserData.strName.c_str()).raw(),
    727715                                                            1);
    728716            if (FAILED(hrc))
     
    803791                    taskMoveVM->getFilesList(taskMoveVM->m_vmFolders[VBox_LogFolder], filesList);
    804792                    cit_t it = filesList.m_list.begin();
    805                     while(it != filesList.m_list.end())
     793                    while (it != filesList.m_list.end())
    806794                    {
    807795                        Utf8Str strFullSourceFilePath = it->first.c_str();
     
    945933                if (FAILED(hrc))
    946934                {
    947                     Log2(("Rollback scenario: can't restore the original paths to the state files. "
    948                           "Machine settings %s can be corrupted.\n", machineData->m_strConfigFileFull.c_str()));
     935                    Log2(("Rollback scenario: can't restore the original paths to the state files. Machine settings %s can be corrupted.\n",
     936                          machineData->m_strConfigFileFull.c_str()));
    949937                    throw hrc;
    950938                }
     
    955943            if (FAILED(hrc))
    956944            {
    957                 Log2(("Rollback scenario: can't delete new created files. Check the destination folder."));
     945                Log2(("Rollback scenario: can't delete new created files. Check the destination folder.\n"));
    958946                throw hrc;
    959947            }
     
    963951            if (RT_FAILURE(vrc))
    964952            {
    965                 Log2(("Rollback scenario: can't delete new destination folder."));
     953                Log2(("Rollback scenario: can't delete new destination folder.\n"));
    966954                throw machine->setErrorVrc(vrc, "Rollback scenario: can't delete new destination folder.");
    967955            }
     
    974962                if (FAILED(hrc))
    975963                {
    976                     Log2(("Rollback scenario: can't save machine settings."));
     964                    Log2(("Rollback scenario: can't save machine settings.\n"));
    977965                    throw hrc;
    978966                }
     
    1004992                if (FAILED(hrc))
    1005993                {
    1006                     Log2(("Rollback scenario: can't save global settings."));
     994                    Log2(("Rollback scenario: can't save global settings.\n"));
    1007995                    throw hrc;
    1008996                }
     
    10511039}
    10521040
    1053 HRESULT MachineMoveVM::moveAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE>& listOfDisks,
    1054                                     const Utf8Str* strTargetFolder)
     1041HRESULT MachineMoveVM::moveAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE> &listOfDisks,
     1042                                    const Utf8Str &strTargetFolder)
    10551043{
    10561044    HRESULT rc = S_OK;
     
    10601048    AutoWriteLock  machineLock(machine COMMA_LOCKVAL_SRC_POS);
    10611049
    1062     try{
     1050    try
     1051    {
    10631052        std::map<Utf8Str, MEDIUMTASKMOVE>::const_iterator itMedium = listOfDisks.begin();
    1064         while(itMedium != listOfDisks.end())
     1053        while (itMedium != listOfDisks.end())
    10651054        {
    10661055            const MEDIUMTASKMOVE &mt = itMedium->second;
     
    10731062            if (FAILED(rc)) throw rc;
    10741063
    1075             if (strTargetFolder != NULL && !strTargetFolder->isEmpty())
    1076             {
    1077                 strTargetImageName = *strTargetFolder;
     1064            if (strTargetFolder.isNotEmpty())
     1065            {
     1066                strTargetImageName = strTargetFolder;
    10781067                rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
    10791068                if (FAILED(rc)) throw rc;
     
    11431132    catch(HRESULT hrc)
    11441133    {
    1145         Log2(("\nException during moving the disk %s\n", strLocation.c_str()));
     1134        Log2(("Exception during moving the disk %s\n", strLocation.c_str()));
    11461135        rc = hrc;
    11471136        machineLock.release();
     
    11491138    catch (...)
    11501139    {
    1151         Log2(("\nException during moving the disk %s\n", strLocation.c_str()));
     1140        Log2(("Exception during moving the disk %s\n", strLocation.c_str()));
    11521141        rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS);
    11531142        machineLock.release();
     
    11571146}
    11581147
    1159 HRESULT MachineMoveVM::updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASKMOVE>& listOfFiles,
    1160                                                const Utf8Str& sourcePath, const Utf8Str& targetPath)
     1148HRESULT MachineMoveVM::updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASKMOVE> &listOfFiles,
     1149                                               const Utf8Str &sourcePath, const Utf8Str &targetPath)
    11611150{
    11621151    HRESULT rc = S_OK;
     
    11971186}
    11981187
    1199 HRESULT MachineMoveVM::getFilesList(const Utf8Str& strRootFolder, fileList_t &filesList)
     1188HRESULT MachineMoveVM::getFilesList(const Utf8Str &strRootFolder, fileList_t &filesList)
    12001189{
    12011190    RTDIR hDir;
     
    12561245}
    12571246
    1258 HRESULT MachineMoveVM::deleteFiles(const RTCList<Utf8Str>& listOfFiles)
     1247HRESULT MachineMoveVM::deleteFiles(const RTCList<Utf8Str> &listOfFiles)
    12591248{
    12601249    HRESULT hrc = S_OK;
     
    12791268}
    12801269
    1281 HRESULT MachineMoveVM::getFolderSize(const Utf8Str& strRootFolder, uint64_t& size)
     1270HRESULT MachineMoveVM::getFolderSize(const Utf8Str &strRootFolder, uint64_t &size)
    12821271{
    12831272    HRESULT hrc = S_OK;
     
    12931282        {
    12941283            cit_t it = filesList.m_list.begin();
    1295             while(it != filesList.m_list.end())
     1284            while (it != filesList.m_list.end())
    12961285            {
    12971286                uint64_t cbFile = 0;
     
    13341323
    13351324HRESULT MachineMoveVM::createMachineList(const ComPtr<ISnapshot> &pSnapshot,
    1336                                          std::vector< ComObjPtr<Machine> > &aMachineList) const
     1325                                         std::vector<ComObjPtr<Machine> > &aMachineList) const
    13371326{
    13381327    Bstr name;
     
    13941383            ComObjPtr<Medium> pObjMedium = (Medium *)(IMedium *)pMedium;
    13951384
    1396             /*Check for "read-only" medium in terms that VBox can't create this one */
     1385            /* Check for "read-only" medium in terms that VBox can't create this one */
    13971386            rc = isMediumTypeSupportedForMoving(pMedium);
    13981387            if (FAILED(rc))
     
    14521441            m_llMedias.append(mtc);
    14531442        }
     1443
    14541444        /* Add the save state files of this machine if there is one. */
    14551445        rc = addSaveState(machine);
    14561446        if (FAILED(rc)) return rc;
    1457 
    1458     }
     1447    }
     1448
    14591449    /* Build up the index list of the image chain. Unfortunately we can't do
    14601450     * that in the previous loop, cause there we go from child -> parent and
     
    15411531        return rc;
    15421532
    1543     /*Check whether VBox is able to create this medium format or not, i.e. medium can be "read-only" */
     1533    /* Check whether VBox is able to create this medium format or not, i.e. medium can be "read-only" */
    15441534    Bstr bstrFormatName;
    15451535    rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
     
    15501540    if (formatName.compare("VHDX", Utf8Str::CaseInsensitive) == 0)
    15511541    {
    1552         Log2(("Skipping medium %ls. VHDX format is supported in \"read-only\" mode only. \n", bstrLocation.raw()));
     1542        Log2(("Skipping medium %ls. VHDX format is supported in \"read-only\" mode only.\n", bstrLocation.raw()));
    15531543        return S_FALSE;
    15541544    }
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