X-Git-Url: http://git.openafs.org/?p=openafs.git;a=blobdiff_plain;f=src%2Frx%2Frx_packet.c;h=214f3079a11d05e5eb7a0de759ae2d0bfb1f8a3c;hp=37f9957467a1c208705418cd51bcb45cce50f2ef;hb=5b28061fb593f5f48df549b07f0ccd848348b93c;hpb=f591f6fae3d8b8d44140ca64e53bad840aeeeba0 diff --git a/src/rx/rx_packet.c b/src/rx/rx_packet.c index 37f9957..214f307 100644 --- a/src/rx/rx_packet.c +++ b/src/rx/rx_packet.c @@ -72,6 +72,15 @@ #include "rx_conn.h" #include "rx_call.h" +/*! + * \brief structure used to keep track of allocated packets + */ +struct rx_mallocedPacket { + struct opr_queue entry; /*!< chained using opr_queue */ + struct rx_packet *addr; /*!< address of the first element */ + afs_uint32 size; /*!< array size in bytes */ +}; + #ifdef RX_LOCKS_DB /* rxdb_fileID is used to identify the lock location, along with line#. */ static int rxdb_fileID = RXDB_FILE_RX_PACKET; @@ -536,6 +545,33 @@ rxi_AllocDataBuf(struct rx_packet *p, int nb, int class) return nb; } +/** + * Register allocated packets. + * + * @param[in] addr array of packets + * @param[in] npkt number of packets + * + * @return none + */ +static void +registerPackets(struct rx_packet *addr, afs_uint32 npkt) +{ + struct rx_mallocedPacket *mp; + + mp = osi_Alloc(sizeof(*mp)); + + osi_Assert(mp != NULL); + memset(mp, 0, sizeof(*mp)); + + mp->addr = addr; + mp->size = npkt * sizeof(struct rx_packet); + osi_Assert(npkt <= MAX_AFS_UINT32 / sizeof(struct rx_packet)); + + MUTEX_ENTER(&rx_mallocedPktQ_lock); + opr_queue_Append(&rx_mallocedPacketQueue, &mp->entry); + MUTEX_EXIT(&rx_mallocedPktQ_lock); +} + /* Add more packet buffers */ #ifdef RX_ENABLE_TSFPQ void @@ -549,6 +585,7 @@ rxi_MorePackets(int apackets) getme = apackets * sizeof(struct rx_packet); p = osi_Alloc(getme); osi_Assert(p); + registerPackets(p, apackets); PIN(p, getme); /* XXXXX */ memset(p, 0, getme); @@ -603,6 +640,7 @@ rxi_MorePackets(int apackets) getme = apackets * sizeof(struct rx_packet); p = osi_Alloc(getme); osi_Assert(p); + registerPackets(p, apackets); PIN(p, getme); /* XXXXX */ memset(p, 0, getme); @@ -645,6 +683,7 @@ rxi_MorePacketsTSFPQ(int apackets, int flush_global, int num_keep_local) getme = apackets * sizeof(struct rx_packet); p = osi_Alloc(getme); + registerPackets(p, apackets); PIN(p, getme); /* XXXXX */ memset(p, 0, getme); @@ -713,6 +752,7 @@ rxi_MorePacketsNoLock(int apackets) } } while(p == NULL); memset(p, 0, getme); + registerPackets(p, apackets); #ifdef RX_ENABLE_TSFPQ RX_TS_INFO_GET(rx_ts_info); @@ -749,11 +789,19 @@ rxi_MorePacketsNoLock(int apackets) void rxi_FreeAllPackets(void) { - /* must be called at proper interrupt level, etcetera */ - /* MTUXXX need to free all Packets */ - osi_Free(rx_mallocedP, - (rx_maxReceiveWindow + 2) * sizeof(struct rx_packet)); - UNPIN(rx_mallocedP, (rx_maxReceiveWindow + 2) * sizeof(struct rx_packet)); + struct rx_mallocedPacket *mp; + + MUTEX_ENTER(&rx_mallocedPktQ_lock); + + while (!opr_queue_IsEmpty(&rx_mallocedPacketQueue)) { + mp = opr_queue_First(&rx_mallocedPacketQueue, + struct rx_mallocedPacket, entry); + opr_queue_Remove(&mp->entry); + osi_Free(mp->addr, mp->size); + UNPIN(mp->addr, mp->size); + osi_Free(mp, sizeof(*mp)); + } + MUTEX_EXIT(&rx_mallocedPktQ_lock); } #ifdef RX_ENABLE_TSFPQ