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