Whamcloud - gitweb
LU-10391 lnet: extend rspt_next_hop_nid in lnet_rsp_tracker
[fs/lustre-release.git] / lnet / selftest / rpc.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef __SELFTEST_RPC_H__
33 #define __SELFTEST_RPC_H__
34
35 #include <uapi/linux/lnet/lnetst.h>
36
37 /*
38  * LST wired structures
39  *
40  * XXX: *REPLY == *REQST + 1
41  */
42 enum srpc_msg_type {
43         SRPC_MSG_MKSN_REQST     = 0,
44         SRPC_MSG_MKSN_REPLY     = 1,
45         SRPC_MSG_RMSN_REQST     = 2,
46         SRPC_MSG_RMSN_REPLY     = 3,
47         SRPC_MSG_BATCH_REQST    = 4,
48         SRPC_MSG_BATCH_REPLY    = 5,
49         SRPC_MSG_STAT_REQST     = 6,
50         SRPC_MSG_STAT_REPLY     = 7,
51         SRPC_MSG_TEST_REQST     = 8,
52         SRPC_MSG_TEST_REPLY     = 9,
53         SRPC_MSG_DEBUG_REQST    = 10,
54         SRPC_MSG_DEBUG_REPLY    = 11,
55         SRPC_MSG_BRW_REQST      = 12,
56         SRPC_MSG_BRW_REPLY      = 13,
57         SRPC_MSG_PING_REQST     = 14,
58         SRPC_MSG_PING_REPLY     = 15,
59         SRPC_MSG_JOIN_REQST     = 16,
60         SRPC_MSG_JOIN_REPLY     = 17,
61 };
62
63 /* CAVEAT EMPTOR:
64  * All struct srpc_*_reqst's 1st field must be matchbits of reply buffer,
65  * and 2nd field matchbits of bulk buffer if any.
66  *
67  * All struct srpc_*_reply's 1st field must be a __u32 status, and 2nd field
68  * session id if needed.
69  */
70 struct srpc_generic_reqst {
71         __u64                   rpyid;          /* reply buffer matchbits */
72         __u64                   bulkid;         /* bulk buffer matchbits */
73 } __packed;
74
75 struct srpc_generic_reply {
76         __u32                   status;
77         struct lst_sid               sid;
78 } __packed;
79
80 /* FRAMEWORK RPCs */
81 struct srpc_mksn_reqst {
82         __u64                   mksn_rpyid;      /* reply buffer matchbits */
83         struct lst_sid               mksn_sid;        /* session id */
84         __u32                   mksn_force;      /* use brute force */
85         char                    mksn_name[LST_NAME_SIZE];
86 } __packed;                                     /* make session request */
87
88 struct srpc_mksn_reply {
89         __u32                   mksn_status;      /* session status */
90         struct lst_sid               mksn_sid;         /* session id */
91         __u32                   mksn_timeout;     /* session timeout */
92         char                    mksn_name[LST_NAME_SIZE];
93 } __packed;                                     /* make session reply */
94
95 struct srpc_rmsn_reqst {
96         __u64                   rmsn_rpyid;     /* reply buffer matchbits */
97         struct lst_sid          rmsn_sid;       /* session id */
98 } __packed;                                     /* remove session request */
99
100 struct srpc_rmsn_reply {
101         __u32                   rmsn_status;
102         struct lst_sid          rmsn_sid;       /* session id */
103 } __packed;                                     /* remove session reply */
104
105 struct srpc_join_reqst {
106         __u64                   join_rpyid;     /* reply buffer matchbits */
107         struct lst_sid               join_sid;       /* session id to join */
108         char                    join_group[LST_NAME_SIZE]; /* group name */
109 } __packed;
110
111 struct srpc_join_reply {
112         __u32                   join_status;    /* returned status */
113         struct lst_sid               join_sid;       /* session id */
114         __u32                   join_timeout;   /* # seconds' inactivity to expire */
115         char                    join_session[LST_NAME_SIZE]; /* session name */
116 } __packed;
117
118 struct srpc_debug_reqst {
119         __u64                   dbg_rpyid;      /* reply buffer matchbits */ 
120         struct lst_sid               dbg_sid;        /* session id */
121         __u32                   dbg_flags;      /* bitmap of debug */
122 } __packed;
123
124 struct srpc_debug_reply {
125         __u32                   dbg_status;     /* returned code */
126         struct lst_sid               dbg_sid;        /* session id */
127         __u32                   dbg_timeout;    /* session timeout */
128         __u32                   dbg_nbatch;     /* # of batches in the node */
129         char                    dbg_name[LST_NAME_SIZE]; /* session name */
130 } __packed;
131
132 #define SRPC_BATCH_OPC_RUN      1
133 #define SRPC_BATCH_OPC_STOP     2
134 #define SRPC_BATCH_OPC_QUERY    3
135
136 struct srpc_batch_reqst {
137         __u64                   bar_rpyid;      /* reply buffer matchbits */ 
138         struct lst_sid               bar_sid;        /* session id */
139         struct lst_bid               bar_bid;        /* batch id */
140         __u32                   bar_opc;        /* create/start/stop batch */
141         __u32                   bar_testidx;    /* index of test */
142         __u32                   bar_arg;        /* parameters */
143 } __packed;
144
145 struct srpc_batch_reply {
146         __u32                   bar_status;     /* status of request */
147         struct lst_sid          bar_sid;        /* session id */
148         __u32                   bar_active;     /* # of active tests in batch/test */
149         __u32                   bar_time;       /* remained time */
150 } __packed;
151
152 struct srpc_stat_reqst {
153         __u64                   str_rpyid;      /* reply buffer matchbits */
154         struct lst_sid          str_sid;        /* session id */
155         __u32                   str_type;       /* type of stat */
156 } __packed;
157
158 struct srpc_stat_reply {
159         __u32                    str_status;
160         struct lst_sid           str_sid;
161         struct sfw_counters      str_fw;
162         struct srpc_counters     str_rpc;
163         struct lnet_counters_common str_lnet;
164 } __packed;
165
166 struct test_bulk_req {
167         __u32                   blk_opc;        /* bulk operation code */
168         __u32                   blk_npg;        /* # of pages */
169         __u32                   blk_flags;      /* reserved flags */
170 } __packed;
171
172 struct test_bulk_req_v1 {
173         /** bulk operation code */
174         __u16                   blk_opc;
175         /** data check flags */
176         __u16                   blk_flags;
177         /** data length */
178         __u32                   blk_len;
179         /** bulk offset */
180         __u32                   blk_offset;
181 } __packed;
182
183 struct test_ping_req {
184         __u32                   png_size;       /* size of ping message */
185         __u32                   png_flags;      /* reserved flags */
186 } __packed;
187
188 struct srpc_test_reqst {
189         __u64                   tsr_rpyid;      /* reply buffer matchbits */
190         __u64                   tsr_bulkid;     /* bulk buffer matchbits */
191         struct lst_sid          tsr_sid;        /* session id */
192         struct lst_bid          tsr_bid;        /* batch id */
193         __u32                   tsr_service;    /* test type: bulk|ping|... */
194         /* test client loop count or # server buffers needed */
195         __u32                   tsr_loop;
196         __u32                   tsr_concur;     /* concurrency of test */
197         __u8                    tsr_is_client;  /* is test client or not */
198         __u8                    tsr_stop_onerr; /* stop on error */
199         __u32                   tsr_ndest;      /* # of dest nodes */
200
201         union {
202                 struct test_ping_req    ping;
203                 struct test_bulk_req    bulk_v0;
204                 struct test_bulk_req_v1 bulk_v1;
205         } tsr_u;
206 } __packed;
207
208 struct srpc_test_reply {
209         __u32                   tsr_status;     /* returned code */
210         struct lst_sid          tsr_sid;
211 } __packed;
212
213 /* TEST RPCs */
214 struct srpc_ping_reqst {
215         __u64                   pnr_rpyid;
216         __u32                   pnr_magic;
217         __u32                   pnr_seq;
218         __u64                   pnr_time_sec;
219         __u64                   pnr_time_nsec;
220 } __packed;
221
222 struct srpc_ping_reply {
223         __u32                   pnr_status;
224         __u32                   pnr_magic;
225         __u32                   pnr_seq;
226 } __packed;
227
228 struct srpc_brw_reqst {
229         __u64                   brw_rpyid;      /* reply buffer matchbits */
230         __u64                   brw_bulkid;     /* bulk buffer matchbits */
231         __u32                   brw_rw;         /* read or write */
232         __u32                   brw_len;        /* bulk data len */
233         __u32                   brw_flags;      /* bulk data patterns */
234 } __packed;                                     /* bulk r/w request */
235
236 struct srpc_brw_reply {
237         __u32                   brw_status;
238 } __packed; /* bulk r/w reply */
239
240 #define SRPC_MSG_MAGIC                  0xeeb0f00d
241 #define SRPC_MSG_VERSION                1
242
243 struct srpc_msg {
244         /** magic number */
245         __u32   msg_magic;
246         /** message version number */
247         __u32   msg_version;
248         /** type of message body: enum srpc_msg_type */
249         __u32   msg_type;
250         __u32   msg_reserved0;
251         __u32   msg_reserved1;
252         /** test session features */
253         __u32   msg_ses_feats;
254         union {
255                 struct srpc_generic_reqst       reqst;
256                 struct srpc_generic_reply       reply;
257
258                 struct srpc_mksn_reqst          mksn_reqst;
259                 struct srpc_mksn_reply          mksn_reply;
260                 struct srpc_rmsn_reqst          rmsn_reqst;
261                 struct srpc_rmsn_reply          rmsn_reply;
262                 struct srpc_debug_reqst         dbg_reqst;
263                 struct srpc_debug_reply         dbg_reply;
264                 struct srpc_batch_reqst         bat_reqst;
265                 struct srpc_batch_reply         bat_reply;
266                 struct srpc_stat_reqst          stat_reqst;
267                 struct srpc_stat_reply          stat_reply;
268                 struct srpc_test_reqst          tes_reqst;
269                 struct srpc_test_reply          tes_reply;
270                 struct srpc_join_reqst          join_reqst;
271                 struct srpc_join_reply          join_reply;
272
273                 struct srpc_ping_reqst          ping_reqst;
274                 struct srpc_ping_reply          ping_reply;
275                 struct srpc_brw_reqst           brw_reqst;
276                 struct srpc_brw_reply           brw_reply;
277         } msg_body;
278 } __packed;
279
280 static inline void
281 srpc_unpack_msg_hdr(struct srpc_msg *msg)
282 {
283         if (msg->msg_magic == SRPC_MSG_MAGIC)
284                 return; /* no flipping needed */
285
286         /* We do not swap the magic number here as it is needed to
287            determine whether the body needs to be swapped. */
288         /* __swab32s(&msg->msg_magic); */
289         __swab32s(&msg->msg_type);
290         __swab32s(&msg->msg_version);
291         __swab32s(&msg->msg_ses_feats);
292         __swab32s(&msg->msg_reserved0);
293         __swab32s(&msg->msg_reserved1);
294 }
295
296 #endif /* __SELFTEST_RPC_H__ */