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