VirtualBox

Changeset 78836 in vbox for trunk


Ignore:
Timestamp:
May 29, 2019 7:03:20 AM (6 years ago)
Author:
vboxsync
Message:

bugref:8345. Refining and cleaning up the code.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImplMoveVM.h

    r78761 r78836  
    8080    };
    8181
    82     /** @todo r=bird: Why no m_ prefixes here? */
    83     RTCList<MEDIUMTASKCHAINMOVE>            llMedias;
    84     RTCList<SAVESTATETASKMOVE>              llSaveStateFiles;
    85     std::map<Utf8Str, MEDIUMTASKMOVE>       finalMediumsMap;
    86     std::map<Utf8Str, SAVESTATETASKMOVE>    finalSaveStateFilesMap;
    87     std::map<VBoxFolder_t, Utf8Str>         vmFolders;
    88     std::list<ErrorInfoItem>                errorsList;
     82    RTCList<MEDIUMTASKCHAINMOVE>            m_llMedias;
     83    RTCList<SAVESTATETASKMOVE>              m_llSaveStateFiles;
     84    std::map<Utf8Str, MEDIUMTASKMOVE>       m_finalMediumsMap;
     85    std::map<Utf8Str, SAVESTATETASKMOVE>    m_finalSaveStateFilesMap;
     86    std::map<VBoxFolder_t, Utf8Str>         m_vmFolders;
     87    std::list<ErrorInfoItem>                m_errorsList;
    8988
    9089    ComObjPtr<Machine>  m_pMachine;
     
    9594    Utf8Str             m_targetPath;
    9695    Utf8Str             m_type;
    97     HRESULT             result; /**< @todo r=bird: Why no m_ prefix here?    */
     96    HRESULT             m_result;
    9897
    9998public:
     
    107106        , m_targetPath(aTargetPath)
    108107        , m_type(aType.isEmpty() ? "basic" : aType)
    109         , result(S_OK)
     108        , m_result(S_OK)
    110109    {
    111110    }
  • trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp

    r78765 r78836  
    3030#include "LoggingNew.h"
    3131
    32 /** @todo r=klaus this file is abusing the release log by putting pretty much
    33  * everything there. Should be adjusted to use debug logging where appropriate
    34  * and if really necessary some LogRel2 and the like. */
    35 
    36 
    3732/* This variable is global and used in the different places so it must be cleared each time before usage to avoid failure */
    3833std::vector< ComObjPtr<Machine> > machineList;
     
    137132    if (fLog)
    138133    {
    139         LogRelFunc(("(The error code is %Rrc): %s\n",m_code, m_description.c_str()));
     134        Log2(("(The error code is %Rrc): %s\n",m_code, m_description.c_str()));
    140135    }
    141136    else
     
    145140HRESULT MachineMoveVM::init()
    146141{
    147     HRESULT rc = S_OK;
    148 
    149     errorsList.clear();
     142    HRESULT hrc = S_OK;
     143
     144    m_errorsList.clear();
    150145
    151146    Utf8Str strTargetFolder;
     
    155150        if (len >= RTPATH_MAX)
    156151        {
    157             /** @todo r=bird: Why the leading space in errorDesc? */
    158             /** @todo "The destination path exceeds the maximum length" should
    159              *        suffice here, I think. */
    160             /** @todo r=bird: missing tr(). */
    161             /** @todo r=bird: Actually, why bother with these error strings here? Nobody
    162              *        will ever see them, given that the caller deletes the task when
    163              *        init() fails. */
    164             Utf8Str errorDesc(" The destination path isn't correct. The length of path exceeded the maximum value.");
    165             errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    166             /** @todo r=bird: What on earth is this?  It will cause the caller to leak the
    167              *        task structure, unless it's catching exception (which it wasn't, but
    168              *        I made it is now).  I sure hope this wasn't intentional... */
    169             throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str()));
     152            return m_pMachine->setError(VBOX_E_IPRT_ERROR,
     153                                        m_pMachine->tr(Utf8Str("The destination path exceeds "
     154                                                               "the maximum value.").c_str()));
    170155        }
    171156
     
    199184        if (FAILED(vrc))
    200185        {
    201             /** @todo r=bird: What's this RTPrint doing here?!? */
    202             RTPrintf("strTargetFolder is %s\n", strTargetFolder.c_str());
    203             Utf8StrFmt errorDesc("Unable to move machine. Can't get the destination storage size (%s)",
    204                                  strTargetFolder.c_str());
    205             errorsList.push_back(ErrorInfoItem(E_FAIL, errorDesc.c_str()));
    206             rc = m_pMachine->setErrorBoth(E_FAIL, vrc, m_pMachine->tr(errorDesc.c_str()));
    207             throw rc;
     186            return m_pMachine->setErrorBoth(E_FAIL, vrc,
     187                                            m_pMachine->tr(Utf8StrFmt("Unable to move machine. Can't get "
     188                                                                      "the destination storage size (%s)",
     189                                                                      strTargetFolder.c_str()).c_str()));
    208190        }
    209191
     
    211193        Utf8Str strTempFile = strTargetFolder + "test.txt";
    212194        vrc = RTDirOpen(&hDir, strTargetFolder.c_str());
    213         if (FAILED(vrc))
    214             throw rc = vrc; /** @todo r=bird: RTDirOpen returns a VBox status code. That is _not_ the same as a COM HRESULT! */
     195        if (RT_FAILURE(vrc))
     196            return m_pMachine->setErrorVrc(vrc);
    215197        else
    216198        {
    217199            RTFILE hFile;
    218200            vrc = RTFileOpen(&hFile, strTempFile.c_str(), RTFILE_O_OPEN_CREATE | RTFILE_O_READWRITE | RTFILE_O_DENY_NONE);
    219             if (FAILED(vrc))
    220             {
    221                 LogRelFunc(("Can't create a test file %s (The error is %Rrc)\n", strTempFile.c_str(), vrc));
    222                 Utf8StrFmt errorDesc("Can't create a test file test.txt in the %s. Check the access rights of "
    223                                      "the destination folder.", strTargetFolder.c_str());
    224                 errorsList.push_back(ErrorInfoItem(HRESULT(vrc), errorDesc.c_str()));
    225                 rc = m_pMachine->setErrorBoth(VBOX_E_FILE_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
    226                 /** @todo r=bird: What happens to this error and 'rc'?  Should it be ignored? */
    227             }
    228 
    229             RTFileClose(hFile); /** @todo r=bird: Whey close if opening fail? */
     201            if (RT_FAILURE(vrc))
     202            {
     203                return m_pMachine->setErrorVrc(vrc,
     204                                               m_pMachine->tr(Utf8StrFmt("Can't create a test file test.txt in the %s. "
     205                                                                         "Check the access rights of the destination "
     206                                                                         "folder.", strTargetFolder.c_str()).c_str()));
     207            }
     208
     209            /** @todo r=vvp: Do we need to check each return result here? Looks excessively.
     210             *  And it's not so important for the test file. */
     211            RTFileClose(hFile);
    230212            RTFileDelete(strTempFile.c_str());
    231213            RTDirClose(hDir);
    232214        }
    233215
    234         /** @todo r=bird: Why the need for 'info' here?  LogRelFunc can do the exact
    235          *        same thing without touching the heap.  I don't get what this is
    236          *        about...  There is also excessive log duplication here as well as
    237          *        seemingly unnecessary trailing whitespace. */
    238         Utf8Str info = Utf8StrFmt("blocks: total %RTfoff, free %RTfoff ", cbTotal, cbFree);
    239         LogRelFunc(("%s \n", info.c_str()));
    240         LogRelFunc(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G));
    241         LogRelFunc(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G));
     216        Log2(("blocks: total %RTfoff, free %RTfoff ", cbTotal, cbFree));
     217        Log2(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G));
     218        Log2(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G));
    242219
    243220        RTFSPROPERTIES properties;
    244221        vrc = RTFsQueryProperties(strTargetFolder.c_str(), &properties);
    245         if (FAILED(vrc)) throw vrc;
    246         info = Utf8StrFmt("disk properties:\n"
    247                           "remote: %s \n"
    248                           "read only: %s \n"
    249                           "compressed: %s \n",
    250                           properties.fRemote == true ? "true":"false",
    251                           properties.fReadOnly == true ? "true":"false",
    252                           properties.fCompressed == true ? "true":"false");
    253 
    254         LogRelFunc(("%s \n", info.c_str()));
     222        if (FAILED(vrc))
     223            return m_pMachine->setErrorVrc(vrc);
     224
     225        Utf8StrFmt info ("disk properties:\n"
     226                         "remote: %s \n"
     227                         "read only: %s \n"
     228                         "compressed: %s \n",
     229                         properties.fRemote == true ? "true":"false",
     230                         properties.fReadOnly == true ? "true":"false",
     231                         properties.fCompressed == true ? "true":"false");
     232
     233        Log2(("%s \n", info.c_str()));
    255234
    256235        /* Get the original VM path */
    257236        Utf8Str strSettingsFilePath;
    258237        Bstr bstr_settingsFilePath;
    259         m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam()); /** @todo r=bird: check the status code. */
     238        hrc = m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam());
     239        if (FAILED(hrc))
     240            return hrc;
     241
    260242        strSettingsFilePath = bstr_settingsFilePath;
    261243        strSettingsFilePath.stripFilename();
    262244
    263         vmFolders.insert(std::make_pair(VBox_SettingFolder, strSettingsFilePath));
     245        m_vmFolders.insert(std::make_pair(VBox_SettingFolder, strSettingsFilePath));
    264246
    265247        /* Collect all files from the VM's folder */
    266248        fileList_t fullFileList;
    267         rc = getFilesList(strSettingsFilePath, fullFileList);
    268         if (FAILED(rc)) throw rc;
     249        hrc = getFilesList(strSettingsFilePath, fullFileList);
     250        if (FAILED(hrc))
     251            return hrc;
    269252
    270253        /*
     
    276259        Utf8Str strLogFolder;
    277260        Bstr bstr_logFolder;
    278         m_pMachine->COMGETTER(LogFolder)(bstr_logFolder.asOutParam());
     261        hrc = m_pMachine->COMGETTER(LogFolder)(bstr_logFolder.asOutParam());
     262        if (FAILED(hrc))
     263            return hrc;
     264
    279265        strLogFolder = bstr_logFolder;
    280266        if (   m_type.equals("basic")
    281267            && strLogFolder.contains(strSettingsFilePath))
    282268        {
    283             vmFolders.insert(std::make_pair(VBox_LogFolder, strLogFolder));
     269            m_vmFolders.insert(std::make_pair(VBox_LogFolder, strLogFolder));
    284270        }
    285271
     
    287273        Bstr bstr_stateFilePath;
    288274        MachineState_T machineState;
    289         rc = m_pMachine->COMGETTER(State)(&machineState);
    290         if (FAILED(rc)) throw rc;
     275        hrc = m_pMachine->COMGETTER(State)(&machineState);
     276        if (FAILED(hrc))
     277             return hrc;
     278
    291279        if (machineState == MachineState_Saved)
    292280        {
     
    296284            if (   m_type.equals("basic")
    297285                && strStateFilePath.contains(strSettingsFilePath))
    298                 vmFolders.insert(std::make_pair(VBox_StateFolder, strStateFilePath));//Utf8Str(bstr_stateFilePath)));
     286                m_vmFolders.insert(std::make_pair(VBox_StateFolder, strStateFilePath));
    299287        }
    300288
    301289        Utf8Str strSnapshotFolder;
    302290        Bstr bstr_snapshotFolder;
    303         m_pMachine->COMGETTER(SnapshotFolder)(bstr_snapshotFolder.asOutParam());
     291        hrc = m_pMachine->COMGETTER(SnapshotFolder)(bstr_snapshotFolder.asOutParam());
     292        if (FAILED(hrc))
     293             return hrc;
     294
    304295        strSnapshotFolder = bstr_snapshotFolder;
    305296        if (   m_type.equals("basic")
    306297            && strSnapshotFolder.contains(strSettingsFilePath))
    307             vmFolders.insert(std::make_pair(VBox_SnapshotFolder, strSnapshotFolder));
     298            m_vmFolders.insert(std::make_pair(VBox_SnapshotFolder, strSnapshotFolder));
    308299
    309300        if (m_pMachine->i_isSnapshotMachine())
    310301        {
    311302            Bstr bstrSrcMachineId;
    312             rc = m_pMachine->COMGETTER(Id)(bstrSrcMachineId.asOutParam());
    313             if (FAILED(rc)) throw rc;
     303            hrc = m_pMachine->COMGETTER(Id)(bstrSrcMachineId.asOutParam());
     304            if (FAILED(hrc))
     305                 return hrc;
     306
    314307            ComPtr<IMachine> newSrcMachine;
    315             rc = m_pMachine->i_getVirtualBox()->FindMachine(bstrSrcMachineId.raw(), newSrcMachine.asOutParam());
    316             if (FAILED(rc)) throw rc;
     308            hrc = m_pMachine->i_getVirtualBox()->FindMachine(bstrSrcMachineId.raw(), newSrcMachine.asOutParam());
     309            if (FAILED(hrc))
     310                 return hrc;
    317311        }
    318312
     
    333327        {
    334328            ULONG cSnapshots = 0;
    335             rc = m_pMachine->COMGETTER(SnapshotCount)(&cSnapshots);
    336             if (FAILED(rc)) throw rc;
     329            hrc = m_pMachine->COMGETTER(SnapshotCount)(&cSnapshots);
     330            if (FAILED(hrc))
     331                 return hrc;
     332
    337333            if (cSnapshots > 0)
    338334            {
     
    341337                    id = m_pMachine->i_getSnapshotId().toString();
    342338                ComPtr<ISnapshot> pSnapshot;
    343                 rc = m_pMachine->FindSnapshot(Bstr(id).raw(), pSnapshot.asOutParam());
    344                 if (FAILED(rc)) throw rc;
    345                 rc = createMachineList(pSnapshot, machineList);
    346                 if (FAILED(rc)) throw rc;
     339                hrc = m_pMachine->FindSnapshot(Bstr(id).raw(), pSnapshot.asOutParam());
     340                if (FAILED(hrc))
     341                     return hrc;
     342                hrc = createMachineList(pSnapshot, machineList);
     343                if (FAILED(hrc))
     344                     return hrc;
    347345            }
    348346        }
     
    351349        ULONG uTotalWeight = 1;
    352350
    353         /* The lists llMedias and llSaveStateFiles are filled in the queryMediasForAllStates() */
    354         queryMediasForAllStates(machineList); /** @todo r=bird: As a rule status codes needs checking every time. */
     351        /* The lists m_llMedias and m_llSaveStateFiles are filled in the queryMediasForAllStates() */
     352        hrc = queryMediasForAllStates(machineList);
     353        if (FAILED(hrc))
     354             return hrc;
    355355
    356356        {
    357357            uint64_t totalMediumsSize = 0;
    358358
    359             for (size_t i = 0; i < llMedias.size(); ++i)
     359            for (size_t i = 0; i < m_llMedias.size(); ++i)
    360360            {
    361361                LONG64  cbSize = 0;
    362                 MEDIUMTASKCHAINMOVE &mtc = llMedias.at(i);
     362                MEDIUMTASKCHAINMOVE &mtc = m_llMedias.at(i);
    363363                for (size_t a = mtc.chain.size(); a > 0; --a)
    364364                {
     
    367367                    Utf8Str name = mtc.chain[a - 1].strBaseName;
    368368                    ComPtr<IMedium> plMedium = mtc.chain[a - 1].pMedium;
    369                     rc = plMedium->COMGETTER(Location)(bstrLocation.asOutParam());
    370                     if (FAILED(rc)) throw rc;
    371                         strLocation = bstrLocation;
     369                    hrc = plMedium->COMGETTER(Location)(bstrLocation.asOutParam());
     370                    if (FAILED(hrc))
     371                         return hrc;
     372
     373                    strLocation = bstrLocation;
    372374
    373375                    /*if an image is located in the actual VM folder it will be added to the actual list */
    374376                    if (strLocation.contains(strSettingsFilePath))
    375377                    {
    376                         rc = plMedium->COMGETTER(Size)(&cbSize);
    377                         if (FAILED(rc)) throw rc;
     378                        hrc = plMedium->COMGETTER(Size)(&cbSize);
     379                        if (FAILED(hrc))
     380                             return hrc;
    378381
    379382                        std::pair<std::map<Utf8Str, MEDIUMTASKMOVE>::iterator,bool> ret;
    380                         ret = finalMediumsMap.insert(std::make_pair(name, mtc.chain[a - 1]));
     383                        ret = m_finalMediumsMap.insert(std::make_pair(name, mtc.chain[a - 1]));
    381384                        if (ret.second == true)
    382385                        {
     
    385388                            uTotalWeight += mtc.chain[a - 1].uWeight;
    386389                            totalMediumsSize += cbSize;
    387                             LogRelFunc(("Image %s was added into the moved list\n", name.c_str()));
     390                            Log2(("Image %s was added into the moved list\n", name.c_str()));
    388391                        }
    389392                    }
     
    391394            }
    392395
    393             LogRelFunc(("Total Size of images is %lld bytes\n", totalMediumsSize));
     396            Log2(("Total Size of images is %lld bytes\n", totalMediumsSize));
    394397            neededFreeSpace += totalMediumsSize;
    395398        }
     
    399402            uint64_t totalStateSize = 0;
    400403
    401             for (size_t i = 0; i < llSaveStateFiles.size(); ++i)
     404            for (size_t i = 0; i < m_llSaveStateFiles.size(); ++i)
    402405            {
    403406                uint64_t cbFile = 0;
    404                 SAVESTATETASKMOVE &sst = llSaveStateFiles.at(i);
     407                SAVESTATETASKMOVE &sst = m_llSaveStateFiles.at(i);
    405408
    406409                Utf8Str name = sst.strSaveStateFile;
     
    412415                    {
    413416                        std::pair<std::map<Utf8Str, SAVESTATETASKMOVE>::iterator,bool> ret;
    414                         ret = finalSaveStateFilesMap.insert(std::make_pair(name, sst));
     417                        ret = m_finalSaveStateFilesMap.insert(std::make_pair(name, sst));
    415418                        if (ret.second == true)
    416419                        {
     
    418421                            ++uCount;
    419422                            uTotalWeight += sst.uWeight;
    420                             LogRelFunc(("The state file %s was added into the moved list\n", name.c_str()));
     423                            Log2(("The state file %s was added into the moved list\n", name.c_str()));
    421424                        }
    422425                    }
    423426                    else
    424                         LogRelFunc(("The state file %s wasn't added into the moved list. Couldn't get the file size.\n",
    425                                          name.c_str()));
     427                    {
     428                        Log2(("The state file %s wasn't added into the moved list. Couldn't get the file size.\n",
     429                              name.c_str()));
     430                        return m_pMachine->setErrorVrc(vrc);
     431                    }
    426432                }
    427433            }
     
    432438        /* Prepare data for moving the log files */
    433439        {
    434             Utf8Str strFolder = vmFolders[VBox_LogFolder];
     440            Utf8Str strFolder = m_vmFolders[VBox_LogFolder];
    435441
    436442            if (RTPathExists(strFolder.c_str()))
    437443            {
    438444                uint64_t totalLogSize = 0;
    439                 rc = getFolderSize(strFolder, totalLogSize);
    440                 if (SUCCEEDED(rc))
     445                hrc = getFolderSize(strFolder, totalLogSize);
     446                if (SUCCEEDED(hrc))
    441447                {
    442448                    neededFreeSpace += totalLogSize;
    443449                    if (cbFree - neededFreeSpace <= _1M)
    444450                    {
    445                         throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location
     451                        return m_pMachine->setError(VBOX_E_IPRT_ERROR,
     452                                                    m_pMachine->tr(Utf8StrFmt("There is lack of disk space "
     453                                                                              "(%Rrc)", VERR_OUT_OF_RESOURCES).c_str()));
    446454                    }
    447455
    448456                    fileList_t filesList;
    449                     getFilesList(strFolder, filesList); /** @todo r=bird: return code check */
     457                    hrc = getFilesList(strFolder, filesList);
     458                    if (FAILED(hrc))
     459                        return hrc;
     460
    450461                    cit_t it = filesList.m_list.begin();
    451462                    while (it != filesList.m_list.end())
     
    461472                            uTotalWeight += (ULONG)((cbFile + _1M - 1) / _1M);
    462473                            actualFileList.add(strFile);
    463                             LogRelFunc(("The log file %s added into the moved list\n", strFile.c_str()));
     474                            Log2(("The log file %s added into the moved list\n", strFile.c_str()));
    464475                        }
    465476                        else
    466                             LogRelFunc(("The log file %s wasn't added into the moved list. Couldn't get the file size."
    467                                              "\n", strFile.c_str()));
     477                            Log2(("The log file %s wasn't added into the moved list. "
     478                                  "Couldn't get the file size.\n", strFile.c_str()));
    468479                        ++it;
    469480                    }
    470481                }
     482                else
     483                    return hrc;
    471484            }
    472485            else
    473486            {
    474                 LogRelFunc(("Information: The original log folder %s doesn't exist\n", strFolder.c_str()));
    475                 rc = S_OK;//it's not error in this case if there isn't an original log folder
    476             }
    477         }
    478 
    479         LogRelFunc(("Total space needed is %lld bytes\n", neededFreeSpace));
     487                Log2(("Information: The original log folder %s doesn't exist\n", strFolder.c_str()));
     488                hrc = S_OK;//it's not error in this case if there isn't an original log folder
     489            }
     490        }
     491
     492        LogRel(("Total space needed is %lld bytes\n", neededFreeSpace));
    480493        /* Check a target location on enough room */
    481494        if (cbFree - neededFreeSpace <= _1M)
    482495        {
    483             LogRelFunc(("but free space on destination is %RTfoff\n", cbFree));
    484             /** @todo r=bird: You're throwing a VBox status code here, but only catching
    485              *        HRESULT.  So, this will go to the caller or someone else up the
    486              *        stack, which is unacceptable throw behaviour. */
    487             throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location
     496            LogRel(("but free space on destination is %RTfoff\n", cbFree));
     497            return m_pMachine->setError(VBOX_E_IPRT_ERROR,
     498                                        m_pMachine->tr(Utf8StrFmt ("There is lack of disk space"
     499                                                                   " (%Rrc)", VERR_OUT_OF_RESOURCES).c_str()));
    488500        }
    489501
    490502        /* Add step for .vbox machine setting file */
    491         { /** @todo what's the scoping for? */
    492             ++uCount;
    493             uTotalWeight += 1;
    494         }
     503        ++uCount;
     504        uTotalWeight += 1;
    495505
    496506        /* Reserve additional steps in case of failure and rollback all changes */
    497         {
    498             uTotalWeight += uCount;//just add 1 for each possible rollback operation
    499             uCount += uCount;//and increase the steps twice
    500         }
     507        uTotalWeight += uCount;//just add 1 for each possible rollback operation
     508        uCount += uCount;//and increase the steps twice
    501509
    502510        /* Init Progress instance */
    503511        {
    504             rc = m_pProgress->init(m_pMachine->i_getVirtualBox(),
    505                                    static_cast<IMachine*>(m_pMachine) /* aInitiator */,
    506                                    Utf8Str(m_pMachine->tr("Moving Machine")),
    507                                    true /* fCancellable */,
    508                                    uCount,
    509                                    uTotalWeight,
    510                                    Utf8Str(m_pMachine->tr("Initialize Moving")),
    511                                    1);
    512             if (FAILED(rc))
    513             {
    514                 Utf8StrFmt errorDesc("Couldn't correctly setup the progress object for moving VM operation (%Rrc)", rc);
    515                 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    516 
    517                 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str()));
     512            hrc = m_pProgress->init(m_pMachine->i_getVirtualBox(),
     513                                    static_cast<IMachine*>(m_pMachine) /* aInitiator */,
     514                                    Utf8Str(m_pMachine->tr("Moving Machine")),
     515                                    true /* fCancellable */,
     516                                    uCount,
     517                                    uTotalWeight,
     518                                    Utf8Str(m_pMachine->tr("Initialize Moving")),
     519                                    1);
     520            if (FAILED(hrc))
     521            {
     522                return m_pMachine->setError(VBOX_E_IPRT_ERROR,
     523                                            m_pMachine->tr(Utf8StrFmt("Couldn't correctly setup the progress "
     524                                                                      "object for moving VM operation (%Rrc)", hrc).c_str()));
    518525            }
    519526        }
     
    521528        /* save all VM data */
    522529        m_pMachine->i_setModified(Machine::IsModified_MachineData);
    523         rc = m_pMachine->SaveSettings();
    524     }
    525     catch(HRESULT hrc)
    526     {
    527 /** @todo r=bird: Seriously, why throw any error when you can just return
    528  *        them.  This is just copying the thrown message and passing it onto
    529  *        the return statemnt a few lines later.  (The log statemnt doesn't
    530  *        really count as it doesn't log the status.) */
    531         rc = hrc;
     530        hrc = m_pMachine->SaveSettings();
     531        if (FAILED(hrc))
     532            return hrc;
     533    }
     534    catch(HRESULT aRc)
     535    {
     536        hrc = aRc;
    532537    }
    533538
    534539    LogFlowFuncLeave();
    535540
    536     return rc;
     541    return hrc;
    537542}
    538543
     
    545550        {
    546551            settings::Snapshot snap = (settings::Snapshot)(*it);
    547             LogRelFunc(("snap.uuid = %s\n", snap.uuid.toStringCurly().c_str()));
    548             LogRelFunc(("snap.strStateFile = %s\n", snap.strStateFile.c_str()));
     552            Log2(("snap.uuid = %s\n", snap.uuid.toStringCurly().c_str()));
     553            Log2(("snap.strStateFile = %s\n", snap.strStateFile.c_str()));
    549554        }
    550555
     
    593598{
    594599    LogFlowFuncEnter();
    595     HRESULT rc = S_OK;
     600    HRESULT hrc = S_OK;
    596601
    597602    MachineMoveVM* taskMoveVM = task;
     
    604609    {
    605610        Bstr bstrMachineName;
    606         machine->COMGETTER(Name)(bstrMachineName.asOutParam());
     611        hrc = machine->COMGETTER(Name)(bstrMachineName.asOutParam());
     612        if (FAILED(hrc))
     613        {
     614            taskMoveVM->m_result = hrc;
     615            if (!taskMoveVM->m_pProgress.isNull())
     616                taskMoveVM->m_pProgress->i_notifyComplete(taskMoveVM->m_result);
     617            return;
     618        }
    607619        strTargetFolder.append(Utf8Str(bstrMachineName));
    608620    }
     
    652664    {
    653665        /* Move all disks */
    654         rc = taskMoveVM->moveAllDisks(taskMoveVM->finalMediumsMap, &strTargetFolder);
    655         if (FAILED(rc))
    656             throw rc;
     666        hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap, &strTargetFolder);
     667        if (FAILED(hrc))
     668            throw hrc;
    657669
    658670        /* Get Machine::Data here because moveAllDisks() change it */
     
    675687            /* Check if a snapshot folder is necessary and if so doesn't already
    676688             * exists. */
    677             if (   taskMoveVM->finalSaveStateFilesMap.size() != 0
     689            if (   taskMoveVM->m_finalSaveStateFilesMap.size() != 0
    678690                && !RTDirExists(strTrgSnapshotFolder.c_str()))
    679691            {
     
    682694                {
    683695                    Utf8StrFmt errorDesc("Could not create snapshots folder '%s' (%Rrc)", strTrgSnapshotFolder.c_str(), vrc);
    684                     taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     696                    taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    685697
    686698                    throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str()));
     
    688700            }
    689701
    690             std::map<Utf8Str, SAVESTATETASKMOVE>::iterator itState = taskMoveVM->finalSaveStateFilesMap.begin();
    691             while (itState != taskMoveVM->finalSaveStateFilesMap.end())
     702            std::map<Utf8Str, SAVESTATETASKMOVE>::iterator itState = taskMoveVM->m_finalSaveStateFilesMap.begin();
     703            while (itState != taskMoveVM->m_finalSaveStateFilesMap.end())
    692704            {
    693705                const SAVESTATETASKMOVE &sst = itState->second;
     
    696708
    697709                /* Move to next sub-operation. */
    698                 rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy the save state file '%s' ..."),
     710                hrc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy the save state file '%s' ..."),
    699711                                                            RTPathFilename(sst.strSaveStateFile.c_str())).raw(), sst.uWeight);
    700                 if (FAILED(rc)) throw rc;
     712                if (FAILED(hrc))
     713                    throw hrc;
    701714
    702715                int vrc = RTFileCopyEx(sst.strSaveStateFile.c_str(), strTrgSaveState.c_str(), 0,
     
    706719                    Utf8StrFmt errorDesc("Could not copy state file '%s' to '%s' (%Rrc)",
    707720                                         sst.strSaveStateFile.c_str(), strTrgSaveState.c_str(), vrc);
    708                     taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     721                    taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    709722
    710723                    throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str()));
     
    725738         */
    726739        {
    727             LogRelFunc(("Update state file path\n"));
    728             rc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->finalSaveStateFilesMap,
    729                                                      taskMoveVM->vmFolders[VBox_SettingFolder],
     740            Log2(("Update state file path\n"));
     741            hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap,
     742                                                     taskMoveVM->m_vmFolders[VBox_SettingFolder],
    730743                                                     strTargetFolder);
    731             if (FAILED(rc))
    732                 throw rc;
     744            if (FAILED(hrc))
     745                throw hrc;
    733746        }
    734747
     
    739752         */
    740753        {
    741             LogRelFunc(("Copy Machine settings file \n"));
    742 
    743             rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy Machine settings file '%s' ..."),
     754            Log2(("Copy Machine settings file \n"));
     755
     756            hrc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copy Machine settings file '%s' ..."),
    744757                                                (*machineConfFile).machineUserData.strName.c_str()).raw(), 1);
    745             if (FAILED(rc)) throw rc;
     758            if (FAILED(hrc))
     759                throw hrc;
    746760
    747761            Utf8Str strTargetSettingsFilePath = strTargetFolder;
     
    755769                    Utf8StrFmt errorDesc("Could not create a home machine folder '%s' (%Rrc)",
    756770                                         strTargetSettingsFilePath.c_str(), vrc);
    757                     taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     771                    taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    758772
    759773                    throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str()));
    760774                }
    761                 LogRelFunc(("Created a home machine folder %s\n", strTargetSettingsFilePath.c_str()));
     775                Log2(("Created a home machine folder %s\n", strTargetSettingsFilePath.c_str()));
    762776            }
    763777
     
    765779            Bstr bstrMachineName;
    766780            machine->COMGETTER(Name)(bstrMachineName.asOutParam());
     781            if (FAILED(hrc))
     782                throw hrc;
    767783            strTargetSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName));
    768784            strTargetSettingsFilePath.append(".vbox");
     
    771787            Bstr bstr_settingsFilePath;
    772788            machine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam());
     789            if (FAILED(hrc))
     790                throw hrc;
    773791            strSettingsFilePath = bstr_settingsFilePath;
    774792
     
    779797                Utf8StrFmt errorDesc("Could not copy the setting file '%s' to '%s' (%Rrc)",
    780798                                     strSettingsFilePath.c_str(), strTargetSettingsFilePath.stripFilename().c_str(), vrc);
    781                 taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     799                taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    782800
    783801                throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str()));
    784802            }
    785803
    786             LogRelFunc(("The setting file %s has been copied into the folder %s\n", strSettingsFilePath.c_str(),
     804            Log2(("The setting file %s has been copied into the folder %s\n", strSettingsFilePath.c_str(),
    787805                        strTargetSettingsFilePath.stripFilename().c_str()));
    788806
     
    795813        /* Moving Machine log files */
    796814        {
    797             LogRelFunc(("Copy machine log files \n"));
    798 
    799             if (taskMoveVM->vmFolders[VBox_LogFolder].isNotEmpty())
     815            Log2(("Copy machine log files \n"));
     816
     817            if (taskMoveVM->m_vmFolders[VBox_LogFolder].isNotEmpty())
    800818            {
    801819                /* Check an original log folder existence */
    802                 if (RTDirExists(taskMoveVM->vmFolders[VBox_LogFolder].c_str()))
     820                if (RTDirExists(taskMoveVM->m_vmFolders[VBox_LogFolder].c_str()))
    803821                {
    804822                    Utf8Str strTargetLogFolderPath = strTargetFolder;
     
    813831                            Utf8StrFmt errorDesc("Could not create log folder '%s' (%Rrc)",
    814832                                                 strTargetLogFolderPath.c_str(), vrc);
    815                             taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     833                            taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    816834
    817835                            throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str()));
    818836                        }
    819                         LogRelFunc(("Created a log machine folder %s\n", strTargetLogFolderPath.c_str()));
     837                        Log2(("Created a log machine folder %s\n", strTargetLogFolderPath.c_str()));
    820838                    }
    821839
    822840                    fileList_t filesList;
    823                     taskMoveVM->getFilesList(taskMoveVM->vmFolders[VBox_LogFolder], filesList);
     841                    taskMoveVM->getFilesList(taskMoveVM->m_vmFolders[VBox_LogFolder], filesList);
    824842                    cit_t it = filesList.m_list.begin();
    825843                    while(it != filesList.m_list.end())
     
    832850
    833851                        /* Move to next sub-operation. */
    834                         rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copying the log file '%s' ..."),
     852                        hrc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt(machine->tr("Copying the log file '%s' ..."),
    835853                                                                               RTPathFilename(strFullSourceFilePath.c_str())).raw(),
    836854                                                                       1);
    837                         if (FAILED(rc)) throw rc;
     855                        if (FAILED(hrc))
     856                            throw hrc;
    838857
    839858                        int vrc = RTFileCopyEx(strFullSourceFilePath.c_str(), strFullTargetFilePath.c_str(), 0,
     
    845864                                                 strFullTargetFilePath.stripFilename().c_str(),
    846865                                                 vrc);
    847                             taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     866                            taskMoveVM->m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    848867
    849868                            throw machine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, machine->tr(errorDesc.c_str()));
    850869                        }
    851870
    852                         LogRelFunc(("The log file %s has been copied into the folder %s\n", strFullSourceFilePath.c_str(),
    853                                     strFullTargetFilePath.stripFilename().c_str()));
     871                        Log2(("The log file %s has been copied into the folder %s\n", strFullSourceFilePath.c_str(),
     872                              strFullTargetFilePath.stripFilename().c_str()));
    854873
    855874                        /* save new file in case of restoring */
     
    865884
    866885        /* save all VM data */
    867         {
    868             rc = machine->SaveSettings();
    869         }
    870 
    871         {
    872             LogRelFunc(("Update path to XML setting file\n"));
     886        hrc = machine->SaveSettings();
     887        if (FAILED(hrc))
     888            throw hrc;
     889
     890        {
     891            Log2(("Update path to XML setting file\n"));
    873892            Utf8Str strTargetSettingsFilePath = strTargetFolder;
    874893            Bstr bstrMachineName;
    875             machine->COMGETTER(Name)(bstrMachineName.asOutParam());
     894            hrc = machine->COMGETTER(Name)(bstrMachineName.asOutParam());
     895            if (FAILED(hrc))
     896                throw hrc;
    876897            strTargetSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName)).append(".vbox");
    877898            machineData->m_strConfigFileFull = strTargetSettingsFilePath;
     
    888909            AutoWriteLock vboxLock(machine->mParent COMMA_LOCKVAL_SRC_POS);
    889910
    890             rc = machine->mParent->i_saveSettings();
    891         }
    892     }
    893     catch(HRESULT hrc)
    894     {
    895         LogRelFunc(("Moving machine to a new destination was failed. Check original and destination places.\n"));
    896         rc = hrc;
    897         taskMoveVM->result = rc;
     911            hrc = machine->mParent->i_saveSettings();
     912            if (FAILED(hrc))
     913                throw hrc;
     914        }
     915    }
     916    catch(HRESULT aRc)
     917    {
     918        hrc = aRc;
     919        taskMoveVM->m_result = hrc;
    898920    }
    899921    catch (...)
    900922    {
    901         LogRelFunc(("Moving machine to a new destination was failed. Check original and destination places.\n"));
    902         rc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS);
    903         taskMoveVM->result = rc;
     923        Log2(("Moving machine to a new destination was failed. Check original and destination places.\n"));
     924        hrc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS);
     925        taskMoveVM->m_result = hrc;
    904926    }
    905927
    906928    /* Cleanup on failure */
    907     if (FAILED(rc))
     929    if (FAILED(hrc))
    908930    {
    909931        Machine::Data *machineData = machine->mData.data();
    910 
    911         /* ! Apparently we should update the Progress object !*/
    912         ULONG operationCount = 0;
    913         rc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount);
    914         ULONG operation = 0;
    915         rc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation);
    916         Bstr bstrOperationDescription;
    917         rc = taskMoveVM->m_pProgress->COMGETTER(OperationDescription)(bstrOperationDescription.asOutParam());
    918         Utf8Str strOperationDescription = bstrOperationDescription;
    919         ULONG operationPercent = 0;
    920         rc = taskMoveVM->m_pProgress->COMGETTER(OperationPercent)(&operationPercent);
    921 
    922         Bstr bstrMachineName;
    923         machine->COMGETTER(Name)(bstrMachineName.asOutParam());
    924         LogRelFunc(("Moving machine %s was failed on operation %s\n",
    925                     Utf8Str(bstrMachineName.raw()).c_str(), Utf8Str(bstrOperationDescription.raw()).c_str()));
    926932
    927933        /* Restoring the original mediums */
     
    940946             * Thus we start from "operation + 1" and finish when "i < operationCount - operation".
    941947             */
     948
     949            /** @todo r=vvp: Do we need to check each return result here? Looks excessively
     950             *  and what to do with any failure here? We are already in the rollback action.
     951             *  Throw only the important errors?
     952             *  We MUST finish this action anyway to avoid garbage and get the original VM state. */
     953            /* ! Apparently we should update the Progress object !*/
     954            ULONG operationCount = 0;
     955            hrc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount);
     956            if (FAILED(hrc))
     957                throw hrc;
     958            ULONG operation = 0;
     959            hrc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation);
     960            if (FAILED(hrc))
     961                throw hrc;
     962            Bstr bstrOperationDescription;
     963            hrc = taskMoveVM->m_pProgress->COMGETTER(OperationDescription)(bstrOperationDescription.asOutParam());
     964            if (FAILED(hrc))
     965                throw hrc;
     966            Utf8Str strOperationDescription = bstrOperationDescription;
     967            ULONG operationPercent = 0;
     968            hrc = taskMoveVM->m_pProgress->COMGETTER(OperationPercent)(&operationPercent);
     969            if (FAILED(hrc))
     970                throw hrc;
     971            Bstr bstrMachineName;
     972            hrc = machine->COMGETTER(Name)(bstrMachineName.asOutParam());
     973            if (FAILED(hrc))
     974                throw hrc;
     975
     976            Log2(("Moving machine %s was failed on operation %s\n",
     977                  Utf8Str(bstrMachineName.raw()).c_str(), Utf8Str(bstrOperationDescription.raw()).c_str()));
     978
    942979            for (ULONG i = operation + 1; i < operationCount - operation; ++i)
    943             {
    944                 rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i + 1).raw(), 1);
    945                 if (FAILED(rc)) throw rc;
    946             }
    947 
    948             rc = taskMoveVM->moveAllDisks(taskMoveVM->finalMediumsMap);
    949             if (FAILED(rc))
    950                 throw rc;
    951         }
    952         catch(HRESULT hrc)
    953         {
    954             LogRelFunc(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n"));
    955             taskMoveVM->result = hrc;
     980                taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i + 1).raw(), 1);
     981
     982            hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap);
     983            if (FAILED(hrc))
     984                throw hrc;
     985
     986            /* Revert original paths to the state files */
     987            {
     988                hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap,
     989                                                          strTargetFolder,
     990                                                          taskMoveVM->m_vmFolders[VBox_SettingFolder]);
     991                if (FAILED(hrc))
     992                {
     993                    Log2(("Rollback scenario: can't restore the original paths to the state files. "
     994                          "Machine settings %s can be corrupted.\n", machineData->m_strConfigFileFull.c_str()));
     995                    throw hrc;
     996                }
     997            }
     998
     999            /* Delete all created files. Here we update progress object */
     1000            hrc = taskMoveVM->deleteFiles(newFiles);
     1001            if (FAILED(hrc))
     1002            {
     1003                Log2(("Rollback scenario: can't delete new created files. Check the destination folder."));
     1004                throw hrc;
     1005            }
     1006
     1007            /* Delete destination folder */
     1008            int vrc = RTDirRemove(strTargetFolder.c_str());
     1009            if (RT_FAILURE(vrc))
     1010            {
     1011                Log2(("Rollback scenario: can't delete new destination folder."));
     1012                throw machine->setErrorVrc(vrc, "Rollback scenario: can't delete new destination folder.");
     1013            }
     1014
     1015            /* save all VM data */
     1016            {
     1017                AutoWriteLock  srcLock(machine COMMA_LOCKVAL_SRC_POS);
     1018                srcLock.release();
     1019                hrc = machine->SaveSettings();
     1020                if (FAILED(hrc))
     1021                {
     1022                    Log2(("Rollback scenario: can't save machine settings."));
     1023                    throw hrc;
     1024                }
     1025                srcLock.acquire();
     1026            }
     1027
     1028            /* Restore an original path to XML setting file */
     1029            {
     1030                Log2(("Rollback scenario: restoration of the original path to XML setting file\n"));
     1031                Utf8Str strOriginalSettingsFilePath = taskMoveVM->m_vmFolders[VBox_SettingFolder];
     1032                strOriginalSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName)).append(".vbox");
     1033                machineData->m_strConfigFileFull = strOriginalSettingsFilePath;
     1034                machine->mParent->i_copyPathRelativeToConfig(strOriginalSettingsFilePath, machineData->m_strConfigFile);
     1035            }
     1036
     1037            /* Marks the global registry for uuid as modified */
     1038            {
     1039                AutoWriteLock  srcLock(machine COMMA_LOCKVAL_SRC_POS);
     1040                srcLock.release();
     1041                Guid uuid = machine->mData->mUuid;
     1042                machine->mParent->i_markRegistryModified(uuid);
     1043                srcLock.acquire();
     1044            }
     1045
     1046            /* save the global settings; for that we should hold only the VirtualBox lock */
     1047            {
     1048                AutoWriteLock vboxLock(machine->mParent COMMA_LOCKVAL_SRC_POS);
     1049                hrc = machine->mParent->i_saveSettings();
     1050                if (FAILED(hrc))
     1051                {
     1052                    Log2(("Rollback scenario: can't save global settings."));
     1053                    throw hrc;
     1054                }
     1055            }
     1056        }
     1057        catch(HRESULT aRc)
     1058        {
     1059            Log2(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n"));
     1060            taskMoveVM->m_result = aRc;
    9561061        }
    9571062        catch (...)
    9581063        {
    959             LogRelFunc(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n"));
    960             rc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS);
    961             taskMoveVM->result = rc;
    962         }
    963 
    964         /* Revert original paths to the state files */
    965         rc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->finalSaveStateFilesMap,
    966                                                  strTargetFolder,
    967                                                  taskMoveVM->vmFolders[VBox_SettingFolder]);
    968         if (FAILED(rc))
    969         {
    970             LogRelFunc(("Rollback scenario: can't restore the original paths to the state files. "
    971                         "Machine settings %s can be corrupted.\n", machineData->m_strConfigFileFull.c_str()));
    972         }
    973 
    974         /* Delete all created files. Here we update progress object */
    975         rc = taskMoveVM->deleteFiles(newFiles);
    976         if (FAILED(rc))
    977             LogRelFunc(("Rollback scenario: can't delete new created files. Check the destination folder."));
    978 
    979         /* Delete destination folder */
    980         RTDirRemove(strTargetFolder.c_str());
    981 
    982         /* save all VM data */
    983         {
    984             AutoWriteLock  srcLock(machine COMMA_LOCKVAL_SRC_POS);
    985             srcLock.release();
    986             rc = machine->SaveSettings();
    987             srcLock.acquire();
    988         }
    989 
    990         /* Restore an original path to XML setting file */
    991         {
    992             LogRelFunc(("Rollback scenario: restoration of the original path to XML setting file\n"));
    993             Utf8Str strOriginalSettingsFilePath = taskMoveVM->vmFolders[VBox_SettingFolder];
    994             strOriginalSettingsFilePath.append(RTPATH_DELIMITER).append(Utf8Str(bstrMachineName)).append(".vbox");
    995             machineData->m_strConfigFileFull = strOriginalSettingsFilePath;
    996             machine->mParent->i_copyPathRelativeToConfig(strOriginalSettingsFilePath, machineData->m_strConfigFile);
    997         }
    998 
    999         /* Marks the global registry for uuid as modified */
    1000         {
    1001             AutoWriteLock  srcLock(machine COMMA_LOCKVAL_SRC_POS);
    1002             srcLock.release();
    1003             Guid uuid = machine->mData->mUuid;
    1004             machine->mParent->i_markRegistryModified(uuid);
    1005             srcLock.acquire();
    1006         }
    1007 
    1008         /* save the global settings; for that we should hold only the VirtualBox lock */
    1009         {
    1010             AutoWriteLock vboxLock(machine->mParent COMMA_LOCKVAL_SRC_POS);
    1011             rc = machine->mParent->i_saveSettings();
    1012         }
    1013 
     1064            Log2(("Rollback scenario: restoration the original mediums were failed. Machine can be corrupted.\n"));
     1065            hrc = VirtualBoxBase::handleUnexpectedExceptions(machine, RT_SRC_POS);
     1066            taskMoveVM->m_result = hrc;
     1067        }
    10141068        /* In case of failure the progress object on the other side (user side) get notification about operation
    10151069           completion but the operation percentage may not be set to 100% */
     
    10221076         * because we doubled the number of operations for rollback case.
    10231077         * But if we want to update the progress object corectly it's needed to add all medium moved by standard
    1024          * "move medium" logic (for us it's taskMoveVM->finalMediumsMap) to the current number of operation.
     1078         * "move medium" logic (for us it's taskMoveVM->m_finalMediumsMap) to the current number of operation.
    10251079         */
    10261080
    10271081        ULONG operationCount = 0;
    1028         rc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount);
     1082        hrc = taskMoveVM->m_pProgress->COMGETTER(OperationCount)(&operationCount);
    10291083        ULONG operation = 0;
    1030         rc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation);
    1031 
    1032         for (ULONG i = operation; i < operation + taskMoveVM->finalMediumsMap.size() - 1; ++i)
    1033         {
    1034             rc = taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i).raw(), 1);
    1035             if (FAILED(rc)) throw rc; /** @todo r=bird: Who exactly should be catching this? Our caller is
    1036                                        * ThreadTask::taskHandlerThreadProc and it doesn't catch anything, nor does the
    1037                                        * IPRT. */
    1038         }
    1039 
    1040         rc = taskMoveVM->deleteFiles(originalFiles);
    1041         if (FAILED(rc))
    1042             LogRelFunc(("Forward scenario: can't delete all original files.\n"));
     1084        hrc = taskMoveVM->m_pProgress->COMGETTER(Operation)(&operation);
     1085
     1086        for (ULONG i = operation; i < operation + taskMoveVM->m_finalMediumsMap.size() - 1; ++i)
     1087            taskMoveVM->m_pProgress->SetNextOperation(BstrFmt("Skip the empty operation %d...", i).raw(), 1);
     1088
     1089        hrc = taskMoveVM->deleteFiles(originalFiles);
     1090        if (FAILED(hrc))
     1091            Log2(("Forward scenario: can't delete all original files.\n"));
    10431092    }
    10441093
     
    10461095    {
    10471096        /* Set the first error happened */
    1048         if (!taskMoveVM->errorsList.empty())
    1049         {
    1050             ErrorInfoItem ei = taskMoveVM->errorsList.front();
     1097        if (!taskMoveVM->m_errorsList.empty())
     1098        {
     1099            ErrorInfoItem ei = taskMoveVM->m_errorsList.front();
    10511100            machine->setError(ei.m_code, machine->tr(ei.m_description.c_str()));
    10521101        }
    10531102
    1054         taskMoveVM->m_pProgress->i_notifyComplete(taskMoveVM->result);
     1103        taskMoveVM->m_pProgress->i_notifyComplete(taskMoveVM->m_result);
    10551104    }
    10561105
     
    10881137
    10891138                if (mt.fSnapshot == true)
    1090                 {
    10911139                    strLocation.stripFilename().stripPath().append(RTPATH_DELIMITER).append(Utf8Str(bstrSrcName));
    1092                 }
    10931140                else
    1094                 {
    10951141                    strLocation.stripPath();
    1096                 }
    10971142
    10981143                strTargetImageName.append(RTPATH_DELIMITER).append(strLocation);
     
    11481193                com::ErrorInfoKeeper eik;
    11491194                Utf8Str errorDesc(eik.getText().raw());
    1150                 errorsList.push_back(ErrorInfoItem(eik.getResultCode(), errorDesc.c_str()));
     1195                m_errorsList.push_back(ErrorInfoItem(eik.getResultCode(), errorDesc.c_str()));
    11511196            }
    11521197
    11531198            if (FAILED(rc)) throw rc;
    11541199
    1155             LogRelFunc(("Moving %s has been finished\n", strTargetImageName.c_str()));
     1200            Log2(("Moving %s has been finished\n", strTargetImageName.c_str()));
    11561201
    11571202            ++itMedium;
     
    11621207    catch(HRESULT hrc)
    11631208    {
    1164         LogRelFunc(("\nException during moving the disk %s\n", strLocation.c_str()));
     1209        Log2(("\nException during moving the disk %s\n", strLocation.c_str()));
    11651210        rc = hrc;
    11661211        machineLock.release();
     
    11681213    catch (...)
    11691214    {
    1170         LogRelFunc(("\nException during moving the disk %s\n", strLocation.c_str()));
     1215        Log2(("\nException during moving the disk %s\n", strLocation.c_str()));
    11711216        rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS);
    11721217        machineLock.release();
     
    11761221    {
    11771222        Utf8StrFmt errorDesc("Exception during moving the disk %s\n", strLocation.c_str());
    1178         errorsList.push_back(ErrorInfoItem(rc, errorDesc.c_str()));
     1223        m_errorsList.push_back(ErrorInfoItem(rc, errorDesc.c_str()));
    11791224    }
    11801225
     
    12281273{
    12291274    RTDIR hDir;
    1230     HRESULT rc = S_OK;
     1275    HRESULT hrc = S_OK;
    12311276    int vrc = RTDirOpen(&hDir, strRootFolder.c_str());
    12321277    if (RT_SUCCESS(vrc))
     
    12471292                Utf8Str strNextFolder(strRootFolder);
    12481293                strNextFolder.append(RTPATH_DELIMITER).append(DirEntry.szName);
    1249                 rc = getFilesList(strNextFolder, filesList);
    1250                 if (FAILED(rc))
     1294                hrc = getFilesList(strNextFolder, filesList);
     1295                if (FAILED(hrc))
    12511296                    break;
    12521297            }
     
    12591304    {
    12601305        Utf8StrFmt errorDesc("Folder '%s' doesn't exist (%Rrc)", strRootFolder.c_str(), vrc);
    1261         errorsList.push_back(ErrorInfoItem(VERR_FILE_NOT_FOUND, errorDesc.c_str()));
    1262 
    1263         rc = m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
     1306        m_errorsList.push_back(ErrorInfoItem(VERR_FILE_NOT_FOUND, errorDesc.c_str()));
     1307
     1308        hrc = m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
    12641309    }
    12651310    else
    12661311    {
    12671312        Utf8StrFmt errorDesc("Could not open folder '%s' (%Rrc)", strRootFolder.c_str(), vrc);
    1268         errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    1269 
    1270 /** @todo r=bird: document this throwing business, please!  Error handling is
    1271  *        a bit fishy here.  See also */
    1272         throw m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
    1273     }
    1274 
    1275     return rc;
     1313        m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     1314
     1315        hrc = m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
     1316    }
     1317
     1318    return hrc;
    12761319}
    12771320
    12781321HRESULT MachineMoveVM::deleteFiles(const RTCList<Utf8Str>& listOfFiles)
    12791322{
    1280     HRESULT rc = S_OK;
     1323    HRESULT hrc = S_OK;
    12811324    /* Delete all created files. */
    12821325    try
     
    12841327        for (size_t i = 0; i < listOfFiles.size(); ++i)
    12851328        {
    1286             LogRelFunc(("Deleting file %s ...\n", listOfFiles.at(i).c_str()));
    1287             rc = m_pProgress->SetNextOperation(BstrFmt("Deleting file %s...", listOfFiles.at(i).c_str()).raw(), 1);
    1288             if (FAILED(rc)) throw rc;
     1329            Log2(("Deleting file %s ...\n", listOfFiles.at(i).c_str()));
     1330            hrc = m_pProgress->SetNextOperation(BstrFmt("Deleting file %s...", listOfFiles.at(i).c_str()).raw(), 1);
     1331            if (FAILED(hrc)) throw hrc;
    12891332
    12901333            int vrc = RTFileDelete(listOfFiles.at(i).c_str());
    12911334            if (RT_FAILURE(vrc))
    12921335            {
    1293                 Utf8StrFmt errorDesc("Could not delete file '%s' (%Rrc)", listOfFiles.at(i).c_str(), rc);
    1294                 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    1295 
    1296                 rc = m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
     1336                Utf8StrFmt errorDesc("Could not delete file '%s' (%Rrc)", listOfFiles.at(i).c_str(), hrc);
     1337                m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     1338
     1339                throw m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
    12971340            }
    12981341            else
    1299                 LogRelFunc(("File %s has been deleted\n", listOfFiles.at(i).c_str()));
    1300         }
    1301     }
    1302     catch(HRESULT hrc)
    1303     {
    1304         rc = hrc;
     1342                Log2(("File %s has been deleted\n", listOfFiles.at(i).c_str()));
     1343        }
     1344    }
     1345    catch(HRESULT aRc)
     1346    {
     1347        hrc = aRc;
    13051348    }
    13061349    catch (...)
    13071350    {
    1308         rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS);
    1309     }
    1310 
    1311     return rc;
     1351        hrc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS);
     1352    }
     1353
     1354    return hrc;
    13121355}
    13131356
    13141357HRESULT MachineMoveVM::getFolderSize(const Utf8Str& strRootFolder, uint64_t& size)
    13151358{
    1316     HRESULT rc = S_OK;
     1359    HRESULT hrc = S_OK;
    13171360    int vrc = 0;
    13181361    uint64_t totalFolderSize = 0;
     
    13221365    if (ex == true)
    13231366    {
    1324         rc = getFilesList(strRootFolder, filesList);
    1325         if (SUCCEEDED(rc))
     1367        hrc = getFilesList(strRootFolder, filesList);
     1368        if (SUCCEEDED(hrc))
    13261369        {
    13271370            cit_t it = filesList.m_list.begin();
     
    13391382                {
    13401383                    Utf8StrFmt errorDesc("Could not get the size of file '%s' (%Rrc)", fullPath.c_str(), vrc);
    1341                     errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    1342 
    1343                     throw m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
     1384                    m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     1385
     1386                    return m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
    13441387                }
    13451388                ++it;
     
    13481391            size = totalFolderSize;
    13491392        }
    1350         else
    1351         {
    1352 /** @todo r=bird: This only happens if RTDirOpen fails.  So, I'm not sure
    1353  * what you're going for here... See not about throwing in getFilesList(). */
    1354             Utf8StrFmt errorDesc("Could not calculate the size of folder '%s'", strRootFolder.c_str());
    1355             errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    1356 
    1357             m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str()));
    1358         }
    13591393    }
    13601394    else
    13611395        size = 0;
    13621396
    1363     return rc;
     1397    return hrc;
    13641398}
    13651399
     
    14331467            Bstr bstrLocation;
    14341468            rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
    1435             if (FAILED(rc)) throw rc;
     1469            if (FAILED(rc)) return rc;
    14361470
    14371471            /* Cast to ComObjPtr<Medium> */
     
    14391473
    14401474            /*Check for "read-only" medium in terms that VBox can't create this one */
    1441             bool fPass = isMediumTypeSupportedForMoving(pMedium);
    1442             if(!fPass)
    1443             {
    1444                 LogRelFunc(("Skipping file %s because of this medium type hasn't been supported for moving.\n",
    1445                          Utf8Str(bstrLocation.raw()).c_str()));
    1446                 continue;
     1475            try
     1476            {
     1477                bool fPass = isMediumTypeSupportedForMoving(pMedium);
     1478                if(!fPass)
     1479                {
     1480                    Log2(("Skipping file %s because of this medium type hasn't been supported for moving.\n",
     1481                          Utf8Str(bstrLocation.raw()).c_str()));
     1482                    continue;
     1483                }
     1484            } catch (HRESULT aRc)
     1485            {
     1486                return aRc;
    14471487            }
    14481488
     
    14651505                MediumType_T mediumType;//immutable, shared, passthrough
    14661506                rc = pMedium->COMGETTER(Type)(&mediumType);
    1467                 if (FAILED(rc)) throw rc;
     1507                if (FAILED(rc)) return rc;
    14681508
    14691509                rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
    1470                 if (FAILED(rc)) throw rc;
     1510                if (FAILED(rc)) return rc;
    14711511
    14721512                MEDIUMTASKMOVE mt;// = {false, "basename", NULL, 0, 0};
    14731513                mt.strBaseName = bstrLocation;
    1474                 Utf8Str strFolder = vmFolders[VBox_SnapshotFolder];
     1514                Utf8Str strFolder = m_vmFolders[VBox_SnapshotFolder];
    14751515                if (strFolder.isNotEmpty() && mt.strBaseName.contains(strFolder))
    14761516                {
     
    14901530            }
    14911531
    1492             llMedias.append(mtc);
     1532            m_llMedias.append(mtc);
    14931533        }
    14941534        /* Add the save state files of this machine if there is one. */
     
    15001540     * that in the previous loop, cause there we go from child -> parent and
    15011541     * didn't know how many are between. */
    1502     for (size_t i = 0; i < llMedias.size(); ++i)
     1542    for (size_t i = 0; i < m_llMedias.size(); ++i)
    15031543    {
    15041544        uint32_t uIdx = 0;
    1505         MEDIUMTASKCHAINMOVE &mtc = llMedias.at(i);
     1545        MEDIUMTASKCHAINMOVE &mtc = m_llMedias.at(i);
    15061546        for (size_t a = mtc.chain.size(); a > 0; --a)
    15071547            mtc.chain[a - 1].uIdx = uIdx++;
     
    15281568        {
    15291569            Utf8StrFmt errorDesc("Could not get file size of '%s' (%Rrc)", sst.strSaveStateFile.c_str(), vrc);
    1530             errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     1570            m_errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
    15311571
    15321572            return m_pMachine->setErrorBoth(VBOX_E_IPRT_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
     
    15351575         * be read and written */
    15361576        sst.uWeight = (ULONG)(2 * (cbSize + _1M - 1) / _1M);
    1537         llSaveStateFiles.append(sst);
     1577        m_llSaveStateFiles.append(sst);
    15381578    }
    15391579    return S_OK;
     
    16051645    if (formatName.compare("VHDX", Utf8Str::CaseInsensitive) == 0)
    16061646    {
    1607         LogRelFunc(("Skipping medium %s. VHDX format is supported in \"read-only\" mode only. \n",
    1608                     Utf8Str(bstrLocation.raw()).c_str()));
     1647        Log2(("Skipping medium %s. VHDX format is supported in \"read-only\" mode only. \n",
     1648              Utf8Str(bstrLocation.raw()).c_str()));
    16091649        fSupported = false;
    16101650    }
     
    16171657        if (!fSupported)
    16181658        {
    1619             LogRelFunc(("Skipping medium %s because it's not a real file on the disk.\n",
    1620                         Utf8Str(bstrLocation.raw()).c_str()));
     1659            Log2(("Skipping medium %s because it's not a real file on the disk.\n",
     1660                  Utf8Str(bstrLocation.raw()).c_str()));
    16211661        }
    16221662    }
     
    16311671        if (fIso == false)
    16321672        {
    1633             LogRelFunc(("Skipping file %s. Only ISO images are supported for now.\n",
    1634                          Utf8Str(bstrLocation.raw()).c_str()));
     1673            Log2(("Skipping file %s. Only ISO images are supported for now.\n",
     1674                  Utf8Str(bstrLocation.raw()).c_str()));
    16351675            fSupported = false;
    16361676        }
Note: See TracChangeset for help on using the changeset viewer.

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