diff --git a/include/libnfs-private.h b/include/libnfs-private.h index 2077153..14511ad 100644 --- a/include/libnfs-private.h +++ b/include/libnfs-private.h @@ -118,6 +118,7 @@ struct rpc_context { struct rpc_queue outqueue; struct sockaddr_storage udp_src; struct rpc_queue waitpdu[HASHES]; + uint32_t waitpdu_len; uint32_t inpos; char rm_buf[4]; diff --git a/lib/init.c b/lib/init.c index 0b097b6..fe1b20f 100644 --- a/lib/init.c +++ b/lib/init.c @@ -275,6 +275,7 @@ void rpc_error_all_pdus(struct rpc_context *rpc, const char *error) } q->tail = NULL; } + rpc->waitpdu_len = 0; } static void rpc_free_fragment(struct rpc_fragment *fragment) diff --git a/lib/pdu.c b/lib/pdu.c index bb4c1ac..550ecd0 100644 --- a/lib/pdu.c +++ b/lib/pdu.c @@ -239,6 +239,7 @@ int rpc_queue_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu) hash = rpc_hash_xid(pdu->xid); rpc_enqueue(&rpc->waitpdu[hash], pdu); + rpc->waitpdu_len++; return 0; } @@ -547,6 +548,7 @@ int rpc_process_pdu(struct rpc_context *rpc, char *buf, int size) q->tail = prev_pdu; if (prev_pdu != NULL) prev_pdu->next = pdu->next; + rpc->waitpdu_len--; } if (rpc_process_reply(rpc, pdu, &zdr) != 0) { rpc_set_error(rpc, "rpc_procdess_reply failed"); diff --git a/lib/socket.c b/lib/socket.c index dbf664e..99b1ed1 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -216,6 +216,7 @@ static int rpc_write_to_socket(struct rpc_context *rpc) hash = rpc_hash_xid(pdu->xid); rpc_enqueue(&rpc->waitpdu[hash], pdu); + rpc->waitpdu_len++; } } return 0; @@ -709,6 +710,7 @@ static int rpc_reconnect_requeue(struct rpc_context *rpc) } rpc_reset_queue(q); } + rpc->waitpdu_len = 0; if (rpc->auto_reconnect != 0) { rpc->connect_cb = reconnect_cb; @@ -808,9 +810,8 @@ struct sockaddr *rpc_get_recv_sockaddr(struct rpc_context *rpc) int rpc_queue_length(struct rpc_context *rpc) { - int i=0; + int i = 0; struct rpc_pdu *pdu; - unsigned int n; assert(rpc->magic == RPC_CONTEXT_MAGIC); @@ -818,12 +819,8 @@ int rpc_queue_length(struct rpc_context *rpc) i++; } - for (n = 0; n < HASHES; n++) { - struct rpc_queue *q = &rpc->waitpdu[n]; + i += rpc->waitpdu_len; - for(pdu = q->head; pdu; pdu = pdu->next) - i++; - } return i; }