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