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