VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImplPrivate.h@ 59071

Last change on this file since 59071 was 58005, checked in by vboxsync, 9 years ago

pr7179. Part related to Appliance class and TaskOVF tasks like import, export, reading.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette