Whamcloud - gitweb
Land b_release_1_4_3 onto HEAD (20050619_0305)
[fs/lustre-release.git] / lnet / klnds / iiblnd / iiblnd_cb.c
index a827ba5..eb9e6fa 100644 (file)
@@ -485,17 +485,20 @@ kibnal_rx_callback (IB_WORK_COMPLETION *wc)
                         goto failed;
                 }
 
+                if (flipped) {
+                        __swab32(msg->ibm_u.rdma.rd_key);
+                }
+
                 for(i = 0; i < msg->ibm_u.rdma.ibrm_num_descs; i++) {
                         kib_rdma_desc_t *desc = &msg->ibm_u.rdma.ibrm_desc[i];
 
                         if (flipped) {
-                                __swab32(desc->rd_key);
                                 __swab32(desc->rd_nob);
                                 __swab64(desc->rd_addr);
                         }
 
                         CDEBUG(D_NET, "  key %x, " "addr "LPX64", nob %u\n",
-                               desc->rd_key, desc->rd_addr, desc->rd_nob);
+                               msg->ibm_u.rdma.rd_key, desc->rd_addr, desc->rd_nob);
                 }
                 break;
                         
@@ -628,9 +631,9 @@ kibnal_fill_ibrm(kib_tx_t *tx, struct page *page, unsigned long page_offset,
 
         desc = &ibrm->ibrm_desc[ibrm->ibrm_num_descs];
         if (active)
-                desc->rd_key = kibnal_data.kib_md.md_lkey;
+                ibrm->rd_key = kibnal_data.kib_md.md_lkey;
         else
-                desc->rd_key = kibnal_data.kib_md.md_rkey;
+                ibrm->rd_key = kibnal_data.kib_md.md_rkey;
         desc->rd_nob = len; /*PAGE_SIZE - kiov->kiov_offset; */
         desc->rd_addr = kibnal_page2phys(page) + page_offset +
                         kibnal_data.kib_md.md_addr;
@@ -845,7 +848,7 @@ kibnal_map_kiov (kib_tx_t *tx, IB_ACCESS_CONTROL access,
                 tx->tx_mapped = KIB_TX_MAPPED;
 #endif
         } else {
-                CERROR ("Can't map phys: %d\n", rc);
+                CERROR ("Can't map phys: %d\n", frc);
                 rc = -EFAULT;
         }
 
@@ -1090,6 +1093,10 @@ kibnal_ca_callback (void *ca_arg, void *cq_arg)
 
         for(;;) {
                 while (iibt_cq_poll(cq, &wc) == FSUCCESS) {
+
+                        /* We will need to rearm the CQ to avoid a potential race. */
+                        armed = 0;
+                        
                         if (kibnal_wreqid_is_rx(wc.WorkReqId))
                                 kibnal_rx_callback(&wc);
                         else
@@ -1175,11 +1182,11 @@ kibnal_launch_tx (kib_tx_t *tx, ptl_nid_t nid)
         LASSERT (tx->tx_conn == NULL);          /* only set when assigned a conn */
         LASSERT (tx->tx_nsp > 0);               /* work items have been set up */
 
-        read_lock (g_lock);
+        read_lock_irqsave(g_lock, flags);
         
         peer = kibnal_find_peer_locked (nid);
         if (peer == NULL) {
-                read_unlock (g_lock);
+                read_unlock_irqrestore(g_lock, flags);
                 tx->tx_status = -EHOSTUNREACH;
                 kibnal_tx_done (tx);
                 return;
@@ -1191,15 +1198,15 @@ kibnal_launch_tx (kib_tx_t *tx, ptl_nid_t nid)
                        conn, conn->ibc_state, conn->ibc_peer->ibp_nid,
                        atomic_read (&conn->ibc_refcount));
                 atomic_inc (&conn->ibc_refcount); /* 1 ref for the tx */
-                read_unlock (g_lock);
+                read_unlock_irqrestore(g_lock, flags);
                 
                 kibnal_queue_tx (tx, conn);
                 return;
         }
         
         /* Making one or more connections; I'll need a write lock... */
-        read_unlock (g_lock);
-        write_lock_irqsave (g_lock, flags);
+        read_unlock(g_lock);
+        write_lock(g_lock);
 
         peer = kibnal_find_peer_locked (nid);
         if (peer == NULL) {
@@ -1306,7 +1313,7 @@ kibnal_start_passive_rdma (int type, ptl_nid_t nid,
         ibmsg->ibm_u.rdma.ibrm_cookie = tx->tx_passive_rdma_cookie;
         /* map_kiov alrady filled the rdma descs for the whole_mem case */
         if (!kibnal_whole_mem()) {
-                ibmsg->ibm_u.rdma.ibrm_desc[0].rd_key = tx->tx_md.md_rkey;
+                ibmsg->ibm_u.rdma.rd_key = tx->tx_md.md_rkey;
                 ibmsg->ibm_u.rdma.ibrm_desc[0].rd_addr = tx->tx_md.md_addr;
                 ibmsg->ibm_u.rdma.ibrm_desc[0].rd_nob = nob;
                 ibmsg->ibm_u.rdma.ibrm_num_descs = 1;
@@ -1408,7 +1415,7 @@ kibnal_start_active_rdma (int type, int status,
         } 
 
         if (!kibnal_whole_mem()) {
-                tx->tx_msg->ibm_u.rdma.ibrm_desc[0].rd_key = tx->tx_md.md_lkey;
+                tx->tx_msg->ibm_u.rdma.rd_key = tx->tx_md.md_lkey;
                 tx->tx_msg->ibm_u.rdma.ibrm_desc[0].rd_addr = tx->tx_md.md_addr;
                 tx->tx_msg->ibm_u.rdma.ibrm_desc[0].rd_nob = nob;
                 tx->tx_msg->ibm_u.rdma.ibrm_num_descs = 1;
@@ -1439,7 +1446,7 @@ kibnal_start_active_rdma (int type, int status,
 
                 ds->Address = ldesc->rd_addr;
                 ds->Length  = ldesc->rd_nob;
-                ds->Lkey    = ldesc->rd_key;
+                ds->Lkey    = tx->tx_msg->ibm_u.rdma.rd_key;
 
                 memset(wrq, 0, sizeof(*wrq));
                 wrq->WorkReqId      = kibnal_ptr2wreqid(tx, 0);
@@ -1453,7 +1460,7 @@ kibnal_start_active_rdma (int type, int status,
                 wrq->Req.SendRC.Options.s.ImmediateData          = 0;
                 wrq->Req.SendRC.Options.s.Fence                  = 0;
                 wrq->Req.SendRC.RemoteDS.Address = rdesc->rd_addr;
-                wrq->Req.SendRC.RemoteDS.Rkey = rdesc->rd_key;
+                wrq->Req.SendRC.RemoteDS.Rkey = rxmsg->ibm_u.rdma.rd_key;
 
                 /* only the last rdma post triggers tx completion */
                 if (i == rxmsg->ibm_u.rdma.ibrm_num_descs - 1)
@@ -1479,7 +1486,7 @@ init_tx:
         } else {
                 LASSERT (tx->tx_nsp == 1);
                 /* No RDMA: local completion happens now! */
-                CDEBUG(D_WARNING,"No data: immediate completion\n");
+                CWARN("No data: immediate completion\n");
                 lib_finalize (&kibnal_lib, NULL, libmsg,
                               status == 0 ? PTL_OK : PTL_FAIL);
         }
@@ -1770,9 +1777,9 @@ kibnal_close_conn_locked (kib_conn_t *conn, int error)
                 atomic_inc (&conn->ibc_refcount);
         }
         
-        if (list_empty (&peer->ibp_conns) &&
-            peer->ibp_persistence == 0) {
-                /* Non-persistent peer with no more conns... */
+        if (list_empty (&peer->ibp_conns) &&    /* no more conns */
+            peer->ibp_persistence == 0 &&       /* non-persistent peer */
+            kibnal_peer_active(peer)) {         /* still in peer table */
                 kibnal_unlink_peer_locked (peer);
         }
 
@@ -2394,7 +2401,9 @@ kibnal_listen_callback(IB_HANDLE cep, CM_CONN_INFO *info, void *arg)
         PORTAL_ALLOC(rep, sizeof(*rep));
         PORTAL_ALLOC(rcv, sizeof(*rcv));
         if (rep == NULL || rcv == NULL) {
-                CERROR ("can't reply and receive buffers\n");
+                if (rep) PORTAL_FREE(rep, sizeof(*rep));
+                if (rcv) PORTAL_FREE(rcv, sizeof(*rcv));
+                CERROR ("can't allocate reply and receive buffers\n");
                 GOTO(out, reason = RC_INSUFFICIENT_RESP_RES);
         }
 
@@ -2440,7 +2449,7 @@ kibnal_listen_callback(IB_HANDLE cep, CM_CONN_INFO *info, void *arg)
                 goto out;
         }
 
-        CDEBUG(D_WARNING, "Connection %p -> "LPX64" ESTABLISHED.\n",
+        CWARN("Connection %p -> "LPX64" ESTABLISHED.\n",
                conn, conn->ibc_peer->ibp_nid);
 
 out:
@@ -2747,12 +2756,13 @@ kibnal_check_conns (int idx)
         kib_peer_t        *peer;
         kib_conn_t        *conn;
         struct list_head  *ctmp;
+        unsigned long      flags;
 
  again:
         /* NB. We expect to have a look at all the peers and not find any
          * rdmas to time out, so we just use a shared lock while we
          * take a look... */
-        read_lock (&kibnal_data.kib_global_lock);
+        read_lock_irqsave(&kibnal_data.kib_global_lock, flags);
 
         list_for_each (ptmp, peers) {
                 peer = list_entry (ptmp, kib_peer_t, ibp_list);
@@ -2775,7 +2785,8 @@ kibnal_check_conns (int idx)
                                atomic_read (&conn->ibc_refcount));
 
                         atomic_inc (&conn->ibc_refcount);
-                        read_unlock (&kibnal_data.kib_global_lock);
+                        read_unlock_irqrestore(&kibnal_data.kib_global_lock,
+                                               flags);
 
                         CERROR("Timed out RDMA with "LPX64"\n",
                                peer->ibp_nid);
@@ -2788,7 +2799,7 @@ kibnal_check_conns (int idx)
                 }
         }
 
-        read_unlock (&kibnal_data.kib_global_lock);
+        read_unlock_irqrestore(&kibnal_data.kib_global_lock, flags);
 }
 
 static void