1 | /** @file
|
---|
2 | * VirtualBox Appliance private data definitions
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ____H_APPLIANCEIMPLPRIVATE
|
---|
18 | #define ____H_APPLIANCEIMPLPRIVATE
|
---|
19 |
|
---|
20 | class VirtualSystemDescription;
|
---|
21 |
|
---|
22 | #include "ovfreader.h"
|
---|
23 | #include <map>
|
---|
24 | #include <iprt/vfs.h>
|
---|
25 |
|
---|
26 | ////////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // Appliance data definition
|
---|
29 | //
|
---|
30 | ////////////////////////////////////////////////////////////////////////////////
|
---|
31 |
|
---|
32 | typedef std::pair<Utf8Str, Utf8Str> STRPAIR;
|
---|
33 |
|
---|
34 | /* Describe a location for the import/export. The location could be a file on a
|
---|
35 | * local hard disk or a remote target based on the supported inet protocols. */
|
---|
36 | struct LocationInfo
|
---|
37 | {
|
---|
38 | LocationInfo()
|
---|
39 | : storageType(VFSType_File) {}
|
---|
40 | VFSType_T storageType; /* Which type of storage should be handled */
|
---|
41 | Utf8Str strPath; /* File path for the import/export */
|
---|
42 | Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
|
---|
43 | Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
|
---|
44 | Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
|
---|
45 | };
|
---|
46 |
|
---|
47 | // opaque private instance data of Appliance class
|
---|
48 | struct Appliance::Data
|
---|
49 | {
|
---|
50 | enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
|
---|
51 | enum digest_T {SHA1, SHA256};
|
---|
52 |
|
---|
53 | Data()
|
---|
54 | : state(ApplianceIdle)
|
---|
55 | , fManifest(true)
|
---|
56 | , fSha256(false)
|
---|
57 | , fExportISOImages(false)
|
---|
58 | , pReader(NULL)
|
---|
59 | , ulWeightForXmlOperation(0)
|
---|
60 | , ulWeightForManifestOperation(0)
|
---|
61 | , ulTotalDisksMB(0)
|
---|
62 | , cDisks(0)
|
---|
63 | {
|
---|
64 | }
|
---|
65 |
|
---|
66 | ~Data()
|
---|
67 | {
|
---|
68 | if (pReader)
|
---|
69 | {
|
---|
70 | delete pReader;
|
---|
71 | pReader = NULL;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | ApplianceState state;
|
---|
76 |
|
---|
77 | LocationInfo locInfo; // location info for the currently processed OVF
|
---|
78 | bool fManifest; // Create a manifest file on export
|
---|
79 | bool fSha256; // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0)
|
---|
80 | Utf8Str strOVFSHADigest;//SHA digest of OVf file. It is stored here after reading OVF file (before import)
|
---|
81 |
|
---|
82 | bool fExportISOImages;// when 1 the ISO images are exported
|
---|
83 | bool fX509;// wether X509 is used or not
|
---|
84 |
|
---|
85 | RTCList<ImportOptions_T> optListImport;
|
---|
86 | RTCList<ExportOptions_T> optListExport;
|
---|
87 |
|
---|
88 | ovf::OVFReader *pReader;
|
---|
89 |
|
---|
90 | std::list< ComObjPtr<VirtualSystemDescription> >
|
---|
91 | virtualSystemDescriptions;
|
---|
92 |
|
---|
93 | std::list<Utf8Str> llWarnings;
|
---|
94 |
|
---|
95 | ULONG ulWeightForXmlOperation;
|
---|
96 | ULONG ulWeightForManifestOperation;
|
---|
97 | ULONG ulTotalDisksMB;
|
---|
98 | ULONG cDisks;
|
---|
99 |
|
---|
100 | std::list<Guid> llGuidsMachinesCreated;
|
---|
101 | };
|
---|
102 |
|
---|
103 | struct Appliance::XMLStack
|
---|
104 | {
|
---|
105 | std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
|
---|
106 | std::map<Utf8Str, bool> mapNetworks;
|
---|
107 | };
|
---|
108 |
|
---|
109 | struct Appliance::TaskOVF
|
---|
110 | {
|
---|
111 | enum TaskType
|
---|
112 | {
|
---|
113 | Read,
|
---|
114 | Import,
|
---|
115 | Write
|
---|
116 | };
|
---|
117 |
|
---|
118 | TaskOVF(Appliance *aThat,
|
---|
119 | TaskType aType,
|
---|
120 | LocationInfo aLocInfo,
|
---|
121 | ComObjPtr<Progress> &aProgress)
|
---|
122 | : pAppliance(aThat),
|
---|
123 | taskType(aType),
|
---|
124 | locInfo(aLocInfo),
|
---|
125 | pProgress(aProgress),
|
---|
126 | enFormat(ovf::OVFVersion_unknown),
|
---|
127 | rc(S_OK)
|
---|
128 | {}
|
---|
129 |
|
---|
130 | static int updateProgress(unsigned uPercent, void *pvUser);
|
---|
131 |
|
---|
132 | HRESULT startThread();
|
---|
133 |
|
---|
134 | Appliance *pAppliance;
|
---|
135 | TaskType taskType;
|
---|
136 | const LocationInfo locInfo;
|
---|
137 | ComObjPtr<Progress> pProgress;
|
---|
138 |
|
---|
139 | ovf::OVFVersion_T enFormat;
|
---|
140 |
|
---|
141 | HRESULT rc;
|
---|
142 | };
|
---|
143 |
|
---|
144 | struct MyHardDiskAttachment
|
---|
145 | {
|
---|
146 | ComPtr<IMachine> pMachine;
|
---|
147 | Bstr controllerType;
|
---|
148 | int32_t lControllerPort; // 0-29 for SATA
|
---|
149 | int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
|
---|
150 | };
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Used by Appliance::importMachineGeneric() to store
|
---|
154 | * input parameters and rollback information.
|
---|
155 | */
|
---|
156 | struct Appliance::ImportStack
|
---|
157 | {
|
---|
158 | // input pointers
|
---|
159 | const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
|
---|
160 | Utf8Str strSourceDir; // directory where source files reside
|
---|
161 | const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
|
---|
162 | ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
|
---|
163 |
|
---|
164 | // input parameters from VirtualSystemDescriptions
|
---|
165 | Utf8Str strNameVBox; // VM name
|
---|
166 | Utf8Str strMachineFolder; // FQ host folder where the VirtualBox machine would be created
|
---|
167 | Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
|
---|
168 | Utf8Str strDescription;
|
---|
169 | uint32_t cCPUs; // CPU count
|
---|
170 | bool fForceHWVirt; // if true, we force enabling hardware virtualization
|
---|
171 | bool fForceIOAPIC; // if true, we force enabling the IOAPIC
|
---|
172 | uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
|
---|
173 | #ifdef VBOX_WITH_USB
|
---|
174 | bool fUSBEnabled;
|
---|
175 | #endif
|
---|
176 | Utf8Str strAudioAdapter; // if not empty, then the guest has audio enabled, and this is the decimal
|
---|
177 | // representation of the audio adapter (should always be "0" for AC97 presently)
|
---|
178 |
|
---|
179 | // session (not initially created)
|
---|
180 | ComPtr<ISession> pSession; // session opened in Appliance::importFS() for machine manipulation
|
---|
181 | bool fSessionOpen; // true if the pSession is currently open and needs closing
|
---|
182 |
|
---|
183 | // a list of images that we created/imported; this is initially empty
|
---|
184 | // and will be cleaned up on errors
|
---|
185 | std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached
|
---|
186 | std::list<STRPAIR> llSrcDisksDigest; // Digests of the source disks
|
---|
187 | std::map<Utf8Str , Utf8Str> mapNewUUIDsToOriginalUUIDs;
|
---|
188 |
|
---|
189 | ImportStack(const LocationInfo &aLocInfo,
|
---|
190 | const ovf::DiskImagesMap &aMapDisks,
|
---|
191 | ComObjPtr<Progress> &aProgress)
|
---|
192 | : locInfo(aLocInfo),
|
---|
193 | mapDisks(aMapDisks),
|
---|
194 | pProgress(aProgress),
|
---|
195 | cCPUs(1),
|
---|
196 | fForceHWVirt(false),
|
---|
197 | fForceIOAPIC(false),
|
---|
198 | ulMemorySizeMB(0),
|
---|
199 | fSessionOpen(false)
|
---|
200 | {
|
---|
201 | // disk images have to be on the same place as the OVF file. So
|
---|
202 | // strip the filename out of the full file path
|
---|
203 | strSourceDir = aLocInfo.strPath;
|
---|
204 | strSourceDir.stripFilename();
|
---|
205 | }
|
---|
206 |
|
---|
207 | HRESULT restoreOriginalUUIDOfAttachedDevice(settings::MachineConfigFile *config);
|
---|
208 | HRESULT saveOriginalUUIDOfAttachedDevice(settings::AttachedDevice &device,
|
---|
209 | const Utf8Str &newlyUuid);
|
---|
210 | };
|
---|
211 |
|
---|
212 | ////////////////////////////////////////////////////////////////////////////////
|
---|
213 | //
|
---|
214 | // VirtualSystemDescription data definition
|
---|
215 | //
|
---|
216 | ////////////////////////////////////////////////////////////////////////////////
|
---|
217 |
|
---|
218 | struct VirtualSystemDescription::Data
|
---|
219 | {
|
---|
220 | std::vector<VirtualSystemDescriptionEntry>
|
---|
221 | maDescriptions; // item descriptions
|
---|
222 |
|
---|
223 | ComPtr<Machine> pMachine; // VirtualBox machine this description was exported from (export only)
|
---|
224 |
|
---|
225 | settings::MachineConfigFile
|
---|
226 | *pConfig; // machine config created from <vbox:Machine> element if found (import only)
|
---|
227 | };
|
---|
228 |
|
---|
229 | ////////////////////////////////////////////////////////////////////////////////
|
---|
230 | //
|
---|
231 | // Internal helpers
|
---|
232 | //
|
---|
233 | ////////////////////////////////////////////////////////////////////////////////
|
---|
234 |
|
---|
235 | void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr);
|
---|
236 |
|
---|
237 | ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode);
|
---|
238 |
|
---|
239 | Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type);
|
---|
240 |
|
---|
241 |
|
---|
242 | typedef struct SHASTORAGE
|
---|
243 | {
|
---|
244 | PVDINTERFACE pVDImageIfaces;
|
---|
245 | bool fCreateDigest;
|
---|
246 | bool fSha256; /* false = SHA1 (OVF 1.x), true = SHA256 (OVF 2.0) */
|
---|
247 | Utf8Str strDigest;
|
---|
248 | } SHASTORAGE, *PSHASTORAGE;
|
---|
249 |
|
---|
250 | PVDINTERFACEIO ShaCreateInterface();
|
---|
251 | PVDINTERFACEIO FileCreateInterface();
|
---|
252 | PVDINTERFACEIO tarWriterCreateInterface(void);
|
---|
253 |
|
---|
254 | /** Pointer to the instance data for the fssRdOnly_ methods. */
|
---|
255 | typedef struct FSSRDONLYINTERFACEIO *PFSSRDONLYINTERFACEIO;
|
---|
256 |
|
---|
257 | int fssRdOnlyCreateInterfaceForTarFile(const char *pszFilename, PFSSRDONLYINTERFACEIO *pTarIo);
|
---|
258 | void fssRdOnlyDestroyInterface(PFSSRDONLYINTERFACEIO pFssIo);
|
---|
259 | int fssRdOnlyGetCurrentName(PFSSRDONLYINTERFACEIO pFssIo, const char **ppszName);
|
---|
260 | int fssRdOnlySkipCurrent(PFSSRDONLYINTERFACEIO pFssIo);
|
---|
261 | bool fssRdOnlyIsCurrentDirectory(PFSSRDONLYINTERFACEIO pFssIo);
|
---|
262 |
|
---|
263 | int readFileIntoBuffer(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser);
|
---|
264 | int writeBufferToFile(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);
|
---|
265 | int decompressImageAndSave(const char *pcszFullFilenameIn, const char *pcszFullFilenameOut, PVDINTERFACEIO pIfIo, void *pvUser);
|
---|
266 | int copyFileAndCalcShaDigest(const char *pcszSourceFilename, const char *pcszTargetFilename, PVDINTERFACEIO pIfIo, void *pvUser);
|
---|
267 | #endif // !____H_APPLIANCEIMPLPRIVATE
|
---|
268 |
|
---|