- Timestamp:
- May 26, 2010 9:52:08 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 62013
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r29580 r29804 3417 3417 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3418 3418 3419 /* Don't do anything if the VM isn't running */ 3420 if (!mpVM) 3421 return S_OK; 3422 3423 /* protect mpVM */ 3424 AutoVMCaller autoVMCaller(this); 3425 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3426 3427 /* Get the properties we need from the adapter */ 3428 BOOL fCableConnected, fTraceEnabled; 3429 HRESULT rc = aNetworkAdapter->COMGETTER(CableConnected)(&fCableConnected); 3430 AssertComRC(rc); 3431 if (SUCCEEDED(rc)) 3432 { 3433 rc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fTraceEnabled); 3434 AssertComRC(rc); 3435 } 3436 if (SUCCEEDED(rc)) 3437 { 3438 ULONG ulInstance; 3439 rc = aNetworkAdapter->COMGETTER(Slot)(&ulInstance); 3419 HRESULT rc = S_OK; 3420 3421 /* don't trigger network change if the VM isn't running */ 3422 if (mpVM) 3423 { 3424 /* protect mpVM */ 3425 AutoVMCaller autoVMCaller(this); 3426 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3427 3428 /* Get the properties we need from the adapter */ 3429 BOOL fCableConnected, fTraceEnabled; 3430 rc = aNetworkAdapter->COMGETTER(CableConnected)(&fCableConnected); 3440 3431 AssertComRC(rc); 3441 3432 if (SUCCEEDED(rc)) 3442 3433 { 3443 /* 3444 * Find the pcnet instance, get the config interface and update 3445 * the link state. 3446 */ 3447 NetworkAdapterType_T adapterType; 3448 rc = aNetworkAdapter->COMGETTER(AdapterType)(&adapterType); 3434 rc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fTraceEnabled); 3449 3435 AssertComRC(rc); 3450 const char *pszAdapterName = NULL; 3451 switch (adapterType) 3436 } 3437 if (SUCCEEDED(rc)) 3438 { 3439 ULONG ulInstance; 3440 rc = aNetworkAdapter->COMGETTER(Slot)(&ulInstance); 3441 AssertComRC(rc); 3442 if (SUCCEEDED(rc)) 3452 3443 { 3453 case NetworkAdapterType_Am79C970A: 3454 case NetworkAdapterType_Am79C973: 3455 pszAdapterName = "pcnet"; 3456 break; 3444 /* 3445 * Find the pcnet instance, get the config interface and update 3446 * the link state. 3447 */ 3448 NetworkAdapterType_T adapterType; 3449 rc = aNetworkAdapter->COMGETTER(AdapterType)(&adapterType); 3450 AssertComRC(rc); 3451 const char *pszAdapterName = NULL; 3452 switch (adapterType) 3453 { 3454 case NetworkAdapterType_Am79C970A: 3455 case NetworkAdapterType_Am79C973: 3456 pszAdapterName = "pcnet"; 3457 break; 3457 3458 #ifdef VBOX_WITH_E1000 3458 case NetworkAdapterType_I82540EM:3459 case NetworkAdapterType_I82543GC:3460 case NetworkAdapterType_I82545EM:3461 pszAdapterName = "e1000";3462 break;3459 case NetworkAdapterType_I82540EM: 3460 case NetworkAdapterType_I82543GC: 3461 case NetworkAdapterType_I82545EM: 3462 pszAdapterName = "e1000"; 3463 break; 3463 3464 #endif 3464 3465 #ifdef VBOX_WITH_VIRTIO 3465 case NetworkAdapterType_Virtio:3466 pszAdapterName = "virtio-net";3467 break;3466 case NetworkAdapterType_Virtio: 3467 pszAdapterName = "virtio-net"; 3468 break; 3468 3469 #endif 3469 default: 3470 AssertFailed(); 3471 pszAdapterName = "unknown"; 3472 break; 3473 } 3474 3475 PPDMIBASE pBase; 3476 int vrc = PDMR3QueryDeviceLun(mpVM, pszAdapterName, ulInstance, 0, &pBase); 3477 ComAssertRC(vrc); 3478 if (RT_SUCCESS(vrc)) 3479 { 3480 Assert(pBase); 3481 PPDMINETWORKCONFIG pINetCfg; 3482 pINetCfg = PDMIBASE_QUERY_INTERFACE(pBase, PDMINETWORKCONFIG); 3483 if (pINetCfg) 3470 default: 3471 AssertFailed(); 3472 pszAdapterName = "unknown"; 3473 break; 3474 } 3475 3476 PPDMIBASE pBase; 3477 int vrc = PDMR3QueryDeviceLun(mpVM, pszAdapterName, ulInstance, 0, &pBase); 3478 ComAssertRC(vrc); 3479 if (RT_SUCCESS(vrc)) 3484 3480 { 3485 Log(("Console::onNetworkAdapterChange: setting link state to %d\n", 3486 fCableConnected)); 3487 vrc = pINetCfg->pfnSetLinkState(pINetCfg, 3488 fCableConnected ? PDMNETWORKLINKSTATE_UP 3489 : PDMNETWORKLINKSTATE_DOWN); 3490 ComAssertRC(vrc); 3491 } 3481 Assert(pBase); 3482 PPDMINETWORKCONFIG pINetCfg; 3483 pINetCfg = PDMIBASE_QUERY_INTERFACE(pBase, PDMINETWORKCONFIG); 3484 if (pINetCfg) 3485 { 3486 Log(("Console::onNetworkAdapterChange: setting link state to %d\n", 3487 fCableConnected)); 3488 vrc = pINetCfg->pfnSetLinkState(pINetCfg, 3489 fCableConnected ? PDMNETWORKLINKSTATE_UP 3490 : PDMNETWORKLINKSTATE_DOWN); 3491 ComAssertRC(vrc); 3492 } 3492 3493 #ifdef VBOX_DYNAMIC_NET_ATTACH 3493 if (RT_SUCCESS(vrc) && changeAdapter) 3494 { 3495 VMSTATE enmVMState = VMR3GetState(mpVM); 3496 if ( enmVMState == VMSTATE_RUNNING /** @todo LiveMigration: Forbit or deal correctly with the _LS variants */ 3497 || enmVMState == VMSTATE_SUSPENDED) 3494 if (RT_SUCCESS(vrc) && changeAdapter) 3498 3495 { 3499 if (fTraceEnabled && fCableConnected && pINetCfg) 3496 VMSTATE enmVMState = VMR3GetState(mpVM); 3497 if ( enmVMState == VMSTATE_RUNNING /** @todo LiveMigration: Forbid or deal correctly with the _LS variants */ 3498 || enmVMState == VMSTATE_SUSPENDED) 3500 3499 { 3501 vrc = pINetCfg->pfnSetLinkState(pINetCfg, PDMNETWORKLINKSTATE_DOWN); 3502 ComAssertRC(vrc); 3503 } 3504 3505 rc = doNetworkAdapterChange(pszAdapterName, ulInstance, 0, aNetworkAdapter); 3506 3507 if (fTraceEnabled && fCableConnected && pINetCfg) 3508 { 3509 vrc = pINetCfg->pfnSetLinkState(pINetCfg, PDMNETWORKLINKSTATE_UP); 3510 ComAssertRC(vrc); 3500 if (fTraceEnabled && fCableConnected && pINetCfg) 3501 { 3502 vrc = pINetCfg->pfnSetLinkState(pINetCfg, PDMNETWORKLINKSTATE_DOWN); 3503 ComAssertRC(vrc); 3504 } 3505 3506 rc = doNetworkAdapterChange(pszAdapterName, ulInstance, 0, aNetworkAdapter); 3507 3508 if (fTraceEnabled && fCableConnected && pINetCfg) 3509 { 3510 vrc = pINetCfg->pfnSetLinkState(pINetCfg, PDMNETWORKLINKSTATE_UP); 3511 ComAssertRC(vrc); 3512 } 3511 3513 } 3512 3514 } 3515 #endif /* VBOX_DYNAMIC_NET_ATTACH */ 3513 3516 } 3514 #endif /* VBOX_DYNAMIC_NET_ATTACH */ 3517 3518 if (RT_FAILURE(vrc)) 3519 rc = E_FAIL; 3515 3520 } 3516 3517 if (RT_FAILURE(vrc))3518 rc = E_FAIL;3519 3521 } 3520 3522 } … … 3724 3726 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3725 3727 3726 /* Don't do anything if the VM isn't running */3727 if (!mpVM)3728 return S_OK;3729 3730 3728 HRESULT rc = S_OK; 3731 3729 3732 /* protect mpVM */ 3733 AutoVMCaller autoVMCaller(this); 3734 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3735 3736 /* nothing to do so far */ 3730 /* don't trigger serial port change if the VM isn't running */ 3731 if (mpVM) 3732 { 3733 /* protect mpVM */ 3734 AutoVMCaller autoVMCaller(this); 3735 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3736 3737 /* nothing to do so far */ 3738 } 3737 3739 3738 3740 /* notify console callbacks on success */ … … 3758 3760 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3759 3761 3760 /* Don't do anything if the VM isn't running */3761 if (!mpVM)3762 return S_OK;3763 3764 3762 HRESULT rc = S_OK; 3765 3763 3766 /* protect mpVM */ 3767 AutoVMCaller autoVMCaller(this); 3768 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3769 3770 /* nothing to do so far */ 3764 /* don't trigger parallel port change if the VM isn't running */ 3765 if (mpVM) 3766 { 3767 /* protect mpVM */ 3768 AutoVMCaller autoVMCaller(this); 3769 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3770 3771 /* nothing to do so far */ 3772 } 3771 3773 3772 3774 /* notify console callbacks on success */ … … 3792 3794 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3793 3795 3794 /* Don't do anything if the VM isn't running */3795 if (!mpVM)3796 return S_OK;3797 3798 3796 HRESULT rc = S_OK; 3799 3797 3800 /* protect mpVM */ 3801 AutoVMCaller autoVMCaller(this); 3802 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3803 3804 /* nothing to do so far */ 3798 /* don't trigger storage controller change if the VM isn't running */ 3799 if (mpVM) 3800 { 3801 /* protect mpVM */ 3802 AutoVMCaller autoVMCaller(this); 3803 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3804 3805 /* nothing to do so far */ 3806 } 3805 3807 3806 3808 /* notify console callbacks on success */ … … 3826 3828 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3827 3829 3828 /* Don't do anything if the VM isn't running */3829 if (!mpVM)3830 return S_OK;3831 3832 3830 HRESULT rc = S_OK; 3833 3831 3834 /* protect mpVM */ 3835 AutoVMCaller autoVMCaller(this); 3836 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3837 3838 rc = doMediumChange(aMediumAttachment, !!aForce); 3832 /* don't trigger medium change if the VM isn't running */ 3833 if (mpVM) 3834 { 3835 /* protect mpVM */ 3836 AutoVMCaller autoVMCaller(this); 3837 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3838 3839 rc = doMediumChange(aMediumAttachment, !!aForce); 3840 } 3839 3841 3840 3842 /* notify console callbacks on success */ … … 3860 3862 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3861 3863 3862 /* Don't do anything if the VM isn't running */3863 if (!mpVM)3864 return S_OK;3865 3866 3864 HRESULT rc = S_OK; 3867 3865 3868 /* protect mpVM */ 3869 AutoVMCaller autoVMCaller(this); 3870 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3871 3872 if (aRemove) 3873 rc = doCPURemove(aCPU); 3874 else 3875 rc = doCPUAdd(aCPU); 3866 /* don't trigger CPU change if the VM isn't running */ 3867 if (mpVM) 3868 { 3869 /* protect mpVM */ 3870 AutoVMCaller autoVMCaller(this); 3871 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3872 3873 if (aRemove) 3874 rc = doCPURemove(aCPU); 3875 else 3876 rc = doCPUAdd(aCPU); 3877 } 3876 3878 3877 3879 /* notify console callbacks on success */ … … 3975 3977 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3976 3978 3977 /* Ignore if no VM is running yet. */3978 if (!mpVM)3979 return S_OK;3980 3981 3979 HRESULT rc = S_OK; 3982 3980 3983 /// @todo (dmik) 3984 // check for the Enabled state and disable virtual USB controller?? 3985 // Anyway, if we want to query the machine's USB Controller we need to cache 3986 // it to mUSBController in #init() (as it is done with mDVDDrive). 3987 // 3988 // bird: While the VM supports hot-plugging, I doubt any guest can handle it at this time... :-) 3989 // 3990 // /* protect mpVM */ 3991 // AutoVMCaller autoVMCaller(this); 3992 // if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3981 /* don't trigger USB controller change if the VM isn't running */ 3982 if (mpVM) 3983 { 3984 /// @todo implement one day. 3985 // Anyway, if we want to query the machine's USB Controller we need 3986 // to cache it to mUSBController in #init() (similar to mDVDDrive). 3987 // 3988 // bird: While the VM supports hot-plugging, I doubt any guest can 3989 // handle it at this time... :-) 3990 3991 /* protect mpVM */ 3992 AutoVMCaller autoVMCaller(this); 3993 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3994 3995 /* nothing to do so far */ 3996 } 3993 3997 3994 3998 /* notify console callbacks on success */
Note:
See TracChangeset
for help on using the changeset viewer.