Ticket #9377: 0001-Converted-the-net_interfaces-mutex-into-a-recursive-.patch

File 0001-Converted-the-net_interfaces-mutex-into-a-recursive-.patch, 5.3 KB (added by jackburton, 6 years ago)
  • src/add-ons/kernel/network/stack/interfaces.cpp

    From ddaf034ff89122b7ae165371674e14c492438c58 Mon Sep 17 00:00:00 2001
    From: Stefano Ceccherini <stefano.ceccherini@gmail.com>
    Date: Mon, 4 Feb 2013 11:30:55 +0100
    Subject: [PATCH] Converted the "net_interfaces" mutex into a recursive
     locker, and acquire it in Interface::SetDown().
    
    ---
     src/add-ons/kernel/network/stack/interfaces.cpp |   33 ++++++++++++-----------
     1 file changed, 17 insertions(+), 16 deletions(-)
    
    diff --git a/src/add-ons/kernel/network/stack/interfaces.cpp b/src/add-ons/kernel/network/stack/interfaces.cpp
    index 9a3c73b..54e7046 100644
    a b struct AddressHashDefinition { 
    7979typedef BOpenHashTable<AddressHashDefinition, true, false> AddressTable;
    8080
    8181
    82 static mutex sLock;
     82static recursive_lock sLock;
    8383static InterfaceList sInterfaces;
    8484static mutex sHashLock;
    8585static AddressTable sAddressTable;
    static uint32 sInterfaceIndex; 
    9191void
    9292dump_interface_refs(void)
    9393{
    94     MutexLocker locker(sLock);
     94    RecursiveLocker locker(sLock);
    9595
    9696    InterfaceList::Iterator iterator = sInterfaces.GetIterator();
    9797    while (Interface* interface = iterator.Next()) {
    Interface::SetDown() 
    933933    if ((flags & IFF_UP) == 0)
    934934        return;
    935935
     936    RecursiveLocker interfacesLocker(sLock);
    936937    RecursiveLocker locker(fLock);
    937938
    938939    DatalinkTable::Iterator iterator = fDatalinkTable.GetIterator();
    Interface::_ChangeAddress(RecursiveLocker& locker, InterfaceAddress* address, 
    11731174static struct Interface*
    11741175find_interface(const char* name)
    11751176{
    1176     ASSERT_LOCKED_MUTEX(&sLock);
     1177    ASSERT_LOCKED_RECURSIVE(&sLock);
    11771178
    11781179    InterfaceList::Iterator iterator = sInterfaces.GetIterator();
    11791180    while (Interface* interface = iterator.Next()) {
    status_t 
    12081209add_interface(const char* name, net_domain_private* domain,
    12091210    const ifaliasreq& request, net_device_interface* deviceInterface)
    12101211{
    1211     MutexLocker locker(sLock);
     1212    RecursiveLocker locker(sLock);
    12121213
    12131214    if (find_interface(name) != NULL)
    12141215        return B_NAME_IN_USE;
    remove_interface(Interface* interface) 
    12491250    interface->SetDown();
    12501251    interface->RemoveAddresses();
    12511252
    1252     MutexLocker locker(sLock);
     1253    RecursiveLocker locker(sLock);
    12531254    sInterfaces.Remove(interface);
    12541255    locker.Unlock();
    12551256
    remove_interface(Interface* interface) 
    12651266void
    12661267interface_removed_device_interface(net_device_interface* deviceInterface)
    12671268{
    1268     MutexLocker locker(sLock);
     1269    RecursiveLocker locker(sLock);
    12691270
    12701271    Interface* interface = find_interface(deviceInterface->device->name);
    12711272    if (interface != NULL)
    update_interface_address(InterfaceAddress* interfaceAddress, int32 option, 
    13961397Interface*
    13971398get_interface(net_domain* domain, uint32 index)
    13981399{
    1399     MutexLocker locker(sLock);
     1400    RecursiveLocker locker(sLock);
    14001401
    14011402    Interface* interface;
    14021403    if (index == 0)
    get_interface(net_domain* domain, uint32 index) 
    14171418Interface*
    14181419get_interface(net_domain* domain, const char* name)
    14191420{
    1420     MutexLocker locker(sLock);
     1421    RecursiveLocker locker(sLock);
    14211422
    14221423    Interface* interface = find_interface(name);
    14231424    if (interface == NULL)
    get_interface(net_domain* domain, const char* name) 
    14341435Interface*
    14351436get_interface_for_device(net_domain* domain, uint32 index)
    14361437{
    1437     MutexLocker locker(sLock);
     1438    RecursiveLocker locker(sLock);
    14381439
    14391440    InterfaceList::Iterator iterator = sInterfaces.GetIterator();
    14401441    while (Interface* interface = iterator.Next()) {
    get_interface_for_link(net_domain* domain, const sockaddr* _linkAddress) 
    14601461{
    14611462    sockaddr_dl& linkAddress = *(sockaddr_dl*)_linkAddress;
    14621463
    1463     MutexLocker locker(sLock);
     1464    RecursiveLocker locker(sLock);
    14641465
    14651466    InterfaceList::Iterator iterator = sInterfaces.GetIterator();
    14661467    while (Interface* interface = iterator.Next()) {
    InterfaceAddress* 
    15061507get_interface_address_for_destination(net_domain* domain,
    15071508    const sockaddr* destination)
    15081509{
    1509     MutexLocker locker(sLock);
     1510    RecursiveLocker locker(sLock);
    15101511
    15111512    InterfaceList::Iterator iterator = sInterfaces.GetIterator();
    15121513    while (Interface* interface = iterator.Next()) {
    get_interface_address_for_link(net_domain* domain, const sockaddr* address, 
    15331534{
    15341535    sockaddr_dl& linkAddress = *(sockaddr_dl*)address;
    15351536
    1536     MutexLocker locker(sLock);
     1537    RecursiveLocker locker(sLock);
    15371538
    15381539    InterfaceList::Iterator iterator = sInterfaces.GetIterator();
    15391540    while (Interface* interface = iterator.Next()) {
    get_interface_address_for_link(net_domain* domain, const sockaddr* address, 
    15581559uint32
    15591560count_interfaces()
    15601561{
    1561     MutexLocker locker(sLock);
     1562    RecursiveLocker locker(sLock);
    15621563
    15631564    return sInterfaces.Count();
    15641565}
    count_interfaces() 
    15711572status_t
    15721573list_interfaces(int family, void* _buffer, size_t* bufferSize)
    15731574{
    1574     MutexLocker locker(sLock);
     1575    RecursiveLocker locker(sLock);
    15751576
    15761577    UserBuffer buffer(_buffer, *bufferSize);
    15771578
    list_interfaces(int family, void* _buffer, size_t* bufferSize) 
    16191620status_t
    16201621init_interfaces()
    16211622{
    1622     mutex_init(&sLock, "net interfaces");
     1623    recursive_lock_init(&sLock, "net interfaces");
    16231624    mutex_init(&sHashLock, "net local addresses");
    16241625
    16251626    new (&sInterfaces) InterfaceList;
    uninit_interfaces() 
    16501651    remove_debugger_command("net_route", &dump_route);
    16511652#endif
    16521653
    1653     mutex_destroy(&sLock);
     1654    recursive_lock_destroy(&sLock);
    16541655    mutex_destroy(&sHashLock);
    16551656    return B_OK;
    16561657}