1 | /* $Id: MachineImplMoveVM.h 71053 2018-02-19 13:35:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Definition of MachineMoveVM
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2017 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 |
|
---|
21 | #include "MachineImpl.h"
|
---|
22 | #include "ProgressImpl.h"
|
---|
23 | #include "ThreadTask.h"
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 |
|
---|
27 | enum VBoxFolder_t
|
---|
28 | {
|
---|
29 | VBox_UnknownFolderType = 0,
|
---|
30 | VBox_OutsideVMfolder,
|
---|
31 | VBox_SettingFolder,
|
---|
32 | VBox_LogFolder,
|
---|
33 | VBox_StateFolder,
|
---|
34 | VBox_SnapshotFolder
|
---|
35 | };
|
---|
36 |
|
---|
37 | typedef struct
|
---|
38 | {
|
---|
39 | Utf8Str strBaseName;
|
---|
40 | ComPtr<IMedium> pMedium;
|
---|
41 | uint32_t uIdx;
|
---|
42 | ULONG uWeight;
|
---|
43 | bool fSnapshot;
|
---|
44 | } MEDIUMTASK;
|
---|
45 |
|
---|
46 | typedef struct
|
---|
47 | {
|
---|
48 | RTCList<MEDIUMTASK> chain;
|
---|
49 | DeviceType_T devType;
|
---|
50 | bool fCreateDiffs;
|
---|
51 | bool fAttachLinked;
|
---|
52 | } MEDIUMTASKCHAIN;
|
---|
53 |
|
---|
54 | typedef struct
|
---|
55 | {
|
---|
56 | Guid snapshotUuid;
|
---|
57 | Utf8Str strSaveStateFile;
|
---|
58 | ULONG uWeight;
|
---|
59 | } SAVESTATETASK;
|
---|
60 |
|
---|
61 | struct fileList_t;
|
---|
62 |
|
---|
63 | class MachineMoveVM : public ThreadTask
|
---|
64 | {
|
---|
65 | public:
|
---|
66 |
|
---|
67 | MachineMoveVM(ComObjPtr<Machine> aMachine,
|
---|
68 | const com::Utf8Str &aTargetPath,
|
---|
69 | const com::Utf8Str &aType,
|
---|
70 | ComObjPtr<Progress> &aProgress)
|
---|
71 | : ThreadTask("TaskMoveVM"),
|
---|
72 | m_pMachine(aMachine),
|
---|
73 | m_pProgress(aProgress),
|
---|
74 | m_targetPath(aTargetPath),
|
---|
75 | m_type(aType),
|
---|
76 | result(S_OK)
|
---|
77 | {
|
---|
78 | }
|
---|
79 |
|
---|
80 | virtual ~MachineMoveVM()
|
---|
81 | {
|
---|
82 | }
|
---|
83 |
|
---|
84 | HRESULT init();
|
---|
85 | static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
|
---|
86 | static DECLCALLBACK(int) copyFileProgress(unsigned uPercentage, void *pvUser);
|
---|
87 | static void i_MoveVMThreadTask(MachineMoveVM* task);
|
---|
88 |
|
---|
89 | RTCList<MEDIUMTASKCHAIN> llMedias;
|
---|
90 | RTCList<SAVESTATETASK> llSaveStateFiles;
|
---|
91 | std::map<Utf8Str, MEDIUMTASK> finalMediumsMap;
|
---|
92 | std::map<Utf8Str, SAVESTATETASK> finalSaveStateFilesMap;
|
---|
93 | std::map<VBoxFolder_t, Utf8Str> vmFolders;
|
---|
94 |
|
---|
95 | ComObjPtr<Machine> m_pMachine;
|
---|
96 | ComObjPtr<Progress> m_pProgress;
|
---|
97 | ComObjPtr<Progress> m_pRollBackProgress;
|
---|
98 | ComPtr<ISession> m_pSession;
|
---|
99 | ComPtr<IMachine> m_pSessionMachine;
|
---|
100 | Utf8Str m_targetPath;
|
---|
101 | Utf8Str m_type;
|
---|
102 | HRESULT result;
|
---|
103 |
|
---|
104 | void handler()
|
---|
105 | {
|
---|
106 | i_MoveVMThreadTask(this);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /* MachineCloneVM::start helper: */
|
---|
110 | HRESULT createMachineList(const ComPtr<ISnapshot> &pSnapshot, std::vector< ComObjPtr<Machine> > &aMachineList) const;
|
---|
111 | inline HRESULT queryBaseName(const ComPtr<IMedium> &pMedium, Utf8Str &strBaseName) const;
|
---|
112 | HRESULT queryMediasForAllStates(const std::vector<ComObjPtr<Machine> > &aMachineList);
|
---|
113 | void updateProgressStats(MEDIUMTASKCHAIN &mtc, ULONG &uCount, ULONG &uTotalWeight) const;
|
---|
114 | HRESULT addSaveState(const ComObjPtr<Machine> &machine);
|
---|
115 | void printStateFile(settings::SnapshotsList &snl);
|
---|
116 | HRESULT getFilesList(const Utf8Str& strRootFolder, fileList_t &filesList);
|
---|
117 | HRESULT getFolderSize(const Utf8Str& strRootFolder, uint64_t& size);
|
---|
118 | HRESULT deleteFiles(const RTCList<Utf8Str>& listOfFiles);
|
---|
119 | HRESULT updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASK>& listOfFiles,
|
---|
120 | const Utf8Str& sourcePath, const Utf8Str& targetPath);
|
---|
121 | HRESULT moveAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks, const Utf8Str* strTargetFolder = NULL);
|
---|
122 | HRESULT restoreAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks);
|
---|
123 | bool isMediumTypeSupportedForMoving(const ComPtr<IMedium> &pMedium);
|
---|
124 | };
|
---|
125 |
|
---|
126 | #endif // ____H_MACHINEIMPLMOVEVM
|
---|
127 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|
128 |
|
---|