Whamcloud - gitweb
89ffe0587e3572aace0f50a79d65eaa142beede8
[fs/lustre-release.git] / lustre / ptlrpc / layout.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/ptlrpc/layout.c
5  *  Lustre Metadata Target (mdt) request handler
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Nikita Danilov <nikita@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28
29 #if !defined(__REQ_LAYOUT_USER__)
30
31 #ifndef EXPORT_SYMTAB
32 # define EXPORT_SYMTAB
33 #endif
34 #define DEBUG_SUBSYSTEM S_RPC
35
36 #ifdef __KERNEL__
37 #include <linux/module.h>
38 #else
39 # include <liblustre.h>
40 #endif
41
42 /* LUSTRE_VERSION_CODE */
43 #include <lustre_ver.h>
44
45 #include <obd_support.h>
46 /* lustre_swab_mdt_body */
47 #include <lustre/lustre_idl.h>
48 /* obd2cli_tgt() (required by DEBUG_REQ()) */
49 #include <obd.h>
50
51 /* __REQ_LAYOUT_USER__ */
52 #endif
53 /* struct ptlrpc_request, lustre_msg* */
54 #include <lustre_req_layout.h>
55 #include <linux/lustre_acl.h>
56
57 /*
58  * empty set of fields... for suitable definition of emptiness.
59  */
60 static const struct req_msg_field *empty[] = {
61         &RMF_PTLRPC_BODY
62 };
63
64 static const struct req_msg_field *mgs_target_info_only[] = {
65         &RMF_PTLRPC_BODY,
66         &RMF_MGS_TARGET_INFO
67 };
68
69 static const struct req_msg_field *mgs_set_info[] = {
70         &RMF_PTLRPC_BODY,
71         &RMF_MGS_SEND_PARAM
72 };
73
74 static const struct req_msg_field *log_cancel_client[] = {
75         &RMF_PTLRPC_BODY,
76         &RMF_LOGCOOKIES
77 };
78
79 static const struct req_msg_field *mdt_body_only[] = {
80         &RMF_PTLRPC_BODY,
81         &RMF_MDT_BODY
82 };
83
84 static const struct req_msg_field *mdt_body_capa[] = {
85         &RMF_PTLRPC_BODY,
86         &RMF_MDT_BODY,
87         &RMF_CAPA1
88 };
89
90 static const struct req_msg_field *quotactl_only[] = {
91         &RMF_PTLRPC_BODY,
92         &RMF_OBD_QUOTACTL
93 };
94
95 static const struct req_msg_field *qunit_data_only[] = {
96         &RMF_PTLRPC_BODY,
97         &RMF_QUNIT_DATA
98 };
99
100 static const struct req_msg_field *mdt_close_client[] = {
101         &RMF_PTLRPC_BODY,
102         &RMF_MDT_EPOCH,
103         &RMF_REC_REINT,
104         &RMF_CAPA1
105 };
106
107 static const struct req_msg_field *obd_statfs_server[] = {
108         &RMF_PTLRPC_BODY,
109         &RMF_OBD_STATFS
110 };
111
112 static const struct req_msg_field *seq_query_client[] = {
113         &RMF_PTLRPC_BODY,
114         &RMF_SEQ_OPC,
115         &RMF_SEQ_RANGE
116 };
117
118 static const struct req_msg_field *seq_query_server[] = {
119         &RMF_PTLRPC_BODY,
120         &RMF_SEQ_RANGE
121 };
122
123 static const struct req_msg_field *fld_query_client[] = {
124         &RMF_PTLRPC_BODY,
125         &RMF_FLD_OPC,
126         &RMF_FLD_MDFLD
127 };
128
129 static const struct req_msg_field *fld_query_server[] = {
130         &RMF_PTLRPC_BODY,
131         &RMF_FLD_MDFLD
132 };
133
134 static const struct req_msg_field *mds_getattr_name_client[] = {
135         &RMF_PTLRPC_BODY,
136         &RMF_MDT_BODY,
137         &RMF_CAPA1,
138         &RMF_NAME
139 };
140
141 static const struct req_msg_field *mds_reint_client[] = {
142         &RMF_PTLRPC_BODY,
143         &RMF_REC_REINT
144 };
145
146 static const struct req_msg_field *mds_reint_create_client[] = {
147         &RMF_PTLRPC_BODY,
148         &RMF_REC_REINT,
149         &RMF_CAPA1,
150         &RMF_NAME
151 };
152
153 static const struct req_msg_field *mds_reint_create_slave_client[] = {
154         &RMF_PTLRPC_BODY,
155         &RMF_REC_REINT,
156         &RMF_CAPA1,
157         &RMF_NAME,
158         &RMF_EADATA,
159         &RMF_DLM_REQ
160 };
161
162 static const struct req_msg_field *mds_reint_create_rmt_acl_client[] = {
163         &RMF_PTLRPC_BODY,
164         &RMF_REC_REINT,
165         &RMF_CAPA1,
166         &RMF_NAME,
167         &RMF_EADATA,
168         &RMF_DLM_REQ
169 };
170
171 static const struct req_msg_field *mds_reint_create_sym_client[] = {
172         &RMF_PTLRPC_BODY,
173         &RMF_REC_REINT,
174         &RMF_CAPA1,
175         &RMF_NAME,
176         &RMF_SYMTGT,
177         &RMF_DLM_REQ
178 };
179
180 static const struct req_msg_field *mds_reint_open_client[] = {
181         &RMF_PTLRPC_BODY,
182         &RMF_REC_REINT,
183         &RMF_CAPA1,
184         &RMF_CAPA2,
185         &RMF_NAME,
186         &RMF_EADATA
187 };
188
189 static const struct req_msg_field *mds_reint_open_server[] = {
190         &RMF_PTLRPC_BODY,
191         &RMF_MDT_BODY,
192         &RMF_MDT_MD,
193         &RMF_ACL,
194         &RMF_CAPA1,
195         &RMF_CAPA2
196 };
197
198 static const struct req_msg_field *mds_reint_unlink_client[] = {
199         &RMF_PTLRPC_BODY,
200         &RMF_REC_REINT,
201         &RMF_CAPA1,
202         &RMF_NAME,
203         &RMF_DLM_REQ
204 };
205
206 static const struct req_msg_field *mds_reint_link_client[] = {
207         &RMF_PTLRPC_BODY,
208         &RMF_REC_REINT,
209         &RMF_CAPA1,
210         &RMF_CAPA2,
211         &RMF_NAME,
212         &RMF_DLM_REQ
213 };
214
215 static const struct req_msg_field *mds_reint_rename_client[] = {
216         &RMF_PTLRPC_BODY,
217         &RMF_REC_REINT,
218         &RMF_CAPA1,
219         &RMF_CAPA2,
220         &RMF_NAME,
221         &RMF_SYMTGT,
222         &RMF_DLM_REQ
223 };
224
225 static const struct req_msg_field *mds_last_unlink_server[] = {
226         &RMF_PTLRPC_BODY,
227         &RMF_MDT_BODY,
228         &RMF_MDT_MD,
229         &RMF_LOGCOOKIES
230 };
231
232 static const struct req_msg_field *mds_reint_setattr_client[] = {
233         &RMF_PTLRPC_BODY,
234         &RMF_REC_REINT,
235         &RMF_CAPA1,
236         &RMF_MDT_EPOCH,
237         &RMF_EADATA,
238         &RMF_LOGCOOKIES,
239         &RMF_DLM_REQ
240 };
241
242 static const struct req_msg_field *mds_reint_setxattr_client[] = {
243         &RMF_PTLRPC_BODY,
244         &RMF_REC_REINT,
245         &RMF_CAPA1,
246         &RMF_NAME,
247         &RMF_EADATA
248 };
249
250 static const struct req_msg_field *obd_connect_client[] = {
251         &RMF_PTLRPC_BODY,
252         &RMF_TGTUUID,
253         &RMF_CLUUID,
254         &RMF_CONN,
255         &RMF_CONNECT_DATA
256 };
257
258 static const struct req_msg_field *obd_connect_server[] = {
259         &RMF_PTLRPC_BODY,
260         &RMF_CONNECT_DATA
261 };
262
263 static const struct req_msg_field *mds_set_info_client[] = {
264         &RMF_PTLRPC_BODY,
265         &RMF_SETINFO_KEY,
266         &RMF_SETINFO_VAL
267 };
268
269 static const struct req_msg_field *ldlm_enqueue_client[] = {
270         &RMF_PTLRPC_BODY,
271         &RMF_DLM_REQ
272 };
273
274 static const struct req_msg_field *ldlm_enqueue_server[] = {
275         &RMF_PTLRPC_BODY,
276         &RMF_DLM_REP
277 };
278
279 static const struct req_msg_field *ldlm_enqueue_lvb_server[] = {
280         &RMF_PTLRPC_BODY,
281         &RMF_DLM_REP,
282         &RMF_DLM_LVB
283 };
284
285 static const struct req_msg_field *ldlm_cp_callback_client[] = {
286         &RMF_PTLRPC_BODY,
287         &RMF_DLM_REQ,
288         &RMF_DLM_LVB
289 };
290
291 static const struct req_msg_field *ldlm_gl_callback_server[] = {
292         &RMF_PTLRPC_BODY,
293         &RMF_DLM_LVB
294 };
295
296 static const struct req_msg_field *ldlm_intent_client[] = {
297         &RMF_PTLRPC_BODY,
298         &RMF_DLM_REQ,
299         &RMF_LDLM_INTENT,
300         &RMF_REC_REINT
301 };
302
303 static const struct req_msg_field *ldlm_intent_server[] = {
304         &RMF_PTLRPC_BODY,
305         &RMF_DLM_REP,
306         &RMF_MDT_BODY,
307         &RMF_MDT_MD,
308         &RMF_ACL
309 };
310
311 static const struct req_msg_field *ldlm_intent_open_server[] = {
312         &RMF_PTLRPC_BODY,
313         &RMF_DLM_REP,
314         &RMF_MDT_BODY,
315         &RMF_MDT_MD,
316         &RMF_ACL,
317         &RMF_CAPA1,
318         &RMF_CAPA2
319 };
320
321 static const struct req_msg_field *ldlm_intent_getattr_client[] = {
322         &RMF_PTLRPC_BODY,
323         &RMF_DLM_REQ,
324         &RMF_LDLM_INTENT,
325         &RMF_MDT_BODY,     /* coincides with mds_getattr_name_client[] */
326         &RMF_CAPA1,
327         &RMF_NAME
328 };
329
330 static const struct req_msg_field *ldlm_intent_getattr_server[] = {
331         &RMF_PTLRPC_BODY,
332         &RMF_DLM_REP,
333         &RMF_MDT_BODY,
334         &RMF_MDT_MD,
335         &RMF_ACL,
336         &RMF_CAPA1
337 };
338
339 static const struct req_msg_field *ldlm_intent_create_client[] = {
340         &RMF_PTLRPC_BODY,
341         &RMF_DLM_REQ,
342         &RMF_LDLM_INTENT,
343         &RMF_REC_REINT,    /* coincides with mds_reint_create_client[] */
344         &RMF_CAPA1,
345         &RMF_NAME,
346         &RMF_EADATA
347 };
348
349 static const struct req_msg_field *ldlm_intent_open_client[] = {
350         &RMF_PTLRPC_BODY,
351         &RMF_DLM_REQ,
352         &RMF_LDLM_INTENT,
353         &RMF_REC_REINT,    /* coincides with mds_reint_open_client[] */
354         &RMF_CAPA1,
355         &RMF_CAPA2,
356         &RMF_NAME,
357         &RMF_EADATA,
358         &RMF_REC_JOINFILE
359 };
360
361 static const struct req_msg_field *ldlm_intent_unlink_client[] = {
362         &RMF_PTLRPC_BODY,
363         &RMF_DLM_REQ,
364         &RMF_LDLM_INTENT,
365         &RMF_REC_REINT,    /* coincides with mds_reint_unlink_client[] */
366         &RMF_CAPA1,
367         &RMF_NAME
368 };
369
370 static const struct req_msg_field *mds_getxattr_client[] = {
371         &RMF_PTLRPC_BODY,
372         &RMF_MDT_BODY,
373         &RMF_CAPA1,
374         &RMF_NAME,
375         &RMF_EADATA
376 };
377
378 static const struct req_msg_field *mds_getxattr_server[] = {
379         &RMF_PTLRPC_BODY,
380         &RMF_MDT_BODY,
381         &RMF_EADATA
382 };
383
384 static const struct req_msg_field *mds_getattr_server[] = {
385         &RMF_PTLRPC_BODY,
386         &RMF_MDT_BODY,
387         &RMF_MDT_MD,
388         &RMF_ACL,
389         &RMF_CAPA1,
390         &RMF_CAPA2
391 };
392
393 static const struct req_msg_field *mds_setattr_server[] = {
394         &RMF_PTLRPC_BODY,
395         &RMF_MDT_BODY,
396         &RMF_MDT_MD,
397         &RMF_ACL,
398         &RMF_CAPA1,
399         &RMF_CAPA2
400 };
401
402 static const struct req_msg_field *llog_catinfo_client[] = {
403         &RMF_PTLRPC_BODY,
404         &RMF_NAME,
405         &RMF_STRING
406 };
407
408 static const struct req_msg_field *llog_catinfo_server[] = {
409         &RMF_PTLRPC_BODY,
410         &RMF_STRING
411 };
412
413 static const struct req_msg_field *llog_origin_handle_create_client[] = {
414         &RMF_PTLRPC_BODY,
415         &RMF_LLOGD_BODY,
416         &RMF_NAME
417 };
418
419 static const struct req_msg_field *llogd_body_only[] = {
420         &RMF_PTLRPC_BODY,
421         &RMF_LLOGD_BODY
422 };
423
424 static const struct req_msg_field *llog_log_hdr_only[] = {
425         &RMF_PTLRPC_BODY,
426         &RMF_LLOG_LOG_HDR
427 };
428
429 static const struct req_msg_field *llogd_conn_body_only[] = {
430         &RMF_PTLRPC_BODY,
431         &RMF_LLOGD_CONN_BODY
432 };
433
434 static const struct req_msg_field *llog_origin_handle_next_block_server[] = {
435         &RMF_PTLRPC_BODY,
436         &RMF_LLOGD_BODY,
437         &RMF_EADATA
438 };
439
440 static const struct req_msg_field *ost_body_only[] = {
441         &RMF_PTLRPC_BODY,
442         &RMF_OST_BODY
443 };
444
445 static const struct req_msg_field *ost_body_capa[] = {
446         &RMF_PTLRPC_BODY,
447         &RMF_OST_BODY,
448         &RMF_CAPA1
449 };
450
451 static const struct req_msg_field *ost_destroy_client[] = {
452         &RMF_PTLRPC_BODY,
453         &RMF_OST_BODY,
454         &RMF_DLM_REQ
455 };
456
457
458 static const struct req_msg_field *ost_brw_client[] = {
459         &RMF_PTLRPC_BODY,
460         &RMF_OST_BODY,
461         &RMF_OBD_IOOBJ,
462         &RMF_NIOBUF_REMOTE,
463         &RMF_CAPA1
464 };
465
466 static const struct req_msg_field *ost_brw_server[] = {
467         &RMF_PTLRPC_BODY,
468         &RMF_OST_BODY,
469         &RMF_NIOBUF_REMOTE
470 };
471
472 static const struct req_msg_field *ost_set_info_client[] = {
473         &RMF_PTLRPC_BODY,
474         &RMF_SETINFO_KEY,
475         &RMF_SETINFO_VAL
476 };
477
478 static const struct req_msg_field *ost_get_info_client[] = {
479         &RMF_PTLRPC_BODY,
480         &RMF_SETINFO_KEY
481 };
482
483 static const struct req_msg_field *ost_get_info_server[] = {
484         &RMF_PTLRPC_BODY,
485         &RMF_OBD_ID
486 };
487 static const struct req_format *req_formats[] = {
488         &RQF_OBD_PING,
489         &RQF_SEC_CTX,
490         &RQF_SEQ_QUERY,
491         &RQF_FLD_QUERY,
492         &RQF_MGS_TARGET_REG,
493         &RQF_MGS_SET_INFO,
494         &RQF_MDS_CONNECT,
495         &RQF_MDS_DISCONNECT,
496         &RQF_MDS_SET_INFO,
497         &RQF_MDS_GETSTATUS,
498         &RQF_MDS_STATFS,
499         &RQF_MDS_GETATTR,
500         &RQF_MDS_GETATTR_NAME,
501         &RQF_MDS_GETXATTR,
502         &RQF_MDS_SYNC,
503         &RQF_MDS_CLOSE,
504         &RQF_MDS_PIN,
505         &RQF_MDS_UNPIN,
506         &RQF_MDS_READPAGE,
507         &RQF_MDS_WRITEPAGE,
508         &RQF_MDS_IS_SUBDIR,
509         &RQF_MDS_DONE_WRITING,
510         &RQF_MDS_REINT,
511         &RQF_MDS_REINT_CREATE,
512         &RQF_MDS_REINT_CREATE_RMT_ACL,
513         &RQF_MDS_REINT_CREATE_SLAVE,
514         &RQF_MDS_REINT_CREATE_SYM,
515         &RQF_MDS_REINT_OPEN,
516         &RQF_MDS_REINT_UNLINK,
517         &RQF_MDS_REINT_LINK,
518         &RQF_MDS_REINT_RENAME,
519         &RQF_MDS_REINT_SETATTR,
520         &RQF_MDS_REINT_SETXATTR,
521         &RQF_MDS_QUOTACHECK,
522         &RQF_MDS_QUOTACTL,
523         &RQF_MDS_QUOTA_DQACQ,
524         &RQF_OST_CONNECT,
525         &RQF_OST_DISCONNECT,
526         &RQF_OST_QUOTACHECK,
527         &RQF_OST_QUOTACTL,
528         &RQF_OST_GETATTR,
529         &RQF_OST_SETATTR,
530         &RQF_OST_CREATE,
531         &RQF_OST_PUNCH,
532         &RQF_OST_SYNC,
533         &RQF_OST_DESTROY,
534         &RQF_OST_BRW,
535         &RQF_OST_STATFS,
536         &RQF_OST_SET_INFO,
537         &RQF_OST_GET_INFO,
538         &RQF_LDLM_ENQUEUE,
539         &RQF_LDLM_ENQUEUE_LVB,
540         &RQF_LDLM_CONVERT,
541         &RQF_LDLM_CANCEL,
542         &RQF_LDLM_CALLBACK,
543         &RQF_LDLM_CP_CALLBACK,
544         &RQF_LDLM_BL_CALLBACK,
545         &RQF_LDLM_GL_CALLBACK,
546         &RQF_LDLM_INTENT,
547         &RQF_LDLM_INTENT_GETATTR,
548         &RQF_LDLM_INTENT_OPEN,
549         &RQF_LDLM_INTENT_CREATE,
550         &RQF_LDLM_INTENT_UNLINK,
551         &RQF_LOG_CANCEL,
552         &RQF_LLOG_CATINFO,
553         &RQF_LLOG_ORIGIN_HANDLE_CREATE,
554         &RQF_LLOG_ORIGIN_HANDLE_DESTROY,
555         &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK,
556         &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK,
557         &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER,
558         &RQF_LLOG_ORIGIN_CONNECT
559 };
560
561 struct req_msg_field {
562         __u32       rmf_flags;
563         const char *rmf_name;
564         /*
565          * Field length. (-1) means "variable length".
566          */
567         int         rmf_size;
568         void      (*rmf_swabber)(void *);
569         int         rmf_offset[ARRAY_SIZE(req_formats)][RCL_NR];
570 };
571
572 enum rmf_flags {
573         RMF_F_STRING = 1 << 0
574 };
575
576 struct req_capsule;
577
578 /*
579  * Request fields.
580  */
581 #define DEFINE_MSGF(name, flags, size, swabber) {       \
582         .rmf_name    = (name),                          \
583         .rmf_flags   = (flags),                         \
584         .rmf_size    = (size),                          \
585         .rmf_swabber = (void (*)(void*))(swabber)       \
586 }
587
588 const struct req_msg_field RMF_MGS_TARGET_INFO =
589         DEFINE_MSGF("mgs_target_info", 0,
590                     sizeof(struct mgs_target_info),
591                     lustre_swab_mgs_target_info);
592 EXPORT_SYMBOL(RMF_MGS_TARGET_INFO);
593
594 const struct req_msg_field RMF_MGS_SEND_PARAM =
595         DEFINE_MSGF("mgs_send_param", 0,
596                     sizeof(struct mgs_send_param),
597                     NULL);
598 EXPORT_SYMBOL(RMF_MGS_SEND_PARAM);
599
600 const struct req_msg_field RMF_SETINFO_VAL =
601         DEFINE_MSGF("setinfo_val", 0,
602                     sizeof(__u32), lustre_swab_generic_32s);
603 EXPORT_SYMBOL(RMF_SETINFO_VAL);
604
605 const struct req_msg_field RMF_SEQ_OPC =
606         DEFINE_MSGF("seq_query_opc", 0,
607                     sizeof(__u32), lustre_swab_generic_32s);
608 EXPORT_SYMBOL(RMF_SEQ_OPC);
609
610 const struct req_msg_field RMF_SEQ_RANGE =
611         DEFINE_MSGF("seq_query_range", 0,
612                     sizeof(struct lu_range), lustre_swab_lu_range);
613 EXPORT_SYMBOL(RMF_SEQ_RANGE);
614
615 const struct req_msg_field RMF_FLD_OPC =
616         DEFINE_MSGF("fld_query_opc", 0,
617                     sizeof(__u32), lustre_swab_generic_32s);
618 EXPORT_SYMBOL(RMF_FLD_OPC);
619
620 const struct req_msg_field RMF_FLD_MDFLD =
621         DEFINE_MSGF("fld_query_mdfld", 0,
622                     sizeof(struct md_fld), lustre_swab_md_fld);
623 EXPORT_SYMBOL(RMF_FLD_MDFLD);
624
625 const struct req_msg_field RMF_MDT_BODY =
626         DEFINE_MSGF("mdt_body", 0,
627                     sizeof(struct mdt_body), lustre_swab_mdt_body);
628 EXPORT_SYMBOL(RMF_MDT_BODY);
629
630 const struct req_msg_field RMF_OBD_QUOTACTL =
631         DEFINE_MSGF("obd_quotactl", 0,
632                     sizeof(struct obd_quotactl), lustre_swab_obd_quotactl);
633 EXPORT_SYMBOL(RMF_OBD_QUOTACTL);
634
635 const struct req_msg_field RMF_QUNIT_DATA =
636         DEFINE_MSGF("qunit_data", 0,
637                     sizeof(struct qunit_data), NULL);
638 EXPORT_SYMBOL(RMF_QUNIT_DATA);
639
640 const struct req_msg_field RMF_MDT_EPOCH =
641         DEFINE_MSGF("mdt_epoch", 0,
642                     sizeof(struct mdt_epoch), lustre_swab_mdt_epoch);
643 EXPORT_SYMBOL(RMF_MDT_EPOCH);
644
645 const struct req_msg_field RMF_PTLRPC_BODY =
646         DEFINE_MSGF("ptlrpc_body", 0,
647                     sizeof(struct ptlrpc_body), lustre_swab_ptlrpc_body);
648 EXPORT_SYMBOL(RMF_PTLRPC_BODY);
649
650 const struct req_msg_field RMF_OBD_STATFS =
651         DEFINE_MSGF("obd_statfs", 0,
652                     sizeof(struct obd_statfs), lustre_swab_obd_statfs);
653 EXPORT_SYMBOL(RMF_OBD_STATFS);
654
655 const struct req_msg_field RMF_SETINFO_KEY =
656         DEFINE_MSGF("setinfo_key", 0, -1, NULL);
657 EXPORT_SYMBOL(RMF_SETINFO_KEY);
658
659 const struct req_msg_field RMF_NAME =
660         DEFINE_MSGF("name", RMF_F_STRING, -1, NULL);
661 EXPORT_SYMBOL(RMF_NAME);
662
663 const struct req_msg_field RMF_SYMTGT =
664         DEFINE_MSGF("symtgt", RMF_F_STRING, -1, NULL);
665 EXPORT_SYMBOL(RMF_SYMTGT);
666
667 const struct req_msg_field RMF_TGTUUID =
668         DEFINE_MSGF("tgtuuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL);
669 EXPORT_SYMBOL(RMF_TGTUUID);
670
671 const struct req_msg_field RMF_CLUUID =
672         DEFINE_MSGF("cluuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL);
673 EXPORT_SYMBOL(RMF_CLUUID);
674
675 const struct req_msg_field RMF_STRING =
676         DEFINE_MSGF("string", RMF_F_STRING, -1, NULL);
677 EXPORT_SYMBOL(RMF_STRING);
678
679 const struct req_msg_field RMF_LLOGD_BODY =
680         DEFINE_MSGF("llogd_body", 0,
681                     sizeof(struct llogd_body), lustre_swab_llogd_body);
682 EXPORT_SYMBOL(RMF_LLOGD_BODY);
683
684 const struct req_msg_field RMF_LLOG_LOG_HDR =
685         DEFINE_MSGF("llog_log_hdr", 0,
686                     sizeof(struct llog_log_hdr), lustre_swab_llog_hdr);
687 EXPORT_SYMBOL(RMF_LLOG_LOG_HDR);
688
689 const struct req_msg_field RMF_LLOGD_CONN_BODY =
690         DEFINE_MSGF("llogd_conn_body", 0,
691                     sizeof(struct llogd_conn_body),
692                     lustre_swab_llogd_conn_body);
693 EXPORT_SYMBOL(RMF_LLOGD_CONN_BODY);
694
695 /*
696  * connection handle received in MDS_CONNECT request.
697  *
698  * XXX no swabbing?
699  */
700 const struct req_msg_field RMF_CONN =
701         DEFINE_MSGF("conn", 0, sizeof(struct lustre_handle), NULL);
702 EXPORT_SYMBOL(RMF_CONN);
703
704 const struct req_msg_field RMF_CONNECT_DATA =
705         DEFINE_MSGF("cdata", 0,
706                     sizeof(struct obd_connect_data), lustre_swab_connect);
707 EXPORT_SYMBOL(RMF_CONNECT_DATA);
708
709 const struct req_msg_field RMF_DLM_REQ =
710         DEFINE_MSGF("dlm_req", 0,
711                     sizeof(struct ldlm_request), lustre_swab_ldlm_request);
712 EXPORT_SYMBOL(RMF_DLM_REQ);
713
714 const struct req_msg_field RMF_DLM_REP =
715         DEFINE_MSGF("dlm_rep", 0,
716                     sizeof(struct ldlm_reply), lustre_swab_ldlm_reply);
717 EXPORT_SYMBOL(RMF_DLM_REP);
718
719 const struct req_msg_field RMF_LDLM_INTENT =
720         DEFINE_MSGF("ldlm_intent", 0,
721                     sizeof(struct ldlm_intent), lustre_swab_ldlm_intent);
722 EXPORT_SYMBOL(RMF_LDLM_INTENT);
723
724 const struct req_msg_field RMF_DLM_LVB =
725         DEFINE_MSGF("dlm_lvb", 0, sizeof(struct ost_lvb), NULL);
726 EXPORT_SYMBOL(RMF_DLM_LVB);
727
728 const struct req_msg_field RMF_MDT_MD =
729         DEFINE_MSGF("mdt_md", 0, MIN_MD_SIZE, NULL);
730 EXPORT_SYMBOL(RMF_MDT_MD);
731
732 const struct req_msg_field RMF_REC_REINT =
733         DEFINE_MSGF("rec_reint", 0, sizeof(struct mdt_rec_reint),
734                     lustre_swab_mdt_rec_reint);
735 EXPORT_SYMBOL(RMF_REC_REINT);
736
737 const struct req_msg_field RMF_REC_JOINFILE =
738         DEFINE_MSGF("rec_joinfile", 0, sizeof(struct mdt_rec_join),
739                     lustre_swab_mdt_rec_join);
740 EXPORT_SYMBOL(RMF_REC_JOINFILE);
741
742 /* FIXME: this length should be defined as a macro */
743 const struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1, NULL);
744 EXPORT_SYMBOL(RMF_EADATA);
745
746 const struct req_msg_field RMF_ACL = 
747         DEFINE_MSGF("acl", 0, LUSTRE_POSIX_ACL_MAX_SIZE, NULL);
748 EXPORT_SYMBOL(RMF_ACL);
749
750 const struct req_msg_field RMF_LOGCOOKIES =
751         DEFINE_MSGF("logcookies", 0, sizeof(struct llog_cookie), NULL);
752 EXPORT_SYMBOL(RMF_LOGCOOKIES);
753
754 const struct req_msg_field RMF_CAPA1 =
755         DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
756                     lustre_swab_lustre_capa);
757 EXPORT_SYMBOL(RMF_CAPA1);
758
759 const struct req_msg_field RMF_CAPA2 =
760         DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
761                     lustre_swab_lustre_capa);
762 EXPORT_SYMBOL(RMF_CAPA2);
763
764 /* 
765  * OST request field.
766  */
767 const struct req_msg_field RMF_OST_BODY =
768         DEFINE_MSGF("ost_body", 0,
769                     sizeof(struct ost_body), lustre_swab_ost_body);
770 EXPORT_SYMBOL(RMF_OST_BODY);
771
772 const struct req_msg_field RMF_OBD_IOOBJ =
773         DEFINE_MSGF("obd_ioobj", 0,
774                     sizeof(struct obd_ioobj), lustre_swab_obd_ioobj);
775 EXPORT_SYMBOL(RMF_OBD_IOOBJ);
776
777 const struct req_msg_field RMF_NIOBUF_REMOTE =
778         DEFINE_MSGF("niobuf_remote", 0, -1, lustre_swab_niobuf_remote);
779 EXPORT_SYMBOL(RMF_NIOBUF_REMOTE);
780
781 const struct req_msg_field RMF_OBD_ID =
782         DEFINE_MSGF("obd_id", 0,
783                     sizeof(obd_id), lustre_swab_ost_last_id);
784 EXPORT_SYMBOL(RMF_OBD_ID);
785
786
787 /*
788  * Request formats.
789  */
790
791 struct req_format {
792         const char *rf_name;
793         int         rf_idx;
794         struct {
795                 int                          nr;
796                 const struct req_msg_field **d;
797         } rf_fields[RCL_NR];
798 };
799
800 #define DEFINE_REQ_FMT(name, client, client_nr, server, server_nr) {    \
801         .rf_name   = name,                                              \
802         .rf_fields = {                                                  \
803                 [RCL_CLIENT] = {                                        \
804                         .nr = client_nr,                                \
805                         .d  = client                                    \
806                 },                                                      \
807                 [RCL_SERVER] = {                                        \
808                         .nr = server_nr,                                \
809                         .d  = server                                    \
810                 }                                                       \
811         }                                                               \
812 }
813
814 #define DEFINE_REQ_FMT0(name, client, server)                                  \
815 DEFINE_REQ_FMT(name, client, ARRAY_SIZE(client), server, ARRAY_SIZE(server))
816
817 const struct req_format RQF_OBD_PING =
818         DEFINE_REQ_FMT0("OBD_PING", empty, empty);
819 EXPORT_SYMBOL(RQF_OBD_PING);
820  
821 const struct req_format RQF_SEC_CTX =
822         DEFINE_REQ_FMT0("SEC_CTX", empty, empty);
823 EXPORT_SYMBOL(RQF_SEC_CTX);
824  
825 const struct req_format RQF_MGS_TARGET_REG =
826         DEFINE_REQ_FMT0("MGS_TARGET_REG", mgs_target_info_only,
827                          mgs_target_info_only);
828 EXPORT_SYMBOL(RQF_MGS_TARGET_REG);
829
830 const struct req_format RQF_MGS_SET_INFO =
831         DEFINE_REQ_FMT0("MGS_SET_INTO", mgs_set_info,
832                          mgs_set_info);
833 EXPORT_SYMBOL(RQF_MGS_SET_INFO);
834
835 const struct req_format RQF_LOG_CANCEL =
836         DEFINE_REQ_FMT0("OBD_LOG_CANCEL", log_cancel_client, empty);
837 EXPORT_SYMBOL(RQF_LOG_CANCEL);
838
839 const struct req_format RQF_MDS_QUOTACHECK =
840         DEFINE_REQ_FMT0("MDS_QUOTACHECK", quotactl_only, empty);
841 EXPORT_SYMBOL(RQF_MDS_QUOTACHECK);
842
843 const struct req_format RQF_OST_QUOTACHECK =
844         DEFINE_REQ_FMT0("OST_QUOTACHECK", quotactl_only, empty);
845 EXPORT_SYMBOL(RQF_OST_QUOTACHECK);
846
847 const struct req_format RQF_MDS_QUOTACTL =
848         DEFINE_REQ_FMT0("MDS_QUOTACTL", quotactl_only, quotactl_only);
849 EXPORT_SYMBOL(RQF_MDS_QUOTACTL);
850
851 const struct req_format RQF_OST_QUOTACTL =
852         DEFINE_REQ_FMT0("OST_QUOTACTL", quotactl_only, quotactl_only);
853 EXPORT_SYMBOL(RQF_OST_QUOTACTL);
854
855 const struct req_format RQF_QC_CALLBACK =
856         DEFINE_REQ_FMT0("QC_CALLBACK", quotactl_only, empty);
857 EXPORT_SYMBOL(RQF_QC_CALLBACK);
858
859 const struct req_format RQF_MDS_QUOTA_DQACQ =
860         DEFINE_REQ_FMT0("MDS_QUOTA_DQACQ", qunit_data_only, qunit_data_only);
861 EXPORT_SYMBOL(RQF_MDS_QUOTA_DQACQ);
862
863 const struct req_format RQF_SEQ_QUERY =
864         DEFINE_REQ_FMT0("SEQ_QUERY", seq_query_client, seq_query_server);
865 EXPORT_SYMBOL(RQF_SEQ_QUERY);
866
867 const struct req_format RQF_FLD_QUERY =
868         DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
869 EXPORT_SYMBOL(RQF_FLD_QUERY);
870
871 const struct req_format RQF_MDS_GETSTATUS =
872         DEFINE_REQ_FMT0("MDS_GETSTATUS", mdt_body_only, mdt_body_capa);
873 EXPORT_SYMBOL(RQF_MDS_GETSTATUS);
874
875 const struct req_format RQF_MDS_STATFS =
876         DEFINE_REQ_FMT0("MDS_STATFS", empty, obd_statfs_server);
877 EXPORT_SYMBOL(RQF_MDS_STATFS);
878
879 const struct req_format RQF_MDS_SYNC =
880         DEFINE_REQ_FMT0("MDS_SYNC", mdt_body_capa, mdt_body_only);
881 EXPORT_SYMBOL(RQF_MDS_SYNC);
882
883 const struct req_format RQF_MDS_GETATTR =
884         DEFINE_REQ_FMT0("MDS_GETATTR", mdt_body_capa, mds_getattr_server);
885 EXPORT_SYMBOL(RQF_MDS_GETATTR);
886
887 const struct req_format RQF_MDS_GETXATTR =
888         DEFINE_REQ_FMT0("MDS_GETXATTR",
889                         mds_getxattr_client, mds_getxattr_server);
890 EXPORT_SYMBOL(RQF_MDS_GETXATTR);
891
892 const struct req_format RQF_MDS_GETATTR_NAME =
893         DEFINE_REQ_FMT0("MDS_GETATTR_NAME",
894                         mds_getattr_name_client, mds_getattr_server);
895 EXPORT_SYMBOL(RQF_MDS_GETATTR_NAME);
896
897 const struct req_format RQF_MDS_REINT =
898         DEFINE_REQ_FMT0("MDS_REINT", mds_reint_client, mdt_body_only);
899 EXPORT_SYMBOL(RQF_MDS_REINT);
900
901 const struct req_format RQF_MDS_REINT_CREATE =
902         DEFINE_REQ_FMT0("MDS_REINT_CREATE",
903                         mds_reint_create_client, mdt_body_capa);
904 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE);
905
906 const struct req_format RQF_MDS_REINT_CREATE_RMT_ACL =
907         DEFINE_REQ_FMT0("MDS_REINT_CREATE_RMT_ACL",
908                         mds_reint_create_rmt_acl_client, mdt_body_capa);
909 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_RMT_ACL);
910
911 const struct req_format RQF_MDS_REINT_CREATE_SLAVE =
912         DEFINE_REQ_FMT0("MDS_REINT_CREATE_EA",
913                         mds_reint_create_slave_client, mdt_body_capa);
914 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SLAVE);
915
916 const struct req_format RQF_MDS_REINT_CREATE_SYM =
917         DEFINE_REQ_FMT0("MDS_REINT_CREATE_SYM",
918                         mds_reint_create_sym_client, mdt_body_capa);
919 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SYM);
920
921 const struct req_format RQF_MDS_REINT_OPEN =
922         DEFINE_REQ_FMT0("MDS_REINT_OPEN",
923                         mds_reint_open_client, mds_reint_open_server);
924 EXPORT_SYMBOL(RQF_MDS_REINT_OPEN);
925
926 const struct req_format RQF_MDS_REINT_UNLINK =
927         DEFINE_REQ_FMT0("MDS_REINT_UNLINK", mds_reint_unlink_client,
928                         mds_last_unlink_server);
929 EXPORT_SYMBOL(RQF_MDS_REINT_UNLINK);
930
931 const struct req_format RQF_MDS_REINT_LINK =
932         DEFINE_REQ_FMT0("MDS_REINT_LINK",
933                         mds_reint_link_client, mdt_body_only);
934 EXPORT_SYMBOL(RQF_MDS_REINT_LINK);
935
936 const struct req_format RQF_MDS_REINT_RENAME =
937         DEFINE_REQ_FMT0("MDS_REINT_RENAME", mds_reint_rename_client,
938                         mds_last_unlink_server);
939 EXPORT_SYMBOL(RQF_MDS_REINT_RENAME);
940
941 const struct req_format RQF_MDS_REINT_SETATTR =
942         DEFINE_REQ_FMT0("MDS_REINT_SETATTR",
943                         mds_reint_setattr_client, mds_setattr_server);
944 EXPORT_SYMBOL(RQF_MDS_REINT_SETATTR);
945
946 const struct req_format RQF_MDS_REINT_SETXATTR =
947         DEFINE_REQ_FMT0("MDS_REINT_SETXATTR",
948                         mds_reint_setxattr_client, mdt_body_only);
949 EXPORT_SYMBOL(RQF_MDS_REINT_SETXATTR);
950
951 const struct req_format RQF_MDS_CONNECT =
952         DEFINE_REQ_FMT0("MDS_CONNECT",
953                         obd_connect_client, obd_connect_server);
954 EXPORT_SYMBOL(RQF_MDS_CONNECT);
955
956 const struct req_format RQF_MDS_DISCONNECT =
957         DEFINE_REQ_FMT0("MDS_DISCONNECT", empty, empty);
958 EXPORT_SYMBOL(RQF_MDS_DISCONNECT);
959  
960 const struct req_format RQF_MDS_SET_INFO =
961         DEFINE_REQ_FMT0("MDS_SET_INFO", mds_set_info_client, empty);
962 EXPORT_SYMBOL(RQF_MDS_SET_INFO);
963  
964 const struct req_format RQF_LDLM_ENQUEUE =
965         DEFINE_REQ_FMT0("LDLM_ENQUEUE",
966                         ldlm_enqueue_client, ldlm_enqueue_lvb_server);
967 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE);
968
969 const struct req_format RQF_LDLM_ENQUEUE_LVB =
970         DEFINE_REQ_FMT0("LDLM_ENQUEUE_LVB",
971                         ldlm_enqueue_client, ldlm_enqueue_lvb_server);
972 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE_LVB);
973
974 const struct req_format RQF_LDLM_CONVERT =
975         DEFINE_REQ_FMT0("LDLM_CONVERT",
976                         ldlm_enqueue_client, ldlm_enqueue_server);
977 EXPORT_SYMBOL(RQF_LDLM_CONVERT);
978
979 const struct req_format RQF_LDLM_CANCEL =
980         DEFINE_REQ_FMT0("LDLM_CANCEL", ldlm_enqueue_client, empty);
981 EXPORT_SYMBOL(RQF_LDLM_CANCEL);
982
983 const struct req_format RQF_LDLM_CALLBACK =
984         DEFINE_REQ_FMT0("LDLM_CALLBACK", ldlm_enqueue_client, empty);
985 EXPORT_SYMBOL(RQF_LDLM_CALLBACK);
986
987 const struct req_format RQF_LDLM_CP_CALLBACK =
988         DEFINE_REQ_FMT0("LDLM_CP_CALLBACK", ldlm_cp_callback_client, empty);
989 EXPORT_SYMBOL(RQF_LDLM_CP_CALLBACK);
990
991 const struct req_format RQF_LDLM_BL_CALLBACK =
992         DEFINE_REQ_FMT0("LDLM_BL_CALLBACK", ldlm_enqueue_client, empty);
993 EXPORT_SYMBOL(RQF_LDLM_BL_CALLBACK);
994
995 const struct req_format RQF_LDLM_GL_CALLBACK =
996         DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_enqueue_client,
997                         ldlm_gl_callback_server);
998 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK);
999
1000 const struct req_format RQF_LDLM_INTENT =
1001         DEFINE_REQ_FMT0("LDLM_INTENT",
1002                         ldlm_intent_client, ldlm_intent_server);
1003 EXPORT_SYMBOL(RQF_LDLM_INTENT);
1004
1005 const struct req_format RQF_LDLM_INTENT_GETATTR =
1006         DEFINE_REQ_FMT0("LDLM_INTENT_GETATTR",
1007                         ldlm_intent_getattr_client, ldlm_intent_getattr_server);
1008 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETATTR);
1009
1010 const struct req_format RQF_LDLM_INTENT_OPEN =
1011         DEFINE_REQ_FMT0("LDLM_INTENT_OPEN",
1012                         ldlm_intent_open_client, ldlm_intent_open_server);
1013 EXPORT_SYMBOL(RQF_LDLM_INTENT_OPEN);
1014
1015 const struct req_format RQF_LDLM_INTENT_CREATE =
1016         DEFINE_REQ_FMT0("LDLM_INTENT_CREATE",
1017                         ldlm_intent_create_client, ldlm_intent_getattr_server);
1018 EXPORT_SYMBOL(RQF_LDLM_INTENT_CREATE);
1019
1020 const struct req_format RQF_LDLM_INTENT_UNLINK =
1021         DEFINE_REQ_FMT0("LDLM_INTENT_UNLINK",
1022                         ldlm_intent_unlink_client, ldlm_intent_server);
1023 EXPORT_SYMBOL(RQF_LDLM_INTENT_UNLINK);
1024
1025 const struct req_format RQF_MDS_CLOSE =
1026         DEFINE_REQ_FMT0("MDS_CLOSE",
1027                         mdt_close_client, mds_last_unlink_server);
1028 EXPORT_SYMBOL(RQF_MDS_CLOSE);
1029
1030 const struct req_format RQF_MDS_PIN =
1031         DEFINE_REQ_FMT0("MDS_PIN",
1032                         mdt_body_capa, mdt_body_only);
1033 EXPORT_SYMBOL(RQF_MDS_PIN);
1034
1035 const struct req_format RQF_MDS_UNPIN =
1036         DEFINE_REQ_FMT0("MDS_UNPIN", mdt_body_only, empty);
1037 EXPORT_SYMBOL(RQF_MDS_UNPIN);
1038
1039 const struct req_format RQF_MDS_DONE_WRITING =
1040         DEFINE_REQ_FMT0("MDS_DONE_WRITING",
1041                         mdt_close_client, mdt_body_only);
1042 EXPORT_SYMBOL(RQF_MDS_DONE_WRITING);
1043
1044 const struct req_format RQF_MDS_READPAGE =
1045         DEFINE_REQ_FMT0("MDS_READPAGE",
1046                         mdt_body_capa, mdt_body_only);
1047 EXPORT_SYMBOL(RQF_MDS_READPAGE);
1048
1049 /* This is for split */
1050 const struct req_format RQF_MDS_WRITEPAGE =
1051         DEFINE_REQ_FMT0("MDS_WRITEPAGE",
1052                         mdt_body_capa, mdt_body_only);
1053 EXPORT_SYMBOL(RQF_MDS_WRITEPAGE);
1054
1055 const struct req_format RQF_MDS_IS_SUBDIR =
1056         DEFINE_REQ_FMT0("MDS_IS_SUBDIR",
1057                         mdt_body_only, mdt_body_only);
1058 EXPORT_SYMBOL(RQF_MDS_IS_SUBDIR);
1059
1060 const struct req_format RQF_LLOG_CATINFO =
1061         DEFINE_REQ_FMT0("LLOG_CATINFO",
1062                         llog_catinfo_client, llog_catinfo_server);
1063 EXPORT_SYMBOL(RQF_LLOG_CATINFO);
1064
1065 const struct req_format RQF_LLOG_ORIGIN_HANDLE_CREATE =
1066         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_CREATE",
1067                         llog_origin_handle_create_client, llogd_body_only);
1068 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_CREATE);
1069
1070 const struct req_format RQF_LLOG_ORIGIN_HANDLE_DESTROY =
1071         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_DESTROY",
1072                         llogd_body_only, llogd_body_only);
1073 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1074
1075 const struct req_format RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK =
1076         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_NEXT_BLOCK",
1077                         llogd_body_only, llog_origin_handle_next_block_server);
1078 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1079
1080 const struct req_format RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK =
1081         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_PREV_BLOCK",
1082                         llogd_body_only, llog_origin_handle_next_block_server);
1083 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1084
1085 const struct req_format RQF_LLOG_ORIGIN_HANDLE_READ_HEADER =
1086         DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_READ_HEADER",
1087                         llogd_body_only, llog_log_hdr_only);
1088 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1089
1090 const struct req_format RQF_LLOG_ORIGIN_CONNECT =
1091         DEFINE_REQ_FMT0("LLOG_ORIGIN_CONNECT", llogd_conn_body_only, empty);
1092 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_CONNECT);
1093
1094 const struct req_format RQF_OST_CONNECT =
1095         DEFINE_REQ_FMT0("OST_CONNECT",
1096                         obd_connect_client, obd_connect_server);
1097 EXPORT_SYMBOL(RQF_OST_CONNECT);
1098
1099 const struct req_format RQF_OST_DISCONNECT =
1100         DEFINE_REQ_FMT0("OST_DISCONNECT", empty, empty);
1101 EXPORT_SYMBOL(RQF_OST_DISCONNECT);
1102
1103 const struct req_format RQF_OST_GETATTR =
1104         DEFINE_REQ_FMT0("OST_GETATTR", ost_body_capa, ost_body_only);
1105 EXPORT_SYMBOL(RQF_OST_GETATTR);
1106
1107 const struct req_format RQF_OST_SETATTR =
1108         DEFINE_REQ_FMT0("OST_SETATTR", ost_body_capa, ost_body_only);
1109 EXPORT_SYMBOL(RQF_OST_SETATTR);
1110
1111 const struct req_format RQF_OST_CREATE =
1112         DEFINE_REQ_FMT0("OST_CREATE", ost_body_only, ost_body_only);
1113 EXPORT_SYMBOL(RQF_OST_CREATE);
1114
1115 const struct req_format RQF_OST_PUNCH =
1116         DEFINE_REQ_FMT0("OST_PUNCH", ost_body_capa, ost_body_only);
1117 EXPORT_SYMBOL(RQF_OST_PUNCH);
1118
1119 const struct req_format RQF_OST_SYNC =
1120         DEFINE_REQ_FMT0("OST_SYNC", ost_body_capa, ost_body_only);
1121 EXPORT_SYMBOL(RQF_OST_SYNC);
1122
1123 const struct req_format RQF_OST_DESTROY =
1124         DEFINE_REQ_FMT0("OST_DESTROY", ost_destroy_client, ost_body_only);
1125 EXPORT_SYMBOL(RQF_OST_DESTROY);
1126
1127 const struct req_format RQF_OST_BRW =
1128         DEFINE_REQ_FMT0("OST_BRW", ost_brw_client, ost_brw_server);
1129 EXPORT_SYMBOL(RQF_OST_BRW);
1130
1131 const struct req_format RQF_OST_STATFS =
1132         DEFINE_REQ_FMT0("OST_STATFS", empty, obd_statfs_server);
1133 EXPORT_SYMBOL(RQF_OST_STATFS);
1134
1135 const struct req_format RQF_OST_SET_INFO =
1136         DEFINE_REQ_FMT0("OST_SET_INFO", ost_set_info_client, empty);
1137 EXPORT_SYMBOL(RQF_OST_SET_INFO);
1138
1139 const struct req_format RQF_OST_GET_INFO =
1140         DEFINE_REQ_FMT0("OST_GET_INFO", ost_get_info_client,
1141                                         ost_get_info_server);
1142 EXPORT_SYMBOL(RQF_OST_GET_INFO);
1143
1144
1145 #if !defined(__REQ_LAYOUT_USER__)
1146
1147 int req_layout_init(void)
1148 {
1149         int i;
1150         int j;
1151         int k;
1152
1153         for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
1154                 struct req_format *rf;
1155
1156                 rf = (struct req_format *)req_formats[i];
1157                 rf->rf_idx = i;
1158                 for (j = 0; j < RCL_NR; ++j) {
1159                         LASSERT(rf->rf_fields[j].nr <= REQ_MAX_FIELD_NR);
1160                         for (k = 0; k < rf->rf_fields[j].nr; ++k) {
1161                                 struct req_msg_field *field;
1162
1163                                 field = (typeof(field))rf->rf_fields[j].d[k];
1164                                 LASSERT(field->rmf_offset[i][j] == 0);
1165                                 /*
1166                                  * k + 1 to detect unused format/field
1167                                  * combinations.
1168                                  */
1169                                 field->rmf_offset[i][j] = k + 1;
1170                         }
1171                 }
1172         }
1173         return 0;
1174 }
1175 EXPORT_SYMBOL(req_layout_init);
1176
1177 void req_layout_fini(void)
1178 {
1179 }
1180 EXPORT_SYMBOL(req_layout_fini);
1181
1182 void req_capsule_init_area(struct req_capsule *pill)
1183 {
1184         int i;
1185
1186         for (i = 0; i < ARRAY_SIZE(pill->rc_area[RCL_CLIENT]); i++) {
1187                 pill->rc_area[RCL_CLIENT][i] = -1;
1188                 pill->rc_area[RCL_SERVER][i] = -1;
1189         }
1190 }
1191 EXPORT_SYMBOL(req_capsule_init_area);
1192
1193 /*
1194  * Initialize capsule.
1195  *
1196  * @area is an array of REQ_MAX_FIELD_NR elements, used to store sizes of
1197  * variable-sized fields.
1198  */
1199 void req_capsule_init(struct req_capsule *pill,
1200                       struct ptlrpc_request *req,
1201                       enum req_location location)
1202 {
1203         LASSERT(location == RCL_SERVER || location == RCL_CLIENT);
1204
1205         memset(pill, 0, sizeof *pill);
1206         pill->rc_req = req;
1207         pill->rc_loc = location;
1208         req_capsule_init_area(pill);
1209 }
1210 EXPORT_SYMBOL(req_capsule_init);
1211
1212 void req_capsule_fini(struct req_capsule *pill)
1213 {
1214 }
1215 EXPORT_SYMBOL(req_capsule_fini);
1216
1217 static int __req_format_is_sane(const struct req_format *fmt)
1218 {
1219         return
1220                 0 <= fmt->rf_idx && fmt->rf_idx < ARRAY_SIZE(req_formats) &&
1221                 req_formats[fmt->rf_idx] == fmt;
1222 }
1223
1224 static struct lustre_msg *__req_msg(const struct req_capsule *pill,
1225                                     enum req_location loc)
1226 {
1227         struct ptlrpc_request *req;
1228
1229         req = pill->rc_req;
1230         return loc == RCL_CLIENT ? req->rq_reqmsg : req->rq_repmsg;
1231 }
1232
1233 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt)
1234 {
1235         LASSERT(pill->rc_fmt == NULL);
1236         LASSERT(__req_format_is_sane(fmt));
1237
1238         pill->rc_fmt = fmt;
1239 }
1240 EXPORT_SYMBOL(req_capsule_set);
1241
1242 int req_capsule_filled_sizes(struct req_capsule *pill,
1243                            enum req_location loc)
1244 {
1245         const struct req_format *fmt = pill->rc_fmt;
1246         int                      i;
1247
1248         LASSERT(fmt != NULL);
1249
1250         for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1251                 if (pill->rc_area[loc][i] == -1) {
1252                         pill->rc_area[loc][i] = 
1253                                             fmt->rf_fields[loc].d[i]->rmf_size;
1254                         if (pill->rc_area[loc][i] == -1) {
1255                                 /* skip the following fields */
1256                                 LASSERT(loc != RCL_SERVER);
1257                                 break;
1258                         }
1259                 }
1260         }
1261         return i;
1262 }
1263 EXPORT_SYMBOL(req_capsule_filled_sizes);
1264
1265 int req_capsule_server_pack(struct req_capsule *pill)
1266 {
1267         const struct req_format *fmt;
1268         int                      count;
1269         int                      rc;
1270
1271         LASSERT(pill->rc_loc == RCL_SERVER);
1272         fmt = pill->rc_fmt;
1273         LASSERT(fmt != NULL);
1274
1275         count = req_capsule_filled_sizes(pill, RCL_SERVER);
1276         rc = lustre_pack_reply(pill->rc_req, count,
1277                                pill->rc_area[RCL_SERVER], NULL);
1278         if (rc != 0) {
1279                 DEBUG_REQ(D_ERROR, pill->rc_req,
1280                           "Cannot pack %d fields in format `%s': ",
1281                           count, fmt->rf_name);
1282         }
1283         return rc;
1284 }
1285 EXPORT_SYMBOL(req_capsule_server_pack);
1286
1287 static int __req_capsule_offset(const struct req_capsule *pill,
1288                                 const struct req_msg_field *field,
1289                                 enum req_location loc)
1290 {
1291         int offset;
1292
1293         offset = field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1294         LASSERTF(offset > 0, "%s:%s, off=%d, loc=%d\n",
1295                             pill->rc_fmt->rf_name,
1296                             field->rmf_name, offset, loc);
1297         offset --;
1298         LASSERT(0 <= offset && offset < (sizeof(pill->rc_swabbed) << 3));
1299         return offset;
1300 }
1301
1302 static void *__req_capsule_get(struct req_capsule *pill,
1303                                const struct req_msg_field *field,
1304                                enum req_location loc,
1305                                void (*swabber)( void *))
1306 {
1307         const struct req_format *fmt;
1308         struct lustre_msg       *msg;
1309         void                    *value;
1310         int                      len;
1311         int                      offset;
1312
1313         void *(*getter)(struct lustre_msg *m, int n, int minlen);
1314
1315         static const char *rcl_names[RCL_NR] = {
1316                 [RCL_CLIENT] = "client",
1317                 [RCL_SERVER] = "server"
1318         };
1319
1320         fmt = pill->rc_fmt;
1321         LASSERT(fmt != NULL);
1322         LASSERT(__req_format_is_sane(fmt));
1323
1324         offset = __req_capsule_offset(pill, field, loc);
1325
1326         msg = __req_msg(pill, loc);
1327         LASSERT(msg != NULL);
1328
1329         getter = (field->rmf_flags & RMF_F_STRING) ?
1330                 (typeof(getter))lustre_msg_string : lustre_msg_buf;
1331
1332         if (pill->rc_area[loc][offset] != -1)
1333                 len = pill->rc_area[loc][offset];
1334         else
1335                 len = max(field->rmf_size, 0);
1336         value = getter(msg, offset, len);
1337
1338         swabber = swabber ?: field->rmf_swabber;
1339         if (!(pill->rc_swabbed & (1 << offset)) && loc != pill->rc_loc &&
1340             swabber != NULL && value != NULL &&
1341             lustre_msg_swabbed(msg)) {
1342                 swabber(value);
1343                 pill->rc_swabbed |= (1 << offset);
1344         }
1345         if (value == NULL) {
1346                 DEBUG_REQ(D_ERROR, pill->rc_req,
1347                           "Wrong buffer for field `%s' (%d of %d) "
1348                           "in format `%s': %d vs. %d (%s)\n",
1349                           field->rmf_name, offset, lustre_msg_bufcount(msg), fmt->rf_name,
1350                           lustre_msg_buflen(msg, offset), len,
1351                           rcl_names[loc]);
1352         }
1353
1354         return value;
1355 }
1356
1357 void *req_capsule_client_get(struct req_capsule *pill,
1358                              const struct req_msg_field *field)
1359 {
1360         return __req_capsule_get(pill, field, RCL_CLIENT, NULL);
1361 }
1362 EXPORT_SYMBOL(req_capsule_client_get);
1363
1364 void *req_capsule_client_swab_get(struct req_capsule *pill,
1365                                   const struct req_msg_field *field,
1366                                   void (*swabber)(void* ))
1367 {
1368         return __req_capsule_get(pill, field, RCL_CLIENT, swabber);
1369 }
1370 EXPORT_SYMBOL(req_capsule_client_swab_get);
1371
1372 void *req_capsule_client_sized_get(struct req_capsule *pill,
1373                                    const struct req_msg_field *field,
1374                                    int len)
1375 {
1376         req_capsule_set_size(pill, field, RCL_CLIENT, len);
1377         return __req_capsule_get(pill, field, RCL_CLIENT, NULL);
1378 }
1379 EXPORT_SYMBOL(req_capsule_client_sized_get);
1380
1381 void *req_capsule_server_get(struct req_capsule *pill,
1382                              const struct req_msg_field *field)
1383 {
1384         return __req_capsule_get(pill, field, RCL_SERVER, NULL);
1385 }
1386 EXPORT_SYMBOL(req_capsule_server_get);
1387
1388 void *req_capsule_server_swab_get(struct req_capsule *pill,
1389                                   const struct req_msg_field *field,
1390                                   void *swabber)
1391 {
1392         return __req_capsule_get(pill, field, RCL_SERVER, swabber);
1393 }
1394 EXPORT_SYMBOL(req_capsule_server_swab_get);
1395
1396
1397 void *req_capsule_server_sized_get(struct req_capsule *pill,
1398                                    const struct req_msg_field *field,
1399                                    int len)
1400 {
1401         req_capsule_set_size(pill, field, RCL_SERVER, len);
1402         return __req_capsule_get(pill, field, RCL_SERVER, NULL);
1403 }
1404 EXPORT_SYMBOL(req_capsule_server_sized_get);
1405
1406 const void *req_capsule_other_get(struct req_capsule *pill,
1407                                   const struct req_msg_field *field)
1408 {
1409         return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL);
1410 }
1411 EXPORT_SYMBOL(req_capsule_other_get);
1412
1413 void req_capsule_set_size(struct req_capsule *pill,
1414                           const struct req_msg_field *field,
1415                           enum req_location loc, int size)
1416 {
1417         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1418
1419         pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size;
1420 }
1421 EXPORT_SYMBOL(req_capsule_set_size);
1422
1423 /* NB: this function doesn't correspond with req_capsule_set_size(), which
1424  * actually sets the size in pill.rc_area[loc][offset], but this function
1425  * returns the message buflen[offset], maybe we should use another name.
1426  */
1427 int req_capsule_get_size(const struct req_capsule *pill,
1428                          const struct req_msg_field *field,
1429                          enum req_location loc)
1430 {
1431         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1432
1433         return lustre_msg_buflen(__req_msg(pill, loc),
1434                                  __req_capsule_offset(pill, field, loc));
1435 }
1436 EXPORT_SYMBOL(req_capsule_get_size);
1437
1438 int req_capsule_msg_size(const struct req_capsule *pill, enum req_location loc)
1439 {
1440         return lustre_msg_size(pill->rc_req->rq_import->imp_msg_magic,
1441                                pill->rc_fmt->rf_fields[loc].nr,
1442                                (int *)pill->rc_area[loc]);
1443 }
1444
1445 int req_capsule_fmt_size(__u32 magic, const struct req_format *fmt,
1446                          enum req_location loc)
1447 {
1448         int size, i = 0;
1449
1450         size = lustre_msg_hdr_size(magic, fmt->rf_fields[loc].nr);
1451         if (size < 0)
1452                 return size;
1453
1454         if (magic == LUSTRE_MSG_MAGIC_V1)
1455                 i++;
1456
1457         for (; i < fmt->rf_fields[loc].nr; ++i)
1458                 if (fmt->rf_fields[loc].d[i]->rmf_size != -1)
1459                         size += size_round(fmt->rf_fields[loc].d[i]->rmf_size);
1460         return size;
1461 }
1462
1463 #define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1464
1465 void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
1466 {
1467         int i;
1468         int j;
1469
1470         const struct req_format *old;
1471
1472         LASSERT(pill->rc_fmt != NULL);
1473         LASSERT(__req_format_is_sane(fmt));
1474
1475         old = pill->rc_fmt;
1476         /*
1477          * Sanity checking...
1478          */
1479         for (i = 0; i < RCL_NR; ++i) {
1480                 LASSERT(fmt->rf_fields[i].nr >= old->rf_fields[i].nr);
1481                 for (j = 0; j < old->rf_fields[i].nr - 1; ++j) {
1482                         LASSERT(FMT_FIELD(fmt, i, j) == FMT_FIELD(old, i, j));
1483                 }
1484                 /*
1485                  * Last field in old format can be shorter than in new.
1486                  */
1487                 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
1488                         FMT_FIELD(old, i, j)->rmf_size);
1489         }
1490         /* last field should be returned to the unswabbed state */
1491         pill->rc_swabbed &= ~(__u32)(1 << j);
1492         pill->rc_fmt = fmt;
1493 }
1494 EXPORT_SYMBOL(req_capsule_extend);
1495
1496 int req_capsule_has_field(const struct req_capsule *pill,
1497                           const struct req_msg_field *field,
1498                           enum req_location loc)
1499 {
1500         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1501
1502         return field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1503 }
1504 EXPORT_SYMBOL(req_capsule_has_field);
1505
1506 int req_capsule_field_present(const struct req_capsule *pill,
1507                               const struct req_msg_field *field,
1508                               enum req_location loc)
1509 {
1510         int offset;
1511
1512         LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1513         LASSERT(req_capsule_has_field(pill, field, loc));
1514
1515         offset = __req_capsule_offset(pill, field, loc);
1516         return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
1517 }
1518 EXPORT_SYMBOL(req_capsule_field_present);
1519
1520 void req_capsule_shrink(struct req_capsule *pill,
1521                         const struct req_msg_field *field,
1522                         unsigned int newlen,
1523                         enum req_location loc)
1524 {
1525         const struct req_format *fmt;
1526         struct lustre_msg       *msg;
1527         int                      len;
1528         int                      offset;
1529
1530         fmt = pill->rc_fmt;
1531         LASSERT(fmt != NULL);
1532         LASSERT(__req_format_is_sane(fmt));
1533         LASSERT(req_capsule_has_field(pill, field, loc));
1534         LASSERT(req_capsule_field_present(pill, field, loc));
1535
1536         offset = __req_capsule_offset(pill, field, loc);
1537
1538         msg = __req_msg(pill, loc);
1539         len = lustre_msg_buflen(msg, offset);
1540         LASSERTF(newlen <= len, "%s:%s, oldlen=%d, newlen=%d\n",
1541                                 fmt->rf_name, field->rmf_name, len, newlen);
1542
1543         if (loc == RCL_CLIENT)
1544                 pill->rc_req->rq_reqlen = lustre_shrink_msg(msg, offset, newlen,
1545                                                             1);
1546         else
1547                 pill->rc_req->rq_replen = lustre_shrink_msg(msg, offset, newlen,
1548                                                             1);
1549 }
1550 EXPORT_SYMBOL(req_capsule_shrink);
1551
1552 /* __REQ_LAYOUT_USER__ */
1553 #endif