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