VirtualBox

source: vbox/trunk/src/VBox/Main/include/MediumImpl.h@ 48392

Last change on this file since 48392 was 48297, checked in by vboxsync, 11 years ago

Main/Medium: redesign API level medium locking, needed conversions from MediaList to MediumLockLists in several places, forced cleanups elsewhere, too
Main/Token: introduced token objects for controlling the unlocking, will be used as a general concept in the future
Main/Snapshot: snapshot deletion needed significant cleanups as it was still using many shortcuts, directly calling the API to lock media instead of using lock lists. Now much better, and the online snapshot deletion is also a lot cleaner as it no longer passes unnecessary parameters around which are already known in the machine/snapshot code
Main/MediumLock: small improvements, now has a mode which skips locking already locked media, needed by the Snapshot code where we have overlapping lock lists and have to update the original one instead
Main/Console+Session+Machine: follow-up changes for the online snapshot merging parameter passing simplification, plus an unrelated lock order violation fix in Machine which happens only for inaccessible machines
Main/testcase: update correspondingly
doc: update SDK reference

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.0 KB
Line 
1/* $Id: MediumImpl.h 48297 2013-09-05 09:57:44Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2013 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#ifndef ____H_MEDIUMIMPL
21#define ____H_MEDIUMIMPL
22
23#include <VBox/vd.h>
24
25#include "VirtualBoxBase.h"
26#include "MediumLock.h"
27
28class Progress;
29class MediumFormat;
30
31namespace settings
32{
33 struct Medium;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37
38/**
39 * Medium component class for all media types.
40 */
41class ATL_NO_VTABLE Medium :
42 public VirtualBoxBase,
43 VBOX_SCRIPTABLE_IMPL(IMedium)
44{
45public:
46 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium, IMedium)
47
48 DECLARE_NOT_AGGREGATABLE(Medium)
49
50 DECLARE_PROTECT_FINAL_CONSTRUCT()
51
52 BEGIN_COM_MAP(Medium)
53 VBOX_DEFAULT_INTERFACE_ENTRIES(IMedium)
54 END_COM_MAP()
55
56 DECLARE_EMPTY_CTOR_DTOR(Medium)
57
58 HRESULT FinalConstruct();
59 void FinalRelease();
60
61 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
62 // have to use a special enum for the overloaded init() below;
63 // can't use AccessMode_T from XIDL because that's mapped to an int
64 // and would be ambiguous
65
66 // public initializer/uninitializer for internal purposes only
67
68 // initializer to create empty medium (VirtualBox::CreateHardDisk())
69 HRESULT init(VirtualBox *aVirtualBox,
70 const Utf8Str &aFormat,
71 const Utf8Str &aLocation,
72 const Guid &uuidMachineRegistry);
73
74 // initializer for opening existing media
75 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
76 HRESULT init(VirtualBox *aVirtualBox,
77 const Utf8Str &aLocation,
78 HDDOpenMode enOpenMode,
79 bool fForceNewUuid,
80 DeviceType_T aDeviceType);
81
82 // initializer used when loading settings
83 HRESULT init(VirtualBox *aVirtualBox,
84 Medium *aParent,
85 DeviceType_T aDeviceType,
86 const Guid &uuidMachineRegistry,
87 const settings::Medium &data,
88 const Utf8Str &strMachineFolder);
89
90 // initializer for host floppy/DVD
91 HRESULT init(VirtualBox *aVirtualBox,
92 DeviceType_T aDeviceType,
93 const Utf8Str &aLocation,
94 const Utf8Str &aDescription = Utf8Str::Empty);
95
96 void uninit();
97
98 void deparent();
99 void setParent(const ComObjPtr<Medium> &pParent);
100
101 // IMedium properties
102 STDMETHOD(COMGETTER(Id))(BSTR *aId);
103 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
104 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
105 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
106 STDMETHOD(COMGETTER(Variant))(ComSafeArrayOut(MediumVariant_T, aVariant));
107 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
108 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
109 STDMETHOD(COMGETTER(Name))(BSTR *aName);
110 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
111 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
112 STDMETHOD(COMGETTER(Size))(LONG64 *aSize);
113 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
114 STDMETHOD(COMGETTER(MediumFormat))(IMediumFormat **aMediumFormat);
115 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
116 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
117 STDMETHOD(COMGETTER(AllowedTypes))(ComSafeArrayOut(MediumType_T, aAllowedTypes));
118 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
119 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
120 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
121 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
122 STDMETHOD(COMGETTER(LogicalSize))(LONG64 *aLogicalSize);
123 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
124 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
125 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
126 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
127
128 // IMedium methods
129 STDMETHOD(SetIds)(BOOL aSetImageId, IN_BSTR aImageId,
130 BOOL aSetParentId, IN_BSTR aParentId);
131 STDMETHOD(RefreshState)(MediumState_T *aState);
132 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
133 ComSafeArrayOut(BSTR, aSnapshotIds));
134 STDMETHOD(LockRead)(IToken **aToken);
135 STDMETHOD(LockWrite)(IToken **aToken);
136 STDMETHOD(Close)();
137 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
138 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
139 STDMETHOD(GetProperties)(IN_BSTR aNames,
140 ComSafeArrayOut(BSTR, aReturnNames),
141 ComSafeArrayOut(BSTR, aReturnValues));
142 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
143 ComSafeArrayIn(IN_BSTR, aValues));
144 STDMETHOD(CreateBaseStorage)(LONG64 aLogicalSize,
145 ComSafeArrayIn(MediumVariant_T, aVariant),
146 IProgress **aProgress);
147 STDMETHOD(DeleteStorage)(IProgress **aProgress);
148 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
149 ComSafeArrayIn(MediumVariant_T, aVariant),
150 IProgress **aProgress);
151 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
152 STDMETHOD(CloneTo)(IMedium *aTarget, ComSafeArrayIn(MediumVariant_T, aVariant),
153 IMedium *aParent, IProgress **aProgress);
154 STDMETHOD(CloneToBase)(IMedium *aTarget, ComSafeArrayIn(MediumVariant_T, aVariant),
155 IProgress **aProgress);
156 STDMETHOD(Compact)(IProgress **aProgress);
157 STDMETHOD(Resize)(LONG64 aLogicalSize, IProgress **aProgress);
158 STDMETHOD(Reset)(IProgress **aProgress);
159
160 // unsafe methods for internal purposes only (ensure there is
161 // a caller and a read lock before calling them!)
162 const ComObjPtr<Medium>& getParent() const;
163 const MediaList& getChildren() const;
164
165 const Guid& getId() const;
166 MediumState_T getState() const;
167 MediumVariant_T getVariant() const;
168 bool isHostDrive() const;
169 const Utf8Str& getLocationFull() const;
170 const Utf8Str& getFormat() const;
171 const ComObjPtr<MediumFormat> & getMediumFormat() const;
172 bool isMediumFormatFile() const;
173 uint64_t getSize() const;
174 DeviceType_T getDeviceType() const;
175 MediumType_T getType() const;
176 Utf8Str getName();
177
178 /* handles caller/locking itself */
179 bool addRegistry(const Guid& id, bool fRecurse);
180 /* handles caller/locking itself */
181 bool removeRegistry(const Guid& id, bool fRecurse);
182 bool isInRegistry(const Guid& id);
183 bool getFirstRegistryMachineId(Guid &uuid) const;
184 void markRegistriesModified();
185
186 HRESULT setPropertyDirect(const Utf8Str &aName, const Utf8Str &aValue);
187
188 HRESULT addBackReference(const Guid &aMachineId,
189 const Guid &aSnapshotId = Guid::Empty);
190 HRESULT removeBackReference(const Guid &aMachineId,
191 const Guid &aSnapshotId = Guid::Empty);
192
193
194 const Guid* getFirstMachineBackrefId() const;
195 const Guid* getAnyMachineBackref() const;
196 const Guid* getFirstMachineBackrefSnapshotId() const;
197 size_t getMachineBackRefCount() const;
198
199#ifdef DEBUG
200 void dumpBackRefs();
201#endif
202
203 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
204
205 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
206
207 bool isReadOnly();
208 void updateId(const Guid &id);
209
210 HRESULT saveSettings(settings::Medium &data,
211 const Utf8Str &strHardDiskFolder);
212
213 HRESULT createMediumLockList(bool fFailIfInaccessible,
214 bool fMediumLockWrite,
215 Medium *pToBeParent,
216 MediumLockList &mediumLockList);
217
218 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
219 MediumVariant_T aVariant,
220 MediumLockList *pMediumLockList,
221 ComObjPtr<Progress> *aProgress,
222 bool aWait);
223 Utf8Str getPreferredDiffFormat();
224
225 HRESULT close(AutoCaller &autoCaller);
226 HRESULT unlockRead(MediumState_T *aState);
227 HRESULT unlockWrite(MediumState_T *aState);
228 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait);
229 HRESULT markForDeletion();
230 HRESULT unmarkForDeletion();
231 HRESULT markLockedForDeletion();
232 HRESULT unmarkLockedForDeletion();
233
234 HRESULT queryPreferredMergeDirection(const ComObjPtr<Medium> &pOther,
235 bool &fMergeForward);
236
237 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
238 const Guid *aMachineId,
239 const Guid *aSnapshotId,
240 bool fLockMedia,
241 bool &fMergeForward,
242 ComObjPtr<Medium> &pParentForTarget,
243 MediumLockList * &aChildrenToReparent,
244 MediumLockList * &aMediumLockList);
245 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
246 bool fMergeForward,
247 const ComObjPtr<Medium> &pParentForTarget,
248 MediumLockList *aChildrenToReparent,
249 MediumLockList *aMediumLockList,
250 ComObjPtr<Progress> *aProgress,
251 bool aWait);
252 void cancelMergeTo(MediumLockList *aChildrenToReparent,
253 MediumLockList *aMediumLockList);
254
255 HRESULT fixParentUuidOfChildren(MediumLockList *pChildrenToReparent);
256
257 HRESULT exportFile(const char *aFilename,
258 const ComObjPtr<MediumFormat> &aFormat,
259 MediumVariant_T aVariant,
260 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
261 const ComObjPtr<Progress> &aProgress);
262 HRESULT importFile(const char *aFilename,
263 const ComObjPtr<MediumFormat> &aFormat,
264 MediumVariant_T aVariant,
265 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
266 const ComObjPtr<Medium> &aParent,
267 const ComObjPtr<Progress> &aProgress);
268
269 HRESULT cloneToEx(const ComObjPtr<Medium> &aTarget, ULONG aVariant,
270 const ComObjPtr<Medium> &aParent, IProgress **aProgress,
271 uint32_t idxSrcImageSame, uint32_t idxDstImageSame);
272
273private:
274
275 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
276
277 HRESULT canClose();
278 HRESULT unregisterWithVirtualBox();
279
280 HRESULT setStateError();
281
282 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
283 HRESULT setFormat(const Utf8Str &aFormat);
284
285 VDTYPE convertDeviceType();
286 DeviceType_T convertToDeviceType(VDTYPE enmType);
287
288 Utf8Str vdError(int aVRC);
289
290 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
291 const char *pszFormat, va_list va);
292
293 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
294 const char *pszzValid);
295 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
296 size_t *pcbValue);
297 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
298 char *pszValue, size_t cchValue);
299
300 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
301 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
302 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
303 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
304 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
305 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
306 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
307 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
308 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
309 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
310 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
311 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
312 static DECLCALLBACK(int) vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
313
314 class Task;
315 class CreateBaseTask;
316 class CreateDiffTask;
317 class CloneTask;
318 class CompactTask;
319 class ResizeTask;
320 class ResetTask;
321 class DeleteTask;
322 class MergeTask;
323 class ExportTask;
324 class ImportTask;
325 friend class Task;
326 friend class CreateBaseTask;
327 friend class CreateDiffTask;
328 friend class CloneTask;
329 friend class CompactTask;
330 friend class ResizeTask;
331 friend class ResetTask;
332 friend class DeleteTask;
333 friend class MergeTask;
334 friend class ExportTask;
335 friend class ImportTask;
336
337 HRESULT startThread(Medium::Task *pTask);
338 HRESULT runNow(Medium::Task *pTask);
339
340 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
341 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
342 HRESULT taskMergeHandler(Medium::MergeTask &task);
343 HRESULT taskCloneHandler(Medium::CloneTask &task);
344 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
345 HRESULT taskResetHandler(Medium::ResetTask &task);
346 HRESULT taskCompactHandler(Medium::CompactTask &task);
347 HRESULT taskResizeHandler(Medium::ResizeTask &task);
348 HRESULT taskExportHandler(Medium::ExportTask &task);
349 HRESULT taskImportHandler(Medium::ImportTask &task);
350
351 struct Data; // opaque data struct, defined in MediumImpl.cpp
352 Data *m;
353};
354
355#endif /* ____H_MEDIUMIMPL */
356
Note: See TracBrowser for help on using the repository browser.

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