Changeset 81393 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Oct 21, 2019 8:33:26 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 134106
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp
r81362 r81393 31 31 32 32 /* 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< 33 std::vector<ComObjPtr<Machine> > machineList; 34 34 35 35 typedef std::multimap<Utf8Str, Utf8Str> list_t; … … 40 40 struct fileList_t 41 41 { 42 HRESULT add(const Utf8Str & folder, const Utf8Str&file)42 HRESULT add(const Utf8Str &folder, const Utf8Str &file) 43 43 { 44 44 HRESULT rc = S_OK; … … 47 47 } 48 48 49 HRESULT add(const Utf8Str &fullPath)49 HRESULT add(const Utf8Str &fullPath) 50 50 { 51 51 HRESULT rc = S_OK; … … 58 58 } 59 59 60 HRESULT removeFileFromList(const Utf8Str &fullPath)60 HRESULT removeFileFromList(const Utf8Str &fullPath) 61 61 { 62 62 HRESULT rc = S_OK; … … 81 81 } 82 82 83 HRESULT removeFileFromList(const Utf8Str & path, const Utf8Str&fileName)83 HRESULT removeFileFromList(const Utf8Str &path, const Utf8Str &fileName) 84 84 { 85 85 HRESULT rc = S_OK; … … 99 99 } 100 100 101 HRESULT removeFolderFromList(const Utf8Str &path)101 HRESULT removeFolderFromList(const Utf8Str &path) 102 102 { 103 103 HRESULT rc = S_OK; … … 106 106 } 107 107 108 rangeRes_t getFilesInRange(const Utf8Str &path)108 rangeRes_t getFilesInRange(const Utf8Str &path) 109 109 { 110 110 rangeRes_t res; … … 113 113 } 114 114 115 std::list<Utf8Str> getFilesInList(const Utf8Str &path)115 std::list<Utf8Str> getFilesInList(const Utf8Str &path) 116 116 { 117 117 std::list<Utf8Str> list_; … … 128 128 129 129 130 #ifdef DEBUG131 void MachineMoveVM::ErrorInfoItem::logItem() const132 {133 Log2(("(The error code is %Rrc): %s\n", m_code, m_description.c_str()));134 }135 #endif136 137 130 HRESULT MachineMoveVM::init() 138 131 { … … 149 142 * for doing this. We need this often and code like this doesn't 150 143 * need to be repeated and re-optimized in each instance... */ 151 char *path = new char [len];144 char *path = new char [len]; 152 145 RTStrCopy(path, len, m_targetPath.c_str()); 153 146 RTPathEnsureTrailingSeparator(path, len); … … 201 194 vrc = RTDirClose(hDir); AssertRC(vrc); 202 195 203 Log2(("blocks: total %RTfoff, free %RTfoff 196 Log2(("blocks: total %RTfoff, free %RTfoff\n", cbTotal, cbFree)); 204 197 Log2(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G)); 205 198 Log2(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G)); … … 210 203 return m_pMachine->setErrorVrc(vrc, "RTFsQueryProperties(%s): %Rrc", strTargetFolder.c_str(), vrc); 211 204 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)); 219 207 220 208 /* Get the original VM path */ … … 493 481 { 494 482 hrc = m_pProgress->init(m_pMachine->i_getVirtualBox(), 495 static_cast<IMachine *>(m_pMachine) /* aInitiator */,483 static_cast<IMachine *>(m_pMachine) /* aInitiator */, 496 484 Utf8Str(m_pMachine->tr("Moving Machine")), 497 485 true /* fCancellable */, … … 536 524 DECLCALLBACK(int) MachineMoveVM::updateProgress(unsigned uPercent, void *pvUser) 537 525 { 538 MachineMoveVM * pTask = *(MachineMoveVM**)pvUser;526 MachineMoveVM *pTask = *(MachineMoveVM **)pvUser; 539 527 540 528 if ( pTask … … 553 541 DECLCALLBACK(int) MachineMoveVM::copyFileProgress(unsigned uPercentage, void *pvUser) 554 542 { 555 ComObjPtr<Progress> pProgress = *static_cast< ComObjPtr<Progress>*>(pvUser);543 ComObjPtr<Progress> pProgress = *static_cast<ComObjPtr<Progress> *>(pvUser); 556 544 557 545 BOOL fCanceled = false; … … 568 556 569 557 /* static */ 570 void MachineMoveVM::i_MoveVMThreadTask(MachineMoveVM *task)558 void MachineMoveVM::i_MoveVMThreadTask(MachineMoveVM *task) 571 559 { 572 560 LogFlowFuncEnter(); 573 561 HRESULT hrc = S_OK; 574 562 575 MachineMoveVM *taskMoveVM = task;563 MachineMoveVM *taskMoveVM = task; 576 564 ComObjPtr<Machine> &machine = taskMoveVM->m_pMachine; 577 565 … … 637 625 { 638 626 /* Move all disks */ 639 hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap, &strTargetFolder);627 hrc = taskMoveVM->moveAllDisks(taskMoveVM->m_finalMediumsMap, strTargetFolder); 640 628 if (FAILED(hrc)) 641 629 throw hrc; … … 650 638 /* When the current snapshot folder is absolute we reset it to the 651 639 * 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 = ""; 655 643 656 644 /* The absolute name of the snapshot folder. */ 657 645 strTrgSnapshotFolder = Utf8StrFmt("%s%c%s", strTargetFolder.c_str(), RTPATH_DELIMITER, 658 (*machineConfFile).machineUserData.strSnapshotFolder.c_str());646 machineConfFile->machineUserData.strSnapshotFolder.c_str()); 659 647 660 648 /* Check if a snapshot folder is necessary and if so doesn't already … … 709 697 Log2(("Update state file path\n")); 710 698 hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap, 711 taskMoveVM->m_vmFolders[VBox_SettingFolder],712 strTargetFolder);699 taskMoveVM->m_vmFolders[VBox_SettingFolder], 700 strTargetFolder); 713 701 if (FAILED(hrc)) 714 702 throw hrc; … … 721 709 */ 722 710 { 723 Log2(("Copy Machine settings file 711 Log2(("Copy Machine settings file\n")); 724 712 725 713 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(), 727 715 1); 728 716 if (FAILED(hrc)) … … 803 791 taskMoveVM->getFilesList(taskMoveVM->m_vmFolders[VBox_LogFolder], filesList); 804 792 cit_t it = filesList.m_list.begin(); 805 while (it != filesList.m_list.end())793 while (it != filesList.m_list.end()) 806 794 { 807 795 Utf8Str strFullSourceFilePath = it->first.c_str(); … … 945 933 if (FAILED(hrc)) 946 934 { 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())); 949 937 throw hrc; 950 938 } … … 955 943 if (FAILED(hrc)) 956 944 { 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")); 958 946 throw hrc; 959 947 } … … 963 951 if (RT_FAILURE(vrc)) 964 952 { 965 Log2(("Rollback scenario: can't delete new destination folder. "));953 Log2(("Rollback scenario: can't delete new destination folder.\n")); 966 954 throw machine->setErrorVrc(vrc, "Rollback scenario: can't delete new destination folder."); 967 955 } … … 974 962 if (FAILED(hrc)) 975 963 { 976 Log2(("Rollback scenario: can't save machine settings. "));964 Log2(("Rollback scenario: can't save machine settings.\n")); 977 965 throw hrc; 978 966 } … … 1004 992 if (FAILED(hrc)) 1005 993 { 1006 Log2(("Rollback scenario: can't save global settings. "));994 Log2(("Rollback scenario: can't save global settings.\n")); 1007 995 throw hrc; 1008 996 } … … 1051 1039 } 1052 1040 1053 HRESULT MachineMoveVM::moveAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE> &listOfDisks,1054 const Utf8Str *strTargetFolder)1041 HRESULT MachineMoveVM::moveAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE> &listOfDisks, 1042 const Utf8Str &strTargetFolder) 1055 1043 { 1056 1044 HRESULT rc = S_OK; … … 1060 1048 AutoWriteLock machineLock(machine COMMA_LOCKVAL_SRC_POS); 1061 1049 1062 try{ 1050 try 1051 { 1063 1052 std::map<Utf8Str, MEDIUMTASKMOVE>::const_iterator itMedium = listOfDisks.begin(); 1064 while (itMedium != listOfDisks.end())1053 while (itMedium != listOfDisks.end()) 1065 1054 { 1066 1055 const MEDIUMTASKMOVE &mt = itMedium->second; … … 1073 1062 if (FAILED(rc)) throw rc; 1074 1063 1075 if (strTargetFolder != NULL && !strTargetFolder->isEmpty())1076 { 1077 strTargetImageName = *strTargetFolder;1064 if (strTargetFolder.isNotEmpty()) 1065 { 1066 strTargetImageName = strTargetFolder; 1078 1067 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 1079 1068 if (FAILED(rc)) throw rc; … … 1143 1132 catch(HRESULT hrc) 1144 1133 { 1145 Log2((" \nException during moving the disk %s\n", strLocation.c_str()));1134 Log2(("Exception during moving the disk %s\n", strLocation.c_str())); 1146 1135 rc = hrc; 1147 1136 machineLock.release(); … … 1149 1138 catch (...) 1150 1139 { 1151 Log2((" \nException during moving the disk %s\n", strLocation.c_str()));1140 Log2(("Exception during moving the disk %s\n", strLocation.c_str())); 1152 1141 rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS); 1153 1142 machineLock.release(); … … 1157 1146 } 1158 1147 1159 HRESULT MachineMoveVM::updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASKMOVE> &listOfFiles,1160 const Utf8Str & sourcePath, const Utf8Str&targetPath)1148 HRESULT MachineMoveVM::updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASKMOVE> &listOfFiles, 1149 const Utf8Str &sourcePath, const Utf8Str &targetPath) 1161 1150 { 1162 1151 HRESULT rc = S_OK; … … 1197 1186 } 1198 1187 1199 HRESULT MachineMoveVM::getFilesList(const Utf8Str &strRootFolder, fileList_t &filesList)1188 HRESULT MachineMoveVM::getFilesList(const Utf8Str &strRootFolder, fileList_t &filesList) 1200 1189 { 1201 1190 RTDIR hDir; … … 1256 1245 } 1257 1246 1258 HRESULT MachineMoveVM::deleteFiles(const RTCList<Utf8Str> &listOfFiles)1247 HRESULT MachineMoveVM::deleteFiles(const RTCList<Utf8Str> &listOfFiles) 1259 1248 { 1260 1249 HRESULT hrc = S_OK; … … 1279 1268 } 1280 1269 1281 HRESULT MachineMoveVM::getFolderSize(const Utf8Str & strRootFolder, uint64_t&size)1270 HRESULT MachineMoveVM::getFolderSize(const Utf8Str &strRootFolder, uint64_t &size) 1282 1271 { 1283 1272 HRESULT hrc = S_OK; … … 1293 1282 { 1294 1283 cit_t it = filesList.m_list.begin(); 1295 while (it != filesList.m_list.end())1284 while (it != filesList.m_list.end()) 1296 1285 { 1297 1286 uint64_t cbFile = 0; … … 1334 1323 1335 1324 HRESULT MachineMoveVM::createMachineList(const ComPtr<ISnapshot> &pSnapshot, 1336 std::vector< 1325 std::vector<ComObjPtr<Machine> > &aMachineList) const 1337 1326 { 1338 1327 Bstr name; … … 1394 1383 ComObjPtr<Medium> pObjMedium = (Medium *)(IMedium *)pMedium; 1395 1384 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 */ 1397 1386 rc = isMediumTypeSupportedForMoving(pMedium); 1398 1387 if (FAILED(rc)) … … 1452 1441 m_llMedias.append(mtc); 1453 1442 } 1443 1454 1444 /* Add the save state files of this machine if there is one. */ 1455 1445 rc = addSaveState(machine); 1456 1446 if (FAILED(rc)) return rc; 1457 1458 } 1447 } 1448 1459 1449 /* Build up the index list of the image chain. Unfortunately we can't do 1460 1450 * that in the previous loop, cause there we go from child -> parent and … … 1541 1531 return rc; 1542 1532 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" */ 1544 1534 Bstr bstrFormatName; 1545 1535 rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); … … 1550 1540 if (formatName.compare("VHDX", Utf8Str::CaseInsensitive) == 0) 1551 1541 { 1552 Log2(("Skipping medium %ls. VHDX format is supported in \"read-only\" mode only. 1542 Log2(("Skipping medium %ls. VHDX format is supported in \"read-only\" mode only.\n", bstrLocation.raw())); 1553 1543 return S_FALSE; 1554 1544 }
Note:
See TracChangeset
for help on using the changeset viewer.