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