VirtualBox

Changeset 38492 in vbox


Ignore:
Timestamp:
Aug 19, 2011 3:24:58 AM (13 years ago)
Author:
vboxsync
Message:

NAT: logging.

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/debug.c

    r37938 r38492  
    3030#include <iprt/string.h>
    3131#include <iprt/stream.h>
     32#include <iprt/critsect.h>
     33#include "zone.h"
    3234
    3335#ifdef DEBUG
     
    362364}
    363365
     366/*
     367 * Prints zone state
     368 */
     369static DECLCALLBACK(size_t)
     370printMbufZone(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
     371                 const char *pszType, void const *pvValue,
     372                 int cchWidth, int cchPrecision, unsigned fFlags,
     373                 void *pvUser)
     374{
     375    size_t cb = 0;
     376    const uma_zone_t zone = (const uma_zone_t)pvValue;
     377    AssertReturn(RTStrCmp(pszType, "mzone") == 0, 0);
     378    if (!zone)
     379        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:NULL]");
     380    else
     381        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:%p name:%s, master_zone:%R[mzone]]",
     382                          zone, zone->name, zone->master_zone);
     383    return cb;
     384}
     385
     386/*
     387 * Prints zone's item state
     388 */
     389static DECLCALLBACK(size_t)
     390printMbufZoneItem(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
     391                 const char *pszType, void const *pvValue,
     392                 int cchWidth, int cchPrecision, unsigned fFlags,
     393                 void *pvUser)
     394{
     395    size_t cb = 0;
     396    const struct item *it = (const struct item *)pvValue;
     397    AssertReturn(RTStrCmp(pszType, "mzoneitem") == 0, 0);
     398    if (!it)
     399        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[item:NULL]");
     400    else
     401        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[iptem:%p ref_count:%d, zone:%R[mzone]]",
     402                          it, it->ref_count, it->zone);
     403    return cb;
     404}
     405
    364406static DECLCALLBACK(size_t)
    365407print_networkevents(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
     
    420462    {
    421463
    422         rc = RTStrFormatTypeRegister("natsock", print_socket, NULL);
    423         AssertRC(rc);
     464        rc = RTStrFormatTypeRegister("natsock", print_socket, NULL);            AssertRC(rc);
    424465        rc = RTStrFormatTypeRegister("natwinnetevents",
    425                                      print_networkevents, NULL);
    426         AssertRC(rc);
    427         rc = RTStrFormatTypeRegister("tcpcb793", printTcpcbRfc793, NULL);
    428         AssertRC(rc);
    429         rc = RTStrFormatTypeRegister("tcpseg793", printTcpSegmentRfc793, NULL);
    430         AssertRC(rc);
    431         rc = RTStrFormatTypeRegister("tcpstate", printTcpState, NULL);
    432         AssertRC(rc);
    433         rc = RTStrFormatTypeRegister("sbuf", printSbuf, NULL);
    434         AssertRC(rc);
     466                                     print_networkevents, NULL);                AssertRC(rc);
     467        rc = RTStrFormatTypeRegister("tcpcb793", printTcpcbRfc793, NULL);       AssertRC(rc);
     468        rc = RTStrFormatTypeRegister("tcpseg793", printTcpSegmentRfc793, NULL); AssertRC(rc);
     469        rc = RTStrFormatTypeRegister("tcpstate", printTcpState, NULL);          AssertRC(rc);
     470        rc = RTStrFormatTypeRegister("sbuf", printSbuf, NULL);                  AssertRC(rc);
     471        rc = RTStrFormatTypeRegister("mzone", printMbufZone, NULL);             AssertRC(rc);
     472        rc = RTStrFormatTypeRegister("mzoneitem", printMbufZoneItem, NULL);     AssertRC(rc);
    435473        g_fFormatRegistered = 1;
    436474    }
  • trunk/src/VBox/Devices/Network/slirp/misc.c

    r35957 r38492  
    2727#define WANT_SYS_IOCTL_H
    2828#include <slirp.h>
     29#include "zone.h"
    2930
    3031#ifndef HAVE_INET_ATON
     
    9798
    9899
    99 #define ITEM_MAGIC 0xdead0001
    100 struct item
    101 {
    102     uint32_t magic;
    103     uma_zone_t zone;
    104     uint32_t ref_count;
    105     LIST_ENTRY(item) list;
    106 };
    107 
    108 #define ZONE_MAGIC 0xdead0002
    109 struct uma_zone
    110 {
    111     uint32_t magic;
    112     PNATState pData; /* to minimize changes in the rest of UMA emulation code */
    113     RTCRITSECT csZone;
    114     const char *name;
    115     size_t size; /* item size */
    116     ctor_t pfCtor;
    117     dtor_t pfDtor;
    118     zinit_t pfInit;
    119     zfini_t pfFini;
    120     uma_alloc_t pfAlloc;
    121     uma_free_t pfFree;
    122     int max_items;
    123     int cur_items;
    124     LIST_HEAD(RT_NOTHING, item) used_items;
    125     LIST_HEAD(RT_NOTHING, item) free_items;
    126     uma_zone_t master_zone;
    127     void *area;
    128     /** Needs call pfnXmitPending when memory becomes available if @c true.
    129      * @remarks Only applies to the master zone (master_zone == NULL) */
    130     bool fDoXmitPending;
    131 };
    132100
    133101
     
    143111DECLINLINE(void) slirp_zone_check_and_send_pending(uma_zone_t zone)
    144112{
     113    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
    145114    if (   zone->fDoXmitPending
    146115        && zone->master_zone == NULL)
     
    154123        rc2 = RTCritSectEnter(&zone->csZone); AssertRC(rc2);
    155124    }
     125    LogFlowFuncLeave();
    156126}
    157127
     
    164134    int rc;
    165135
     136    LogFlowFunc(("ENTER: %R[mzone], size:%d, pflags:%p, %RTbool\n", zone, size, pflags, fWait));
    166137    RTCritSectEnter(&zone->csZone);
    167138    for (;;)
     
    229200    }
    230201    RTCritSectLeave(&zone->csZone);
     202    LogFlowFunc(("LEAVE: %p\n", ret));
    231203    return ret;
    232204}
     
    240212    Assert(item);
    241213    it = &((struct item *)item)[-1];
     214    LogFlowFunc(("ENTER: item:%p(%R[mzoneitem]), size:%d, flags:%RX8\n", item, it, size, flags));
    242215    Assert(it->magic == ITEM_MAGIC);
    243216    zone = it->zone;
     
    260233    slirp_zone_check_and_send_pending(zone); /* may exit+enter the cs! */
    261234    RTCritSectLeave(&zone->csZone);
     235    LogFlowFuncLeave();
    262236}
    263237
     
    265239                       ctor_t ctor, dtor_t dtor, zinit_t init, zfini_t fini, int flags1, int flags2)
    266240{
    267     uma_zone_t zone = RTMemAllocZ(sizeof(struct uma_zone));
     241    uma_zone_t zone = NULL;
     242    LogFlowFunc(("ENTER: name:%s size:%d, ctor:%p, dtor:%p, init:%p, fini:%p, flags1:%RX32, flags2:%RX32\n",
     243                name, ctor, dtor, init, fini, flags1, flags2));
     244    zone = RTMemAllocZ(sizeof(struct uma_zone));
    268245    Assert((pData));
    269246    zone->magic = ZONE_MAGIC;
     
    278255    zone->pfFree = slirp_uma_free;
    279256    RTCritSectInit(&zone->csZone);
     257    LogFlowFunc(("LEAVE: %R[mzone]\n", zone));
    280258    return zone;
    281259
     
    286264    uma_zone_t zone;
    287265    Assert(master);
     266    LogFlowFunc(("ENTER: name:%s ctor:%p, dtor:%p, init:%p, fini:%p, master:%R[mzone]\n",
     267                name, ctor, dtor, init, fini, master));
    288268    zone = RTMemAllocZ(sizeof(struct uma_zone));
    289269    if (zone == NULL)
     270    {
     271        LogFlowFunc(("LEAVE: %R[mzone]\n", NULL));
    290272        return NULL;
     273    }
    291274
    292275    Assert((master && master->pData));
     
    303286    zone->master_zone = master;
    304287    RTCritSectInit(&zone->csZone);
     288    LogFlowFunc(("LEAVE: %R[mzone]\n", zone));
    305289    return zone;
    306290}
     
    310294    int i = 0;
    311295    struct item *it;
     296    LogFlowFunc(("ENTER: zone:%R[mzone], max:%d\n", zone, max));
    312297    zone->max_items = max;
    313298    zone->area = RTMemAllocZ(max * (sizeof(struct item) + zone->size + sizeof(uint32_t)));
     
    320305        LIST_INSERT_HEAD(&zone->free_items, it, list);
    321306    }
    322 
     307    LogFlowFuncLeave();
    323308}
    324309
    325310void uma_zone_set_allocf(uma_zone_t zone, uma_alloc_t pfAlloc)
    326311{
    327    zone->pfAlloc = pfAlloc;
     312    LogFlowFunc(("ENTER: zone:%R[mzone], pfAlloc:%Rfn\n", zone, pfAlloc));
     313    zone->pfAlloc = pfAlloc;
     314    LogFlowFuncLeave();
    328315}
    329316
    330317void uma_zone_set_freef(uma_zone_t zone, uma_free_t pfFree)
    331318{
    332    zone->pfFree = pfFree;
     319    LogFlowFunc(("ENTER: zone:%R[mzone], pfAlloc:%Rfn\n", zone, pfFree));
     320    zone->pfFree = pfFree;
     321    LogFlowFuncLeave();
    333322}
    334323
     
    337326    /** @todo (vvl) this function supposed to work with special zone storing
    338327    reference counters */
    339     struct item *it = (struct item *)mem; /* 1st element */
     328    struct item *it = NULL;
     329    LogFlowFunc(("ENTER: zone:%R[mzone], mem:%p\n", zone, mem));
     330    it = (struct item *)mem; /* 1st element */
    340331    Assert(mem != NULL);
    341332    Assert(zone->magic == ZONE_MAGIC);
    342333    /* for returning pointer to counter we need get 0 elemnt */
    343334    Assert(it[-1].magic == ITEM_MAGIC);
     335    LogFlowFunc(("LEAVE: %p\n", &it[-1].ref_count));
    344336    return &it[-1].ref_count;
    345337}
     
    349341    void *mem;
    350342    Assert(zone->magic == ZONE_MAGIC);
     343    LogFlowFunc(("ENTER: zone:%R[mzone], args:%p, how:%RX32\n", zone, args, how));
    351344    if (zone->pfAlloc == NULL)
     345    {
     346        LogFlowFunc(("LEAVE: NULL\n"));
    352347        return NULL;
     348    }
    353349    RTCritSectEnter(&zone->csZone);
    354350    mem = zone->pfAlloc(zone, zone->size, NULL, 0);
     
    359355    }
    360356    RTCritSectLeave(&zone->csZone);
     357    LogFlowFunc(("LEAVE: %p\n", mem));
    361358    return mem;
    362359}
     
    364361void uma_zfree(uma_zone_t zone, void *item)
    365362{
     363    LogFlowFunc(("ENTER: zone:%R[mzone], item:%p\n", zone, item));
    366364    uma_zfree_arg(zone, item, NULL);
     365    LogFlowFuncLeave();
    367366}
    368367
     
    373372    Assert((zone->pfFree));
    374373    Assert((mem));
     374    LogFlowFunc(("ENTER: zone:%R[mzone], mem:%p, flags:%p\n", zone, mem, flags));
    375375
    376376    RTCritSectEnter(&zone->csZone);
     
    381381    zone->pfFree(mem,  0, 0);
    382382    RTCritSectLeave(&zone->csZone);
     383    LogFlowFuncLeave();
    383384}
    384385
     
    386387{
    387388    int fExhausted;
     389    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
    388390    RTCritSectEnter(&zone->csZone);
    389391    fExhausted = (zone->cur_items == zone->max_items);
    390392    RTCritSectLeave(&zone->csZone);
     393    LogFlowFunc(("LEAVE: %RTbool\n", fExhausted));
    391394    return fExhausted;
    392395}
     
    399402    /* vvl: Huh? What to do with zone which hasn't got backstore ? */
    400403    Assert((zone->master_zone));
     404    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
    401405    master_zone = zone->master_zone;
    402406    while (!LIST_EMPTY(&zone->free_items))
     
    418422        RTCritSectLeave(&master_zone->csZone);
    419423    }
     424    LogFlowFuncLeave();
    420425}
    421426
     
    423428{
    424429    /** @todo (vvl) make it wiser  */
     430    LogFlowFunc(("ENTER: mem:%p, arg:%p\n", mem, arg));
    425431    Assert(mem);
    426432    RTMemFree(mem);
     433    LogFlowFuncLeave();
    427434}
    428435
    429436void *uma_zalloc(uma_zone_t zone, int len)
    430437{
     438    LogFlowFunc(("ENTER: zone:%R[mzone], len:%d\n", zone, len));
     439    LogFlowFunc(("LEAVE: NULL"));
    431440    return NULL;
    432441}
     
    436445    struct mbuf *m;
    437446    size_t size = MCLBYTES;
     447    LogFlowFunc(("ENTER: cbMin:%d, ppvBuf:%p, pcbBuf:%p\n", cbMin, ppvBuf, pcbBuf));
    438448    if (cbMin < MSIZE)
    439449        size = MCLBYTES;
     
    452462        *ppvBuf = NULL;
    453463        *pcbBuf = 0;
     464        LogFlowFunc(("LEAVE: NULL\n"));
    454465        return NULL;
    455466    }
     
    457468    *ppvBuf = mtod(m, void *);
    458469    *pcbBuf = size;
     470    LogFlowFunc(("LEAVE: %p\n", m));
    459471    return m;
    460472}
     
    463475{
    464476
     477    LogFlowFunc(("ENTER: m:%p, pu8Buf:%p\n", m, pu8Buf));
    465478    if (   !pu8Buf
    466479        && pu8Buf != mtod(m, uint8_t *))
    467480        RTMemFree(pu8Buf); /* This buffer was allocated on heap */
    468481    m_freem(pData, m);
     482    LogFlowFuncLeave();
    469483}
    470484
     
    472486{
    473487    RTCritSectEnter(&zone->csZone);
     488    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
    474489    LogRel(("NAT: zone(nm:%s, used:%d)\n", zone->name, zone->cur_items));
    475490    if (zone->master_zone)
     
    478493    RTCritSectDelete(&zone->csZone);
    479494    RTMemFree(zone);
     495    LogFlowFuncLeave();
    480496}
    481497
    482498void m_fini(PNATState pData)
    483499{
     500    LogFlowFuncEnter();
    484501    zone_destroy(pData->zone_mbuf);
    485502    zone_destroy(pData->zone_clust);
     
    489506    zone_destroy(pData->zone_jumbo16);
    490507    /** @todo do finalize here.*/
     508    LogFlowFuncLeave();
    491509}
    492510
  • trunk/src/VBox/Devices/Network/slirp/misc.h

    r30016 r38492  
    4444struct uma_zone;
    4545typedef struct uma_zone *uma_zone_t;
     46
    4647typedef void *(*uma_alloc_t)(uma_zone_t, int, u_int8_t *, int);
    4748typedef void (*uma_free_t)(void *, int, u_int8_t);
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