Whamcloud - gitweb
LU-5319 ptlrpc: Add OBD_CONNECT_MULTIMODRPCS flag
[fs/lustre-release.git] / lustre / ptlrpc / layout.c
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) 2011, 2014, 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  * lustre/ptlrpc/layout.c
37  *
38  * Lustre Metadata Target (mdt) request handler
39  *
40  * Author: Nikita Danilov <nikita@clusterfs.com>
41  */
42 /*
43  * This file contains the "capsule/pill" abstraction layered above PTLRPC.
44  *
45  * Every struct ptlrpc_request contains a "pill", which points to a description
46  * of the format that the request conforms to.
47  */
48
49 #if !defined(__REQ_LAYOUT_USER__)
50
51 #define DEBUG_SUBSYSTEM S_RPC
52
53 #include <linux/module.h>
54
55 /* LUSTRE_VERSION_CODE */
56 #include <lustre_ver.h>
57
58 #include <obd_support.h>
59 /* lustre_swab_mdt_body */
60 #include <lustre/lustre_idl.h>
61 /* obd2cli_tgt() (required by DEBUG_REQ()) */
62 #include <obd.h>
63 #include <lustre_debug.h>
64 #include <lustre_update.h>
65 #endif /* !__REQ_LAYOUT_USER__ */
66
67 /* struct ptlrpc_request, lustre_msg* */
68 #include <lustre_req_layout.h>
69 #include <lustre_acl.h>
70
71 /*
72  * RQFs (see below) refer to two struct req_msg_field arrays describing the
73  * client request and server reply, respectively.
74  */
75 /* empty set of fields... for suitable definition of emptiness. */
76 static const struct req_msg_field *empty[] = {
77         &RMF_PTLRPC_BODY
78 };
79
80 static const struct req_msg_field *mgs_target_info_only[] = {
81         &RMF_PTLRPC_BODY,
82         &RMF_MGS_TARGET_INFO
83 };
84
85 static const struct req_msg_field *mgs_set_info[] = {
86         &RMF_PTLRPC_BODY,
87         &RMF_MGS_SEND_PARAM
88 };
89
90 static const struct req_msg_field *mgs_config_read_client[] = {
91         &RMF_PTLRPC_BODY,
92         &RMF_MGS_CONFIG_BODY
93 };
94
95 static const struct req_msg_field *mgs_config_read_server[] = {
96         &RMF_PTLRPC_BODY,
97         &RMF_MGS_CONFIG_RES
98 };
99
100 static const struct req_msg_field *log_cancel_client[] = {
101         &RMF_PTLRPC_BODY,
102         &RMF_LOGCOOKIES
103 };
104
105 static const struct req_msg_field *mdt_body_only[] = {
106         &RMF_PTLRPC_BODY,
107         &RMF_MDT_BODY
108 };
109
110 static const struct req_msg_field *mdt_body_capa[] = {
111         &RMF_PTLRPC_BODY,
112         &RMF_MDT_BODY,
113         &RMF_CAPA1
114 };
115
116 static const struct req_msg_field *quotactl_only[] = {
117         &RMF_PTLRPC_BODY,
118         &RMF_OBD_QUOTACTL
119 };
120
121 static const struct req_msg_field *quota_body_only[] = {
122         &RMF_PTLRPC_BODY,
123         &RMF_QUOTA_BODY
124 };
125
126 static const struct req_msg_field *ldlm_intent_quota_client[] = {
127         &RMF_PTLRPC_BODY,
128         &RMF_DLM_REQ,
129         &RMF_LDLM_INTENT,
130         &RMF_QUOTA_BODY
131 };
132
133 static const struct req_msg_field *ldlm_intent_quota_server[] = {
134         &RMF_PTLRPC_BODY,
135         &RMF_DLM_REP,
136         &RMF_DLM_LVB,
137         &RMF_QUOTA_BODY
138 };
139
140 static const struct req_msg_field *mdt_close_client[] = {
141         &RMF_PTLRPC_BODY,
142         &RMF_MDT_EPOCH,
143         &RMF_REC_REINT,
144         &RMF_CAPA1
145 };
146
147 static const struct req_msg_field *mdt_release_close_client[] = {
148         &RMF_PTLRPC_BODY,
149         &RMF_MDT_EPOCH,
150         &RMF_REC_REINT,
151         &RMF_CAPA1,
152         &RMF_CLOSE_DATA
153 };
154
155 static const struct req_msg_field *obd_statfs_server[] = {
156         &RMF_PTLRPC_BODY,
157         &RMF_OBD_STATFS
158 };
159
160 static const struct req_msg_field *seq_query_client[] = {
161         &RMF_PTLRPC_BODY,
162         &RMF_SEQ_OPC,
163         &RMF_SEQ_RANGE
164 };
165
166 static const struct req_msg_field *seq_query_server[] = {
167         &RMF_PTLRPC_BODY,
168         &RMF_SEQ_RANGE
169 };
170
171 static const struct req_msg_field *fld_query_client[] = {
172         &RMF_PTLRPC_BODY,
173         &RMF_FLD_OPC,
174         &RMF_FLD_MDFLD
175 };
176
177 static const struct req_msg_field *fld_query_server[] = {
178         &RMF_PTLRPC_BODY,
179         &RMF_FLD_MDFLD
180 };
181
182 static const struct req_msg_field *fld_read_client[] = {
183         &RMF_PTLRPC_BODY,
184         &RMF_FLD_MDFLD
185 };
186
187 static const struct req_msg_field *fld_read_server[] = {
188         &RMF_PTLRPC_BODY,
189         &RMF_GENERIC_DATA
190 };
191
192 static const struct req_msg_field *mds_getattr_name_client[] = {
193         &RMF_PTLRPC_BODY,
194         &RMF_MDT_BODY,
195         &RMF_CAPA1,
196         &RMF_NAME
197 };
198
199 static const struct req_msg_field *mds_reint_client[] = {
200         &RMF_PTLRPC_BODY,
201         &RMF_REC_REINT
202 };
203
204 static const struct req_msg_field *mds_reint_create_client[] = {
205         &RMF_PTLRPC_BODY,
206         &RMF_REC_REINT,
207         &RMF_CAPA1,
208         &RMF_NAME
209 };
210
211 static const struct req_msg_field *mds_reint_create_slave_client[] = {
212         &RMF_PTLRPC_BODY,
213         &RMF_REC_REINT,
214         &RMF_CAPA1,
215         &RMF_NAME,
216         &RMF_EADATA,
217         &RMF_DLM_REQ
218 };
219
220 static const struct req_msg_field *mds_reint_create_rmt_acl_client[] = {
221         &RMF_PTLRPC_BODY,
222         &RMF_REC_REINT,
223         &RMF_CAPA1,
224         &RMF_NAME,
225         &RMF_EADATA,
226         &RMF_DLM_REQ
227 };
228
229 static const struct req_msg_field *mds_reint_create_sym_client[] = {
230         &RMF_PTLRPC_BODY,
231         &RMF_REC_REINT,
232         &RMF_CAPA1,
233         &RMF_NAME,
234         &RMF_SYMTGT,
235         &RMF_DLM_REQ
236 };
237
238 static const struct req_msg_field *mds_reint_open_client[] = {
239         &RMF_PTLRPC_BODY,
240         &RMF_REC_REINT,
241         &RMF_CAPA1,
242         &RMF_CAPA2,
243         &RMF_NAME,
244         &RMF_EADATA
245 };
246
247 static const struct req_msg_field *mds_reint_open_server[] = {
248         &RMF_PTLRPC_BODY,
249         &RMF_MDT_BODY,
250         &RMF_MDT_MD,
251         &RMF_ACL,
252         &RMF_CAPA1,
253         &RMF_CAPA2
254 };
255
256 static const struct req_msg_field *mds_reint_unlink_client[] = {
257         &RMF_PTLRPC_BODY,
258         &RMF_REC_REINT,
259         &RMF_CAPA1,
260         &RMF_NAME,
261         &RMF_DLM_REQ
262 };
263
264 static const struct req_msg_field *mds_reint_link_client[] = {
265         &RMF_PTLRPC_BODY,
266         &RMF_REC_REINT,
267         &RMF_CAPA1,
268         &RMF_CAPA2,
269         &RMF_NAME,
270         &RMF_DLM_REQ
271 };
272
273 static const struct req_msg_field *mds_reint_rename_client[] = {
274         &RMF_PTLRPC_BODY,
275         &RMF_REC_REINT,
276         &RMF_CAPA1,
277         &RMF_CAPA2,
278         &RMF_NAME,
279         &RMF_SYMTGT,
280         &RMF_DLM_REQ
281 };
282
283 static const struct req_msg_field *mds_last_unlink_server[] = {
284         &RMF_PTLRPC_BODY,
285         &RMF_MDT_BODY,
286         &RMF_MDT_MD,
287         &RMF_LOGCOOKIES,
288         &RMF_CAPA1,
289         &RMF_CAPA2
290 };
291
292 static const struct req_msg_field *mds_reint_setattr_client[] = {
293         &RMF_PTLRPC_BODY,
294         &RMF_REC_REINT,
295         &RMF_CAPA1,
296         &RMF_MDT_EPOCH,
297         &RMF_EADATA,
298         &RMF_LOGCOOKIES,
299         &RMF_DLM_REQ
300 };
301
302 static const struct req_msg_field *mds_reint_setxattr_client[] = {
303         &RMF_PTLRPC_BODY,
304         &RMF_REC_REINT,
305         &RMF_CAPA1,
306         &RMF_NAME,
307         &RMF_EADATA,
308         &RMF_DLM_REQ
309 };
310
311 static const struct req_msg_field *mdt_swap_layouts[] = {
312         &RMF_PTLRPC_BODY,
313         &RMF_MDT_BODY,
314         &RMF_SWAP_LAYOUTS,
315         &RMF_CAPA1,
316         &RMF_CAPA2,
317         &RMF_DLM_REQ
318 };
319
320 static const struct req_msg_field *obd_connect_client[] = {
321         &RMF_PTLRPC_BODY,
322         &RMF_TGTUUID,
323         &RMF_CLUUID,
324         &RMF_CONN,
325         &RMF_CONNECT_DATA
326 };
327
328 static const struct req_msg_field *obd_connect_server[] = {
329         &RMF_PTLRPC_BODY,
330         &RMF_CONNECT_DATA
331 };
332
333 static const struct req_msg_field *obd_set_info_client[] = {
334         &RMF_PTLRPC_BODY,
335         &RMF_SETINFO_KEY,
336         &RMF_SETINFO_VAL
337 };
338
339 static const struct req_msg_field *ost_grant_shrink_client[] = {
340         &RMF_PTLRPC_BODY,
341         &RMF_SETINFO_KEY,
342         &RMF_OST_BODY
343 };
344
345 static const struct req_msg_field *mds_getinfo_client[] = {
346         &RMF_PTLRPC_BODY,
347         &RMF_GETINFO_KEY,
348         &RMF_GETINFO_VALLEN
349 };
350
351 static const struct req_msg_field *mds_getinfo_server[] = {
352         &RMF_PTLRPC_BODY,
353         &RMF_GETINFO_VAL,
354 };
355
356 static const struct req_msg_field *ldlm_enqueue_client[] = {
357         &RMF_PTLRPC_BODY,
358         &RMF_DLM_REQ
359 };
360
361 static const struct req_msg_field *ldlm_enqueue_server[] = {
362         &RMF_PTLRPC_BODY,
363         &RMF_DLM_REP
364 };
365
366 static const struct req_msg_field *ldlm_enqueue_lvb_server[] = {
367         &RMF_PTLRPC_BODY,
368         &RMF_DLM_REP,
369         &RMF_DLM_LVB
370 };
371
372 static const struct req_msg_field *ldlm_cp_callback_client[] = {
373         &RMF_PTLRPC_BODY,
374         &RMF_DLM_REQ,
375         &RMF_DLM_LVB
376 };
377
378 static const struct req_msg_field *ldlm_gl_callback_desc_client[] = {
379         &RMF_PTLRPC_BODY,
380         &RMF_DLM_REQ,
381         &RMF_DLM_GL_DESC
382 };
383
384 static const struct req_msg_field *ldlm_gl_callback_server[] = {
385         &RMF_PTLRPC_BODY,
386         &RMF_DLM_LVB
387 };
388
389 static const struct req_msg_field *ldlm_intent_basic_client[] = {
390         &RMF_PTLRPC_BODY,
391         &RMF_DLM_REQ,
392         &RMF_LDLM_INTENT,
393 };
394
395 static const struct req_msg_field *ldlm_intent_client[] = {
396         &RMF_PTLRPC_BODY,
397         &RMF_DLM_REQ,
398         &RMF_LDLM_INTENT,
399         &RMF_REC_REINT
400 };
401
402 static const struct req_msg_field *ldlm_intent_server[] = {
403         &RMF_PTLRPC_BODY,
404         &RMF_DLM_REP,
405         &RMF_MDT_BODY,
406         &RMF_MDT_MD,
407         &RMF_ACL
408 };
409
410 static const struct req_msg_field *ldlm_intent_layout_client[] = {
411         &RMF_PTLRPC_BODY,
412         &RMF_DLM_REQ,
413         &RMF_LDLM_INTENT,
414         &RMF_LAYOUT_INTENT,
415         &RMF_EADATA /* for new layout to be set up */
416 };
417 static const struct req_msg_field *ldlm_intent_open_server[] = {
418         &RMF_PTLRPC_BODY,
419         &RMF_DLM_REP,
420         &RMF_MDT_BODY,
421         &RMF_MDT_MD,
422         &RMF_ACL,
423         &RMF_CAPA1,
424         &RMF_CAPA2
425 };
426
427 static const struct req_msg_field *ldlm_intent_getattr_client[] = {
428         &RMF_PTLRPC_BODY,
429         &RMF_DLM_REQ,
430         &RMF_LDLM_INTENT,
431         &RMF_MDT_BODY,     /* coincides with mds_getattr_name_client[] */
432         &RMF_CAPA1,
433         &RMF_NAME
434 };
435
436 static const struct req_msg_field *ldlm_intent_getattr_server[] = {
437         &RMF_PTLRPC_BODY,
438         &RMF_DLM_REP,
439         &RMF_MDT_BODY,
440         &RMF_MDT_MD,
441         &RMF_ACL,
442         &RMF_CAPA1
443 };
444
445 static const struct req_msg_field *ldlm_intent_create_client[] = {
446         &RMF_PTLRPC_BODY,
447         &RMF_DLM_REQ,
448         &RMF_LDLM_INTENT,
449         &RMF_REC_REINT,    /* coincides with mds_reint_create_client[] */
450         &RMF_CAPA1,
451         &RMF_NAME,
452         &RMF_EADATA
453 };
454
455 static const struct req_msg_field *ldlm_intent_open_client[] = {
456         &RMF_PTLRPC_BODY,
457         &RMF_DLM_REQ,
458         &RMF_LDLM_INTENT,
459         &RMF_REC_REINT,    /* coincides with mds_reint_open_client[] */
460         &RMF_CAPA1,
461         &RMF_CAPA2,
462         &RMF_NAME,
463         &RMF_EADATA
464 };
465
466 static const struct req_msg_field *ldlm_intent_unlink_client[] = {
467         &RMF_PTLRPC_BODY,
468         &RMF_DLM_REQ,
469         &RMF_LDLM_INTENT,
470         &RMF_REC_REINT,    /* coincides with mds_reint_unlink_client[] */
471         &RMF_CAPA1,
472         &RMF_NAME
473 };
474
475 static const struct req_msg_field *ldlm_intent_getxattr_client[] = {
476         &RMF_PTLRPC_BODY,
477         &RMF_DLM_REQ,
478         &RMF_LDLM_INTENT,
479         &RMF_MDT_BODY,
480         &RMF_CAPA1,
481 };
482
483 static const struct req_msg_field *ldlm_intent_getxattr_server[] = {
484         &RMF_PTLRPC_BODY,
485         &RMF_DLM_REP,
486         &RMF_MDT_BODY,
487         &RMF_MDT_MD,
488         &RMF_ACL, /* for req_capsule_extend/mdt_intent_policy */
489         &RMF_EADATA,
490         &RMF_EAVALS,
491         &RMF_EAVALS_LENS
492 };
493
494 static const struct req_msg_field *mds_getxattr_client[] = {
495         &RMF_PTLRPC_BODY,
496         &RMF_MDT_BODY,
497         &RMF_CAPA1,
498         &RMF_NAME,
499         &RMF_EADATA
500 };
501
502 static const struct req_msg_field *mds_getxattr_server[] = {
503         &RMF_PTLRPC_BODY,
504         &RMF_MDT_BODY,
505         &RMF_EADATA
506 };
507
508 static const struct req_msg_field *mds_getattr_server[] = {
509         &RMF_PTLRPC_BODY,
510         &RMF_MDT_BODY,
511         &RMF_MDT_MD,
512         &RMF_ACL,
513         &RMF_CAPA1,
514         &RMF_CAPA2
515 };
516
517 static const struct req_msg_field *mds_setattr_server[] = {
518         &RMF_PTLRPC_BODY,
519         &RMF_MDT_BODY,
520         &RMF_MDT_MD,
521         &RMF_ACL,
522         &RMF_CAPA1,
523         &RMF_CAPA2
524 };
525
526 static const struct req_msg_field *mds_update_client[] = {
527         &RMF_PTLRPC_BODY,
528         &RMF_OUT_UPDATE,
529 };
530
531 static const struct req_msg_field *mds_update_server[] = {
532         &RMF_PTLRPC_BODY,
533         &RMF_OUT_UPDATE_REPLY,
534 };
535
536 static const struct req_msg_field *llog_origin_handle_create_client[] = {
537         &RMF_PTLRPC_BODY,
538         &RMF_LLOGD_BODY,
539         &RMF_NAME
540 };
541
542 static const struct req_msg_field *llogd_body_only[] = {
543         &RMF_PTLRPC_BODY,
544         &RMF_LLOGD_BODY
545 };
546
547 static const struct req_msg_field *llog_log_hdr_only[] = {
548         &RMF_PTLRPC_BODY,
549         &RMF_LLOG_LOG_HDR
550 };
551
552 static const struct req_msg_field *llogd_conn_body_only[] = {
553         &RMF_PTLRPC_BODY,
554         &RMF_LLOGD_CONN_BODY
555 };
556
557 static const struct req_msg_field *llog_origin_handle_next_block_server[] = {
558         &RMF_PTLRPC_BODY,
559         &RMF_LLOGD_BODY,
560         &RMF_EADATA
561 };
562
563 static const struct req_msg_field *obd_idx_read_client[] = {
564         &RMF_PTLRPC_BODY,
565         &RMF_IDX_INFO
566 };
567
568 static const struct req_msg_field *obd_idx_read_server[] = {
569         &RMF_PTLRPC_BODY,
570         &RMF_IDX_INFO
571 };
572
573 static const struct req_msg_field *ost_body_only[] = {
574         &RMF_PTLRPC_BODY,
575         &RMF_OST_BODY
576 };
577
578 static const struct req_msg_field *ost_body_capa[] = {
579         &RMF_PTLRPC_BODY,
580         &RMF_OST_BODY,
581         &RMF_CAPA1
582 };
583
584 static const struct req_msg_field *ost_destroy_client[] = {
585         &RMF_PTLRPC_BODY,
586         &RMF_OST_BODY,
587         &RMF_DLM_REQ,
588         &RMF_CAPA1
589 };
590
591
592 static const struct req_msg_field *ost_brw_client[] = {
593         &RMF_PTLRPC_BODY,
594         &RMF_OST_BODY,
595         &RMF_OBD_IOOBJ,
596         &RMF_NIOBUF_REMOTE,
597         &RMF_CAPA1
598 };
599
600 static const struct req_msg_field *ost_brw_read_server[] = {
601         &RMF_PTLRPC_BODY,
602         &RMF_OST_BODY
603 };
604
605 static const struct req_msg_field *ost_brw_write_server[] = {
606         &RMF_PTLRPC_BODY,
607         &RMF_OST_BODY,
608         &RMF_RCS
609 };
610
611 static const struct req_msg_field *ost_get_info_generic_server[] = {
612         &RMF_PTLRPC_BODY,
613         &RMF_GENERIC_DATA,
614 };
615
616 static const struct req_msg_field *ost_get_info_generic_client[] = {
617         &RMF_PTLRPC_BODY,
618         &RMF_GETINFO_KEY
619 };
620
621 static const struct req_msg_field *ost_get_last_id_server[] = {
622         &RMF_PTLRPC_BODY,
623         &RMF_OBD_ID
624 };
625
626 static const struct req_msg_field *ost_get_last_fid_client[] = {
627         &RMF_PTLRPC_BODY,
628         &RMF_GETINFO_KEY,
629         &RMF_FID,
630 };
631
632 static const struct req_msg_field *ost_get_last_fid_server[] = {
633         &RMF_PTLRPC_BODY,
634         &RMF_FID,
635 };
636
637 static const struct req_msg_field *ost_get_fiemap_client[] = {
638         &RMF_PTLRPC_BODY,
639         &RMF_FIEMAP_KEY,
640         &RMF_FIEMAP_VAL
641 };
642
643 static const struct req_msg_field *ost_get_fiemap_server[] = {
644         &RMF_PTLRPC_BODY,
645         &RMF_FIEMAP_VAL
646 };
647
648 static const struct req_msg_field *mdt_hsm_progress[] = {
649         &RMF_PTLRPC_BODY,
650         &RMF_MDT_BODY,
651         &RMF_MDS_HSM_PROGRESS,
652 };
653
654 static const struct req_msg_field *mdt_hsm_ct_register[] = {
655         &RMF_PTLRPC_BODY,
656         &RMF_MDT_BODY,
657         &RMF_MDS_HSM_ARCHIVE,
658 };
659
660 static const struct req_msg_field *mdt_hsm_ct_unregister[] = {
661         &RMF_PTLRPC_BODY,
662         &RMF_MDT_BODY,
663 };
664
665 static const struct req_msg_field *mdt_hsm_action_server[] = {
666         &RMF_PTLRPC_BODY,
667         &RMF_MDT_BODY,
668         &RMF_MDS_HSM_CURRENT_ACTION,
669 };
670
671 static const struct req_msg_field *mdt_hsm_state_get_server[] = {
672         &RMF_PTLRPC_BODY,
673         &RMF_MDT_BODY,
674         &RMF_HSM_USER_STATE,
675 };
676
677 static const struct req_msg_field *mdt_hsm_state_set[] = {
678         &RMF_PTLRPC_BODY,
679         &RMF_MDT_BODY,
680         &RMF_CAPA1,
681         &RMF_HSM_STATE_SET,
682 };
683
684 static const struct req_msg_field *mdt_hsm_request[] = {
685         &RMF_PTLRPC_BODY,
686         &RMF_MDT_BODY,
687         &RMF_MDS_HSM_REQUEST,
688         &RMF_MDS_HSM_USER_ITEM,
689         &RMF_GENERIC_DATA,
690 };
691
692 static const struct req_msg_field *obd_lfsck_request[] = {
693         &RMF_PTLRPC_BODY,
694         &RMF_LFSCK_REQUEST,
695 };
696
697 static const struct req_msg_field *obd_lfsck_reply[] = {
698         &RMF_PTLRPC_BODY,
699         &RMF_LFSCK_REPLY,
700 };
701
702 static struct req_format *req_formats[] = {
703         &RQF_OBD_PING,
704         &RQF_OBD_SET_INFO,
705         &RQF_OBD_IDX_READ,
706         &RQF_SEC_CTX,
707         &RQF_MGS_TARGET_REG,
708         &RQF_MGS_SET_INFO,
709         &RQF_MGS_CONFIG_READ,
710         &RQF_SEQ_QUERY,
711         &RQF_FLD_QUERY,
712         &RQF_FLD_READ,
713         &RQF_MDS_CONNECT,
714         &RQF_MDS_DISCONNECT,
715         &RQF_MDS_GET_INFO,
716         &RQF_MDS_GETSTATUS,
717         &RQF_MDS_STATFS,
718         &RQF_MDS_GETATTR,
719         &RQF_MDS_GETATTR_NAME,
720         &RQF_MDS_GETXATTR,
721         &RQF_MDS_SYNC,
722         &RQF_MDS_CLOSE,
723         &RQF_MDS_RELEASE_CLOSE,
724         &RQF_MDS_READPAGE,
725         &RQF_MDS_DONE_WRITING,
726         &RQF_MDS_REINT,
727         &RQF_MDS_REINT_CREATE,
728         &RQF_MDS_REINT_CREATE_RMT_ACL,
729         &RQF_MDS_REINT_CREATE_SLAVE,
730         &RQF_MDS_REINT_CREATE_SYM,
731         &RQF_MDS_REINT_OPEN,
732         &RQF_MDS_REINT_UNLINK,
733         &RQF_MDS_REINT_LINK,
734         &RQF_MDS_REINT_RENAME,
735         &RQF_MDS_REINT_SETATTR,
736         &RQF_MDS_REINT_SETXATTR,
737         &RQF_MDS_QUOTACHECK,
738         &RQF_MDS_QUOTACTL,
739         &RQF_MDS_HSM_PROGRESS,
740         &RQF_MDS_HSM_CT_REGISTER,
741         &RQF_MDS_HSM_CT_UNREGISTER,
742         &RQF_MDS_HSM_STATE_GET,
743         &RQF_MDS_HSM_STATE_SET,
744         &RQF_MDS_HSM_ACTION,
745         &RQF_MDS_HSM_REQUEST,
746         &RQF_MDS_SWAP_LAYOUTS,
747         &RQF_OUT_UPDATE,
748         &RQF_QC_CALLBACK,
749         &RQF_OST_CONNECT,
750         &RQF_OST_DISCONNECT,
751         &RQF_OST_QUOTACHECK,
752         &RQF_OST_QUOTACTL,
753         &RQF_OST_GETATTR,
754         &RQF_OST_SETATTR,
755         &RQF_OST_CREATE,
756         &RQF_OST_PUNCH,
757         &RQF_OST_SYNC,
758         &RQF_OST_DESTROY,
759         &RQF_OST_BRW_READ,
760         &RQF_OST_BRW_WRITE,
761         &RQF_OST_STATFS,
762         &RQF_OST_SET_GRANT_INFO,
763         &RQF_OST_GET_INFO,
764         &RQF_OST_GET_INFO_LAST_ID,
765         &RQF_OST_GET_INFO_LAST_FID,
766         &RQF_OST_SET_INFO_LAST_FID,
767         &RQF_OST_GET_INFO_FIEMAP,
768         &RQF_LDLM_ENQUEUE,
769         &RQF_LDLM_ENQUEUE_LVB,
770         &RQF_LDLM_CONVERT,
771         &RQF_LDLM_CANCEL,
772         &RQF_LDLM_CALLBACK,
773         &RQF_LDLM_CP_CALLBACK,
774         &RQF_LDLM_BL_CALLBACK,
775         &RQF_LDLM_GL_CALLBACK,
776         &RQF_LDLM_GL_DESC_CALLBACK,
777         &RQF_LDLM_INTENT,
778         &RQF_LDLM_INTENT_BASIC,
779         &RQF_LDLM_INTENT_LAYOUT,
780         &RQF_LDLM_INTENT_GETATTR,
781         &RQF_LDLM_INTENT_OPEN,
782         &RQF_LDLM_INTENT_CREATE,
783         &RQF_LDLM_INTENT_UNLINK,
784         &RQF_LDLM_INTENT_GETXATTR,
785         &RQF_LDLM_INTENT_QUOTA,
786         &RQF_QUOTA_DQACQ,
787         &RQF_LOG_CANCEL,
788         &RQF_LLOG_ORIGIN_HANDLE_CREATE,
789         &RQF_LLOG_ORIGIN_HANDLE_DESTROY,
790         &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK,
791         &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK,
792         &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER,
793         &RQF_LLOG_ORIGIN_CONNECT,
794         &RQF_CONNECT,
795         &RQF_LFSCK_NOTIFY,
796         &RQF_LFSCK_QUERY,
797 };
798
799 struct req_msg_field {
800         const __u32 rmf_flags;
801         const char  *rmf_name;
802         /**
803          * Field length. (-1) means "variable length".  If the
804          * \a RMF_F_STRUCT_ARRAY flag is set the field is also variable-length,
805          * but the actual size must be a whole multiple of \a rmf_size.
806          */
807         const int   rmf_size;
808         void        (*rmf_swabber)(void *);
809         void        (*rmf_dumper)(void *);
810         int         rmf_offset[ARRAY_SIZE(req_formats)][RCL_NR];
811 };
812
813 enum rmf_flags {
814         /**
815          * The field is a string, must be NUL-terminated.
816          */
817         RMF_F_STRING = 1 << 0,
818         /**
819          * The field's buffer size need not match the declared \a rmf_size.
820          */
821         RMF_F_NO_SIZE_CHECK = 1 << 1,
822         /**
823          * The field's buffer size must be a whole multiple of the declared \a
824          * rmf_size and the \a rmf_swabber function must work on the declared \a
825          * rmf_size worth of bytes.
826          */
827         RMF_F_STRUCT_ARRAY = 1 << 2
828 };
829
830 struct req_capsule;
831
832 /*
833  * Request fields.
834  */
835 #define DEFINE_MSGF(name, flags, size, swabber, dumper) {       \
836         .rmf_name    = (name),                                  \
837         .rmf_flags   = (flags),                                 \
838         .rmf_size    = (size),                                  \
839         .rmf_swabber = (void (*)(void*))(swabber),              \
840         .rmf_dumper  = (void (*)(void*))(dumper)                \
841 }
842
843 struct req_msg_field RMF_GENERIC_DATA =
844         DEFINE_MSGF("generic_data", 0,
845                     -1, NULL, NULL);
846 EXPORT_SYMBOL(RMF_GENERIC_DATA);
847
848 struct req_msg_field RMF_MGS_TARGET_INFO =
849         DEFINE_MSGF("mgs_target_info", 0,
850                     sizeof(struct mgs_target_info),
851                     lustre_swab_mgs_target_info, NULL);
852 EXPORT_SYMBOL(RMF_MGS_TARGET_INFO);
853
854 struct req_msg_field RMF_MGS_SEND_PARAM =
855         DEFINE_MSGF("mgs_send_param", 0,
856                     sizeof(struct mgs_send_param),
857                     NULL, NULL);
858 EXPORT_SYMBOL(RMF_MGS_SEND_PARAM);
859
860 struct req_msg_field RMF_MGS_CONFIG_BODY =
861         DEFINE_MSGF("mgs_config_read request", 0,
862                     sizeof(struct mgs_config_body),
863                     lustre_swab_mgs_config_body, NULL);
864 EXPORT_SYMBOL(RMF_MGS_CONFIG_BODY);
865
866 struct req_msg_field RMF_MGS_CONFIG_RES =
867         DEFINE_MSGF("mgs_config_read reply ", 0,
868                     sizeof(struct mgs_config_res),
869                     lustre_swab_mgs_config_res, NULL);
870 EXPORT_SYMBOL(RMF_MGS_CONFIG_RES);
871
872 struct req_msg_field RMF_U32 =
873         DEFINE_MSGF("generic u32", 0,
874                     sizeof(__u32), lustre_swab_generic_32s, NULL);
875 EXPORT_SYMBOL(RMF_U32);
876
877 struct req_msg_field RMF_SETINFO_VAL =
878         DEFINE_MSGF("setinfo_val", 0, -1, NULL, NULL);
879 EXPORT_SYMBOL(RMF_SETINFO_VAL);
880
881 struct req_msg_field RMF_GETINFO_KEY =
882         DEFINE_MSGF("getinfo_key", 0, -1, NULL, NULL);
883 EXPORT_SYMBOL(RMF_GETINFO_KEY);
884
885 struct req_msg_field RMF_GETINFO_VALLEN =
886         DEFINE_MSGF("getinfo_vallen", 0,
887                     sizeof(__u32), lustre_swab_generic_32s, NULL);
888 EXPORT_SYMBOL(RMF_GETINFO_VALLEN);
889
890 struct req_msg_field RMF_GETINFO_VAL =
891         DEFINE_MSGF("getinfo_val", 0, -1, NULL, NULL);
892 EXPORT_SYMBOL(RMF_GETINFO_VAL);
893
894 struct req_msg_field RMF_SEQ_OPC =
895         DEFINE_MSGF("seq_query_opc", 0,
896                     sizeof(__u32), lustre_swab_generic_32s, NULL);
897 EXPORT_SYMBOL(RMF_SEQ_OPC);
898
899 struct req_msg_field RMF_SEQ_RANGE =
900         DEFINE_MSGF("seq_query_range", 0,
901                     sizeof(struct lu_seq_range),
902                     lustre_swab_lu_seq_range, NULL);
903 EXPORT_SYMBOL(RMF_SEQ_RANGE);
904
905 struct req_msg_field RMF_FLD_OPC =
906         DEFINE_MSGF("fld_query_opc", 0,
907                     sizeof(__u32), lustre_swab_generic_32s, NULL);
908 EXPORT_SYMBOL(RMF_FLD_OPC);
909
910 struct req_msg_field RMF_FLD_MDFLD =
911         DEFINE_MSGF("fld_query_mdfld", 0,
912                     sizeof(struct lu_seq_range),
913                     lustre_swab_lu_seq_range, NULL);
914 EXPORT_SYMBOL(RMF_FLD_MDFLD);
915
916 struct req_msg_field RMF_MDT_BODY =
917         DEFINE_MSGF("mdt_body", 0,
918                     sizeof(struct mdt_body), lustre_swab_mdt_body, NULL);
919 EXPORT_SYMBOL(RMF_MDT_BODY);
920
921 struct req_msg_field RMF_OBD_QUOTACTL =
922         DEFINE_MSGF("obd_quotactl", 0,
923                     sizeof(struct obd_quotactl),
924                     lustre_swab_obd_quotactl, NULL);
925 EXPORT_SYMBOL(RMF_OBD_QUOTACTL);
926
927 struct req_msg_field RMF_QUOTA_BODY =
928         DEFINE_MSGF("quota_body", 0,
929                     sizeof(struct quota_body), lustre_swab_quota_body, NULL);
930 EXPORT_SYMBOL(RMF_QUOTA_BODY);
931
932 struct req_msg_field RMF_MDT_EPOCH =
933         DEFINE_MSGF("mdt_ioepoch", 0,
934                     sizeof(struct mdt_ioepoch), lustre_swab_mdt_ioepoch, NULL);
935 EXPORT_SYMBOL(RMF_MDT_EPOCH);
936
937 struct req_msg_field RMF_PTLRPC_BODY =
938         DEFINE_MSGF("ptlrpc_body", 0,
939                     sizeof(struct ptlrpc_body), lustre_swab_ptlrpc_body, NULL);
940 EXPORT_SYMBOL(RMF_PTLRPC_BODY);
941
942 struct req_msg_field RMF_CLOSE_DATA =
943         DEFINE_MSGF("data_version", 0,
944                     sizeof(struct close_data), lustre_swab_close_data, NULL);
945 EXPORT_SYMBOL(RMF_CLOSE_DATA);
946
947 struct req_msg_field RMF_OBD_STATFS =
948         DEFINE_MSGF("obd_statfs", 0,
949                     sizeof(struct obd_statfs), lustre_swab_obd_statfs, NULL);
950 EXPORT_SYMBOL(RMF_OBD_STATFS);
951
952 struct req_msg_field RMF_SETINFO_KEY =
953         DEFINE_MSGF("setinfo_key", 0, -1, NULL, NULL);
954 EXPORT_SYMBOL(RMF_SETINFO_KEY);
955
956 struct req_msg_field RMF_NAME =
957         DEFINE_MSGF("name", RMF_F_STRING, -1, NULL, NULL);
958 EXPORT_SYMBOL(RMF_NAME);
959
960 struct req_msg_field RMF_SYMTGT =
961         DEFINE_MSGF("symtgt", RMF_F_STRING, -1, NULL, NULL);
962 EXPORT_SYMBOL(RMF_SYMTGT);
963
964 struct req_msg_field RMF_TGTUUID =
965         DEFINE_MSGF("tgtuuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
966         NULL);
967 EXPORT_SYMBOL(RMF_TGTUUID);
968
969 struct req_msg_field RMF_CLUUID =
970         DEFINE_MSGF("cluuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
971         NULL);
972 EXPORT_SYMBOL(RMF_CLUUID);
973
974 struct req_msg_field RMF_STRING =
975         DEFINE_MSGF("string", RMF_F_STRING, -1, NULL, NULL);
976 EXPORT_SYMBOL(RMF_STRING);
977
978 struct req_msg_field RMF_LLOGD_BODY =
979         DEFINE_MSGF("llogd_body", 0,
980                     sizeof(struct llogd_body), lustre_swab_llogd_body, NULL);
981 EXPORT_SYMBOL(RMF_LLOGD_BODY);
982
983 struct req_msg_field RMF_LLOG_LOG_HDR =
984         DEFINE_MSGF("llog_log_hdr", 0,
985                     sizeof(struct llog_log_hdr), lustre_swab_llog_hdr, NULL);
986 EXPORT_SYMBOL(RMF_LLOG_LOG_HDR);
987
988 struct req_msg_field RMF_LLOGD_CONN_BODY =
989         DEFINE_MSGF("llogd_conn_body", 0,
990                     sizeof(struct llogd_conn_body),
991                     lustre_swab_llogd_conn_body, NULL);
992 EXPORT_SYMBOL(RMF_LLOGD_CONN_BODY);
993
994 /*
995  * connection handle received in MDS_CONNECT request.
996  *
997  * No swabbing needed because struct lustre_handle contains only a 64-bit cookie
998  * that the client does not interpret at all.
999  */
1000 struct req_msg_field RMF_CONN =
1001         DEFINE_MSGF("conn", 0, sizeof(struct lustre_handle), NULL, NULL);
1002 EXPORT_SYMBOL(RMF_CONN);
1003
1004 struct req_msg_field RMF_CONNECT_DATA =
1005         DEFINE_MSGF("cdata",
1006                     RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */,
1007                     sizeof(struct obd_connect_data),
1008                     lustre_swab_connect, NULL);
1009 EXPORT_SYMBOL(RMF_CONNECT_DATA);
1010
1011 struct req_msg_field RMF_DLM_REQ =
1012         DEFINE_MSGF("dlm_req", RMF_F_NO_SIZE_CHECK /* ldlm_request_bufsize */,
1013                     sizeof(struct ldlm_request),
1014                     lustre_swab_ldlm_request, NULL);
1015 EXPORT_SYMBOL(RMF_DLM_REQ);
1016
1017 struct req_msg_field RMF_DLM_REP =
1018         DEFINE_MSGF("dlm_rep", 0,
1019                     sizeof(struct ldlm_reply), lustre_swab_ldlm_reply, NULL);
1020 EXPORT_SYMBOL(RMF_DLM_REP);
1021
1022 struct req_msg_field RMF_LDLM_INTENT =
1023         DEFINE_MSGF("ldlm_intent", 0,
1024                     sizeof(struct ldlm_intent), lustre_swab_ldlm_intent, NULL);
1025 EXPORT_SYMBOL(RMF_LDLM_INTENT);
1026
1027 struct req_msg_field RMF_DLM_LVB =
1028         DEFINE_MSGF("dlm_lvb", 0, -1, NULL, NULL);
1029 EXPORT_SYMBOL(RMF_DLM_LVB);
1030
1031 struct req_msg_field RMF_DLM_GL_DESC =
1032         DEFINE_MSGF("dlm_gl_desc", 0, sizeof(union ldlm_gl_desc),
1033                     lustre_swab_gl_desc, NULL);
1034 EXPORT_SYMBOL(RMF_DLM_GL_DESC);
1035
1036 struct req_msg_field RMF_MDT_MD =
1037         DEFINE_MSGF("mdt_md", RMF_F_NO_SIZE_CHECK, MIN_MD_SIZE, NULL, NULL);
1038 EXPORT_SYMBOL(RMF_MDT_MD);
1039
1040 struct req_msg_field RMF_REC_REINT =
1041         DEFINE_MSGF("rec_reint", 0, sizeof(struct mdt_rec_reint),
1042                     lustre_swab_mdt_rec_reint, NULL);
1043 EXPORT_SYMBOL(RMF_REC_REINT);
1044
1045 /* FIXME: this length should be defined as a macro */
1046 struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1,
1047                                                     NULL, NULL);
1048 EXPORT_SYMBOL(RMF_EADATA);
1049
1050 struct req_msg_field RMF_EAVALS = DEFINE_MSGF("eavals", 0, -1, NULL, NULL);
1051 EXPORT_SYMBOL(RMF_EAVALS);
1052
1053 struct req_msg_field RMF_ACL =
1054         DEFINE_MSGF("acl", RMF_F_NO_SIZE_CHECK,
1055                     LUSTRE_POSIX_ACL_MAX_SIZE, NULL, NULL);
1056 EXPORT_SYMBOL(RMF_ACL);
1057
1058 /* FIXME: this should be made to use RMF_F_STRUCT_ARRAY */
1059 struct req_msg_field RMF_LOGCOOKIES =
1060         DEFINE_MSGF("logcookies", RMF_F_NO_SIZE_CHECK /* multiple cookies */,
1061                     sizeof(struct llog_cookie), NULL, NULL);
1062 EXPORT_SYMBOL(RMF_LOGCOOKIES);
1063
1064 struct req_msg_field RMF_CAPA1 =
1065         DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
1066                     lustre_swab_lustre_capa, NULL);
1067 EXPORT_SYMBOL(RMF_CAPA1);
1068
1069 struct req_msg_field RMF_CAPA2 =
1070         DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
1071                     lustre_swab_lustre_capa, NULL);
1072 EXPORT_SYMBOL(RMF_CAPA2);
1073
1074 struct req_msg_field RMF_LAYOUT_INTENT =
1075         DEFINE_MSGF("layout_intent", 0,
1076                     sizeof(struct layout_intent), lustre_swab_layout_intent,
1077                     NULL);
1078 EXPORT_SYMBOL(RMF_LAYOUT_INTENT);
1079
1080 /*
1081  * OST request field.
1082  */
1083 struct req_msg_field RMF_OST_BODY =
1084         DEFINE_MSGF("ost_body", 0,
1085                     sizeof(struct ost_body), lustre_swab_ost_body, dump_ost_body);
1086 EXPORT_SYMBOL(RMF_OST_BODY);
1087
1088 struct req_msg_field RMF_OBD_IOOBJ =
1089         DEFINE_MSGF("obd_ioobj", RMF_F_STRUCT_ARRAY,
1090                     sizeof(struct obd_ioobj), lustre_swab_obd_ioobj, dump_ioo);
1091 EXPORT_SYMBOL(RMF_OBD_IOOBJ);
1092
1093 struct req_msg_field RMF_NIOBUF_REMOTE =
1094         DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY,
1095                     sizeof(struct niobuf_remote), lustre_swab_niobuf_remote,
1096                     dump_rniobuf);
1097 EXPORT_SYMBOL(RMF_NIOBUF_REMOTE);
1098
1099 struct req_msg_field RMF_RCS =
1100         DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY, sizeof(__u32),
1101                     lustre_swab_generic_32s, dump_rcs);
1102 EXPORT_SYMBOL(RMF_RCS);
1103
1104 struct req_msg_field RMF_EAVALS_LENS =
1105         DEFINE_MSGF("eavals_lens", RMF_F_STRUCT_ARRAY, sizeof(__u32),
1106                 lustre_swab_generic_32s, NULL);
1107 EXPORT_SYMBOL(RMF_EAVALS_LENS);
1108
1109 struct req_msg_field RMF_OBD_ID =
1110         DEFINE_MSGF("obd_id", 0,
1111                     sizeof(__u64), lustre_swab_ost_last_id, NULL);
1112 EXPORT_SYMBOL(RMF_OBD_ID);
1113
1114 struct req_msg_field RMF_FID =
1115         DEFINE_MSGF("fid", 0,
1116                     sizeof(struct lu_fid), lustre_swab_lu_fid, NULL);
1117 EXPORT_SYMBOL(RMF_FID);
1118
1119 struct req_msg_field RMF_OST_ID =
1120         DEFINE_MSGF("ost_id", 0,
1121                     sizeof(struct ost_id), lustre_swab_ost_id, NULL);
1122 EXPORT_SYMBOL(RMF_OST_ID);
1123
1124 struct req_msg_field RMF_FIEMAP_KEY =
1125         DEFINE_MSGF("fiemap", 0, sizeof(struct ll_fiemap_info_key),
1126                     lustre_swab_fiemap, NULL);
1127 EXPORT_SYMBOL(RMF_FIEMAP_KEY);
1128
1129 struct req_msg_field RMF_FIEMAP_VAL =
1130         DEFINE_MSGF("fiemap", 0, -1, lustre_swab_fiemap, NULL);
1131 EXPORT_SYMBOL(RMF_FIEMAP_VAL);
1132
1133 struct req_msg_field RMF_IDX_INFO =
1134         DEFINE_MSGF("idx_info", 0, sizeof(struct idx_info),
1135                     lustre_swab_idx_info, NULL);
1136 EXPORT_SYMBOL(RMF_IDX_INFO);
1137 struct req_msg_field RMF_HSM_USER_STATE =
1138         DEFINE_MSGF("hsm_user_state", 0, sizeof(struct hsm_user_state),
1139                     lustre_swab_hsm_user_state, NULL);
1140 EXPORT_SYMBOL(RMF_HSM_USER_STATE);
1141
1142 struct req_msg_field RMF_HSM_STATE_SET =
1143         DEFINE_MSGF("hsm_state_set", 0, sizeof(struct hsm_state_set),
1144                     lustre_swab_hsm_state_set, NULL);
1145 EXPORT_SYMBOL(RMF_HSM_STATE_SET);
1146
1147 struct req_msg_field RMF_MDS_HSM_PROGRESS =
1148         DEFINE_MSGF("hsm_progress", 0, sizeof(struct hsm_progress_kernel),
1149                     lustre_swab_hsm_progress_kernel, NULL);
1150 EXPORT_SYMBOL(RMF_MDS_HSM_PROGRESS);
1151
1152 struct req_msg_field RMF_MDS_HSM_CURRENT_ACTION =
1153         DEFINE_MSGF("hsm_current_action", 0, sizeof(struct hsm_current_action),
1154                     lustre_swab_hsm_current_action, NULL);
1155 EXPORT_SYMBOL(RMF_MDS_HSM_CURRENT_ACTION);
1156
1157 struct req_msg_field RMF_MDS_HSM_USER_ITEM =
1158         DEFINE_MSGF("hsm_user_item", RMF_F_STRUCT_ARRAY,
1159                     sizeof(struct hsm_user_item), lustre_swab_hsm_user_item,
1160                     NULL);
1161 EXPORT_SYMBOL(RMF_MDS_HSM_USER_ITEM);
1162
1163 struct req_msg_field RMF_MDS_HSM_ARCHIVE =
1164         DEFINE_MSGF("hsm_archive", 0,
1165                     sizeof(__u32), lustre_swab_generic_32s, NULL);
1166 EXPORT_SYMBOL(RMF_MDS_HSM_ARCHIVE);
1167
1168 struct req_msg_field RMF_MDS_HSM_REQUEST =
1169         DEFINE_MSGF("hsm_request", 0, sizeof(struct hsm_request),
1170                     lustre_swab_hsm_request, NULL);
1171 EXPORT_SYMBOL(RMF_MDS_HSM_REQUEST);
1172
1173 struct req_msg_field RMF_OUT_UPDATE = DEFINE_MSGF("object_update", 0, -1,
1174                                 lustre_swab_object_update_request, NULL);
1175 EXPORT_SYMBOL(RMF_OUT_UPDATE);
1176
1177 struct req_msg_field RMF_OUT_UPDATE_REPLY =
1178                         DEFINE_MSGF("object_update_reply", 0, -1,
1179                                     lustre_swab_object_update_reply, NULL);
1180 EXPORT_SYMBOL(RMF_OUT_UPDATE_REPLY);
1181
1182 struct req_msg_field RMF_SWAP_LAYOUTS =
1183         DEFINE_MSGF("swap_layouts", 0, sizeof(struct  mdc_swap_layouts),
1184                     lustre_swab_swap_layouts, NULL);
1185 EXPORT_SYMBOL(RMF_SWAP_LAYOUTS);
1186
1187 struct req_msg_field RMF_LFSCK_REQUEST =
1188         DEFINE_MSGF("lfsck_request", 0, sizeof(struct lfsck_request),
1189                     lustre_swab_lfsck_request, NULL);
1190 EXPORT_SYMBOL(RMF_LFSCK_REQUEST);
1191
1192 struct req_msg_field RMF_LFSCK_REPLY =
1193         DEFINE_MSGF("lfsck_reply", 0, sizeof(struct lfsck_reply),
1194                     lustre_swab_lfsck_reply, NULL);
1195 EXPORT_SYMBOL(RMF_LFSCK_REPLY);
1196
1197 /*
1198  * Request formats.
1199  */
1200
1201 struct req_format {
1202         const char *rf_name;
1203         size_t      rf_idx;
1204         struct {
1205                 size_t                       nr;
1206                 const struct req_msg_field **d;
1207         } rf_fields[RCL_NR];
1208 };
1209
1210 #define DEFINE_REQ_FMT(name, client, client_nr, server, server_nr) {    \
1211         .rf_name   = name,                                              \
1212         .rf_fields = {                                                  \
1213                 [RCL_CLIENT] = {                                        \
1214                         .nr = client_nr,                                \
1215                         .d  = client                                    \
1216                 },                                                      \
1217                 [RCL_SERVER] = {                                        \
1218                         .nr = server_nr,                                \
1219                         .d  = server                                    \
1220                 }                                                       \
1221         }                                                               \
1222 }
1223
1224 #define DEFINE_REQ_FMT0(name, client, server)                                  \
1225 DEFINE_REQ_FMT(name, client, ARRAY_SIZE(client), server, ARRAY_SIZE(server))
1226
1227 struct req_format RQF_OBD_PING =
1228         DEFINE_REQ_FMT0("OBD_PING", empty, empty);
1229 EXPORT_SYMBOL(RQF_OBD_PING);
1230
1231 struct req_format RQF_OBD_SET_INFO =
1232         DEFINE_REQ_FMT0("OBD_SET_INFO", obd_set_info_client, empty);
1233 EXPORT_SYMBOL(RQF_OBD_SET_INFO);
1234
1235 /* Read index file through the network */
1236 struct req_format RQF_OBD_IDX_READ =
1237         DEFINE_REQ_FMT0("OBD_IDX_READ",
1238                         obd_idx_read_client, obd_idx_read_server);
1239 EXPORT_SYMBOL(RQF_OBD_IDX_READ);
1240
1241 struct req_format RQF_SEC_CTX =
1242         DEFINE_REQ_FMT0("SEC_CTX", empty, empty);
1243 EXPORT_SYMBOL(RQF_SEC_CTX);
1244
1245 struct req_format RQF_MGS_TARGET_REG =
1246         DEFINE_REQ_FMT0("MGS_TARGET_REG", mgs_target_info_only,
1247                          mgs_target_info_only);
1248 EXPORT_SYMBOL(RQF_MGS_TARGET_REG);
1249
1250 struct req_format RQF_MGS_SET_INFO =
1251         DEFINE_REQ_FMT0("MGS_SET_INFO", mgs_set_info,
1252                          mgs_set_info);
1253 EXPORT_SYMBOL(RQF_MGS_SET_INFO);
1254
1255 struct req_format RQF_MGS_CONFIG_READ =
1256         DEFINE_REQ_FMT0("MGS_CONFIG_READ", mgs_config_read_client,
1257                          mgs_config_read_server);
1258 EXPORT_SYMBOL(RQF_MGS_CONFIG_READ);
1259
1260 struct req_format RQF_SEQ_QUERY =
1261         DEFINE_REQ_FMT0("SEQ_QUERY", seq_query_client, seq_query_server);
1262 EXPORT_SYMBOL(RQF_SEQ_QUERY);
1263
1264 struct req_format RQF_FLD_QUERY =
1265         DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
1266 EXPORT_SYMBOL(RQF_FLD_QUERY);
1267
1268 struct req_format RQF_FLD_READ =
1269         DEFINE_REQ_FMT0("FLD_READ", fld_read_client, fld_read_server);
1270 EXPORT_SYMBOL(RQF_FLD_READ);
1271
1272 struct req_format RQF_LOG_CANCEL =
1273         DEFINE_REQ_FMT0("OBD_LOG_CANCEL", log_cancel_client, empty);
1274 EXPORT_SYMBOL(RQF_LOG_CANCEL);
1275
1276 struct req_format RQF_MDS_QUOTACHECK =
1277         DEFINE_REQ_FMT0("MDS_QUOTACHECK", quotactl_only, empty);
1278 EXPORT_SYMBOL(RQF_MDS_QUOTACHECK);
1279
1280 struct req_format RQF_OST_QUOTACHECK =
1281         DEFINE_REQ_FMT0("OST_QUOTACHECK", quotactl_only, empty);
1282 EXPORT_SYMBOL(RQF_OST_QUOTACHECK);
1283
1284 struct req_format RQF_MDS_QUOTACTL =
1285         DEFINE_REQ_FMT0("MDS_QUOTACTL", quotactl_only, quotactl_only);
1286 EXPORT_SYMBOL(RQF_MDS_QUOTACTL);
1287
1288 struct req_format RQF_OST_QUOTACTL =
1289         DEFINE_REQ_FMT0("OST_QUOTACTL", quotactl_only, quotactl_only);
1290 EXPORT_SYMBOL(RQF_OST_QUOTACTL);
1291
1292 struct req_format RQF_QC_CALLBACK =
1293         DEFINE_REQ_FMT0("QC_CALLBACK", quotactl_only, empty);
1294 EXPORT_SYMBOL(RQF_QC_CALLBACK);
1295
1296 struct req_format RQF_QUOTA_DQACQ =
1297         DEFINE_REQ_FMT0("QUOTA_DQACQ", quota_body_only, quota_body_only);
1298 EXPORT_SYMBOL(RQF_QUOTA_DQACQ);
1299
1300 struct req_format RQF_LDLM_INTENT_QUOTA =
1301         DEFINE_REQ_FMT0("LDLM_INTENT_QUOTA",
1302                         ldlm_intent_quota_client,
1303                         ldlm_intent_quota_server);
1304 EXPORT_SYMBOL(RQF_LDLM_INTENT_QUOTA);
1305
1306 struct req_format RQF_MDS_GETSTATUS =
1307         DEFINE_REQ_FMT0("MDS_GETSTATUS", mdt_body_only, mdt_body_capa);
1308 EXPORT_SYMBOL(RQF_MDS_GETSTATUS);
1309
1310 struct req_format RQF_MDS_STATFS =
1311         DEFINE_REQ_FMT0("MDS_STATFS", empty, obd_statfs_server);
1312 EXPORT_SYMBOL(RQF_MDS_STATFS);
1313
1314 struct req_format RQF_MDS_SYNC =
1315         DEFINE_REQ_FMT0("MDS_SYNC", mdt_body_capa, mdt_body_only);
1316 EXPORT_SYMBOL(RQF_MDS_SYNC);
1317
1318 struct req_format RQF_MDS_GETATTR =
1319         DEFINE_REQ_FMT0("MDS_GETATTR", mdt_body_capa, mds_getattr_server);
1320 EXPORT_SYMBOL(RQF_MDS_GETATTR);
1321
1322 struct req_format RQF_MDS_GETXATTR =
1323         DEFINE_REQ_FMT0("MDS_GETXATTR",
1324                         mds_getxattr_client, mds_getxattr_server);
1325 EXPORT_SYMBOL(RQF_MDS_GETXATTR);
1326
1327 struct req_format RQF_MDS_GETATTR_NAME =
1328         DEFINE_REQ_FMT0("MDS_GETATTR_NAME",
1329                         mds_getattr_name_client, mds_getattr_server);
1330 EXPORT_SYMBOL(RQF_MDS_GETATTR_NAME);
1331
1332 struct req_format RQF_MDS_REINT =
1333         DEFINE_REQ_FMT0("MDS_REINT", mds_reint_client, mdt_body_only);
1334 EXPORT_SYMBOL(RQF_MDS_REINT);
1335
1336 struct req_format RQF_MDS_REINT_CREATE =
1337         DEFINE_REQ_FMT0("MDS_REINT_CREATE",
1338                         mds_reint_create_client, mdt_body_capa);
1339 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE);
1340
1341 struct req_format RQF_MDS_REINT_CREATE_RMT_ACL =
1342         DEFINE_REQ_FMT0("MDS_REINT_CREATE_RMT_ACL",
1343                         mds_reint_create_rmt_acl_client, mdt_body_capa);
1344 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_RMT_ACL);
1345
1346 struct req_format RQF_MDS_REINT_CREATE_SLAVE =
1347         DEFINE_REQ_FMT0("MDS_REINT_CREATE_EA",
1348                         mds_reint_create_slave_client, mdt_body_capa);
1349 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SLAVE);
1350
1351 struct req_format RQF_MDS_REINT_CREATE_SYM =
1352         DEFINE_REQ_FMT0("MDS_REINT_CREATE_SYM",
1353                         mds_reint_create_sym_client, mdt_body_capa);
1354 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SYM);
1355
1356 struct req_format RQF_MDS_REINT_OPEN =
1357         DEFINE_REQ_FMT0("MDS_REINT_OPEN",
1358                         mds_reint_open_client, mds_reint_open_server);
1359 EXPORT_SYMBOL(RQF_MDS_REINT_OPEN);
1360
1361 struct req_format RQF_MDS_REINT_UNLINK =
1362         DEFINE_REQ_FMT0("MDS_REINT_UNLINK", mds_reint_unlink_client,
1363                         mds_last_unlink_server);
1364 EXPORT_SYMBOL(RQF_MDS_REINT_UNLINK);
1365
1366 struct req_format RQF_MDS_REINT_LINK =
1367         DEFINE_REQ_FMT0("MDS_REINT_LINK",
1368                         mds_reint_link_client, mdt_body_only);
1369 EXPORT_SYMBOL(RQF_MDS_REINT_LINK);
1370
1371 struct req_format RQF_MDS_REINT_RENAME =
1372         DEFINE_REQ_FMT0("MDS_REINT_RENAME", mds_reint_rename_client,
1373                         mds_last_unlink_server);
1374 EXPORT_SYMBOL(RQF_MDS_REINT_RENAME);
1375
1376 struct req_format RQF_MDS_REINT_SETATTR =
1377         DEFINE_REQ_FMT0("MDS_REINT_SETATTR",
1378                         mds_reint_setattr_client, mds_setattr_server);
1379 EXPORT_SYMBOL(RQF_MDS_REINT_SETATTR);
1380
1381 struct req_format RQF_MDS_REINT_SETXATTR =
1382         DEFINE_REQ_FMT0("MDS_REINT_SETXATTR",
1383                         mds_reint_setxattr_client, mdt_body_only);
1384 EXPORT_SYMBOL(RQF_MDS_REINT_SETXATTR);
1385
1386 struct req_format RQF_MDS_CONNECT =
1387         DEFINE_REQ_FMT0("MDS_CONNECT",
1388                         obd_connect_client, obd_connect_server);
1389 EXPORT_SYMBOL(RQF_MDS_CONNECT);
1390
1391 struct req_format RQF_MDS_DISCONNECT =
1392         DEFINE_REQ_FMT0("MDS_DISCONNECT", empty, empty);
1393 EXPORT_SYMBOL(RQF_MDS_DISCONNECT);
1394
1395 struct req_format RQF_MDS_GET_INFO =
1396         DEFINE_REQ_FMT0("MDS_GET_INFO", mds_getinfo_client,
1397                         mds_getinfo_server);
1398 EXPORT_SYMBOL(RQF_MDS_GET_INFO);
1399
1400 struct req_format RQF_OUT_UPDATE =
1401         DEFINE_REQ_FMT0("OUT_UPDATE_OBJ", mds_update_client,
1402                         mds_update_server);
1403 EXPORT_SYMBOL(RQF_OUT_UPDATE);
1404
1405 struct req_format RQF_LDLM_ENQUEUE =
1406         DEFINE_REQ_FMT0("LDLM_ENQUEUE",
1407                         ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1408 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE);
1409
1410 struct req_format RQF_LDLM_ENQUEUE_LVB =
1411         DEFINE_REQ_FMT0("LDLM_ENQUEUE_LVB",
1412                         ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1413 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE_LVB);
1414
1415 struct req_format RQF_LDLM_CONVERT =
1416         DEFINE_REQ_FMT0("LDLM_CONVERT",
1417                         ldlm_enqueue_client, ldlm_enqueue_server);
1418 EXPORT_SYMBOL(RQF_LDLM_CONVERT);
1419
1420 struct req_format RQF_LDLM_CANCEL =
1421         DEFINE_REQ_FMT0("LDLM_CANCEL", ldlm_enqueue_client, empty);
1422 EXPORT_SYMBOL(RQF_LDLM_CANCEL);
1423
1424 struct req_format RQF_LDLM_CALLBACK =
1425         DEFINE_REQ_FMT0("LDLM_CALLBACK", ldlm_enqueue_client, empty);
1426 EXPORT_SYMBOL(RQF_LDLM_CALLBACK);
1427
1428 struct req_format RQF_LDLM_CP_CALLBACK =
1429         DEFINE_REQ_FMT0("LDLM_CP_CALLBACK", ldlm_cp_callback_client, empty);
1430 EXPORT_SYMBOL(RQF_LDLM_CP_CALLBACK);
1431
1432 struct req_format RQF_LDLM_BL_CALLBACK =
1433         DEFINE_REQ_FMT0("LDLM_BL_CALLBACK", ldlm_enqueue_client, empty);
1434 EXPORT_SYMBOL(RQF_LDLM_BL_CALLBACK);
1435
1436 struct req_format RQF_LDLM_GL_CALLBACK =
1437         DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_enqueue_client,
1438                         ldlm_gl_callback_server);
1439 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK);
1440
1441 struct req_format RQF_LDLM_GL_DESC_CALLBACK =
1442         DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_gl_callback_desc_client,
1443                         ldlm_gl_callback_server);
1444 EXPORT_SYMBOL(RQF_LDLM_GL_DESC_CALLBACK);
1445
1446 struct req_format RQF_LDLM_INTENT_BASIC =
1447         DEFINE_REQ_FMT0("LDLM_INTENT_BASIC",
1448                         ldlm_intent_basic_client, ldlm_enqueue_lvb_server);
1449 EXPORT_SYMBOL(RQF_LDLM_INTENT_BASIC);
1450
1451 struct req_format RQF_LDLM_INTENT =
1452         DEFINE_REQ_FMT0("LDLM_INTENT",
1453                         ldlm_intent_client, ldlm_intent_server);
1454 EXPORT_SYMBOL(RQF_LDLM_INTENT);
1455
1456 struct req_format RQF_LDLM_INTENT_LAYOUT =
1457         DEFINE_REQ_FMT0("LDLM_INTENT_LAYOUT ",
1458                         ldlm_intent_layout_client, ldlm_enqueue_lvb_server);
1459 EXPORT_SYMBOL(RQF_LDLM_INTENT_LAYOUT);
1460
1461 struct req_format RQF_LDLM_INTENT_GETATTR =
1462         DEFINE_REQ_FMT0("LDLM_INTENT_GETATTR",
1463                         ldlm_intent_getattr_client, ldlm_intent_getattr_server);
1464 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETATTR);
1465
1466 struct req_format RQF_LDLM_INTENT_OPEN =
1467         DEFINE_REQ_FMT0("LDLM_INTENT_OPEN",
1468                         ldlm_intent_open_client, ldlm_intent_open_server);
1469 EXPORT_SYMBOL(RQF_LDLM_INTENT_OPEN);
1470
1471 struct req_format RQF_LDLM_INTENT_CREATE =
1472         DEFINE_REQ_FMT0("LDLM_INTENT_CREATE",
1473                         ldlm_intent_create_client, ldlm_intent_getattr_server);
1474 EXPORT_SYMBOL(RQF_LDLM_INTENT_CREATE);
1475
1476 struct req_format RQF_LDLM_INTENT_UNLINK =
1477         DEFINE_REQ_FMT0("LDLM_INTENT_UNLINK",
1478                         ldlm_intent_unlink_client, ldlm_intent_server);
1479 EXPORT_SYMBOL(RQF_LDLM_INTENT_UNLINK);
1480
1481 struct req_format RQF_LDLM_INTENT_GETXATTR =
1482         DEFINE_REQ_FMT0("LDLM_INTENT_GETXATTR",
1483                         ldlm_intent_getxattr_client,
1484                         ldlm_intent_getxattr_server);
1485 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETXATTR);
1486
1487 struct req_format RQF_MDS_CLOSE =
1488         DEFINE_REQ_FMT0("MDS_CLOSE",
1489                         mdt_close_client, mds_last_unlink_server);
1490 EXPORT_SYMBOL(RQF_MDS_CLOSE);
1491
1492 struct req_format RQF_MDS_RELEASE_CLOSE =
1493         DEFINE_REQ_FMT0("MDS_CLOSE",
1494                         mdt_release_close_client, mds_last_unlink_server);
1495 EXPORT_SYMBOL(RQF_MDS_RELEASE_CLOSE);
1496
1497 struct req_format RQF_MDS_DONE_WRITING =
1498         DEFINE_REQ_FMT0("MDS_DONE_WRITING",
1499                         mdt_close_client, mdt_body_only);
1500 EXPORT_SYMBOL(RQF_MDS_DONE_WRITING);
1501
1502 struct req_format RQF_MDS_READPAGE =
1503         DEFINE_REQ_FMT0("MDS_READPAGE",
1504                         mdt_body_capa, mdt_body_only);
1505 EXPORT_SYMBOL(RQF_MDS_READPAGE);
1506
1507 struct req_format RQF_MDS_HSM_ACTION =
1508         DEFINE_REQ_FMT0("MDS_HSM_ACTION", mdt_body_capa, mdt_hsm_action_server);
1509 EXPORT_SYMBOL(RQF_MDS_HSM_ACTION);
1510
1511 struct req_format RQF_MDS_HSM_PROGRESS =
1512         DEFINE_REQ_FMT0("MDS_HSM_PROGRESS", mdt_hsm_progress, empty);
1513 EXPORT_SYMBOL(RQF_MDS_HSM_PROGRESS);
1514
1515 struct req_format RQF_MDS_HSM_CT_REGISTER =
1516         DEFINE_REQ_FMT0("MDS_HSM_CT_REGISTER", mdt_hsm_ct_register, empty);
1517 EXPORT_SYMBOL(RQF_MDS_HSM_CT_REGISTER);
1518
1519 struct req_format RQF_MDS_HSM_CT_UNREGISTER =
1520         DEFINE_REQ_FMT0("MDS_HSM_CT_UNREGISTER", mdt_hsm_ct_unregister, empty);
1521 EXPORT_SYMBOL(RQF_MDS_HSM_CT_UNREGISTER);
1522
1523 struct req_format RQF_MDS_HSM_STATE_GET =
1524         DEFINE_REQ_FMT0("MDS_HSM_STATE_GET",
1525                         mdt_body_capa, mdt_hsm_state_get_server);
1526 EXPORT_SYMBOL(RQF_MDS_HSM_STATE_GET);
1527
1528 struct req_format RQF_MDS_HSM_STATE_SET =
1529         DEFINE_REQ_FMT0("MDS_HSM_STATE_SET", mdt_hsm_state_set, empty);
1530 EXPORT_SYMBOL(RQF_MDS_HSM_STATE_SET);
1531
1532 struct req_format RQF_MDS_HSM_REQUEST =
1533         DEFINE_REQ_FMT0("MDS_HSM_REQUEST", mdt_hsm_request, empty);
1534 EXPORT_SYMBOL(RQF_MDS_HSM_REQUEST);
1535
1536 struct req_format RQF_MDS_SWAP_LAYOUTS =
1537         DEFINE_REQ_FMT0("MDS_SWAP_LAYOUTS",
1538                         mdt_swap_layouts, empty);
1539 EXPORT_SYMBOL(RQF_MDS_SWAP_LAYOUTS);
1540
1541 struct req_format RQF_LLOG_ORIGIN_HANDLE_CREATE =
1542         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_CREATE",
1543                         llog_origin_handle_create_client, llogd_body_only);
1544 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_CREATE);
1545
1546 struct req_format RQF_LLOG_ORIGIN_HANDLE_DESTROY =
1547         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_DESTROY",
1548                         llogd_body_only, llogd_body_only);
1549 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1550
1551 struct req_format RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK =
1552         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_NEXT_BLOCK",
1553                         llogd_body_only, llog_origin_handle_next_block_server);
1554 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1555
1556 struct req_format RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK =
1557         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_PREV_BLOCK",
1558                         llogd_body_only, llog_origin_handle_next_block_server);
1559 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1560
1561 struct req_format RQF_LLOG_ORIGIN_HANDLE_READ_HEADER =
1562         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_READ_HEADER",
1563                         llogd_body_only, llog_log_hdr_only);
1564 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1565
1566 struct req_format RQF_LLOG_ORIGIN_CONNECT =
1567         DEFINE_REQ_FMT0("LLOG_ORIGIN_CONNECT", llogd_conn_body_only, empty);
1568 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_CONNECT);
1569
1570 struct req_format RQF_CONNECT =
1571         DEFINE_REQ_FMT0("CONNECT", obd_connect_client, obd_connect_server);
1572 EXPORT_SYMBOL(RQF_CONNECT);
1573
1574 struct req_format RQF_OST_CONNECT =
1575         DEFINE_REQ_FMT0("OST_CONNECT",
1576                         obd_connect_client, obd_connect_server);
1577 EXPORT_SYMBOL(RQF_OST_CONNECT);
1578
1579 struct req_format RQF_OST_DISCONNECT =
1580         DEFINE_REQ_FMT0("OST_DISCONNECT", empty, empty);
1581 EXPORT_SYMBOL(RQF_OST_DISCONNECT);
1582
1583 struct req_format RQF_OST_GETATTR =
1584         DEFINE_REQ_FMT0("OST_GETATTR", ost_body_capa, ost_body_only);
1585 EXPORT_SYMBOL(RQF_OST_GETATTR);
1586
1587 struct req_format RQF_OST_SETATTR =
1588         DEFINE_REQ_FMT0("OST_SETATTR", ost_body_capa, ost_body_only);
1589 EXPORT_SYMBOL(RQF_OST_SETATTR);
1590
1591 struct req_format RQF_OST_CREATE =
1592         DEFINE_REQ_FMT0("OST_CREATE", ost_body_only, ost_body_only);
1593 EXPORT_SYMBOL(RQF_OST_CREATE);
1594
1595 struct req_format RQF_OST_PUNCH =
1596         DEFINE_REQ_FMT0("OST_PUNCH", ost_body_capa, ost_body_only);
1597 EXPORT_SYMBOL(RQF_OST_PUNCH);
1598
1599 struct req_format RQF_OST_SYNC =
1600         DEFINE_REQ_FMT0("OST_SYNC", ost_body_capa, ost_body_only);
1601 EXPORT_SYMBOL(RQF_OST_SYNC);
1602
1603 struct req_format RQF_OST_DESTROY =
1604         DEFINE_REQ_FMT0("OST_DESTROY", ost_destroy_client, ost_body_only);
1605 EXPORT_SYMBOL(RQF_OST_DESTROY);
1606
1607 struct req_format RQF_OST_BRW_READ =
1608         DEFINE_REQ_FMT0("OST_BRW_READ", ost_brw_client, ost_brw_read_server);
1609 EXPORT_SYMBOL(RQF_OST_BRW_READ);
1610
1611 struct req_format RQF_OST_BRW_WRITE =
1612         DEFINE_REQ_FMT0("OST_BRW_WRITE", ost_brw_client, ost_brw_write_server);
1613 EXPORT_SYMBOL(RQF_OST_BRW_WRITE);
1614
1615 struct req_format RQF_OST_STATFS =
1616         DEFINE_REQ_FMT0("OST_STATFS", empty, obd_statfs_server);
1617 EXPORT_SYMBOL(RQF_OST_STATFS);
1618
1619 struct req_format RQF_OST_SET_GRANT_INFO =
1620         DEFINE_REQ_FMT0("OST_SET_GRANT_INFO", ost_grant_shrink_client,
1621                          ost_body_only);
1622 EXPORT_SYMBOL(RQF_OST_SET_GRANT_INFO);
1623
1624 struct req_format RQF_OST_GET_INFO =
1625         DEFINE_REQ_FMT0("OST_GET_INFO", ost_get_info_generic_client,
1626                                         ost_get_info_generic_server);
1627 EXPORT_SYMBOL(RQF_OST_GET_INFO);
1628
1629 struct req_format RQF_OST_GET_INFO_LAST_ID =
1630         DEFINE_REQ_FMT0("OST_GET_INFO_LAST_ID", ost_get_info_generic_client,
1631                                                 ost_get_last_id_server);
1632 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_ID);
1633
1634 struct req_format RQF_OST_GET_INFO_LAST_FID =
1635         DEFINE_REQ_FMT0("OST_GET_INFO_LAST_FID", ost_get_last_fid_client,
1636                                                  ost_get_last_fid_server);
1637 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_FID);
1638
1639 struct req_format RQF_OST_SET_INFO_LAST_FID =
1640         DEFINE_REQ_FMT0("OST_SET_INFO_LAST_FID", obd_set_info_client,
1641                                                  empty);
1642 EXPORT_SYMBOL(RQF_OST_SET_INFO_LAST_FID);
1643
1644 struct req_format RQF_OST_GET_INFO_FIEMAP =
1645         DEFINE_REQ_FMT0("OST_GET_INFO_FIEMAP", ost_get_fiemap_client,
1646                                                ost_get_fiemap_server);
1647 EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP);
1648
1649 struct req_format RQF_LFSCK_NOTIFY =
1650         DEFINE_REQ_FMT0("LFSCK_NOTIFY", obd_lfsck_request, empty);
1651 EXPORT_SYMBOL(RQF_LFSCK_NOTIFY);
1652
1653 struct req_format RQF_LFSCK_QUERY =
1654         DEFINE_REQ_FMT0("LFSCK_QUERY", obd_lfsck_request, obd_lfsck_reply);
1655 EXPORT_SYMBOL(RQF_LFSCK_QUERY);
1656
1657 #if !defined(__REQ_LAYOUT_USER__)
1658
1659 /* Convenience macro */
1660 #define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1661
1662 /**
1663  * Initializes the capsule abstraction by computing and setting the \a rf_idx
1664  * field of RQFs and the \a rmf_offset field of RMFs.
1665  */
1666 int req_layout_init(void)
1667 {
1668         size_t i;
1669         size_t j;
1670         size_t k;
1671         struct req_format *rf = NULL;
1672
1673         for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
1674                 rf = req_formats[i];
1675                 rf->rf_idx = i;
1676                 for (j = 0; j < RCL_NR; ++j) {
1677                         LASSERT(rf->rf_fields[j].nr <= REQ_MAX_FIELD_NR);
1678                         for (k = 0; k < rf->rf_fields[j].nr; ++k) {
1679                                 struct req_msg_field *field;
1680
1681                                 field = (typeof(field))rf->rf_fields[j].d[k];
1682                                 LASSERT(!(field->rmf_flags & RMF_F_STRUCT_ARRAY)
1683                                         || field->rmf_size > 0);
1684                                 LASSERT(field->rmf_offset[i][j] == 0);
1685                                 /*
1686                                  * k + 1 to detect unused format/field
1687                                  * combinations.
1688                                  */
1689                                 field->rmf_offset[i][j] = k + 1;
1690                         }
1691                 }
1692         }
1693         return 0;
1694 }
1695 EXPORT_SYMBOL(req_layout_init);
1696
1697 void req_layout_fini(void)
1698 {
1699 }
1700 EXPORT_SYMBOL(req_layout_fini);
1701
1702 /**
1703  * Initializes the expected sizes of each RMF in a \a pill (\a rc_area) to -1.
1704  *
1705  * Actual/expected field sizes are set elsewhere in functions in this file:
1706  * req_capsule_init(), req_capsule_server_pack(), req_capsule_set_size() and
1707  * req_capsule_msg_size().  The \a rc_area information is used by.
1708  * ptlrpc_request_set_replen().
1709  */
1710 void req_capsule_init_area(struct req_capsule *pill)
1711 {
1712         size_t i;
1713
1714         for (i = 0; i < ARRAY_SIZE(pill->rc_area[RCL_CLIENT]); i++) {
1715                 pill->rc_area[RCL_CLIENT][i] = -1;
1716                 pill->rc_area[RCL_SERVER][i] = -1;
1717         }
1718 }
1719 EXPORT_SYMBOL(req_capsule_init_area);
1720
1721 /**
1722  * Initialize a pill.
1723  *
1724  * The \a location indicates whether the caller is executing on the client side
1725  * (RCL_CLIENT) or server side (RCL_SERVER)..
1726  */
1727 void req_capsule_init(struct req_capsule *pill,
1728                       struct ptlrpc_request *req,
1729                       enum req_location location)
1730 {
1731         LASSERT(location == RCL_SERVER || location == RCL_CLIENT);
1732
1733         /*
1734          * Today all capsules are embedded in ptlrpc_request structs,
1735          * but just in case that ever isn't the case, we don't reach
1736          * into req unless req != NULL and pill is the one embedded in
1737          * the req.
1738          *
1739          * The req->rq_pill_init flag makes it safe to initialize a pill
1740          * twice, which might happen in the OST paths as a result of the
1741          * high-priority RPC queue getting peeked at before ost_handle()
1742          * handles an OST RPC.
1743          */
1744         if (req != NULL && pill == &req->rq_pill && req->rq_pill_init)
1745                 return;
1746
1747         memset(pill, 0, sizeof *pill);
1748         pill->rc_req = req;
1749         pill->rc_loc = location;
1750         req_capsule_init_area(pill);
1751
1752         if (req != NULL && pill == &req->rq_pill)
1753                 req->rq_pill_init = 1;
1754 }
1755 EXPORT_SYMBOL(req_capsule_init);
1756
1757 void req_capsule_fini(struct req_capsule *pill)
1758 {
1759 }
1760 EXPORT_SYMBOL(req_capsule_fini);
1761
1762 static int __req_format_is_sane(const struct req_format *fmt)
1763 {
1764         return fmt->rf_idx < ARRAY_SIZE(req_formats) &&
1765                 req_formats[fmt->rf_idx] == fmt;
1766 }
1767
1768 static struct lustre_msg *__req_msg(const struct req_capsule *pill,
1769                                     enum req_location loc)
1770 {
1771         struct ptlrpc_request *req;
1772
1773         req = pill->rc_req;
1774         return loc == RCL_CLIENT ? req->rq_reqmsg : req->rq_repmsg;
1775 }
1776
1777 /**
1778  * Set the format (\a fmt) of a \a pill; format changes are not allowed here
1779  * (see req_capsule_extend()).
1780  */
1781 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt)
1782 {
1783         LASSERT(pill->rc_fmt == NULL || pill->rc_fmt == fmt);
1784         LASSERT(__req_format_is_sane(fmt));
1785
1786         pill->rc_fmt = fmt;
1787 }
1788 EXPORT_SYMBOL(req_capsule_set);
1789
1790 /**
1791  * Fills in any parts of the \a rc_area of a \a pill that haven't been filled in
1792  * yet.
1793
1794  * \a rc_area is an array of REQ_MAX_FIELD_NR elements, used to store sizes of
1795  * variable-sized fields.  The field sizes come from the declared \a rmf_size
1796  * field of a \a pill's \a rc_fmt's RMF's.
1797  */
1798 size_t req_capsule_filled_sizes(struct req_capsule *pill,
1799                                 enum req_location loc)
1800 {
1801         const struct req_format *fmt = pill->rc_fmt;
1802         size_t                   i;
1803
1804         LASSERT(fmt != NULL);
1805
1806         for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1807                 if (pill->rc_area[loc][i] == -1) {
1808                         pill->rc_area[loc][i] =
1809                                             fmt->rf_fields[loc].d[i]->rmf_size;
1810                         if (pill->rc_area[loc][i] == -1) {
1811                                 /*
1812                                  * Skip the following fields.
1813                                  *
1814                                  * If this LASSERT() trips then you're missing a
1815                                  * call to req_capsule_set_size().
1816                                  */
1817                                 LASSERT(loc != RCL_SERVER);
1818                                 break;
1819                         }
1820                 }
1821         }
1822         return i;
1823 }
1824 EXPORT_SYMBOL(req_capsule_filled_sizes);
1825
1826 /**
1827  * Capsule equivalent of lustre_pack_request() and lustre_pack_reply().
1828  *
1829  * This function uses the \a pill's \a rc_area as filled in by
1830  * req_capsule_set_size() or req_capsule_filled_sizes() (the latter is called by
1831  * this function).
1832  */
1833 int req_capsule_server_pack(struct req_capsule *pill)
1834 {
1835         const struct req_format *fmt;
1836         int                      count;
1837         int                      rc;
1838
1839         LASSERT(pill->rc_loc == RCL_SERVER);
1840         fmt = pill->rc_fmt;
1841         LASSERT(fmt != NULL);
1842
1843         count = req_capsule_filled_sizes(pill, RCL_SERVER);
1844         rc = lustre_pack_reply(pill->rc_req, count,
1845                                pill->rc_area[RCL_SERVER], NULL);
1846         if (rc != 0) {
1847                 DEBUG_REQ(D_ERROR, pill->rc_req,
1848                        "Cannot pack %d fields in format `%s': ",
1849                        count, fmt->rf_name);
1850         }
1851         return rc;
1852 }
1853 EXPORT_SYMBOL(req_capsule_server_pack);
1854
1855 /**
1856  * Returns the PTLRPC request or reply (\a loc) buffer offset of a \a pill
1857  * corresponding to the given RMF (\a field).
1858  */
1859 static __u32 __req_capsule_offset(const struct req_capsule *pill,
1860                                   const struct req_msg_field *field,
1861                                   enum req_location loc)
1862 {
1863         int offset;
1864
1865         offset = field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1866         LASSERTF(offset > 0, "%s:%s, off=%d, loc=%d\n",
1867                             pill->rc_fmt->rf_name,
1868                             field->rmf_name, offset, loc);
1869         offset --;
1870
1871         LASSERT(0 <= offset && offset < REQ_MAX_FIELD_NR);
1872         return offset;
1873 }
1874
1875 /**
1876  * Helper for __req_capsule_get(); swabs value / array of values and/or dumps
1877  * them if desired.
1878  */
1879 static
1880 void
1881 swabber_dumper_helper(struct req_capsule *pill,
1882                       const struct req_msg_field *field,
1883                       enum req_location loc,
1884                       int offset,
1885                       void *value, int len, int dump, void (*swabber)( void *))
1886 {
1887         void    *p;
1888         int     i;
1889         int     n;
1890         int     do_swab;
1891         int     inout = loc == RCL_CLIENT;
1892
1893         swabber = swabber ?: field->rmf_swabber;
1894
1895         if (ptlrpc_buf_need_swab(pill->rc_req, inout, offset) &&
1896             swabber != NULL && value != NULL)
1897                 do_swab = 1;
1898         else
1899                 do_swab = 0;
1900
1901         if (!field->rmf_dumper)
1902                 dump = 0;
1903
1904         if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY)) {
1905                 if (dump) {
1906                         CDEBUG(D_RPCTRACE, "Dump of %sfield %s follows\n",
1907                                do_swab ? "unswabbed " : "", field->rmf_name);
1908                         field->rmf_dumper(value);
1909                 }
1910                 if (!do_swab)
1911                         return;
1912                 swabber(value);
1913                 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1914                 if (dump) {
1915                         CDEBUG(D_RPCTRACE, "Dump of swabbed field %s "
1916                                "follows\n", field->rmf_name);
1917                         field->rmf_dumper(value);
1918                 }
1919
1920                 return;
1921         }
1922
1923         /*
1924          * We're swabbing an array; swabber() swabs a single array element, so
1925          * swab every element.
1926          */
1927         LASSERT((len % field->rmf_size) == 0);
1928         for (p = value, i = 0, n = len / field->rmf_size;
1929              i < n;
1930              i++, p += field->rmf_size) {
1931                 if (dump) {
1932                         CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, "
1933                                "element %d follows\n",
1934                                do_swab ? "unswabbed " : "", field->rmf_name, i);
1935                         field->rmf_dumper(p);
1936                 }
1937                 if (!do_swab)
1938                         continue;
1939                 swabber(p);
1940                 if (dump) {
1941                         CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, "
1942                                "element %d follows\n", field->rmf_name, i);
1943                         field->rmf_dumper(value);
1944                 }
1945         }
1946         if (do_swab)
1947                 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1948 }
1949
1950 /**
1951  * Returns the pointer to a PTLRPC request or reply (\a loc) buffer of a \a pill
1952  * corresponding to the given RMF (\a field).
1953  *
1954  * The buffer will be swabbed using the given \a swabber.  If \a swabber == NULL
1955  * then the \a rmf_swabber from the RMF will be used.  Soon there will be no
1956  * calls to __req_capsule_get() with a non-NULL \a swabber; \a swabber will then
1957  * be removed.  Fields with the \a RMF_F_STRUCT_ARRAY flag set will have each
1958  * element of the array swabbed.
1959  */
1960 static void *__req_capsule_get(struct req_capsule *pill,
1961                                const struct req_msg_field *field,
1962                                enum req_location loc,
1963                                void (*swabber)( void *),
1964                                int dump)
1965 {
1966         const struct req_format *fmt;
1967         struct lustre_msg       *msg;
1968         void                    *value;
1969         __u32                    len;
1970         __u32                    offset;
1971
1972         void *(*getter)(struct lustre_msg *m, __u32 n, __u32 minlen);
1973
1974         static const char *rcl_names[RCL_NR] = {
1975                 [RCL_CLIENT] = "client",
1976                 [RCL_SERVER] = "server"
1977         };
1978
1979         LASSERT(pill != NULL);
1980         LASSERT(pill != LP_POISON);
1981         fmt = pill->rc_fmt;
1982         LASSERT(fmt != NULL);
1983         LASSERT(fmt != LP_POISON);
1984         LASSERT(__req_format_is_sane(fmt));
1985
1986         offset = __req_capsule_offset(pill, field, loc);
1987
1988         msg = __req_msg(pill, loc);
1989         LASSERT(msg != NULL);
1990
1991         getter = (field->rmf_flags & RMF_F_STRING) ?
1992                 (typeof(getter))lustre_msg_string : lustre_msg_buf;
1993
1994         if (field->rmf_flags & (RMF_F_STRUCT_ARRAY|RMF_F_NO_SIZE_CHECK)) {
1995                 /*
1996                  * We've already asserted that field->rmf_size > 0 in
1997                  * req_layout_init().
1998                  */
1999                 len = lustre_msg_buflen(msg, offset);
2000                 if (!(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
2001                     (len % field->rmf_size) != 0) {
2002                         CERROR("%s: array field size mismatch "
2003                                 "%d modulo %u != 0 (%d)\n",
2004                                 field->rmf_name, len, field->rmf_size, loc);
2005                         return NULL;
2006                 }
2007         } else if (pill->rc_area[loc][offset] != -1) {
2008                 len = pill->rc_area[loc][offset];
2009         } else {
2010                 len = max_t(typeof(field->rmf_size), field->rmf_size, 0);
2011         }
2012         value = getter(msg, offset, len);
2013
2014         if (value == NULL) {
2015                 DEBUG_REQ(D_ERROR, pill->rc_req,
2016                           "Wrong buffer for field `%s' (%u of %u) "
2017                           "in format `%s': %u vs. %u (%s)\n",
2018                           field->rmf_name, offset, lustre_msg_bufcount(msg),
2019                           fmt->rf_name, lustre_msg_buflen(msg, offset), len,
2020                           rcl_names[loc]);
2021         } else {
2022                 swabber_dumper_helper(pill, field, loc, offset, value, len,
2023                                       dump, swabber);
2024         }
2025
2026         return value;
2027 }
2028
2029 /**
2030  * Dump a request and/or reply
2031  */
2032 void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
2033 {
2034         const struct    req_format *fmt;
2035         const struct    req_msg_field *field;
2036         __u32           len;
2037         size_t          i;
2038
2039         fmt = pill->rc_fmt;
2040
2041         DEBUG_REQ(D_RPCTRACE, pill->rc_req, "BEGIN REQ CAPSULE DUMP\n");
2042         for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
2043                 field = FMT_FIELD(fmt, loc, i);
2044                 if (field->rmf_dumper == NULL) {
2045                         /*
2046                          * FIXME Add a default hex dumper for fields that don't
2047                          * have a specific dumper
2048                          */
2049                         len = req_capsule_get_size(pill, field, loc);
2050                         CDEBUG(D_RPCTRACE, "Field %s has no dumper function;"
2051                                 "field size is %u\n", field->rmf_name, len);
2052                 } else {
2053                         /* It's the dumping side-effect that we're interested in */
2054                         (void) __req_capsule_get(pill, field, loc, NULL, 1);
2055                 }
2056         }
2057         CDEBUG(D_RPCTRACE, "END REQ CAPSULE DUMP\n");
2058 }
2059
2060 /**
2061  * Dump a request.
2062  */
2063 void req_capsule_client_dump(struct req_capsule *pill)
2064 {
2065         __req_capsule_dump(pill, RCL_CLIENT);
2066 }
2067 EXPORT_SYMBOL(req_capsule_client_dump);
2068
2069 /**
2070  * Dump a reply
2071  */
2072 void req_capsule_server_dump(struct req_capsule *pill)
2073 {
2074         __req_capsule_dump(pill, RCL_SERVER);
2075 }
2076 EXPORT_SYMBOL(req_capsule_server_dump);
2077
2078 /**
2079  * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC request
2080  * buffer corresponding to the given RMF (\a field) of a \a pill.
2081  */
2082 void *req_capsule_client_get(struct req_capsule *pill,
2083                              const struct req_msg_field *field)
2084 {
2085         return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
2086 }
2087 EXPORT_SYMBOL(req_capsule_client_get);
2088
2089 /**
2090  * Same as req_capsule_client_get(), but with a \a swabber argument.
2091  *
2092  * Currently unused; will be removed when req_capsule_server_swab_get() is
2093  * unused too.
2094  */
2095 void *req_capsule_client_swab_get(struct req_capsule *pill,
2096                                   const struct req_msg_field *field,
2097                                   void *swabber)
2098 {
2099         return __req_capsule_get(pill, field, RCL_CLIENT, swabber, 0);
2100 }
2101 EXPORT_SYMBOL(req_capsule_client_swab_get);
2102
2103 /**
2104  * Utility that combines req_capsule_set_size() and req_capsule_client_get().
2105  *
2106  * First the \a pill's request \a field's size is set (\a rc_area) using
2107  * req_capsule_set_size() with the given \a len.  Then the actual buffer is
2108  * returned.
2109  */
2110 void *req_capsule_client_sized_get(struct req_capsule *pill,
2111                                    const struct req_msg_field *field,
2112                                    __u32 len)
2113 {
2114         req_capsule_set_size(pill, field, RCL_CLIENT, len);
2115         return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
2116 }
2117 EXPORT_SYMBOL(req_capsule_client_sized_get);
2118
2119 /**
2120  * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC reply
2121  * buffer corresponding to the given RMF (\a field) of a \a pill.
2122  */
2123 void *req_capsule_server_get(struct req_capsule *pill,
2124                              const struct req_msg_field *field)
2125 {
2126         return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
2127 }
2128 EXPORT_SYMBOL(req_capsule_server_get);
2129
2130 /**
2131  * Same as req_capsule_server_get(), but with a \a swabber argument.
2132  *
2133  * Ideally all swabbing should be done pursuant to RMF definitions, with no
2134  * swabbing done outside this capsule abstraction.
2135  */
2136 void *req_capsule_server_swab_get(struct req_capsule *pill,
2137                                   const struct req_msg_field *field,
2138                                   void *swabber)
2139 {
2140         return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
2141 }
2142 EXPORT_SYMBOL(req_capsule_server_swab_get);
2143
2144 /**
2145  * Utility that combines req_capsule_set_size() and req_capsule_server_get().
2146  *
2147  * First the \a pill's request \a field's size is set (\a rc_area) using
2148  * req_capsule_set_size() with the given \a len.  Then the actual buffer is
2149  * returned.
2150  */
2151 void *req_capsule_server_sized_get(struct req_capsule *pill,
2152                                    const struct req_msg_field *field,
2153                                    __u32 len)
2154 {
2155         req_capsule_set_size(pill, field, RCL_SERVER, len);
2156         return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
2157 }
2158 EXPORT_SYMBOL(req_capsule_server_sized_get);
2159
2160 void *req_capsule_server_sized_swab_get(struct req_capsule *pill,
2161                                         const struct req_msg_field *field,
2162                                         __u32 len, void *swabber)
2163 {
2164         req_capsule_set_size(pill, field, RCL_SERVER, len);
2165         return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
2166 }
2167 EXPORT_SYMBOL(req_capsule_server_sized_swab_get);
2168
2169 /**
2170  * Returns the buffer of a \a pill corresponding to the given \a field from the
2171  * request (if the caller is executing on the server-side) or reply (if the
2172  * caller is executing on the client-side).
2173  *
2174  * This function convienient for use is code that could be executed on the
2175  * client and server alike.
2176  */
2177 const void *req_capsule_other_get(struct req_capsule *pill,
2178                                   const struct req_msg_field *field)
2179 {
2180         return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL, 0);
2181 }
2182 EXPORT_SYMBOL(req_capsule_other_get);
2183
2184 /**
2185  * Set the size of the PTLRPC request/reply (\a loc) buffer for the given \a
2186  * field of the given \a pill.
2187  *
2188  * This function must be used when constructing variable sized fields of a
2189  * request or reply.
2190  */
2191 void req_capsule_set_size(struct req_capsule *pill,
2192                           const struct req_msg_field *field,
2193                           enum req_location loc, __u32 size)
2194 {
2195         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2196
2197         if ((size != (__u32)field->rmf_size) &&
2198             (field->rmf_size != -1) &&
2199             !(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
2200             (size > 0)) {
2201                 __u32 rmf_size = (__u32)field->rmf_size;
2202                 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
2203                     (size % rmf_size != 0)) {
2204                         CERROR("%s: array field size mismatch "
2205                                 "%u %% %u != 0 (%d)\n",
2206                                 field->rmf_name, size, rmf_size, loc);
2207                         LBUG();
2208                 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
2209                            size < rmf_size) {
2210                         CERROR("%s: field size mismatch %u != %u (%d)\n",
2211                                 field->rmf_name, size, rmf_size, loc);
2212                         LBUG();
2213                 }
2214         }
2215
2216         pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size;
2217 }
2218 EXPORT_SYMBOL(req_capsule_set_size);
2219
2220 /**
2221  * Return the actual PTLRPC buffer length of a request or reply (\a loc)
2222  * for the given \a pill's given \a field.
2223  *
2224  * NB: this function doesn't correspond with req_capsule_set_size(), which
2225  * actually sets the size in pill.rc_area[loc][offset], but this function
2226  * returns the message buflen[offset], maybe we should use another name.
2227  */
2228 __u32 req_capsule_get_size(const struct req_capsule *pill,
2229                          const struct req_msg_field *field,
2230                          enum req_location loc)
2231 {
2232         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2233
2234         return lustre_msg_buflen(__req_msg(pill, loc),
2235                                  __req_capsule_offset(pill, field, loc));
2236 }
2237 EXPORT_SYMBOL(req_capsule_get_size);
2238
2239 /**
2240  * Wrapper around lustre_msg_size() that returns the PTLRPC size needed for the
2241  * given \a pill's request or reply (\a loc) given the field size recorded in
2242  * the \a pill's rc_area.
2243  *
2244  * See also req_capsule_set_size().
2245  */
2246 __u32 req_capsule_msg_size(struct req_capsule *pill, enum req_location loc)
2247 {
2248         return lustre_msg_size(pill->rc_req->rq_import->imp_msg_magic,
2249                                pill->rc_fmt->rf_fields[loc].nr,
2250                                pill->rc_area[loc]);
2251 }
2252
2253 /**
2254  * While req_capsule_msg_size() computes the size of a PTLRPC request or reply
2255  * (\a loc) given a \a pill's \a rc_area, this function computes the size of a
2256  * PTLRPC request or reply given only an RQF (\a fmt).
2257  *
2258  * This function should not be used for formats which contain variable size
2259  * fields.
2260  */
2261 __u32 req_capsule_fmt_size(__u32 magic, const struct req_format *fmt,
2262                          enum req_location loc)
2263 {
2264         __u32 size;
2265         size_t i = 0;
2266
2267         /*
2268          * This function should probably LASSERT() that fmt has no fields with
2269          * RMF_F_STRUCT_ARRAY in rmf_flags, since we can't know here how many
2270          * elements in the array there will ultimately be, but then, we could
2271          * assume that there will be at least one element, and that's just what
2272          * we do.
2273          */
2274         size = lustre_msg_hdr_size(magic, fmt->rf_fields[loc].nr);
2275         if (size == 0)
2276                 return size;
2277
2278         for (; i < fmt->rf_fields[loc].nr; ++i)
2279                 if (fmt->rf_fields[loc].d[i]->rmf_size != -1)
2280                         size += cfs_size_round(fmt->rf_fields[loc].d[i]->
2281                                                rmf_size);
2282         return size;
2283 }
2284
2285 /**
2286  * Changes the format of an RPC.
2287  *
2288  * The pill must already have been initialized, which means that it already has
2289  * a request format.  The new format \a fmt must be an extension of the pill's
2290  * old format.  Specifically: the new format must have as many request and reply
2291  * fields as the old one, and all fields shared by the old and new format must
2292  * be at least as large in the new format.
2293  *
2294  * The new format's fields may be of different "type" than the old format, but
2295  * only for fields that are "opaque" blobs: fields which have a) have no
2296  * \a rmf_swabber, b) \a rmf_flags == 0 or RMF_F_NO_SIZE_CHECK, and c) \a
2297  * rmf_size == -1 or \a rmf_flags == RMF_F_NO_SIZE_CHECK.  For example,
2298  * OBD_SET_INFO has a key field and an opaque value field that gets interpreted
2299  * according to the key field.  When the value, according to the key, contains a
2300  * structure (or array thereof) to be swabbed, the format should be changed to
2301  * one where the value field has \a rmf_size/rmf_flags/rmf_swabber set
2302  * accordingly.
2303  */
2304 void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
2305 {
2306         int i;
2307         size_t j;
2308
2309         const struct req_format *old;
2310
2311         LASSERT(pill->rc_fmt != NULL);
2312         LASSERT(__req_format_is_sane(fmt));
2313
2314         old = pill->rc_fmt;
2315         /*
2316          * Sanity checking...
2317          */
2318         for (i = 0; i < RCL_NR; ++i) {
2319                 LASSERT(fmt->rf_fields[i].nr >= old->rf_fields[i].nr);
2320                 for (j = 0; j < old->rf_fields[i].nr - 1; ++j) {
2321                         const struct req_msg_field *ofield = FMT_FIELD(old, i, j);
2322
2323                         /* "opaque" fields can be transmogrified */
2324                         if (ofield->rmf_swabber == NULL &&
2325                             (ofield->rmf_flags & ~RMF_F_NO_SIZE_CHECK) == 0 &&
2326                             (ofield->rmf_size == -1 ||
2327                             ofield->rmf_flags == RMF_F_NO_SIZE_CHECK))
2328                                 continue;
2329                         LASSERT(FMT_FIELD(fmt, i, j) == FMT_FIELD(old, i, j));
2330                 }
2331                 /*
2332                  * Last field in old format can be shorter than in new.
2333                  */
2334                 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
2335                         FMT_FIELD(old, i, j)->rmf_size);
2336         }
2337
2338         pill->rc_fmt = fmt;
2339 }
2340 EXPORT_SYMBOL(req_capsule_extend);
2341
2342 /**
2343  * This function returns a non-zero value if the given \a field is present in
2344  * the format (\a rc_fmt) of \a pill's PTLRPC request or reply (\a loc), else it
2345  * returns 0.
2346  */
2347 int req_capsule_has_field(const struct req_capsule *pill,
2348                           const struct req_msg_field *field,
2349                           enum req_location loc)
2350 {
2351         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2352
2353         return field->rmf_offset[pill->rc_fmt->rf_idx][loc];
2354 }
2355 EXPORT_SYMBOL(req_capsule_has_field);
2356
2357 /**
2358  * Returns a non-zero value if the given \a field is present in the given \a
2359  * pill's PTLRPC request or reply (\a loc), else it returns 0.
2360  */
2361 int req_capsule_field_present(const struct req_capsule *pill,
2362                               const struct req_msg_field *field,
2363                               enum req_location loc)
2364 {
2365         __u32 offset;
2366
2367         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2368         LASSERT(req_capsule_has_field(pill, field, loc));
2369
2370         offset = __req_capsule_offset(pill, field, loc);
2371         return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
2372 }
2373 EXPORT_SYMBOL(req_capsule_field_present);
2374
2375 /**
2376  * This function shrinks the size of the _buffer_ of the \a pill's PTLRPC
2377  * request or reply (\a loc).
2378  *
2379  * This is not the opposite of req_capsule_extend().
2380  */
2381 void req_capsule_shrink(struct req_capsule *pill,
2382                         const struct req_msg_field *field,
2383                         __u32 newlen,
2384                         enum req_location loc)
2385 {
2386         const struct req_format *fmt;
2387         struct lustre_msg       *msg;
2388         __u32                    len;
2389         int                      offset;
2390
2391         fmt = pill->rc_fmt;
2392         LASSERT(fmt != NULL);
2393         LASSERT(__req_format_is_sane(fmt));
2394         LASSERT(req_capsule_has_field(pill, field, loc));
2395         LASSERT(req_capsule_field_present(pill, field, loc));
2396
2397         offset = __req_capsule_offset(pill, field, loc);
2398
2399         msg = __req_msg(pill, loc);
2400         len = lustre_msg_buflen(msg, offset);
2401         LASSERTF(newlen <= len, "%s:%s, oldlen=%u, newlen=%u\n",
2402                                 fmt->rf_name, field->rmf_name, len, newlen);
2403
2404         if (loc == RCL_CLIENT)
2405                 pill->rc_req->rq_reqlen = lustre_shrink_msg(msg, offset, newlen,
2406                                                             1);
2407         else
2408                 pill->rc_req->rq_replen = lustre_shrink_msg(msg, offset, newlen,
2409                                                             1);
2410 }
2411 EXPORT_SYMBOL(req_capsule_shrink);
2412
2413 int req_capsule_server_grow(struct req_capsule *pill,
2414                             const struct req_msg_field *field,
2415                             __u32 newlen)
2416 {
2417         struct ptlrpc_reply_state *rs = pill->rc_req->rq_reply_state, *nrs;
2418         char *from, *to;
2419         int rc;
2420         __u32 offset, len;
2421
2422         LASSERT(pill->rc_fmt != NULL);
2423         LASSERT(__req_format_is_sane(pill->rc_fmt));
2424         LASSERT(req_capsule_has_field(pill, field, RCL_SERVER));
2425         LASSERT(req_capsule_field_present(pill, field, RCL_SERVER));
2426
2427         len = req_capsule_get_size(pill, field, RCL_SERVER);
2428         offset = __req_capsule_offset(pill, field, RCL_SERVER);
2429         if ((__u32)pill->rc_req->rq_repbuf_len >=
2430             lustre_packed_msg_size(pill->rc_req->rq_repmsg) - len + newlen)
2431                 CERROR("Inplace repack might be done\n");
2432
2433         pill->rc_req->rq_reply_state = NULL;
2434         req_capsule_set_size(pill, field, RCL_SERVER, newlen);
2435         rc = req_capsule_server_pack(pill);
2436         if (rc) {
2437                 /* put old rs back, the caller will decide what to do */
2438                 pill->rc_req->rq_reply_state = rs;
2439                 return rc;
2440         }
2441         nrs = pill->rc_req->rq_reply_state;
2442         /* Now we need only buffers, copy first chunk */
2443         to = lustre_msg_buf(nrs->rs_msg, 0, 0);
2444         from = lustre_msg_buf(rs->rs_msg, 0, 0);
2445         len = (char *)lustre_msg_buf(rs->rs_msg, offset, 0) - from;
2446         memcpy(to, from, len);
2447         /* check if we have tail and copy it too */
2448         if (rs->rs_msg->lm_bufcount > offset + 1) {
2449                 to = lustre_msg_buf(nrs->rs_msg, offset + 1, 0);
2450                 from = lustre_msg_buf(rs->rs_msg, offset + 1, 0);
2451                 offset = rs->rs_msg->lm_bufcount - 1;
2452                 len = (char *)lustre_msg_buf(rs->rs_msg, offset, 0) +
2453                       cfs_size_round(rs->rs_msg->lm_buflens[offset]) - from;
2454                 memcpy(to, from, len);
2455         }
2456         /* drop old reply if everything is fine */
2457         if (rs->rs_difficult) {
2458                 /* copy rs data */
2459                 int i;
2460
2461                 nrs->rs_difficult = 1;
2462                 nrs->rs_no_ack = rs->rs_no_ack;
2463                 for (i = 0; i < rs->rs_nlocks; i++) {
2464                         nrs->rs_locks[i] = rs->rs_locks[i];
2465                         nrs->rs_modes[i] = rs->rs_modes[i];
2466                         nrs->rs_nlocks++;
2467                 }
2468                 rs->rs_nlocks = 0;
2469                 rs->rs_difficult = 0;
2470                 rs->rs_no_ack = 0;
2471         }
2472         ptlrpc_rs_decref(rs);
2473         return 0;
2474 }
2475 EXPORT_SYMBOL(req_capsule_server_grow);
2476 /* __REQ_LAYOUT_USER__ */
2477 #endif