VirtualBox

Changeset 29804 in vbox for trunk/src


Ignore:
Timestamp:
May 26, 2010 9:52:08 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
62013
Message:

Main/Console: trigger callbacks even without a running VM, for consistency reasons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r29580 r29804  
    34173417    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    34183418
    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);
    34403431        AssertComRC(rc);
    34413432        if (SUCCEEDED(rc))
    34423433        {
    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);
    34493435            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))
    34523443            {
    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;
    34573458#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;
    34633464#endif
    34643465#ifdef VBOX_WITH_VIRTIO
    3465                 case NetworkAdapterType_Virtio:
    3466                     pszAdapterName = "virtio-net";
    3467                     break;
     3466                    case NetworkAdapterType_Virtio:
     3467                        pszAdapterName = "virtio-net";
     3468                        break;
    34683469#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))
    34843480                {
    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                    }
    34923493#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)
    34983495                    {
    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)
    35003499                        {
    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                            }
    35113513                        }
    35123514                    }
     3515#endif /* VBOX_DYNAMIC_NET_ATTACH */
    35133516                }
    3514 #endif /* VBOX_DYNAMIC_NET_ATTACH */
     3517
     3518                if (RT_FAILURE(vrc))
     3519                    rc = E_FAIL;
    35153520            }
    3516 
    3517             if (RT_FAILURE(vrc))
    3518                 rc = E_FAIL;
    35193521        }
    35203522    }
     
    37243726    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    37253727
    3726     /* Don't do anything if the VM isn't running */
    3727     if (!mpVM)
    3728         return S_OK;
    3729 
    37303728    HRESULT rc = S_OK;
    37313729
    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    }
    37373739
    37383740    /* notify console callbacks on success */
     
    37583760    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    37593761
    3760     /* Don't do anything if the VM isn't running */
    3761     if (!mpVM)
    3762         return S_OK;
    3763 
    37643762    HRESULT rc = S_OK;
    37653763
    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    }
    37713773
    37723774    /* notify console callbacks on success */
     
    37923794    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    37933795
    3794     /* Don't do anything if the VM isn't running */
    3795     if (!mpVM)
    3796         return S_OK;
    3797 
    37983796    HRESULT rc = S_OK;
    37993797
    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    }
    38053807
    38063808    /* notify console callbacks on success */
     
    38263828    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    38273829
    3828     /* Don't do anything if the VM isn't running */
    3829     if (!mpVM)
    3830         return S_OK;
    3831 
    38323830    HRESULT rc = S_OK;
    38333831
    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    }
    38393841
    38403842    /* notify console callbacks on success */
     
    38603862    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    38613863
    3862     /* Don't do anything if the VM isn't running */
    3863     if (!mpVM)
    3864         return S_OK;
    3865 
    38663864    HRESULT rc = S_OK;
    38673865
    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    }
    38763878
    38773879    /* notify console callbacks on success */
     
    39753977    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    39763978
    3977     /* Ignore if no VM is running yet. */
    3978     if (!mpVM)
    3979         return S_OK;
    3980 
    39813979    HRESULT rc = S_OK;
    39823980
    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    }
    39933997
    39943998    /* notify console callbacks on success */
Note: See TracChangeset for help on using the changeset viewer.

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