Whamcloud - gitweb
LU-1078 lnet: two minor issues in lnet
[fs/lustre-release.git] / lnet / selftest / conrpc.c
index 313ca9e..a4cc222 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -295,8 +295,12 @@ lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
 
                 cfs_spin_lock(&rpc->crpc_lock);
 
-                if (!crpc->crp_posted || crpc->crp_stamp != 0) {
-                        /* rpc done or aborted already */
+                if (!crpc->crp_posted || /* not posted */
+                    crpc->crp_stamp != 0) { /* rpc done or aborted already */
+                        if (crpc->crp_stamp == 0) {
+                                crpc->crp_stamp = cfs_time_current();
+                                crpc->crp_status = -EINTR;
+                        }
                         cfs_spin_unlock(&rpc->crpc_lock);
                         continue;
                 }
@@ -353,7 +357,7 @@ lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
                 lstcon_rpc_post(crpc);
         }
 
-        cfs_mutex_up(&console_session.ses_mutex);
+        cfs_mutex_unlock(&console_session.ses_mutex);
 
         cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq,
                                               lstcon_rpc_trans_check(trans),
@@ -361,12 +365,12 @@ lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
 
         rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
 
-        cfs_mutex_down(&console_session.ses_mutex);
+        cfs_mutex_lock(&console_session.ses_mutex);
 
         if (console_session.ses_shutdown)
                 rc = -ESHUTDOWN;
 
-        if (rc != 0) {
+        if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
                 /* treat short timeout as canceled */
                 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
                         rc = -EINTR;
@@ -423,7 +427,6 @@ void
 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
 {
         lstcon_rpc_t      *crpc;
-        srpc_client_rpc_t *rpc;
         srpc_msg_t        *rep;
         int                error;
 
@@ -435,8 +438,6 @@ lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
                                       lstcon_rpc_t, crp_link) {
                 lstcon_rpc_stat_total(stat, 1);
 
-                rpc = crpc->crp_rpc;
-
                 LASSERT (crpc->crp_stamp != 0);
 
                 error = lstcon_rpc_get_reply(crpc, &rep);
@@ -474,7 +475,6 @@ lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
         cfs_list_t           *next;
         lstcon_rpc_ent_t     *ent;
         srpc_generic_reply_t *rep;
-        srpc_client_rpc_t    *rpc;
         lstcon_rpc_t         *crpc;
         srpc_msg_t           *msg;
         lstcon_node_t        *nd;
@@ -499,8 +499,6 @@ lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
 
                 ent = cfs_list_entry(next, lstcon_rpc_ent_t, rpe_link);
 
-                rpc = crpc->crp_rpc;
-
                 LASSERT (crpc->crp_stamp != 0);
 
                 error = lstcon_rpc_get_reply(crpc, &msg);
@@ -703,31 +701,31 @@ lstcon_statrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
         return 0;
 }
 
-lnet_process_id_t *
+lnet_process_id_packed_t *
 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
 {
-        lnet_process_id_t *pid;
-        int                i;
+        lnet_process_id_packed_t *pid;
+        int                       i;
 
-        i = idx / (CFS_PAGE_SIZE / sizeof(lnet_process_id_t));
+        i = idx / SFW_ID_PER_PAGE;
         
         LASSERT (i < nkiov);
 
-        pid = (lnet_process_id_t *)cfs_page_address(kiov[i].kiov_page);
+        pid = (lnet_process_id_packed_t *)cfs_page_address(kiov[i].kiov_page);
 
-        return &pid[idx % (CFS_PAGE_SIZE / sizeof(lnet_process_id_t))];
+        return &pid[idx % SFW_ID_PER_PAGE];
 }
 
 int
 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
                      int dist, int span, int nkiov, lnet_kiov_t *kiov)
 {
-        lnet_process_id_t *pid;
-        lstcon_ndlink_t   *ndl;
-        lstcon_node_t     *nd;
-        int                start;
-        int                end;
-        int                i = 0;
+        lnet_process_id_packed_t *pid;
+        lstcon_ndlink_t          *ndl;
+        lstcon_node_t            *nd;
+        int                       start;
+        int                       end;
+        int                       i = 0;
 
         LASSERT (dist >= 1);
         LASSERT (span >= 1);
@@ -751,7 +749,8 @@ lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
                         break;
 
                 pid = lstcon_next_id((i - start), nkiov, kiov);
-                *pid = nd->nd_id;
+                pid->nid = nd->nd_id.nid;
+                pid->pid = nd->nd_id.pid;
                 i++;
         }
 
@@ -765,7 +764,8 @@ lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
 
                 nd = ndl->ndl_node;
                 pid = lstcon_next_id((i - start), nkiov, kiov);
-                *pid = nd->nd_id;
+                pid->nid = nd->nd_id.nid;
+                pid->pid = nd->nd_id.pid;
                 i++;
         }
 
@@ -1111,10 +1111,10 @@ lstcon_rpc_pinger(void *arg)
         /* RPC pinger is a special case of transaction,
          * it's called by timer at 8 seconds interval.
          */
-        cfs_mutex_down(&console_session.ses_mutex);
+        cfs_mutex_lock(&console_session.ses_mutex);
 
         if (console_session.ses_shutdown || console_session.ses_expired) {
-                cfs_mutex_up(&console_session.ses_mutex);
+                cfs_mutex_unlock(&console_session.ses_mutex);
                 return;
         }
 
@@ -1199,7 +1199,7 @@ lstcon_rpc_pinger(void *arg)
         }
 
         if (console_session.ses_expired) {
-                cfs_mutex_up(&console_session.ses_mutex);
+                cfs_mutex_unlock(&console_session.ses_mutex);
                 return;
         }
 
@@ -1208,7 +1208,7 @@ lstcon_rpc_pinger(void *arg)
         ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
         stt_add_timer(ptimer);
 
-        cfs_mutex_up(&console_session.ses_mutex);
+        cfs_mutex_unlock(&console_session.ses_mutex);
 }
 
 int
@@ -1274,13 +1274,13 @@ lstcon_rpc_cleanup_wait(void)
                         cfs_waitq_signal(&trans->tas_waitq);
                 }
 
-                cfs_mutex_up(&console_session.ses_mutex);
+                cfs_mutex_unlock(&console_session.ses_mutex);
 
                 CWARN("Session is shutting down, "
                       "waiting for termination of transactions\n");
                 cfs_pause(cfs_time_seconds(1));
 
-                cfs_mutex_down(&console_session.ses_mutex);
+                cfs_mutex_lock(&console_session.ses_mutex);
         }
 
         cfs_spin_lock(&console_session.ses_rpc_lock);