VirtualBox

source: vbox/trunk/src/VBox/Main/include/HardDiskImpl.h@ 489

Last change on this file since 489 was 351, checked in by vboxsync, 18 years ago

Main: Fixed: HVirtualDiskImage::geAccessible() blocked all other methods, including simple getters [defect #1789].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ____H_HARDDISKIMPL
23#define ____H_HARDDISKIMPL
24
25#include "VirtualBoxBase.h"
26#include "Collection.h"
27
28#include <VBox/cfgldr.h>
29
30#include <iprt/semaphore.h>
31
32#include <list>
33
34class VirtualBox;
35class Progress;
36class HVirtualDiskImage;
37
38////////////////////////////////////////////////////////////////////////////////
39
40class ATL_NO_VTABLE HardDisk :
41 public VirtualBoxSupportErrorInfoImpl <HardDisk, IHardDisk>,
42 public VirtualBoxSupportTranslation <HardDisk>,
43 public VirtualBoxBaseWithTypedChildren <HardDisk>,
44 public IHardDisk
45{
46
47public:
48
49 typedef VirtualBoxBaseWithTypedChildren <HardDisk>::DependentChildren
50 HardDiskList;
51
52 DECLARE_NOT_AGGREGATABLE(HardDisk)
53
54 DECLARE_PROTECT_FINAL_CONSTRUCT()
55
56 BEGIN_COM_MAP(HardDisk)
57 COM_INTERFACE_ENTRY(ISupportErrorInfo)
58 COM_INTERFACE_ENTRY(IHardDisk)
59 END_COM_MAP()
60
61 NS_DECL_ISUPPORTS
62
63 HRESULT FinalConstruct();
64 void FinalRelease();
65
66protected:
67
68 // protected initializer/uninitializer for internal purposes only
69 HRESULT protectedInit (VirtualBox *aVirtualBox, HardDisk *aParent);
70 void protectedUninit (AutoLock &alock);
71
72public:
73
74 // IHardDisk properties
75 STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
76 STDMETHOD(COMGETTER(StorageType)) (HardDiskStorageType_T *aStorageType);
77 STDMETHOD(COMGETTER(Location)) (BSTR *aLocation);
78 STDMETHOD(COMGETTER(Type)) (HardDiskType_T *aType);
79 STDMETHOD(COMSETTER(Type)) (HardDiskType_T aType);
80 STDMETHOD(COMGETTER(Parent)) (IHardDisk **aParent);
81 STDMETHOD(COMGETTER(Children)) (IHardDiskCollection **aChildren);
82 STDMETHOD(COMGETTER(Root)) (IHardDisk **aRoot);
83 STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
84 STDMETHOD(COMGETTER(AllAccessible)) (BOOL *aAllAccessible);
85 STDMETHOD(COMGETTER(LastAccessError)) (BSTR *aLastAccessError);
86 STDMETHOD(COMGETTER(MachineId)) (GUIDPARAMOUT aMachineId);
87 STDMETHOD(COMGETTER(SnapshotId)) (GUIDPARAMOUT aSnapshotId);
88
89 // IHardDisk methods
90 STDMETHOD(CloneToImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage,
91 IProgress **aProgress);
92
93 // public methods for internal purposes only
94
95 const Guid &id() const { return mId; }
96 HardDiskStorageType_T storageType() const { return mStorageType; }
97 HardDiskType_T type() const { return mType; }
98 const Guid &machineId() const { return mMachineId; }
99 const Guid &snapshotId() const { return mSnapshotId; }
100
101 void setMachineId (const Guid &aId) { mMachineId = aId; }
102 void setSnapshotId (const Guid &aId) { mSnapshotId = aId; }
103
104 bool isDifferencing() const
105 {
106 return mType == HardDiskType_NormalHardDisk &&
107 mStorageType == HardDiskStorageType_VirtualDiskImage &&
108 !mParent.isNull();
109 }
110 bool isParentImmutable() const
111 {
112 AutoLock parentLock (mParent);
113 return !mParent.isNull() && mParent->type() == HardDiskType_ImmutableHardDisk;
114 }
115
116 inline HVirtualDiskImage *asVDI();
117
118 ComObjPtr <HardDisk> parent() const { return static_cast <HardDisk *> (mParent); }
119
120 /** Shortcut to #dependentChildrenLock() */
121 AutoLock::Handle &childrenLock() const { return dependentChildrenLock(); }
122
123 /**
124 * Shortcut to #dependentChildren().
125 * Do |AutoLock alock (childrenLock());| before acceessing the returned list!
126 */
127 const HardDiskList &children() const { return dependentChildren(); }
128
129 ComObjPtr <HardDisk> root() const;
130
131 // virtual methods that need to be [re]implemented by every subclass
132
133 virtual HRESULT trySetRegistered (BOOL aRegistered);
134 virtual HRESULT getAccessible (Bstr &aAccessError);
135
136 virtual HRESULT saveSettings (CFGNODE aHDNode, CFGNODE aStorageNode) = 0;
137
138 virtual void updatePath (const char *aOldPath, const char *aNewPath) {}
139
140 virtual Bstr toString (bool aShort = false) = 0;
141 virtual bool sameAs (HardDisk *that);
142
143 virtual HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
144 Progress *aProgress) = 0;
145 virtual HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
146 Progress *aProgress) = 0;
147public:
148
149 void setBusy();
150 void clearBusy();
151 void addReader();
152 void releaseReader();
153 void addReaderOnAncestors();
154 void releaseReaderOnAncestors();
155 bool hasForeignChildren();
156
157 HRESULT setBusyWithChildren();
158 void clearBusyWithChildren();
159 HRESULT getAccessibleWithChildren (Bstr &aAccessError);
160
161 HRESULT checkConsistency();
162
163 HRESULT createDiffHardDisk (const Bstr &aFolder, const Guid &aMachineId,
164 ComObjPtr <HVirtualDiskImage> &aHardDisk,
165 Progress *aProgress);
166
167 void updatePaths (const char *aOldPath, const char *aNewPath);
168
169 /* these must be are called from under the lock */
170 bool isBusy() { isLockedOnCurrentThread(); return mBusy; }
171 unsigned readers() { isLockedOnCurrentThread(); return mReaders; }
172
173 // for VirtualBoxSupportErrorInfoImpl
174 static const wchar_t *getComponentName() { return L"HardDisk"; }
175
176protected:
177
178 HRESULT loadSettings (CFGNODE aHDNode);
179 HRESULT saveSettings (CFGNODE aHDNode);
180
181 /** weak VirualBox parent */
182 ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
183
184 BOOL mRegistered;
185
186 ComObjPtr <HardDisk, ComWeakRef> mParent;
187
188 Guid mId;
189 HardDiskStorageType_T mStorageType;
190 HardDiskType_T mType;
191 Guid mMachineId;
192 Guid mSnapshotId;
193
194private:
195
196 Bstr mLastAccessError;
197
198 bool mBusy;
199 unsigned mReaders;
200};
201
202////////////////////////////////////////////////////////////////////////////////
203
204class ATL_NO_VTABLE HVirtualDiskImage :
205 public HardDisk,
206 public VirtualBoxSupportTranslation <HVirtualDiskImage>,
207 public IVirtualDiskImage
208{
209
210public:
211
212 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HVirtualDiskImage)
213
214 DECLARE_NOT_AGGREGATABLE(HVirtualDiskImage)
215
216 DECLARE_PROTECT_FINAL_CONSTRUCT()
217
218 BEGIN_COM_MAP(HVirtualDiskImage)
219 COM_INTERFACE_ENTRY(ISupportErrorInfo)
220 COM_INTERFACE_ENTRY(IHardDisk)
221 COM_INTERFACE_ENTRY(IVirtualDiskImage)
222 END_COM_MAP()
223
224 NS_DECL_ISUPPORTS
225
226 HRESULT FinalConstruct();
227 void FinalRelease();
228
229 // public initializer/uninitializer for internal purposes only
230
231 HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
232 CFGNODE aHDNode, CFGNODE aVDINode);
233 HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
234 const BSTR aFilePath, BOOL aRegistered = FALSE);
235 void uninit();
236
237 // IHardDisk properties
238 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
239 STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
240 STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
241 STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
242
243 // IVirtualDiskImage properties
244 STDMETHOD(COMGETTER(FilePath)) (BSTR *aFilePath);
245 STDMETHOD(COMSETTER(FilePath)) (INPTR BSTR aFilePath);
246 STDMETHOD(COMGETTER(Created)) (BOOL *aCreated);
247
248 // IVirtualDiskImage methods
249 STDMETHOD(CreateDynamicImage) (ULONG64 aSize, IProgress **aProgress);
250 STDMETHOD(CreateFixedImage) (ULONG64 aSize, IProgress **aProgress);
251 STDMETHOD(DeleteImage)();
252
253 // public methods for internal purposes only
254
255 const Bstr &filePath() const { return mFilePath; }
256 const Bstr &filePathFull() const { return mFilePathFull; }
257
258 HRESULT trySetRegistered (BOOL aRegistered);
259 HRESULT getAccessible (Bstr &aAccessError);
260
261 HRESULT saveSettings (CFGNODE aHDNode, CFGNODE aStorageNode);
262
263 void updatePath (const char *aOldPath, const char *aNewPath);
264
265 Bstr toString (bool aShort = false);
266
267 HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
268 Progress *aProgress);
269 HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
270 Progress *aProgress);
271
272 HRESULT cloneDiffImage (const Bstr &aFolder, const Guid &aMachineId,
273 ComObjPtr <HVirtualDiskImage> &aHardDisk,
274 Progress *aProgress);
275
276 HRESULT mergeImageToParent (Progress *aProgress);
277 HRESULT mergeImageToChildren (Progress *aProgress);
278
279 HRESULT wipeOutImage();
280
281 // for VirtualBoxSupportErrorInfoImpl
282 static const wchar_t *getComponentName() { return L"VirtualDiskImage"; }
283
284private:
285
286 HRESULT setFilePath (const BSTR aFilePath);
287 HRESULT queryInformation (Bstr *aAccessError);
288 HRESULT createImage (ULONG64 aSize, BOOL aDynamic, IProgress **aProgress);
289
290 /** VDI asynchronous operation thread function */
291 static DECLCALLBACK(int) vdiTaskThread (RTTHREAD thread, void *pvUser);
292
293 enum State
294 {
295 NotCreated,
296 Created,
297 /* the following must be greater than Created */
298 Accessible,
299 };
300
301 State mState;
302
303 RTSEMEVENTMULTI mStateCheckSem;
304 ULONG mStateCheckWaiters;
305
306 Bstr mDescription;
307
308 ULONG64 mSize;
309 ULONG64 mActualSize;
310
311 Bstr mFilePath;
312 Bstr mFilePathFull;
313
314 friend class HardDisk;
315};
316
317// dependent inline members
318////////////////////////////////////////////////////////////////////////////////
319
320inline HVirtualDiskImage *HardDisk::asVDI()
321{
322 AssertReturn (mStorageType == HardDiskStorageType_VirtualDiskImage, 0);
323 return static_cast <HVirtualDiskImage *> (this);
324}
325
326////////////////////////////////////////////////////////////////////////////////
327
328class ATL_NO_VTABLE HISCSIHardDisk :
329 public HardDisk,
330 public VirtualBoxSupportTranslation <HISCSIHardDisk>,
331 public IISCSIHardDisk
332{
333
334public:
335
336 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HISCSIHardDisk)
337
338 DECLARE_NOT_AGGREGATABLE(HISCSIHardDisk)
339
340 DECLARE_PROTECT_FINAL_CONSTRUCT()
341
342 BEGIN_COM_MAP(HISCSIHardDisk)
343 COM_INTERFACE_ENTRY(ISupportErrorInfo)
344 COM_INTERFACE_ENTRY(IHardDisk)
345 COM_INTERFACE_ENTRY(IISCSIHardDisk)
346 END_COM_MAP()
347
348 NS_DECL_ISUPPORTS
349
350 HRESULT FinalConstruct();
351 void FinalRelease();
352
353 // public initializer/uninitializer for internal purposes only
354
355 HRESULT init (VirtualBox *aVirtualBox,
356 CFGNODE aHDNode, CFGNODE aISCSINode);
357 HRESULT init (VirtualBox *aVirtualBox);
358 void uninit();
359
360 // IHardDisk properties
361 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
362 STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
363 STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
364 STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
365
366 // IISCSIHardDisk properties
367 STDMETHOD(COMGETTER(Server)) (BSTR *aServer);
368 STDMETHOD(COMSETTER(Server)) (INPTR BSTR aServer);
369 STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
370 STDMETHOD(COMSETTER(Port)) (USHORT aPort);
371 STDMETHOD(COMGETTER(Target)) (BSTR *aTarget);
372 STDMETHOD(COMSETTER(Target)) (INPTR BSTR aTarget);
373 STDMETHOD(COMGETTER(Lun)) (ULONG64 *aLun);
374 STDMETHOD(COMSETTER(Lun)) (ULONG64 aLun);
375 STDMETHOD(COMGETTER(UserName)) (BSTR *aUserName);
376 STDMETHOD(COMSETTER(UserName)) (INPTR BSTR aUserName);
377 STDMETHOD(COMGETTER(Password)) (BSTR *aPassword);
378 STDMETHOD(COMSETTER(Password)) (INPTR BSTR aPassword);
379
380 // public methods for internal purposes only
381
382 const Bstr &server() const { return mServer; }
383 USHORT port() const { return mPort; }
384 const Bstr &target() const { return mTarget; }
385 ULONG64 lun() const { return mLun; }
386 const Bstr &userName() const { return mUserName; }
387 const Bstr &password() const { return mPassword; }
388
389 HRESULT trySetRegistered (BOOL aRegistered);
390 HRESULT getAccessible (Bstr &aAccessError);
391
392 HRESULT saveSettings (CFGNODE aHDNode, CFGNODE aStorageNode);
393
394 Bstr toString (bool aShort = false);
395
396 HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
397 Progress *aProgress);
398 HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
399 Progress *aProgress);
400
401public:
402
403 // for VirtualBoxSupportErrorInfoImpl
404 static const wchar_t *getComponentName() { return L"ISCSIHardDisk"; }
405
406private:
407
408 HRESULT queryInformation (Bstr &aAccessError);
409
410 Bstr mDescription;
411
412 ULONG64 mSize;
413 ULONG64 mActualSize;
414
415 Bstr mServer;
416 USHORT mPort;
417 Bstr mTarget;
418 ULONG64 mLun;
419 Bstr mUserName;
420 Bstr mPassword;
421};
422
423
424COM_DECL_READONLY_ENUM_AND_COLLECTION (HardDisk)
425
426#endif // ____H_HARDDISKIMPL
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