VirtualBox

source: vbox/trunk/src/VBox/Main/include/ConsoleImpl.h@ 34772

最後變更 在這個檔案從34772是 34587,由 vboxsync 提交於 14 年 前

Main: Bandwidth groups for disks (and later network)

This introduces two new interfaces. The first one named IBandwidthGroup
represents one I/O limit and can be assigned to several mediums which
share this limit (which works only for harddisk images with the disabled
host cache).
The second one IBandwdithControl manages the groups and can create new ones
and destroy them if not required anymore.

VBoxManage: commands to access the bandwidth groups

Syntax:
VBoxManage storageattach <uuid|vmname>

...
--bandwidthgroup <name>

--bandwidthgroup assigns the specified device to the given group.

VBoxManage bandwidthctl <uuid|vmname>

--name <name>
--add disk|network
--limit <megabytes per second>
--delete

The --name parameter gives the name of the bandwidth group.
--add creates a new group of the given type (only disk is implemented so far)

with the given name.

--limit sets the limit to the given amount of MB/s

Note that limit can be changed while the VM is running. The VM
will immediately pick up the new limit for the given group name.

--delete deletes the group with the given name if it isn't used anymore.

Trying to delete a still used group will result in an error.

Example:

VBoxManage bandwidthctl "Test VM" --name Limit --add disk --limit 20
Creates a group named Test having a 20 MB/s limit.

VBoxManage storageattach "Test VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium test.vdi --bandwidthgroup Limit
Adds a new disk to the SATA controller and assigns the bandwidth group Limit to it.

VBoxManage storageattach "Test VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium test.vdi --bandwidthgroup none
Removes the bandwidth limit from the disk.

VBoxManage bandwidthctl "Test VM" --name Limit --add disk --limit 10
Changes the limit of bandwidth group Limit to 10 MB/s. If the VM is running the limit will be picked up
immediately.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 30.3 KB
 
