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