Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[fs/lustre-release.git] / lustre / portals / portals / lib-ni.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * lib/lib-ni.c
5  * Network status registers and distance functions.
6  *
7  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
8  *  Copyright (c) 2001-2002 Sandia National Laboratories
9  *
10  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #define DEBUG_SUBSYSTEM S_PORTALS
27 #include <portals/lib-p30.h>
28 #include <portals/arg-blocks.h>
29
30 #define MAX_DIST 18446744073709551615ULL
31
32 int do_PtlNIDebug(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
33 {
34         PtlNIDebug_in *args = v_args;
35         PtlNIDebug_out *ret = v_ret;
36         lib_ni_t *ni = &nal->ni;
37
38         ret->rc = ni->debug;
39         ni->debug = args->mask_in;
40
41         return 0;
42 }
43
44 int do_PtlNIStatus(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
45 {
46         /*
47          * Incoming:
48          *      ptl_handle_ni_t interface_in
49          *      ptl_sr_index_t register_in
50          *
51          * Outgoing:
52          *      ptl_sr_value_t          * status_out
53          */
54
55         PtlNIStatus_in *args = v_args;
56         PtlNIStatus_out *ret = v_ret;
57         lib_ni_t *ni = &nal->ni;
58         lib_counters_t *count = &ni->counters;
59
60         if (!args)
61                 return ret->rc = PTL_SEGV;
62
63         ret->rc = PTL_OK;
64         ret->status_out = 0;
65
66         /*
67          * I hate this sort of code....  Hash tables, offset lists?
68          * Treat the counters as an array of ints?
69          */
70         if (args->register_in == PTL_SR_DROP_COUNT)
71                 ret->status_out = count->drop_count;
72
73         else if (args->register_in == PTL_SR_DROP_LENGTH)
74                 ret->status_out = count->drop_length;
75
76         else if (args->register_in == PTL_SR_RECV_COUNT)
77                 ret->status_out = count->recv_count;
78
79         else if (args->register_in == PTL_SR_RECV_LENGTH)
80                 ret->status_out = count->recv_length;
81
82         else if (args->register_in == PTL_SR_SEND_COUNT)
83                 ret->status_out = count->send_count;
84
85         else if (args->register_in == PTL_SR_SEND_LENGTH)
86                 ret->status_out = count->send_length;
87
88         else if (args->register_in == PTL_SR_MSGS_MAX)
89                 ret->status_out = count->msgs_max;
90         else
91                 ret->rc = PTL_SR_INDEX_INVALID;
92
93         return ret->rc;
94 }
95
96
97 int do_PtlNIDist(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
98 {
99         /*
100          * Incoming:
101          *      ptl_handle_ni_t interface_in
102          *      ptl_process_id_t process_in
103
104          *
105          * Outgoing:
106          *      unsigned long   * distance_out
107
108          */
109
110         PtlNIDist_in *args = v_args;
111         PtlNIDist_out *ret = v_ret;
112
113         unsigned long dist;
114         ptl_process_id_t id_in = args->process_in;
115         ptl_nid_t nid;
116         int rc;
117
118         nid = id_in.nid;
119
120         if ((rc = nal->cb_dist(nal, nid, &dist)) != 0) {
121                 ret->distance_out = (unsigned long) MAX_DIST;
122                 return PTL_PROCESS_INVALID;
123         }
124
125         ret->distance_out = dist;
126
127         return ret->rc = PTL_OK;
128 }