1 | /* $Id: MachineImplMoveVM.h 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Definition of MachineMoveVM
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ____H_MACHINEIMPLMOVEVM
|
---|
19 | #define ____H_MACHINEIMPLMOVEVM
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include "MachineImpl.h"
|
---|
25 | #include "ProgressImpl.h"
|
---|
26 | #include "ThreadTask.h"
|
---|
27 |
|
---|
28 | /////////////////////////////////////////////////////////////////////////////
|
---|
29 |
|
---|
30 | enum VBoxFolder_t
|
---|
31 | {
|
---|
32 | VBox_UnknownFolderType = 0,
|
---|
33 | VBox_OutsideVMfolder,
|
---|
34 | VBox_SettingFolder,
|
---|
35 | VBox_LogFolder,
|
---|
36 | VBox_StateFolder,
|
---|
37 | VBox_SnapshotFolder
|
---|
38 | };
|
---|
39 |
|
---|
40 | typedef struct
|
---|
41 | {
|
---|
42 | bool fSnapshot;
|
---|
43 | Utf8Str strBaseName;
|
---|
44 | ComPtr<IMedium> pMedium;
|
---|
45 | uint32_t uIdx;
|
---|
46 | ULONG uWeight;
|
---|
47 | } MEDIUMTASKMOVE;
|
---|
48 |
|
---|
49 | typedef struct
|
---|
50 | {
|
---|
51 | RTCList<MEDIUMTASKMOVE> chain;
|
---|
52 | DeviceType_T devType;
|
---|
53 | bool fCreateDiffs;
|
---|
54 | bool fAttachLinked;
|
---|
55 | } MEDIUMTASKCHAINMOVE;
|
---|
56 |
|
---|
57 | typedef struct
|
---|
58 | {
|
---|
59 | Guid snapshotUuid;
|
---|
60 | Utf8Str strSaveStateFile;
|
---|
61 | ULONG uWeight;
|
---|
62 | } SAVESTATETASKMOVE;
|
---|
63 |
|
---|
64 | struct fileList_t;
|
---|
65 |
|
---|
66 | class MachineMoveVM : public ThreadTask
|
---|
67 | {
|
---|
68 | struct ErrorInfoItem
|
---|
69 | {
|
---|
70 | ErrorInfoItem(HRESULT aCode, const char* aDescription):
|
---|
71 | m_code(aCode),
|
---|
72 | m_description(aDescription == NULL ? "There is no description" : aDescription)
|
---|
73 | {
|
---|
74 | }
|
---|
75 |
|
---|
76 | void printItem(bool fLog) const;
|
---|
77 |
|
---|
78 | HRESULT m_code;
|
---|
79 | Utf8Str m_description;
|
---|
80 | };
|
---|
81 |
|
---|
82 | RTCList<MEDIUMTASKCHAINMOVE> llMedias;
|
---|
83 | RTCList<SAVESTATETASKMOVE> llSaveStateFiles;
|
---|
84 | std::map<Utf8Str, MEDIUMTASKMOVE> finalMediumsMap;
|
---|
85 | std::map<Utf8Str, SAVESTATETASKMOVE> finalSaveStateFilesMap;
|
---|
86 | std::map<VBoxFolder_t, Utf8Str> vmFolders;
|
---|
87 | std::list<ErrorInfoItem> errorsList;
|
---|
88 |
|
---|
89 | ComObjPtr<Machine> m_pMachine;
|
---|
90 | ComObjPtr<Progress> m_pProgress;
|
---|
91 | ComObjPtr<Progress> m_pRollBackProgress;
|
---|
92 | ComPtr<ISession> m_pSession;
|
---|
93 | ComPtr<IMachine> m_pSessionMachine;
|
---|
94 | Utf8Str m_targetPath;
|
---|
95 | Utf8Str m_type;
|
---|
96 | HRESULT result;
|
---|
97 |
|
---|
98 | public:
|
---|
99 | MachineMoveVM(ComObjPtr<Machine> aMachine,
|
---|
100 | const com::Utf8Str &aTargetPath,
|
---|
101 | const com::Utf8Str &aType,
|
---|
102 | ComObjPtr<Progress> &aProgress)
|
---|
103 | : ThreadTask("TaskMoveVM"),
|
---|
104 | m_pMachine(aMachine),
|
---|
105 | m_pProgress(aProgress),
|
---|
106 | m_targetPath(aTargetPath),
|
---|
107 | m_type (aType.isEmpty() == true ? "basic" : aType),
|
---|
108 | result(S_OK)
|
---|
109 | {
|
---|
110 | }
|
---|
111 |
|
---|
112 | virtual ~MachineMoveVM()
|
---|
113 | {
|
---|
114 | }
|
---|
115 |
|
---|
116 | HRESULT init();
|
---|
117 | static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
|
---|
118 | static DECLCALLBACK(int) copyFileProgress(unsigned uPercentage, void *pvUser);
|
---|
119 | static void i_MoveVMThreadTask(MachineMoveVM* task);
|
---|
120 |
|
---|
121 | void handler()
|
---|
122 | {
|
---|
123 | i_MoveVMThreadTask(this);
|
---|
124 | }
|
---|
125 |
|
---|
126 | /* MachineCloneVM::start helper: */
|
---|
127 | HRESULT createMachineList(const ComPtr<ISnapshot> &pSnapshot, std::vector< ComObjPtr<Machine> > &aMachineList) const;
|
---|
128 | inline HRESULT queryBaseName(const ComPtr<IMedium> &pMedium, Utf8Str &strBaseName) const;
|
---|
129 | HRESULT queryMediasForAllStates(const std::vector<ComObjPtr<Machine> > &aMachineList);
|
---|
130 | void updateProgressStats(MEDIUMTASKCHAINMOVE &mtc, ULONG &uCount, ULONG &uTotalWeight) const;
|
---|
131 | HRESULT addSaveState(const ComObjPtr<Machine> &machine);
|
---|
132 | void printStateFile(settings::SnapshotsList &snl);
|
---|
133 | HRESULT getFilesList(const Utf8Str& strRootFolder, fileList_t &filesList);
|
---|
134 | HRESULT getFolderSize(const Utf8Str& strRootFolder, uint64_t& size);
|
---|
135 | HRESULT deleteFiles(const RTCList<Utf8Str>& listOfFiles);
|
---|
136 | HRESULT updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASKMOVE>& listOfFiles,
|
---|
137 | const Utf8Str& sourcePath, const Utf8Str& targetPath);
|
---|
138 | HRESULT moveAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE>& listOfDisks, const Utf8Str* strTargetFolder = NULL);
|
---|
139 | HRESULT restoreAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE>& listOfDisks);
|
---|
140 | bool isMediumTypeSupportedForMoving(const ComPtr<IMedium> &pMedium);
|
---|
141 | };
|
---|
142 |
|
---|
143 | #endif // ____H_MACHINEIMPLMOVEVM
|
---|
144 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|
145 |
|
---|