[IB] srp: don't post receive if no send buf available
authorRoland Dreier <rolandd@cisco.com>
Tue, 15 Nov 2005 08:19:21 +0000 (00:19 -0800)
committerRoland Dreier <rolandd@cisco.com>
Tue, 15 Nov 2005 08:19:21 +0000 (00:19 -0800)
Have __srp_get_tx_iu() fail if the target port's request limit will
not allow the initiator to post a send.  This avoids continuing on and
posting a receive, and then failing to post a corresponding send.  If
that happens, then the initiator will end up with an extra receive
posted, and if this happens to much, the receive queue will overflow.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
drivers/infiniband/ulp/srp/ib_srp.c

index a3645303cb99e16ba814d50daa7a211f008c534b..ee9fe226ae994408f50b1180632c8c4b9ba7d7db 100644 (file)
@@ -802,13 +802,21 @@ static int srp_post_recv(struct srp_target_port *target)
 
 /*
  * Must be called with target->scsi_host->host_lock held to protect
- * req_lim and tx_head.
+ * req_lim and tx_head.  Lock cannot be dropped between call here and
+ * call to __srp_post_send().
  */
 static struct srp_iu *__srp_get_tx_iu(struct srp_target_port *target)
 {
        if (target->tx_head - target->tx_tail >= SRP_SQ_SIZE)
                return NULL;
 
+       if (unlikely(target->req_lim < 1)) {
+               if (printk_ratelimit())
+                       printk(KERN_DEBUG PFX "Target has req_lim %d\n",
+                              target->req_lim);
+               return NULL;
+       }
+
        return target->tx_ring[target->tx_head & SRP_SQ_SIZE];
 }
 
@@ -823,11 +831,6 @@ static int __srp_post_send(struct srp_target_port *target,
        struct ib_send_wr wr, *bad_wr;
        int ret = 0;
 
-       if (target->req_lim < 1) {
-               printk(KERN_ERR PFX "Target has req_lim %d\n", target->req_lim);
-               return -EAGAIN;
-       }
-
        list.addr   = iu->dma;
        list.length = len;
        list.lkey   = target->srp_host->mr->lkey;