VirtualBox

Changeset 2805 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 23, 2007 1:45:31 PM (18 years ago)
Author:
vboxsync
Message:

Main: Fixed: Machine-level USB filters are now inserted to the USB proxy only upon VM startup and removed upon termination (defect #1975).

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

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

    r2672 r2805  
    37993799        }
    38003800
    3801         releaseAllUSBDevices();
     3801        /* If the machine has an USB comtroller, release all USB devices
     3802         * (symmectric to the code in captureUSBDevices()) */
     3803        {
     3804            PPDMIBASE pBase;
     3805            int vrc = PDMR3QueryLun (mpVM, "usb-ohci", 0, 0, &pBase);
     3806            if (VBOX_SUCCESS (vrc))
     3807                releaseAllUSBDevices();
     3808        }
    38023809
    38033810        /*
     
    42884295
    42894296/**
    4290  *  USB device attack callback used by AttachUSBDevice().
     4297 *  USB device attach callback used by AttachUSBDevice().
    42914298 *  Note that AttachUSBDevice() doesn't return until this callback is executed,
    42924299 *  so we don't use AutoCaller and don't care about reference counters of
     
    43494356
    43504357/**
    4351  *  USB device attack callback used by AttachUSBDevice().
    4352  *  Note that AttachUSBDevice() doesn't return until this callback is executed,
     4358 *  USB device detach callback used by DetachUSBDevice().
     4359 *  Note that DetachUSBDevice() doesn't return until this callback is executed,
    43534360 *  so we don't use AutoCaller and don't care about reference counters of
    43544361 *  interface pointers passed in.
  • trunk/src/VBox/Main/HostImpl.cpp

    r2587 r2805  
    12941294 *  of IUSBDevice instances.
    12951295 *
    1296  *  Called by Console from the VM process (through IInternalMachineControl).
     1296 *  Called by Console from the VM process (through IInternalMachineControl)
     1297 *  upon VM startup.
     1298 *
     1299 *  @note Locks this object for reading (@todo for writing now, until switched
     1300 *  to the new locking scheme).
    12971301 */
    12981302HRESULT Host::autoCaptureUSBDevices (SessionMachine *aMachine,
    12991303                                     IUSBDeviceCollection **aHostDevices)
    13001304{
    1301     LogFlowMember (("Host::autoCaptureUSBDevices: aMachine=%p\n", aMachine));
     1305    LogFlowThisFunc (("aMachine=%p\n", aMachine));
    13021306
    13031307    AutoLock lock (this);
     
    13211325            if (device->state() == USBDeviceState_USBDeviceCaptured)
    13221326            {
    1323                 // put the device to the return list
     1327                /* put the device to the return list */
    13241328                ComPtr <IUSBDevice> d;
    13251329                device.queryInterfaceTo (d.asOutParam());
     
    13431347 *  by the given machine (excluding this machine's filters).
    13441348 *
    1345  *  Called by Console from the VM process (throug IInternalMachineControl).
     1349 *  Called by Console from the VM process (throug IInternalMachineControl)
     1350 *  upon normal VM termination or by SessionMachine::uninit() upon abnormal
     1351 *  VM termination (from under the Machine/SessionMachine lock).
     1352 *
     1353 *  @note Locks this object for reading (@todo for writing now, until switched
     1354 *  to the new locking scheme).
    13461355 */
    13471356HRESULT Host::releaseAllUSBDevices (SessionMachine *aMachine)
     
    13561365        if (device->machine() == aMachine)
    13571366        {
    1358             // reset the device and apply filters
     1367            /* reset the device and apply filters */
    13591368            device->reset();
    13601369            HRESULT rc = applyAllUSBFilters (device, aMachine);
     
    15111520    LogFlowMember (("Host::applyAllUSBFilters: \n"));
    15121521
    1513     // ignore unsupported devices
     1522    /* ignore unsupported devices */
    15141523    if (aDevice->state() == USBDeviceState_USBDeviceNotSupported)
    15151524        return S_OK;
    1516     // ignore unavailable devices as well
     1525    /* ignore unavailable devices as well */
    15171526    if (aDevice->state() == USBDeviceState_USBDeviceUnavailable)
    15181527        return S_OK;
     
    15211530    mParent->getOpenedMachines (machines);
    15221531
    1523     // apply global filters
     1532    /* apply global filters */
    15241533    USBDeviceFilterList::const_iterator it = mUSBDeviceFilters.begin();
    15251534    while (it != mUSBDeviceFilters.end())
     
    15371546    }
    15381547
    1539     // apply machine filters
     1548    /* apply machine filters */
    15401549    for (size_t i = 0; i < machines.size(); i++)
    15411550    {
     
    15591568    }
    15601569
    1561     // no machine filters were matched.
    1562     // if no global filters were matched as well, release the device
    1563     // to make it available on the host
     1570    /* no machine filters were matched.
     1571     * if no global filters were matched as well, release the device
     1572     * to make it available on the host */
    15641573    if (    it == mUSBDeviceFilters.end()
    15651574        &&  aDevice->state() == USBDeviceState_USBDeviceHeld)
  • trunk/src/VBox/Main/USBControllerImpl.cpp

    r1 r2805  
    295295    CHECK_READY();
    296296
    297     CHECK_MACHINE_MUTABILITY (m_Parent);
     297    /* the machine needs to be mutable */
     298    Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent);
     299    CheckComRCReturnRC (adep.rc());
    298300
    299301    ComObjPtr <USBDeviceFilter> filter = getDependentChild (aFilter);
     
    307309            tr ("The given USB device filter is already in the list"));
    308310
    309     // backup the list before modification
     311    /* backup the list before modification */
    310312    m_DeviceFilters.backup();
    311313
    312     // iterate to the position...
     314    /* iterate to the position... */
    313315    DeviceFilterList::iterator it;
    314316    if (aPosition < m_DeviceFilters->size())
     
    319321    else
    320322        it = m_DeviceFilters->end();
    321     // ...and insert
     323    /* ...and insert */
    322324    m_DeviceFilters->insert (it, filter);
    323325    filter->mInList = true;
    324326
    325     // notify the proxy (only when the filter is active)
     327    /// @todo After rewriting Win32 USB support, no more necessary;
     328    //  a candidate for removal.
     329#if 0
     330    /* notify the proxy (only when the filter is active) */
    326331    if (filter->data().mActive)
     332#else
     333    /* notify the proxy (only when it makes sense) */
     334    if (filter->data().mActive && adep.machineState() >= MachineState_Running)
     335#endif
    327336    {
    328337        USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService();
     
    345354    CHECK_READY();
    346355
    347     CHECK_MACHINE_MUTABILITY (m_Parent);
     356    /* the machine needs to be mutable */
     357    Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent);
     358    CheckComRCReturnRC (adep.rc());
    348359
    349360    if (!m_DeviceFilters->size())
     
    356367            aPosition, m_DeviceFilters->size() - 1);
    357368
    358     // backup the list before modification
     369    /* backup the list before modification */
    359370    m_DeviceFilters.backup();
    360371
    361372    ComObjPtr <USBDeviceFilter> filter;
    362373    {
    363         // iterate to the position...
     374        /* iterate to the position... */
    364375        DeviceFilterList::iterator it = m_DeviceFilters->begin();
    365376        std::advance (it, aPosition);
    366         // ...get an element from there...
     377        /* ...get an element from there... */
    367378        filter = *it;
    368         // ...and remove
     379        /* ...and remove */
    369380        filter->mInList = false;
    370381        m_DeviceFilters->erase (it);
    371382    }
    372383
    373     // cancel sharing (make an independent copy of data)
     384    /* cancel sharing (make an independent copy of data) */
    374385    filter->unshare();
    375386
    376387    filter.queryInterfaceTo (aFilter);
    377388
    378     // notify the proxy (only when the filter is active)
     389    /// @todo After rewriting Win32 USB support, no more necessary;
     390    //  a candidate for removal.
     391#if 0
     392    /* notify the proxy (only when the filter is active) */
    379393    if (filter->data().mActive)
     394#else
     395    /* notify the proxy (only when it makes sense) */
     396    if (filter->data().mActive && adep.machineState() >= MachineState_Running)
     397#endif
    380398    {
    381399        USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService();
     
    607625bool USBController::rollback()
    608626{
    609     AutoLock alock(this);
     627    AutoLock alock (this);
     628
     629    /* we need the machine state */
     630    Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent);
     631    AssertComRCReturn (adep.rc(), false);
    610632
    611633    bool dataChanged = false;
     
    613635    if (m_Data.isBackedUp())
    614636    {
    615         // we need to check all data to see whether anything will be changed
    616         // after rollback
     637        /* we need to check all data to see whether anything will be changed
     638         * after rollback */
    617639        dataChanged = m_Data.hasActualChanges();
    618640        m_Data.rollback();
     
    624646        ComAssertRet (service, false);
    625647
    626         // uninitialize all new filters (absent in the backed up list)
     648        /* uninitialize all new filters (absent in the backed up list) */
    627649        DeviceFilterList::const_iterator it = m_DeviceFilters->begin();
    628650        DeviceFilterList *backedList = m_DeviceFilters.backedUpData();
     
    632654                backedList->end())
    633655            {
    634                 // notify the proxy (only when the filter is active)
     656    /// @todo After rewriting Win32 USB support, no more necessary;
     657    //  a candidate for removal.
     658#if 0
     659                /* notify the proxy (only when the filter is active) */
    635660                if ((*it)->data().mActive)
     661#else
     662                /* notify the proxy (only when it makes sense) */
     663                if ((*it)->data().mActive &&
     664                    adep.machineState() >= MachineState_Running)
     665#endif
    636666                {
    637667                    USBDeviceFilter *filter = *it;
     
    646676        }
    647677
    648         // find all removed old filters (absent in the new list)
    649         // and insert them back to the USB proxy
    650         it = backedList->begin();
    651         while (it != backedList->end())
    652         {
    653             if (std::find (m_DeviceFilters->begin(), m_DeviceFilters->end(), *it) ==
    654                 m_DeviceFilters->end())
     678    /// @todo After rewriting Win32 USB support, no more necessary;
     679    //  a candidate for removal.
     680#if 0
     681#else
     682        if (adep.machineState() >= MachineState_Running)
     683#endif
     684        {
     685            /* find all removed old filters (absent in the new list)
     686             * and insert them back to the USB proxy */
     687            it = backedList->begin();
     688            while (it != backedList->end())
    655689            {
    656                 // notify the proxy (only when the filter is active)
    657                 if ((*it)->data().mActive)
     690                if (std::find (m_DeviceFilters->begin(), m_DeviceFilters->end(), *it) ==
     691                    m_DeviceFilters->end())
    658692                {
    659                     USBDeviceFilter *flt = *it; // resolve ambiguity
    660                     ComAssertRet (flt->id() == NULL, false);
    661                     flt->id() = service->insertFilter (ComPtr <IUSBDeviceFilter> (flt));
     693                    /* notify the proxy (only when necessary) */
     694                    if ((*it)->data().mActive)
     695                    {
     696                        USBDeviceFilter *flt = *it; /* resolve ambiguity */
     697                        ComAssertRet (flt->id() == NULL, false);
     698                        flt->id() = service->insertFilter
     699                            (ComPtr <IUSBDeviceFilter> (flt));
     700                    }
    662701                }
     702                ++ it;
    663703            }
    664             ++ it;
    665         }
    666 
    667         // restore the list
     704        }
     705
     706        /* restore the list */
    668707        m_DeviceFilters.rollback();
    669708    }
    670709
    671     // rollback any changes to filters after restoring the list
     710    /* here we don't depend on the machine state any more */
     711    adep.release();
     712
     713    /* rollback any changes to filters after restoring the list */
    672714    DeviceFilterList::const_iterator it = m_DeviceFilters->begin();
    673715    while (it != m_DeviceFilters->end())
     
    676718        {
    677719            (*it)->rollback();
    678             // call this to notify the USB proxy about changes
     720            /* call this to notify the USB proxy about changes */
    679721            onDeviceFilterChange (*it);
    680722        }
     
    821863    CHECK_READY();
    822864
    823     USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService();
    824     ComAssertRet (service, E_FAIL);
    825 
    826     // iterate over the filter list and notify the proxy accordingly
    827 
    828     DeviceFilterList::const_iterator it = m_DeviceFilters->begin();
    829     while (it != m_DeviceFilters->end())
    830     {
    831         USBDeviceFilter *flt = *it; // resolve ambiguity (for ComPtr below)
    832 
    833         // notify the proxy (only if the filter is active)
    834         if (flt->data().mActive)
    835         {
    836             if (aRegistered)
    837             {
    838                 ComAssertRet (flt->id() == NULL, E_FAIL);
    839                 flt->id() = service->insertFilter (ComPtr <IUSBDeviceFilter> (flt));
    840             }
    841             else
    842             {
    843                 ComAssertRet (flt->id() != NULL, E_FAIL);
    844                 service->removeFilter (flt->id());
    845                 flt->id() = NULL;
    846             }
    847         }
    848         ++ it;
    849     }
     865    /// @todo After rewriting Win32 USB support, no more necessary;
     866    //  a candidate for removal.
     867#if 0
     868    notifyProxy (!!aRegistered);
     869#endif
    850870
    851871    return S_OK;
     
    861881    CHECK_READY();
    862882
     883    /// @todo After rewriting Win32 USB support, no more necessary;
     884    //  a candidate for removal.
     885#if 0
     886#else
     887    /* we need the machine state */
     888    Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent);
     889    AssertComRCReturnRC (adep.rc());
     890
     891    /* nothing to do if the machine isn't running */
     892    if (adep.machineState() < MachineState_Running)
     893        return S_OK;
     894#endif
     895
    863896    if (aFilter->mInList && m_Parent->isRegistered())
    864897    {
     
    868901        if (aActiveChanged)
    869902        {
    870             // insert/remove the filter from the proxy
     903            /* insert/remove the filter from the proxy */
    871904            if (aFilter->data().mActive)
    872905            {
    873906                ComAssertRet (aFilter->id() == NULL, E_FAIL);
    874                 aFilter->id() =
    875                     service->insertFilter (ComPtr <IUSBDeviceFilter> (aFilter));
     907                aFilter->id() = service->insertFilter
     908                    (ComPtr <IUSBDeviceFilter> (aFilter));
    876909            }
    877910            else
     
    886919            if (aFilter->data().mActive)
    887920            {
    888                 // update the filter in the proxy
     921                /* update the filter in the proxy */
    889922                ComAssertRet (aFilter->id() != NULL, E_FAIL);
    890923                service->removeFilter (aFilter->id());
    891                 aFilter->id() =
    892                     service->insertFilter (ComPtr <IUSBDeviceFilter> (aFilter));
     924                aFilter->id() = service->insertFilter
     925                    (ComPtr <IUSBDeviceFilter> (aFilter));
    893926            }
    894927        }
     
    936969bool USBController::hasMatchingFilter (IUSBDevice *aUSBDevice)
    937970{
    938     LogFlowMember (("USBController::hasMatchingFilter()\n"));
     971    LogFlowThisFunc (("\n"));
    939972
    940973    AutoLock alock (this);
     
    10271060}
    10281061
     1062HRESULT USBController::notifyProxy (bool aInsertFilters)
     1063{
     1064    LogFlowThisFunc (("aInsertFilters=%RTbool\n", aInsertFilters));
     1065
     1066    AutoLock alock (this);
     1067    if (!isReady())
     1068        return false;
     1069
     1070    USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService();
     1071    AssertReturn (service, E_FAIL);
     1072
     1073    DeviceFilterList::const_iterator it = m_DeviceFilters->begin();
     1074    while (it != m_DeviceFilters->end())
     1075    {
     1076        USBDeviceFilter *flt = *it; /* resolve ambiguity (for ComPtr below) */
     1077
     1078        /* notify the proxy (only if the filter is active) */
     1079        if (flt->data().mActive)
     1080        {
     1081            if (aInsertFilters)
     1082            {
     1083                AssertReturn (flt->id() == NULL, E_FAIL);
     1084                flt->id() = service->insertFilter
     1085                    (ComPtr <IUSBDeviceFilter> (flt));
     1086            }
     1087            else
     1088            {
     1089                AssertReturn (flt->id() != NULL, E_FAIL);
     1090                service->removeFilter (flt->id());
     1091                flt->id() = NULL;
     1092            }
     1093        }
     1094        ++ it;
     1095    }
     1096
     1097    return S_OK;
     1098}
     1099
    10291100// private methods
    10301101/////////////////////////////////////////////////////////////////////////////
  • trunk/src/VBox/Main/include/USBControllerImpl.h

    r1 r2805  
    111111    bool hasMatchingFilter (IUSBDevice *aUSBDevice);
    112112
     113    HRESULT notifyProxy (bool aInsertFilters);
     114
    113115    // for VirtualBoxSupportErrorInfoImpl
    114116    static const wchar_t *getComponentName() { return L"USBController"; }
Note: See TracChangeset for help on using the changeset viewer.

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