1 | /* $Id: MachineImplMoveVM.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Definition of MachineMoveVM
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_MachineImplMoveVM_h
|
---|
29 | #define MAIN_INCLUDED_MachineImplMoveVM_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "MachineImpl.h"
|
---|
35 | #include "ProgressImpl.h"
|
---|
36 | #include "ThreadTask.h"
|
---|
37 |
|
---|
38 | /////////////////////////////////////////////////////////////////////////////
|
---|
39 |
|
---|
40 | enum VBoxFolder_t
|
---|
41 | {
|
---|
42 | VBox_UnknownFolderType = 0,
|
---|
43 | VBox_OutsideVMfolder,
|
---|
44 | VBox_SettingFolder,
|
---|
45 | VBox_LogFolder,
|
---|
46 | VBox_StateFolder,
|
---|
47 | VBox_SnapshotFolder
|
---|
48 | };
|
---|
49 |
|
---|
50 | typedef struct
|
---|
51 | {
|
---|
52 | bool fSnapshot;
|
---|
53 | Utf8Str strBaseName;
|
---|
54 | ComPtr<IMedium> pMedium;
|
---|
55 | uint32_t uIdx;
|
---|
56 | ULONG uWeight;
|
---|
57 | } MEDIUMTASKMOVE;
|
---|
58 |
|
---|
59 | typedef struct
|
---|
60 | {
|
---|
61 | RTCList<MEDIUMTASKMOVE> chain;
|
---|
62 | DeviceType_T devType;
|
---|
63 | bool fCreateDiffs;
|
---|
64 | bool fAttachLinked;
|
---|
65 | } MEDIUMTASKCHAINMOVE;
|
---|
66 |
|
---|
67 | typedef struct
|
---|
68 | {
|
---|
69 | Guid snapshotUuid;
|
---|
70 | Utf8Str strFile;
|
---|
71 | ULONG uWeight;
|
---|
72 | } SNAPFILETASKMOVE;
|
---|
73 |
|
---|
74 | struct fileList_t;
|
---|
75 |
|
---|
76 | class MachineMoveVM : public ThreadTask
|
---|
77 | {
|
---|
78 | std::vector<ComObjPtr<Machine> > machineList;
|
---|
79 | RTCList<MEDIUMTASKCHAINMOVE> m_llMedia;
|
---|
80 | RTCList<SNAPFILETASKMOVE> m_llSaveStateFiles;
|
---|
81 | RTCList<SNAPFILETASKMOVE> m_llNVRAMFiles;
|
---|
82 | std::map<Utf8Str, MEDIUMTASKMOVE> m_finalMediaMap;
|
---|
83 | std::map<Utf8Str, SNAPFILETASKMOVE> m_finalSaveStateFilesMap;
|
---|
84 | std::map<Utf8Str, SNAPFILETASKMOVE> m_finalNVRAMFilesMap;
|
---|
85 | std::map<VBoxFolder_t, Utf8Str> m_vmFolders;
|
---|
86 |
|
---|
87 | ComObjPtr<Machine> m_pMachine;
|
---|
88 | ComObjPtr<Progress> m_pProgress;
|
---|
89 | ComObjPtr<Progress> m_pRollBackProgress;
|
---|
90 | Utf8Str m_targetPath;
|
---|
91 | Utf8Str m_type;
|
---|
92 | HRESULT m_result;
|
---|
93 |
|
---|
94 | public:
|
---|
95 | DECLARE_TRANSLATE_METHODS(MachineMoveVM)
|
---|
96 |
|
---|
97 | MachineMoveVM(ComObjPtr<Machine> aMachine,
|
---|
98 | const com::Utf8Str &aTargetPath,
|
---|
99 | const com::Utf8Str &aType,
|
---|
100 | ComObjPtr<Progress> &aProgress)
|
---|
101 | : ThreadTask("TaskMoveVM")
|
---|
102 | , m_pMachine(aMachine)
|
---|
103 | , m_pProgress(aProgress)
|
---|
104 | , m_targetPath(aTargetPath)
|
---|
105 | , m_type(aType.isEmpty() ? "basic" : aType)
|
---|
106 | , m_result(S_OK)
|
---|
107 | {
|
---|
108 | }
|
---|
109 |
|
---|
110 | virtual ~MachineMoveVM()
|
---|
111 | {
|
---|
112 | }
|
---|
113 |
|
---|
114 | HRESULT init();
|
---|
115 | private:
|
---|
116 | static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
|
---|
117 | static DECLCALLBACK(int) copyFileProgress(unsigned uPercentage, void *pvUser);
|
---|
118 | static void i_MoveVMThreadTask(MachineMoveVM *task);
|
---|
119 |
|
---|
120 | public:
|
---|
121 | void handler()
|
---|
122 | {
|
---|
123 | i_MoveVMThreadTask(this);
|
---|
124 | }
|
---|
125 |
|
---|
126 | private:
|
---|
127 | HRESULT createMachineList(const ComPtr<ISnapshot> &pSnapshot);
|
---|
128 | inline HRESULT queryBaseName(const ComPtr<IMedium> &pMedium, Utf8Str &strBaseName) const;
|
---|
129 | HRESULT queryMediaForAllStates();
|
---|
130 | void updateProgressStats(MEDIUMTASKCHAINMOVE &mtc, ULONG &uCount, ULONG &uTotalWeight) const;
|
---|
131 | HRESULT addSaveState(const ComObjPtr<Machine> &machine);
|
---|
132 | HRESULT addNVRAM(const ComObjPtr<Machine> &machine);
|
---|
133 | void printStateFile(settings::SnapshotsList &snl);
|
---|
134 | HRESULT getFilesList(const Utf8Str &strRootFolder, fileList_t &filesList);
|
---|
135 | HRESULT getFolderSize(const Utf8Str &strRootFolder, uint64_t &size);
|
---|
136 | HRESULT deleteFiles(const RTCList<Utf8Str> &listOfFiles);
|
---|
137 | void updatePathsToStateFiles(const Utf8Str &sourcePath, const Utf8Str &targetPath);
|
---|
138 | void updatePathsToNVRAMFiles(const Utf8Str &sourcePath, const Utf8Str &targetPath);
|
---|
139 | HRESULT moveAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE> &listOfDisks, const Utf8Str &strTargetFolder = Utf8Str::Empty);
|
---|
140 | HRESULT restoreAllDisks(const std::map<Utf8Str, MEDIUMTASKMOVE> &listOfDisks);
|
---|
141 | HRESULT isMediumTypeSupportedForMoving(const ComPtr<IMedium> &pMedium);
|
---|
142 | };
|
---|
143 |
|
---|
144 | #endif /* !MAIN_INCLUDED_MachineImplMoveVM_h */
|
---|
145 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|
146 |
|
---|