1/* $Id: ConsoleImpl.h 34587 2010-12-01 20:30:02Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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_CONSOLEIMPL
19#define ____H_CONSOLEIMPL
20
21#include "VirtualBoxBase.h"
22#include "SchemaDefs.h"
23#include "VBox/com/array.h"
24#include "EventImpl.h"
25
26class Guest;
27class Keyboard;
28class Mouse;
29class Display;
30class MachineDebugger;
31class TeleporterStateSrc;
32class OUSBDevice;
33class RemoteUSBDevice;
34class SharedFolder;
35class VRDEServerInfo;
36class AudioSniffer;
37class ConsoleVRDPServer;
38class VMMDev;
39class Progress;
40class BusAssignmentManager;
41COM_STRUCT_OR_CLASS(IEventListener);
42#ifdef VBOX_WITH_EXTPACK
43class ExtPackManager;
44#endif
45
46#include <VBox/RemoteDesktop/VRDE.h>
47#include <VBox/pdmdrv.h>
48#ifdef VBOX_WITH_GUEST_PROPS
49# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
50#endif
51
52#ifdef RT_OS_WINDOWS
53# include "win/VBoxComEvents.h"
54#endif
55
56struct VUSBIRHCONFIG;
57typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
58
59#include <list>
60
61// defines
62///////////////////////////////////////////////////////////////////////////////
63
64/**
65 * Checks the availability of the underlying VM device driver corresponding
66 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
67 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
68 * The translatable error message is defined in null context.
69 *
70 * Intended to used only within Console children (i.e. Keyboard, Mouse,
71 * Display, etc.).
72 *
73 * @param drv driver pointer to check (compare it with NULL)
74 */
75#define CHECK_CONSOLE_DRV(drv) \
76 do { \
77 if (!(drv)) \
78 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
79 } while (0)
80
81// Console
82///////////////////////////////////////////////////////////////////////////////
83
84/** IConsole implementation class */
85class ATL_NO_VTABLE Console :
86 public VirtualBoxBase,
87 VBOX_SCRIPTABLE_IMPL(IConsole)
88{
89 Q_OBJECT
90
91public:
92
93 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Console, IConsole)
94
95 DECLARE_NOT_AGGREGATABLE(Console)
96
97 DECLARE_PROTECT_FINAL_CONSTRUCT()
98
99 BEGIN_COM_MAP(Console)
100 COM_INTERFACE_ENTRY(ISupportErrorInfo)
101 COM_INTERFACE_ENTRY(IConsole)
102 COM_INTERFACE_ENTRY(IDispatch)
103 END_COM_MAP()
104
105 Console();
106 ~Console();
107
108 HRESULT FinalConstruct();
109 void FinalRelease();
110
111 // public initializers/uninitializers for internal purposes only
112 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl);
113 void uninit();
114
115 // IConsole properties
116 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
117 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
118 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
119 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
120 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
121 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
122 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
123 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
124 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
125 STDMETHOD(COMGETTER(VRDEServerInfo))(IVRDEServerInfo **aVRDEServerInfo);
126 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
127 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
128 STDMETHOD(COMGETTER(AttachedPciDevices))(ComSafeArrayOut(IPciDeviceAttachment *, aAttachments));
129
130 // IConsole methods
131 STDMETHOD(PowerUp)(IProgress **aProgress);
132 STDMETHOD(PowerUpPaused)(IProgress **aProgress);
133 STDMETHOD(PowerDown)(IProgress **aProgress);
134 STDMETHOD(Reset)();
135 STDMETHOD(Pause)();
136 STDMETHOD(Resume)();
137 STDMETHOD(PowerButton)();
138 STDMETHOD(SleepButton)();
139 STDMETHOD(GetPowerButtonHandled)(BOOL *aHandled);
140 STDMETHOD(GetGuestEnteredACPIMode)(BOOL *aEntered);
141 STDMETHOD(SaveState)(IProgress **aProgress);
142 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
143 STDMETHOD(DiscardSavedState)(BOOL aRemoveFile);
144 STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
145 DeviceActivity_T *aDeviceActivity);
146 STDMETHOD(AttachUSBDevice)(IN_BSTR aId);
147 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, IUSBDevice **aDevice);
148 STDMETHOD(FindUSBDeviceByAddress)(IN_BSTR aAddress, IUSBDevice **aDevice);
149 STDMETHOD(FindUSBDeviceById)(IN_BSTR aId, IUSBDevice **aDevice);
150 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
151 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
152 STDMETHOD(TakeSnapshot)(IN_BSTR aName, IN_BSTR aDescription,
153 IProgress **aProgress);
154 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress);
155 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress);
156 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
157
158 // public methods for internal purposes only
159
160 /*
161 * Note: the following methods do not increase refcount. intended to be
162 * called only by the VM execution thread.
163 */
164
165 Guest *getGuest() const { return mGuest; }
166 Keyboard *getKeyboard() const { return mKeyboard; }
167 Mouse *getMouse() const { return mMouse; }
168 Display *getDisplay() const { return mDisplay; }
169 MachineDebugger *getMachineDebugger() const { return mDebugger; }
170
171 const ComPtr<IMachine> &machine() const { return mMachine; }
172
173 /** Method is called only from ConsoleVRDPServer */
174 IVRDEServer *getVRDEServer() const { return mVRDEServer; }
175
176 ConsoleVRDPServer *consoleVRDPServer() const { return mConsoleVRDPServer; }
177
178 HRESULT updateMachineState(MachineState_T aMachineState);
179
180 // events from IInternalSessionControl
181 HRESULT onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
182 HRESULT onSerialPortChange(ISerialPort *aSerialPort);
183 HRESULT onParallelPortChange(IParallelPort *aParallelPort);
184 HRESULT onStorageControllerChange();
185 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
186 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
187 HRESULT onCPUExecutionCapChange(ULONG aExecutionCap);
188 HRESULT onVRDEServerChange(BOOL aRestart);
189 HRESULT onUSBControllerChange();
190 HRESULT onSharedFolderChange(BOOL aGlobal);
191 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
192 HRESULT onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
193 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
194 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
195 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
196 HRESULT enumerateGuestProperties(IN_BSTR aPatterns,
197 ComSafeArrayOut(BSTR, aNames),
198 ComSafeArrayOut(BSTR, aValues),
199 ComSafeArrayOut(LONG64, aTimestamps),
200 ComSafeArrayOut(BSTR, aFlags));
201 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
202 ULONG aSourceIdx, ULONG aTargetIdx,
203 IMedium *aSource, IMedium *aTarget,
204 BOOL aMergeForward, IMedium *aParentForTarget,
205 ComSafeArrayIn(IMedium *, aChildrenToReparent),
206 IProgress *aProgress);
207 VMMDev *getVMMDev() { return m_pVMMDev; }
208 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
209#ifdef VBOX_WITH_EXTPACK
210 ExtPackManager *getExtPackManager();
211#endif
212
213 int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
214 void VRDPClientConnect(uint32_t u32ClientId);
215 void VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
216 void VRDPInterceptAudio(uint32_t u32ClientId);
217 void VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
218 void VRDPInterceptClipboard(uint32_t u32ClientId);
219
220 void processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList);
221
222 // callback callers (partly; for some events console callbacks are notified
223 // directly from IInternalSessionControl event handlers declared above)
224 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
225 uint32_t xHot, uint32_t yHot,
226 uint32_t width, uint32_t height,
227 ComSafeArrayIn(uint8_t, aShape));
228 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor);
229 void onStateChange(MachineState_T aMachineState);
230 void onAdditionsStateChange();
231 void onAdditionsOutdated();
232 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
233 void onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
234 IVirtualBoxErrorInfo *aError);
235 void onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
236 HRESULT onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
237 void onVRDEServerInfoChange();
238
239 static const PDMDRVREG DrvStatusReg;
240
241 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
242 HRESULT setInvalidMachineStateError();
243
244 static HRESULT handleUnexpectedExceptions(RT_SRC_POS_DECL);
245
246 static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
247 static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
248 // Called from event listener
249 HRESULT onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
250 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
251
252private:
253
254 /**
255 * Base template for AutoVMCaller and SaveVMPtr. Template arguments
256 * have the same meaning as arguments of Console::addVMCaller().
257 */
258 template <bool taQuiet = false, bool taAllowNullVM = false>
259 class AutoVMCallerBase
260 {
261 public:
262 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(S_OK)
263 {
264 Assert(aThat);
265 mRC = aThat->addVMCaller(taQuiet, taAllowNullVM);
266 }
267 ~AutoVMCallerBase()
268 {
269 if (SUCCEEDED(mRC))
270 mThat->releaseVMCaller();
271 }
272 /** Decreases the number of callers before the instance is destroyed. */
273 void release()
274 {
275 AssertReturnVoid(SUCCEEDED(mRC));
276 mThat->releaseVMCaller();
277 mRC = E_FAIL;
278 }
279 /** Restores the number of callers after by #release(). #rc() must be
280 * rechecked to ensure the operation succeeded. */
281 void add()
282 {
283 AssertReturnVoid(!SUCCEEDED(mRC));
284 mRC = mThat->addVMCaller(taQuiet, taAllowNullVM);
285 }
286 /** Returns the result of Console::addVMCaller() */
287 HRESULT rc() const { return mRC; }
288 /** Shortcut to SUCCEEDED(rc()) */
289 bool isOk() const { return SUCCEEDED(mRC); }
290 protected:
291 Console *mThat;
292 HRESULT mRC;
293 private:
294 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
295 DECLARE_CLS_NEW_DELETE_NOOP(AutoVMCallerBase)
296 };
297
298 /**
299 * Helper class that protects sections of code using the mpVM pointer by
300 * automatically calling addVMCaller() on construction and
301 * releaseVMCaller() on destruction. Intended for Console methods dealing
302 * with mpVM. The usage pattern is:
303 * <code>
304 * AutoVMCaller autoVMCaller(this);
305 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
306 * ...
307 * VMR3ReqCall (mpVM, ...
308 * </code>
309 *
310 * @note Temporarily locks the argument for writing.
311 *
312 * @sa SafeVMPtr, SafeVMPtrQuiet
313 */
314 typedef AutoVMCallerBase <false, false> AutoVMCaller;
315
316 /**
317 * Same as AutoVMCaller but doesn't set extended error info on failure.
318 *
319 * @note Temporarily locks the argument for writing.
320 */
321 typedef AutoVMCallerBase <true, false> AutoVMCallerQuiet;
322
323 /**
324 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
325 * instead of assertion).
326 *
327 * @note Temporarily locks the argument for writing.
328 */
329 typedef AutoVMCallerBase <false, true> AutoVMCallerWeak;
330
331 /**
332 * Same as AutoVMCaller but doesn't set extended error info on failure
333 * and allows a null VM pointer (to trigger an error instead of
334 * assertion).
335 *
336 * @note Temporarily locks the argument for writing.
337 */
338 typedef AutoVMCallerBase <true, true> AutoVMCallerQuietWeak;
339
340 /**
341 * Base template for SaveVMPtr and SaveVMPtrQuiet.
342 */
343 template <bool taQuiet = false>
344 class SafeVMPtrBase : public AutoVMCallerBase <taQuiet, true>
345 {
346 typedef AutoVMCallerBase <taQuiet, true> Base;
347 public:
348 SafeVMPtrBase(Console *aThat) : Base(aThat), mpVM(NULL)
349 {
350 if (SUCCEEDED(Base::mRC))
351 mpVM = aThat->mpVM;
352 }
353 /** Smart SaveVMPtr to PVM cast operator */
354 operator PVM() const { return mpVM; }
355 /** Direct PVM access for printf()-like functions */
356 PVM raw() const { return mpVM; }
357 private:
358 PVM mpVM;
359 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
360 DECLARE_CLS_NEW_DELETE_NOOP(SafeVMPtrBase)
361 };
362
363public:
364
365 /**
366 * Helper class that safely manages the Console::mpVM pointer
367 * by calling addVMCaller() on construction and releaseVMCaller() on
368 * destruction. Intended for Console children. The usage pattern is:
369 * <code>
370 * Console::SaveVMPtr pVM(mParent);
371 * if (FAILED(pVM.rc())) return pVM.rc();
372 * ...
373 * VMR3ReqCall(pVM, ...
374 * ...
375 * printf("%p\n", pVM.raw());
376 * </code>
377 *
378 * @note Temporarily locks the argument for writing.
379 *
380 * @sa SafeVMPtrQuiet, AutoVMCaller
381 */
382 typedef SafeVMPtrBase <false> SafeVMPtr;
383
384 /**
385 * A deviation of SaveVMPtr that doesn't set the error info on failure.
386 * Intended for pieces of code that don't need to return the VM access
387 * failure to the caller. The usage pattern is:
388 * <code>
389 * Console::SaveVMPtrQuiet pVM(mParent);
390 * if (pVM.rc())
391 * VMR3ReqCall(pVM, ...
392 * return S_OK;
393 * </code>
394 *
395 * @note Temporarily locks the argument for writing.
396 *
397 * @sa SafeVMPtr, AutoVMCaller
398 */
399 typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
400
401 class SharedFolderData
402 {
403 public:
404 SharedFolderData() {}
405 SharedFolderData(Bstr aHostPath, BOOL aWritable, BOOL aAutoMount)
406 : mHostPath(aHostPath)
407 , mWritable(aWritable)
408 , mAutoMount(aAutoMount) {}
409 SharedFolderData(const SharedFolderData& aThat)
410 : mHostPath(aThat.mHostPath)
411 , mWritable(aThat.mWritable)
412 , mAutoMount(aThat.mAutoMount) {}
413 Bstr mHostPath;
414 BOOL mWritable;
415 BOOL mAutoMount;
416 };
417 typedef std::map <Bstr, ComObjPtr<SharedFolder> > SharedFolderMap;
418 typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap;
419
420private:
421
422 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
423 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
424
425 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
426 void releaseVMCaller();
427
428 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
429
430 HRESULT powerUp(IProgress **aProgress, bool aPaused);
431 HRESULT powerDown(Progress *aProgress = NULL);
432
433 HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
434 Bstr &tapSetupApplication);
435#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
436 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
437 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
438#endif
439 HRESULT powerDownHostInterfaces();
440
441 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
442 HRESULT setMachineStateLocally(MachineState_T aMachineState)
443 {
444 return setMachineState(aMachineState, false /* aUpdateServer */);
445 }
446
447 HRESULT findSharedFolder(CBSTR aName,
448 ComObjPtr<SharedFolder> &aSharedFolder,
449 bool aSetError = false);
450
451 HRESULT fetchSharedFolders(BOOL aGlobal);
452 bool findOtherSharedFolder(IN_BSTR aName,
453 SharedFolderDataMap::const_iterator &aIt);
454
455 HRESULT createSharedFolder(CBSTR aName, SharedFolderData aData);
456 HRESULT removeSharedFolder(CBSTR aName);
457
458 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
459 int configCfgmOverlay(PVM pVM, IVirtualBox *pVirtualBox, IMachine *pMachine);
460
461 int configMediumAttachment(PCFGMNODE pCtlInst,
462 const char *pcszDevice,
463 unsigned uInstance,
464 StorageBus_T enmBus,
465 bool fUseHostIOCache,
466 bool fBuiltinIoCache,
467 bool fSetupMerge,
468 unsigned uMergeSource,
469 unsigned uMergeTarget,
470 IMediumAttachment *pMediumAtt,
471 MachineState_T aMachineState,
472 HRESULT *phrc,
473 bool fAttachDetach,
474 bool fForceUnmount,
475 PVM pVM,
476 DeviceType_T *paLedDevType);
477 int configMedium(PCFGMNODE pLunL0,
478 bool fPassthrough,
479 DeviceType_T enmType,
480 bool fUseHostIOCache,
481 bool fBuiltinIoCache,
482 bool fSetupMerge,
483 unsigned uMergeSource,
484 unsigned uMergeTarget,
485 const char *pcszBwGroup,
486 IMedium *pMedium,
487 MachineState_T aMachineState,
488 HRESULT *phrc);
489 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
490 PVM pVM,
491 const char *pcszDevice,
492 unsigned uInstance,
493 StorageBus_T enmBus,
494 bool fUseHostIOCache,
495 bool fBuiltinIoCache,
496 bool fSetupMerge,
497 unsigned uMergeSource,
498 unsigned uMergeTarget,
499 IMediumAttachment *aMediumAtt,
500 MachineState_T aMachineState,
501 HRESULT *phrc);
502 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
503 const char *pcszDevice,
504 unsigned uInstance,
505 StorageBus_T enmBus,
506 bool fUseHostIOCache,
507 IMediumAttachment *aMediumAtt,
508 bool fForce);
509
510 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
511 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
512 PCFGMNODE pLunL0, PCFGMNODE pInst,
513 bool fAttachDetach, bool fIgnoreConnectFailure);
514
515 static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
516 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
517 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
518 VMSTATE aOldState, void *aUser);
519 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);
520 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);
521 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
522 HRESULT doCPURemove(ULONG aCpu);
523 HRESULT doCPUAdd(ULONG aCpu);
524
525 HRESULT doNetworkAdapterChange(const char *pszDevice, unsigned uInstance,
526 unsigned uLun, INetworkAdapter *aNetworkAdapter);
527 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,
528 unsigned uInstance, unsigned uLun,
529 INetworkAdapter *aNetworkAdapter);
530
531#ifdef VBOX_WITH_USB
532 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
533 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt);
534
535 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,
536 bool aRemote, const char *aAddress, ULONG aMaskedIfs);
537 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
538#endif
539
540 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
541
542 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
543
544 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
545 const char *pszErrorFmt, va_list va);
546
547 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
548 const char *pszErrorId,
549 const char *pszFormat, ...);
550 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
551 const char *pszErrorId,
552 const char *pszFormat, va_list va);
553
554 HRESULT captureUSBDevices(PVM pVM);
555 void detachAllUSBDevices(bool aDone);
556
557 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
558 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
559 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
560
561 static DECLCALLBACK(int) vmm2User_SaveState(PCVMM2USERMETHODS pThis, PVM pVM);
562
563 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
564 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
565 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
566 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
567
568 int mcAudioRefs;
569 volatile uint32_t mcVRDPClients;
570 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
571 volatile bool mcGuestCredentialsProvided;
572
573 static const char *sSSMConsoleUnit;
574 static uint32_t sSSMConsoleVer;
575
576 HRESULT loadDataFromSavedState();
577 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
578
579 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
580 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
581
582#ifdef VBOX_WITH_GUEST_PROPS
583 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
584 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
585 ComSafeArrayOut(BSTR, aNames),
586 ComSafeArrayOut(BSTR, aValues),
587 ComSafeArrayOut(LONG64, aTimestamps),
588 ComSafeArrayOut(BSTR, aFlags));
589
590 bool enabledGuestPropertiesVRDP(void);
591 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
592 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
593#endif
594
595 /** @name Teleporter support
596 * @{ */
597 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
598 HRESULT teleporterSrc(TeleporterStateSrc *pState);
599 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
600 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
601 HRESULT teleporterTrg(PVM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
602 Progress *pProgress, bool *pfPowerOffOnFailure);
603 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
604 /** @} */
605
606 bool mSavedStateDataLoaded : 1;
607
608 const ComPtr<IMachine> mMachine;
609 const ComPtr<IInternalMachineControl> mControl;
610
611 const ComPtr<IVRDEServer> mVRDEServer;
612
613 ConsoleVRDPServer * const mConsoleVRDPServer;
614
615 const ComObjPtr<Guest> mGuest;
616 const ComObjPtr<Keyboard> mKeyboard;
617 const ComObjPtr<Mouse> mMouse;
618 const ComObjPtr<Display> mDisplay;
619 const ComObjPtr<MachineDebugger> mDebugger;
620 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
621 const ComObjPtr<EventSource> mEventSource;
622#ifdef VBOX_WITH_EXTPACK
623 const ComObjPtr<ExtPackManager> mptrExtPackManager;
624#endif
625
626 USBDeviceList mUSBDevices;
627 RemoteUSBDeviceList mRemoteUSBDevices;
628
629 SharedFolderMap mSharedFolders;
630 SharedFolderDataMap mMachineSharedFolders;
631 SharedFolderDataMap mGlobalSharedFolders;
632
633 /** The VM instance handle. */
634 PVM mpVM;
635 /** Holds the number of "readonly" mpVM callers (users) */
636 uint32_t mVMCallers;
637 /** Semaphore posted when the number of mpVM callers drops to zero */
638 RTSEMEVENT mVMZeroCallersSem;
639 /** true when Console has entered the mpVM destruction phase */
640 bool mVMDestroying : 1;
641 /** true when power down is initiated by vmstateChangeCallback (EMT) */
642 bool mVMPoweredOff : 1;
643 /** true when vmstateChangeCallback shouldn't initiate a power down. */
644 bool mVMIsAlreadyPoweringOff : 1;
645 /** true if we already showed the snapshot folder size warning. */
646 bool mfSnapshotFolderSizeWarningShown : 1;
647 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
648 bool mfSnapshotFolderExt4WarningShown : 1;
649
650 /** Pointer to the VMM -> User (that's us) callbacks.
651 * This structure is followed by a pointer to the Console object. */
652 PCVMM2USERMETHODS mpVmm2UserMethods;
653
654 /** The current network attachment type in the VM.
655 * This doesn't have to match the network attachment type maintained in the
656 * NetworkAdapter. This is needed to change the network attachment
657 * dynamically.
658 */
659 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
660
661 VMMDev * m_pVMMDev;
662 AudioSniffer * const mAudioSniffer;
663 BusAssignmentManager* mBusMgr;
664
665 enum
666 {
667 iLedFloppy = 0,
668 cLedFloppy = 1,
669 iLedIde = iLedFloppy + cLedFloppy,
670 cLedIde = 4,
671 iLedSata = iLedIde + cLedIde,
672 cLedSata = 30,
673 iLedScsi = iLedSata + cLedSata,
674 cLedScsi = 16,
675 iLedSas = iLedScsi + cLedScsi,
676 cLedSas = 8,
677 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
678 };
679 DeviceType_T maStorageDevType[cLedStorage];
680 PPDMLED mapStorageLeds[cLedStorage];
681 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
682 PPDMLED mapSharedFolderLed;
683 PPDMLED mapUSBLed[2];
684#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
685 Utf8Str maTAPDeviceName[8];
686 RTFILE maTapFD[8];
687#endif
688
689 bool mVMStateChangeCallbackDisabled;
690
691 /** Local machine state value. */
692 MachineState_T mMachineState;
693
694 /** Pointer to the progress object of a live cancelable task.
695 *
696 * This is currently only used by Console::Teleport(), but is intended to later
697 * be used by the live snapshot code path as well. Actions like
698 * Console::PowerDown, which automatically cancels out the running snapshot /
699 * teleportation operation, will cancel the teleportation / live snapshot
700 * operation before starting. */
701 ComObjPtr<Progress> mptrCancelableProgress;
702
703 struct
704 {
705 /** OnMousePointerShapeChange() cache */
706 struct
707 {
708 bool valid;
709 bool visible;
710 bool alpha;
711 uint32_t xHot;
712 uint32_t yHot;
713 uint32_t width;
714 uint32_t height;
715 com::SafeArray<BYTE> shape;
716 }
717 mpsc;
718
719 /** OnMouseCapabilityChange() cache */
720 struct
721 {
722 bool valid;
723 BOOL supportsAbsolute;
724 BOOL supportsRelative;
725 BOOL needsHostCursor;
726 }
727 mcc;
728
729 /** OnKeyboardLedsChange() cache */
730 struct
731 {
732 bool valid;
733 bool numLock;
734 bool capsLock;
735 bool scrollLock;
736 }
737 klc;
738
739 void clear()
740 {
741 /* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
742 mpsc.shape.setNull();
743 mpsc.valid = mpsc.visible = mpsc.alpha = false;
744 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
745 ::memset(&mcc, 0, sizeof mcc);
746 ::memset(&klc, 0, sizeof klc);
747 }
748 }
749 mCallbackData;
750 COM_STRUCT_OR_CLASS(IEventListener) *mVmListner;
751
752 friend struct VMTask;
753};
754
755#endif // !____H_CONSOLEIMPL
756/* vi: set tabstop=4 shiftwidth=4 expandtab: */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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