Whamcloud - gitweb
LU-1346 libcfs: cleanup macros in kp30.h
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __SELFTEST_RPC_H__
38 #define __SELFTEST_RPC_H__
39
40 #include <lnet/lnetst.h>
41
42 /*
43  * LST wired structures
44  * 
45  * XXX: *REPLY == *REQST + 1
46  */
47 typedef enum {
48         SRPC_MSG_MKSN_REQST     = 0,
49         SRPC_MSG_MKSN_REPLY     = 1,
50         SRPC_MSG_RMSN_REQST     = 2,
51         SRPC_MSG_RMSN_REPLY     = 3,
52         SRPC_MSG_BATCH_REQST    = 4,
53         SRPC_MSG_BATCH_REPLY    = 5,
54         SRPC_MSG_STAT_REQST     = 6,
55         SRPC_MSG_STAT_REPLY     = 7,
56         SRPC_MSG_TEST_REQST     = 8,
57         SRPC_MSG_TEST_REPLY     = 9,
58         SRPC_MSG_DEBUG_REQST    = 10,
59         SRPC_MSG_DEBUG_REPLY    = 11,
60         SRPC_MSG_BRW_REQST      = 12,
61         SRPC_MSG_BRW_REPLY      = 13,
62         SRPC_MSG_PING_REQST     = 14,
63         SRPC_MSG_PING_REPLY     = 15,
64         SRPC_MSG_JOIN_REQST     = 16,
65         SRPC_MSG_JOIN_REPLY     = 17,
66 } srpc_msg_type_t;
67
68 #ifdef __WINNT__
69 #include <libcfs/libcfs_pack.h>
70 #include <libcfs/libcfs_unpack.h>
71 #endif
72
73 /* CAVEAT EMPTOR:
74  * All srpc_*_reqst_t's 1st field must be matchbits of reply buffer,
75  * and 2nd field matchbits of bulk buffer if any.
76  *
77  * All srpc_*_reply_t's 1st field must be a __u32 status, and 2nd field
78  * session id if needed.
79  */
80 typedef struct {
81         __u64                   rpyid;          /* reply buffer matchbits */
82         __u64                   bulkid;         /* bulk buffer matchbits */
83 } WIRE_ATTR srpc_generic_reqst_t;
84
85 typedef struct {
86         __u32                   status;
87         lst_sid_t               sid;
88 } WIRE_ATTR srpc_generic_reply_t;
89
90 /* FRAMEWORK RPCs */
91 typedef struct {
92         __u64                   mksn_rpyid;      /* reply buffer matchbits */
93         lst_sid_t               mksn_sid;        /* session id */
94         __u32                   mksn_force;      /* use brute force */
95         char                    mksn_name[LST_NAME_SIZE];
96 } WIRE_ATTR srpc_mksn_reqst_t;                  /* make session request */
97
98 typedef struct {
99         __u32                   mksn_status;      /* session status */
100         lst_sid_t               mksn_sid;         /* session id */
101         __u32                   mksn_timeout;     /* session timeout */
102         char                    mksn_name[LST_NAME_SIZE];
103 } WIRE_ATTR srpc_mksn_reply_t; /* make session reply */
104
105 typedef struct {
106         __u64                   rmsn_rpyid;      /* reply buffer matchbits */
107         lst_sid_t               rmsn_sid;        /* session id */
108 } WIRE_ATTR srpc_rmsn_reqst_t; /* remove session request */
109
110 typedef struct {
111         __u32                   rmsn_status;
112         lst_sid_t               rmsn_sid;        /* session id */
113 } WIRE_ATTR srpc_rmsn_reply_t; /* remove session reply */
114
115 typedef struct {
116         __u64                   join_rpyid;     /* reply buffer matchbits */
117         lst_sid_t               join_sid;       /* session id to join */
118         char                    join_group[LST_NAME_SIZE]; /* group name */
119 } WIRE_ATTR srpc_join_reqst_t;
120
121 typedef struct {
122         __u32                   join_status;    /* returned status */
123         lst_sid_t               join_sid;       /* session id */
124         __u32                   join_timeout;   /* # seconds' inactivity to expire */
125         char                    join_session[LST_NAME_SIZE]; /* session name */
126 } WIRE_ATTR srpc_join_reply_t;
127
128 typedef struct {
129         __u64                   dbg_rpyid;      /* reply buffer matchbits */ 
130         lst_sid_t               dbg_sid;        /* session id */
131         __u32                   dbg_flags;      /* bitmap of debug */
132 } WIRE_ATTR srpc_debug_reqst_t;
133
134 typedef struct {
135         __u32                   dbg_status;     /* returned code */
136         lst_sid_t               dbg_sid;        /* session id */
137         __u32                   dbg_timeout;    /* session timeout */
138         __u32                   dbg_nbatch;     /* # of batches in the node */
139         char                    dbg_name[LST_NAME_SIZE]; /* session name */
140 } WIRE_ATTR srpc_debug_reply_t;
141
142 #define SRPC_BATCH_OPC_RUN      1
143 #define SRPC_BATCH_OPC_STOP     2
144 #define SRPC_BATCH_OPC_QUERY    3
145
146 typedef struct {
147         __u64                   bar_rpyid;      /* reply buffer matchbits */ 
148         lst_sid_t               bar_sid;        /* session id */
149         lst_bid_t               bar_bid;        /* batch id */
150         __u32                   bar_opc;        /* create/start/stop batch */
151         __u32                   bar_testidx;    /* index of test */
152         __u32                   bar_arg;        /* parameters */
153 } WIRE_ATTR srpc_batch_reqst_t;
154
155 typedef struct {
156         __u32                   bar_status;     /* status of request */
157         lst_sid_t               bar_sid;        /* session id */
158         __u32                   bar_active;     /* # of active tests in batch/test */
159         __u32                   bar_time;       /* remained time */
160 } WIRE_ATTR srpc_batch_reply_t;
161
162 typedef struct {
163         __u64                   str_rpyid;      /* reply buffer matchbits */
164         lst_sid_t               str_sid;        /* session id */
165         __u32                   str_type;       /* type of stat */
166 } WIRE_ATTR srpc_stat_reqst_t;
167
168 typedef struct {
169         __u32                   str_status;
170         lst_sid_t               str_sid;
171         sfw_counters_t          str_fw;
172         srpc_counters_t         str_rpc;
173         lnet_counters_t         str_lnet;
174 } WIRE_ATTR srpc_stat_reply_t;
175
176 typedef struct {
177         __u32                   blk_opc;        /* bulk operation code */
178         __u32                   blk_npg;        /* # of pages */
179         __u32                   blk_flags;      /* reserved flags */
180 } WIRE_ATTR test_bulk_req_t;
181
182 typedef struct {
183         /** bulk operation code */
184         __u16                   blk_opc;
185         /** data check flags */
186         __u16                   blk_flags;
187         /** data length */
188         __u32                   blk_len;
189         /** reserved: offset */
190         __u32                   blk_offset;
191 } WIRE_ATTR test_bulk_req_v1_t;
192
193 typedef struct {
194         __u32                   png_size;       /* size of ping message */
195         __u32                   png_flags;      /* reserved flags */
196 } WIRE_ATTR test_ping_req_t;
197
198 typedef struct {
199         __u64                   tsr_rpyid;      /* reply buffer matchbits */
200         __u64                   tsr_bulkid;     /* bulk buffer matchbits */
201         lst_sid_t               tsr_sid;        /* session id */
202         lst_bid_t               tsr_bid;        /* batch id */
203         __u32                   tsr_service;    /* test type: bulk|ping|... */
204         /* test client loop count or # server buffers needed */
205         __u32                   tsr_loop;
206         __u32                   tsr_concur;     /* concurrency of test */
207         __u8                    tsr_is_client;  /* is test client or not */
208         __u8                    tsr_stop_onerr; /* stop on error */
209         __u32                   tsr_ndest;      /* # of dest nodes */
210
211         union {
212                 test_ping_req_t         ping;
213                 test_bulk_req_t         bulk_v0;
214                 test_bulk_req_v1_t      bulk_v1;
215         }               tsr_u;
216 } WIRE_ATTR srpc_test_reqst_t;
217
218 typedef struct {
219         __u32                   tsr_status;     /* returned code */
220         lst_sid_t               tsr_sid;
221 } WIRE_ATTR srpc_test_reply_t;
222
223 /* TEST RPCs */
224 typedef struct {
225         __u64                   pnr_rpyid;
226         __u32                   pnr_magic;
227         __u32                   pnr_seq;
228         __u64                   pnr_time_sec;
229         __u64                   pnr_time_usec;
230 } WIRE_ATTR srpc_ping_reqst_t;
231
232 typedef struct {
233         __u32                   pnr_status;
234         __u32                   pnr_magic;
235         __u32                   pnr_seq;
236 } WIRE_ATTR srpc_ping_reply_t;
237
238 typedef struct {
239         __u64                   brw_rpyid;      /* reply buffer matchbits */
240         __u64                   brw_bulkid;     /* bulk buffer matchbits */
241         __u32                   brw_rw;         /* read or write */
242         __u32                   brw_len;        /* bulk data len */
243         __u32                   brw_flags;      /* bulk data patterns */
244 } WIRE_ATTR srpc_brw_reqst_t; /* bulk r/w request */
245
246 typedef struct {
247         __u32                   brw_status;
248 } WIRE_ATTR srpc_brw_reply_t; /* bulk r/w reply */
249
250 #define SRPC_MSG_MAGIC                  0xeeb0f00d
251 #define SRPC_MSG_VERSION                1
252
253 typedef struct srpc_msg {
254         /** magic number */
255         __u32   msg_magic;
256         /** message version number */
257         __u32   msg_version;
258         /** type of message body: srpc_msg_type_t */
259         __u32   msg_type;
260         __u32   msg_reserved0;
261         __u32   msg_reserved1;
262         /** test session features */
263         __u32   msg_ses_feats;
264         union {
265                 srpc_generic_reqst_t reqst;
266                 srpc_generic_reply_t reply;
267
268                 srpc_mksn_reqst_t    mksn_reqst;
269                 srpc_mksn_reply_t    mksn_reply;
270                 srpc_rmsn_reqst_t    rmsn_reqst;
271                 srpc_rmsn_reply_t    rmsn_reply;
272                 srpc_debug_reqst_t   dbg_reqst;
273                 srpc_debug_reply_t   dbg_reply;
274                 srpc_batch_reqst_t   bat_reqst;
275                 srpc_batch_reply_t   bat_reply;
276                 srpc_stat_reqst_t    stat_reqst;
277                 srpc_stat_reply_t    stat_reply;
278                 srpc_test_reqst_t    tes_reqst;
279                 srpc_test_reply_t    tes_reply;
280                 srpc_join_reqst_t    join_reqst;
281                 srpc_join_reply_t    join_reply;
282
283                 srpc_ping_reqst_t    ping_reqst;
284                 srpc_ping_reply_t    ping_reply;
285                 srpc_brw_reqst_t     brw_reqst;
286                 srpc_brw_reply_t     brw_reply;
287         }     msg_body;
288 } WIRE_ATTR srpc_msg_t;
289
290 static inline void
291 srpc_unpack_msg_hdr(srpc_msg_t *msg)
292 {
293         if (msg->msg_magic == SRPC_MSG_MAGIC)
294                 return; /* no flipping needed */
295
296         /* We do not swap the magic number here as it is needed to
297            determine whether the body needs to be swapped. */
298         /* __swab32s(&msg->msg_magic); */
299         __swab32s(&msg->msg_type);
300         __swab32s(&msg->msg_version);
301         __swab32s(&msg->msg_ses_feats);
302         __swab32s(&msg->msg_reserved0);
303         __swab32s(&msg->msg_reserved1);
304 }
305
306 #endif /* __SELFTEST_RPC_H__ */