1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/layout.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Nikita Danilov <nikita@clusterfs.com>
43 * This file contains the "capsule/pill" abstraction layered above PTLRPC.
45 * Every struct ptlrpc_request contains a "pill", which points to a description
46 * of the format that the request conforms to.
49 #if !defined(__REQ_LAYOUT_USER__)
52 # define EXPORT_SYMTAB
54 #define DEBUG_SUBSYSTEM S_RPC
57 #include <linux/module.h>
59 # include <liblustre.h>
62 /* LUSTRE_VERSION_CODE */
63 #include <lustre_ver.h>
65 #include <obd_support.h>
66 /* lustre_swab_mdt_body */
67 #include <lustre/lustre_idl.h>
68 /* obd2cli_tgt() (required by DEBUG_REQ()) */
71 /* __REQ_LAYOUT_USER__ */
73 /* struct ptlrpc_request, lustre_msg* */
74 #include <lustre_req_layout.h>
75 #include <lustre_acl.h>
76 #include <lustre_debug.h>
79 * RQFs (see below) refer to two struct req_msg_field arrays describing the
80 * client request and server reply, respectively.
82 /* empty set of fields... for suitable definition of emptiness. */
83 static const struct req_msg_field *empty[] = {
87 static const struct req_msg_field *mgs_target_info_only[] = {
92 static const struct req_msg_field *mgs_set_info[] = {
97 static const struct req_msg_field *log_cancel_client[] = {
102 static const struct req_msg_field *mdt_body_only[] = {
107 static const struct req_msg_field *mdt_body_capa[] = {
113 static const struct req_msg_field *quotactl_only[] = {
117 static const struct req_msg_field *quota_adjust_qunit_only[] = {
119 &RMF_QUOTA_ADJUST_QUNIT
122 static const struct req_msg_field *qunit_data_only[] = {
127 static const struct req_msg_field *mdt_close_client[] = {
134 static const struct req_msg_field *obd_statfs_server[] = {
139 static const struct req_msg_field *seq_query_client[] = {
145 static const struct req_msg_field *seq_query_server[] = {
150 static const struct req_msg_field *fld_query_client[] = {
156 static const struct req_msg_field *fld_query_server[] = {
161 static const struct req_msg_field *mds_getattr_name_client[] = {
168 static const struct req_msg_field *mds_reint_client[] = {
173 static const struct req_msg_field *mds_reint_create_client[] = {
180 static const struct req_msg_field *mds_reint_create_slave_client[] = {
189 static const struct req_msg_field *mds_reint_create_rmt_acl_client[] = {
198 static const struct req_msg_field *mds_reint_create_sym_client[] = {
207 static const struct req_msg_field *mds_reint_open_client[] = {
216 static const struct req_msg_field *mds_reint_open_server[] = {
225 static const struct req_msg_field *mds_reint_unlink_client[] = {
233 static const struct req_msg_field *mds_reint_link_client[] = {
242 static const struct req_msg_field *mds_reint_rename_client[] = {
252 static const struct req_msg_field *mds_last_unlink_server[] = {
261 static const struct req_msg_field *mds_reint_setattr_client[] = {
271 static const struct req_msg_field *mds_reint_setxattr_client[] = {
279 static const struct req_msg_field *obd_connect_client[] = {
287 static const struct req_msg_field *obd_connect_server[] = {
292 static const struct req_msg_field *obd_set_info_client[] = {
298 static const struct req_msg_field *ost_grant_shrink_client[] = {
304 static const struct req_msg_field *mds_getinfo_client[] = {
310 static const struct req_msg_field *mds_getinfo_server[] = {
315 static const struct req_msg_field *ldlm_enqueue_client[] = {
320 static const struct req_msg_field *ldlm_enqueue_server[] = {
325 static const struct req_msg_field *ldlm_enqueue_lvb_server[] = {
331 static const struct req_msg_field *ldlm_cp_callback_client[] = {
337 static const struct req_msg_field *ldlm_gl_callback_server[] = {
342 static const struct req_msg_field *ldlm_intent_client[] = {
349 static const struct req_msg_field *ldlm_intent_server[] = {
357 static const struct req_msg_field *ldlm_intent_open_server[] = {
367 static const struct req_msg_field *ldlm_intent_getattr_client[] = {
371 &RMF_MDT_BODY, /* coincides with mds_getattr_name_client[] */
376 static const struct req_msg_field *ldlm_intent_getattr_server[] = {
385 static const struct req_msg_field *ldlm_intent_create_client[] = {
389 &RMF_REC_REINT, /* coincides with mds_reint_create_client[] */
395 static const struct req_msg_field *ldlm_intent_open_client[] = {
399 &RMF_REC_REINT, /* coincides with mds_reint_open_client[] */
406 static const struct req_msg_field *ldlm_intent_unlink_client[] = {
410 &RMF_REC_REINT, /* coincides with mds_reint_unlink_client[] */
415 static const struct req_msg_field *mds_getxattr_client[] = {
423 static const struct req_msg_field *mds_getxattr_server[] = {
429 static const struct req_msg_field *mds_getattr_server[] = {
438 static const struct req_msg_field *mds_setattr_server[] = {
447 static const struct req_msg_field *llog_catinfo_client[] = {
453 static const struct req_msg_field *llog_catinfo_server[] = {
458 static const struct req_msg_field *llog_origin_handle_create_client[] = {
464 static const struct req_msg_field *llogd_body_only[] = {
469 static const struct req_msg_field *llog_log_hdr_only[] = {
474 static const struct req_msg_field *llogd_conn_body_only[] = {
479 static const struct req_msg_field *llog_origin_handle_next_block_server[] = {
485 static const struct req_msg_field *ost_body_only[] = {
490 static const struct req_msg_field *ost_body_capa[] = {
496 static const struct req_msg_field *ost_destroy_client[] = {
504 static const struct req_msg_field *ost_brw_client[] = {
512 static const struct req_msg_field *ost_brw_read_server[] = {
517 static const struct req_msg_field *ost_brw_write_server[] = {
523 static const struct req_msg_field *ost_get_info_generic_server[] = {
528 static const struct req_msg_field *ost_get_info_generic_client[] = {
533 static const struct req_msg_field *ost_get_last_id_server[] = {
538 static const struct req_msg_field *ost_get_fiemap_client[] = {
544 static const struct req_msg_field *ost_get_fiemap_server[] = {
549 static const struct req_format *req_formats[] = {
563 &RQF_MDS_GETATTR_NAME,
572 &RQF_MDS_DONE_WRITING,
574 &RQF_MDS_REINT_CREATE,
575 &RQF_MDS_REINT_CREATE_RMT_ACL,
576 &RQF_MDS_REINT_CREATE_SLAVE,
577 &RQF_MDS_REINT_CREATE_SYM,
579 &RQF_MDS_REINT_UNLINK,
581 &RQF_MDS_REINT_RENAME,
582 &RQF_MDS_REINT_SETATTR,
583 &RQF_MDS_REINT_SETXATTR,
586 &RQF_MDS_QUOTA_DQACQ,
592 &RQF_OST_QUOTA_ADJUST_QUNIT,
602 &RQF_OST_SET_GRANT_INFO,
603 &RQF_OST_GET_INFO_GENERIC,
604 &RQF_OST_GET_INFO_LAST_ID,
605 &RQF_OST_GET_INFO_FIEMAP,
607 &RQF_LDLM_ENQUEUE_LVB,
611 &RQF_LDLM_CP_CALLBACK,
612 &RQF_LDLM_BL_CALLBACK,
613 &RQF_LDLM_GL_CALLBACK,
615 &RQF_LDLM_INTENT_GETATTR,
616 &RQF_LDLM_INTENT_OPEN,
617 &RQF_LDLM_INTENT_CREATE,
618 &RQF_LDLM_INTENT_UNLINK,
621 &RQF_LLOG_ORIGIN_HANDLE_CREATE,
622 &RQF_LLOG_ORIGIN_HANDLE_DESTROY,
623 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK,
624 &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK,
625 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER,
626 &RQF_LLOG_ORIGIN_CONNECT
629 struct req_msg_field {
631 const char *rmf_name;
633 * Field length. (-1) means "variable length". If the
634 * \a RMF_F_STRUCT_ARRAY flag is set the field is also variable-length,
635 * but the actual size must be a whole multiple of \a rmf_size.
638 void (*rmf_swabber)(void *);
639 void (*rmf_dumper)(void *);
640 int rmf_offset[ARRAY_SIZE(req_formats)][RCL_NR];
645 * The field is a string, must be NUL-terminated.
647 RMF_F_STRING = 1 << 0,
649 * The field's buffer size need not match the declared \a rmf_size.
651 RMF_F_NO_SIZE_CHECK = 1 << 1,
653 * The field's buffer size must be a whole multiple of the declared \a
654 * rmf_size and the \a rmf_swabber function must work on the declared \a
655 * rmf_size worth of bytes.
657 RMF_F_STRUCT_ARRAY = 1 << 2
665 #define DEFINE_MSGF(name, flags, size, swabber, dumper) { \
666 .rmf_name = (name), \
667 .rmf_flags = (flags), \
668 .rmf_size = (size), \
669 .rmf_swabber = (void (*)(void*))(swabber), \
670 .rmf_dumper = (void (*)(void*))(dumper) \
673 const struct req_msg_field RMF_GENERIC_DATA =
674 DEFINE_MSGF("generic_data", 0,
676 EXPORT_SYMBOL(RMF_GENERIC_DATA);
678 const struct req_msg_field RMF_MGS_TARGET_INFO =
679 DEFINE_MSGF("mgs_target_info", 0,
680 sizeof(struct mgs_target_info),
681 lustre_swab_mgs_target_info, NULL);
682 EXPORT_SYMBOL(RMF_MGS_TARGET_INFO);
684 const struct req_msg_field RMF_MGS_SEND_PARAM =
685 DEFINE_MSGF("mgs_send_param", 0,
686 sizeof(struct mgs_send_param),
688 EXPORT_SYMBOL(RMF_MGS_SEND_PARAM);
690 const struct req_msg_field RMF_SETINFO_VAL =
691 DEFINE_MSGF("setinfo_val", 0, -1, NULL, NULL);
692 EXPORT_SYMBOL(RMF_SETINFO_VAL);
694 const struct req_msg_field RMF_GETINFO_KEY =
695 DEFINE_MSGF("getinfo_key", 0, -1, NULL, NULL);
696 EXPORT_SYMBOL(RMF_GETINFO_KEY);
698 const struct req_msg_field RMF_GETINFO_VALLEN =
699 DEFINE_MSGF("getinfo_vallen", 0,
700 sizeof(__u32), lustre_swab_generic_32s, NULL);
701 EXPORT_SYMBOL(RMF_GETINFO_VALLEN);
703 const struct req_msg_field RMF_GETINFO_VAL =
704 DEFINE_MSGF("getinfo_val", 0, -1, NULL, NULL);
705 EXPORT_SYMBOL(RMF_GETINFO_VAL);
707 const struct req_msg_field RMF_SEQ_OPC =
708 DEFINE_MSGF("seq_query_opc", 0,
709 sizeof(__u32), lustre_swab_generic_32s, NULL);
710 EXPORT_SYMBOL(RMF_SEQ_OPC);
712 const struct req_msg_field RMF_SEQ_RANGE =
713 DEFINE_MSGF("seq_query_range", 0,
714 sizeof(struct lu_seq_range),
715 lustre_swab_lu_seq_range, NULL);
716 EXPORT_SYMBOL(RMF_SEQ_RANGE);
718 const struct req_msg_field RMF_FLD_OPC =
719 DEFINE_MSGF("fld_query_opc", 0,
720 sizeof(__u32), lustre_swab_generic_32s, NULL);
721 EXPORT_SYMBOL(RMF_FLD_OPC);
723 const struct req_msg_field RMF_FLD_MDFLD =
724 DEFINE_MSGF("fld_query_mdfld", 0,
725 sizeof(struct lu_seq_range),
726 lustre_swab_lu_seq_range, NULL);
727 EXPORT_SYMBOL(RMF_FLD_MDFLD);
729 const struct req_msg_field RMF_MDT_BODY =
730 DEFINE_MSGF("mdt_body", 0,
731 sizeof(struct mdt_body), lustre_swab_mdt_body, NULL);
732 EXPORT_SYMBOL(RMF_MDT_BODY);
734 const struct req_msg_field RMF_OBD_QUOTACTL =
735 DEFINE_MSGF("obd_quotactl", 0,
736 sizeof(struct obd_quotactl),
737 lustre_swab_obd_quotactl, NULL);
738 EXPORT_SYMBOL(RMF_OBD_QUOTACTL);
740 const struct req_msg_field RMF_QUOTA_ADJUST_QUNIT =
741 DEFINE_MSGF("quota_adjust_qunit", 0,
742 sizeof(struct quota_adjust_qunit),
743 lustre_swab_quota_adjust_qunit, NULL);
744 EXPORT_SYMBOL(RMF_QUOTA_ADJUST_QUNIT);
746 const struct req_msg_field RMF_QUNIT_DATA =
747 DEFINE_MSGF("qunit_data", 0,
748 sizeof(struct qunit_data), lustre_swab_qdata, NULL);
749 EXPORT_SYMBOL(RMF_QUNIT_DATA);
751 const struct req_msg_field RMF_MDT_EPOCH =
752 DEFINE_MSGF("mdt_ioepoch", 0,
753 sizeof(struct mdt_ioepoch), lustre_swab_mdt_ioepoch, NULL);
754 EXPORT_SYMBOL(RMF_MDT_EPOCH);
756 const struct req_msg_field RMF_PTLRPC_BODY =
757 DEFINE_MSGF("ptlrpc_body", 0,
758 sizeof(struct ptlrpc_body), lustre_swab_ptlrpc_body, NULL);
759 EXPORT_SYMBOL(RMF_PTLRPC_BODY);
761 const struct req_msg_field RMF_OBD_STATFS =
762 DEFINE_MSGF("obd_statfs", 0,
763 sizeof(struct obd_statfs), lustre_swab_obd_statfs, NULL);
764 EXPORT_SYMBOL(RMF_OBD_STATFS);
766 const struct req_msg_field RMF_SETINFO_KEY =
767 DEFINE_MSGF("setinfo_key", 0, -1, NULL, NULL);
768 EXPORT_SYMBOL(RMF_SETINFO_KEY);
770 const struct req_msg_field RMF_NAME =
771 DEFINE_MSGF("name", RMF_F_STRING, -1, NULL, NULL);
772 EXPORT_SYMBOL(RMF_NAME);
774 const struct req_msg_field RMF_SYMTGT =
775 DEFINE_MSGF("symtgt", RMF_F_STRING, -1, NULL, NULL);
776 EXPORT_SYMBOL(RMF_SYMTGT);
778 const struct req_msg_field RMF_TGTUUID =
779 DEFINE_MSGF("tgtuuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
781 EXPORT_SYMBOL(RMF_TGTUUID);
783 const struct req_msg_field RMF_CLUUID =
784 DEFINE_MSGF("cluuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
786 EXPORT_SYMBOL(RMF_CLUUID);
788 const struct req_msg_field RMF_STRING =
789 DEFINE_MSGF("string", RMF_F_STRING, -1, NULL, NULL);
790 EXPORT_SYMBOL(RMF_STRING);
792 const struct req_msg_field RMF_LLOGD_BODY =
793 DEFINE_MSGF("llogd_body", 0,
794 sizeof(struct llogd_body), lustre_swab_llogd_body, NULL);
795 EXPORT_SYMBOL(RMF_LLOGD_BODY);
797 const struct req_msg_field RMF_LLOG_LOG_HDR =
798 DEFINE_MSGF("llog_log_hdr", 0,
799 sizeof(struct llog_log_hdr), lustre_swab_llog_hdr, NULL);
800 EXPORT_SYMBOL(RMF_LLOG_LOG_HDR);
802 const struct req_msg_field RMF_LLOGD_CONN_BODY =
803 DEFINE_MSGF("llogd_conn_body", 0,
804 sizeof(struct llogd_conn_body),
805 lustre_swab_llogd_conn_body, NULL);
806 EXPORT_SYMBOL(RMF_LLOGD_CONN_BODY);
809 * connection handle received in MDS_CONNECT request.
811 * No swabbing needed because struct lustre_handle contains only a 64-bit cookie
812 * that the client does not interpret at all.
814 const struct req_msg_field RMF_CONN =
815 DEFINE_MSGF("conn", 0, sizeof(struct lustre_handle), NULL, NULL);
816 EXPORT_SYMBOL(RMF_CONN);
818 const struct req_msg_field RMF_CONNECT_DATA =
820 RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */,
821 sizeof(struct obd_connect_data), lustre_swab_connect, NULL);
822 EXPORT_SYMBOL(RMF_CONNECT_DATA);
824 const struct req_msg_field RMF_DLM_REQ =
825 DEFINE_MSGF("dlm_req", RMF_F_NO_SIZE_CHECK /* ldlm_request_bufsize */,
826 sizeof(struct ldlm_request),
827 lustre_swab_ldlm_request, NULL);
828 EXPORT_SYMBOL(RMF_DLM_REQ);
830 const struct req_msg_field RMF_DLM_REP =
831 DEFINE_MSGF("dlm_rep", 0,
832 sizeof(struct ldlm_reply), lustre_swab_ldlm_reply, NULL);
833 EXPORT_SYMBOL(RMF_DLM_REP);
835 const struct req_msg_field RMF_LDLM_INTENT =
836 DEFINE_MSGF("ldlm_intent", 0,
837 sizeof(struct ldlm_intent), lustre_swab_ldlm_intent, NULL);
838 EXPORT_SYMBOL(RMF_LDLM_INTENT);
840 const struct req_msg_field RMF_DLM_LVB =
841 DEFINE_MSGF("dlm_lvb", 0, sizeof(struct ost_lvb), lustre_swab_ost_lvb,
843 EXPORT_SYMBOL(RMF_DLM_LVB);
845 const struct req_msg_field RMF_MDT_MD =
846 DEFINE_MSGF("mdt_md", RMF_F_NO_SIZE_CHECK, MIN_MD_SIZE, NULL, NULL);
847 EXPORT_SYMBOL(RMF_MDT_MD);
849 const struct req_msg_field RMF_REC_REINT =
850 DEFINE_MSGF("rec_reint", 0, sizeof(struct mdt_rec_reint),
851 lustre_swab_mdt_rec_reint, NULL);
852 EXPORT_SYMBOL(RMF_REC_REINT);
854 /* FIXME: this length should be defined as a macro */
855 const struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1,
857 EXPORT_SYMBOL(RMF_EADATA);
859 const struct req_msg_field RMF_ACL =
860 DEFINE_MSGF("acl", RMF_F_NO_SIZE_CHECK,
861 LUSTRE_POSIX_ACL_MAX_SIZE, NULL, NULL);
862 EXPORT_SYMBOL(RMF_ACL);
864 /* FIXME: this should be made to use RMF_F_STRUCT_ARRAY */
865 const struct req_msg_field RMF_LOGCOOKIES =
866 DEFINE_MSGF("logcookies", RMF_F_NO_SIZE_CHECK /* multiple cookies */,
867 sizeof(struct llog_cookie), NULL, NULL);
868 EXPORT_SYMBOL(RMF_LOGCOOKIES);
870 const struct req_msg_field RMF_CAPA1 =
871 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
872 lustre_swab_lustre_capa, NULL);
873 EXPORT_SYMBOL(RMF_CAPA1);
875 const struct req_msg_field RMF_CAPA2 =
876 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
877 lustre_swab_lustre_capa, NULL);
878 EXPORT_SYMBOL(RMF_CAPA2);
883 const struct req_msg_field RMF_OST_BODY =
884 DEFINE_MSGF("ost_body", 0,
885 sizeof(struct ost_body), lustre_swab_ost_body, dump_ost_body);
886 EXPORT_SYMBOL(RMF_OST_BODY);
888 const struct req_msg_field RMF_OBD_IOOBJ =
889 DEFINE_MSGF("obd_ioobj", RMF_F_STRUCT_ARRAY,
890 sizeof(struct obd_ioobj), lustre_swab_obd_ioobj, dump_ioo);
891 EXPORT_SYMBOL(RMF_OBD_IOOBJ);
893 const struct req_msg_field RMF_NIOBUF_REMOTE =
894 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY,
895 sizeof(struct niobuf_remote), lustre_swab_niobuf_remote,
897 EXPORT_SYMBOL(RMF_NIOBUF_REMOTE);
899 const struct req_msg_field RMF_RCS =
900 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY, sizeof(__u32),
901 lustre_swab_generic_32s, dump_rcs);
902 EXPORT_SYMBOL(RMF_RCS);
904 const struct req_msg_field RMF_OBD_ID =
905 DEFINE_MSGF("obd_id", 0,
906 sizeof(obd_id), lustre_swab_ost_last_id, NULL);
907 EXPORT_SYMBOL(RMF_OBD_ID);
909 const struct req_msg_field RMF_FIEMAP_KEY =
910 DEFINE_MSGF("fiemap", 0, sizeof(struct ll_fiemap_info_key),
911 lustre_swab_fiemap, NULL);
912 EXPORT_SYMBOL(RMF_FIEMAP_KEY);
914 const struct req_msg_field RMF_FIEMAP_VAL =
915 DEFINE_MSGF("fiemap", 0, -1, lustre_swab_fiemap, NULL);
916 EXPORT_SYMBOL(RMF_FIEMAP_VAL);
927 const struct req_msg_field **d;
931 #define DEFINE_REQ_FMT(name, client, client_nr, server, server_nr) { \
945 #define DEFINE_REQ_FMT0(name, client, server) \
946 DEFINE_REQ_FMT(name, client, ARRAY_SIZE(client), server, ARRAY_SIZE(server))
948 const struct req_format RQF_OBD_PING =
949 DEFINE_REQ_FMT0("OBD_PING", empty, empty);
950 EXPORT_SYMBOL(RQF_OBD_PING);
952 const struct req_format RQF_OBD_SET_INFO =
953 DEFINE_REQ_FMT0("OBD_SET_INFO", obd_set_info_client, empty);
954 EXPORT_SYMBOL(RQF_OBD_SET_INFO);
956 const struct req_format RQF_SEC_CTX =
957 DEFINE_REQ_FMT0("SEC_CTX", empty, empty);
958 EXPORT_SYMBOL(RQF_SEC_CTX);
960 const struct req_format RQF_MGS_TARGET_REG =
961 DEFINE_REQ_FMT0("MGS_TARGET_REG", mgs_target_info_only,
962 mgs_target_info_only);
963 EXPORT_SYMBOL(RQF_MGS_TARGET_REG);
965 const struct req_format RQF_MGS_SET_INFO =
966 DEFINE_REQ_FMT0("MGS_SET_INFO", mgs_set_info,
968 EXPORT_SYMBOL(RQF_MGS_SET_INFO);
970 const struct req_format RQF_SEQ_QUERY =
971 DEFINE_REQ_FMT0("SEQ_QUERY", seq_query_client, seq_query_server);
972 EXPORT_SYMBOL(RQF_SEQ_QUERY);
974 const struct req_format RQF_FLD_QUERY =
975 DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
976 EXPORT_SYMBOL(RQF_FLD_QUERY);
978 const struct req_format RQF_LOG_CANCEL =
979 DEFINE_REQ_FMT0("OBD_LOG_CANCEL", log_cancel_client, empty);
980 EXPORT_SYMBOL(RQF_LOG_CANCEL);
982 const struct req_format RQF_MDS_QUOTACHECK =
983 DEFINE_REQ_FMT0("MDS_QUOTACHECK", quotactl_only, empty);
984 EXPORT_SYMBOL(RQF_MDS_QUOTACHECK);
986 const struct req_format RQF_OST_QUOTACHECK =
987 DEFINE_REQ_FMT0("OST_QUOTACHECK", quotactl_only, empty);
988 EXPORT_SYMBOL(RQF_OST_QUOTACHECK);
990 const struct req_format RQF_MDS_QUOTACTL =
991 DEFINE_REQ_FMT0("MDS_QUOTACTL", quotactl_only, quotactl_only);
992 EXPORT_SYMBOL(RQF_MDS_QUOTACTL);
994 const struct req_format RQF_OST_QUOTACTL =
995 DEFINE_REQ_FMT0("OST_QUOTACTL", quotactl_only, quotactl_only);
996 EXPORT_SYMBOL(RQF_OST_QUOTACTL);
998 const struct req_format RQF_OST_QUOTA_ADJUST_QUNIT =
999 DEFINE_REQ_FMT0("OST_QUOTA_ADJUST_QUNIT", quota_adjust_qunit_only,
1000 quota_adjust_qunit_only);
1001 EXPORT_SYMBOL(RQF_OST_QUOTA_ADJUST_QUNIT);
1003 const struct req_format RQF_QC_CALLBACK =
1004 DEFINE_REQ_FMT0("QC_CALLBACK", quotactl_only, empty);
1005 EXPORT_SYMBOL(RQF_QC_CALLBACK);
1007 const struct req_format RQF_MDS_QUOTA_DQACQ =
1008 DEFINE_REQ_FMT0("MDS_QUOTA_DQACQ", qunit_data_only, qunit_data_only);
1009 EXPORT_SYMBOL(RQF_MDS_QUOTA_DQACQ);
1011 const struct req_format RQF_MDS_GETSTATUS =
1012 DEFINE_REQ_FMT0("MDS_GETSTATUS", mdt_body_only, mdt_body_capa);
1013 EXPORT_SYMBOL(RQF_MDS_GETSTATUS);
1015 const struct req_format RQF_MDS_STATFS =
1016 DEFINE_REQ_FMT0("MDS_STATFS", empty, obd_statfs_server);
1017 EXPORT_SYMBOL(RQF_MDS_STATFS);
1019 const struct req_format RQF_MDS_SYNC =
1020 DEFINE_REQ_FMT0("MDS_SYNC", mdt_body_capa, mdt_body_only);
1021 EXPORT_SYMBOL(RQF_MDS_SYNC);
1023 const struct req_format RQF_MDS_GETATTR =
1024 DEFINE_REQ_FMT0("MDS_GETATTR", mdt_body_capa, mds_getattr_server);
1025 EXPORT_SYMBOL(RQF_MDS_GETATTR);
1027 const struct req_format RQF_MDS_GETXATTR =
1028 DEFINE_REQ_FMT0("MDS_GETXATTR",
1029 mds_getxattr_client, mds_getxattr_server);
1030 EXPORT_SYMBOL(RQF_MDS_GETXATTR);
1032 const struct req_format RQF_MDS_GETATTR_NAME =
1033 DEFINE_REQ_FMT0("MDS_GETATTR_NAME",
1034 mds_getattr_name_client, mds_getattr_server);
1035 EXPORT_SYMBOL(RQF_MDS_GETATTR_NAME);
1037 const struct req_format RQF_MDS_REINT =
1038 DEFINE_REQ_FMT0("MDS_REINT", mds_reint_client, mdt_body_only);
1039 EXPORT_SYMBOL(RQF_MDS_REINT);
1041 const struct req_format RQF_MDS_REINT_CREATE =
1042 DEFINE_REQ_FMT0("MDS_REINT_CREATE",
1043 mds_reint_create_client, mdt_body_capa);
1044 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE);
1046 const struct req_format RQF_MDS_REINT_CREATE_RMT_ACL =
1047 DEFINE_REQ_FMT0("MDS_REINT_CREATE_RMT_ACL",
1048 mds_reint_create_rmt_acl_client, mdt_body_capa);
1049 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_RMT_ACL);
1051 const struct req_format RQF_MDS_REINT_CREATE_SLAVE =
1052 DEFINE_REQ_FMT0("MDS_REINT_CREATE_EA",
1053 mds_reint_create_slave_client, mdt_body_capa);
1054 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SLAVE);
1056 const struct req_format RQF_MDS_REINT_CREATE_SYM =
1057 DEFINE_REQ_FMT0("MDS_REINT_CREATE_SYM",
1058 mds_reint_create_sym_client, mdt_body_capa);
1059 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SYM);
1061 const struct req_format RQF_MDS_REINT_OPEN =
1062 DEFINE_REQ_FMT0("MDS_REINT_OPEN",
1063 mds_reint_open_client, mds_reint_open_server);
1064 EXPORT_SYMBOL(RQF_MDS_REINT_OPEN);
1066 const struct req_format RQF_MDS_REINT_UNLINK =
1067 DEFINE_REQ_FMT0("MDS_REINT_UNLINK", mds_reint_unlink_client,
1068 mds_last_unlink_server);
1069 EXPORT_SYMBOL(RQF_MDS_REINT_UNLINK);
1071 const struct req_format RQF_MDS_REINT_LINK =
1072 DEFINE_REQ_FMT0("MDS_REINT_LINK",
1073 mds_reint_link_client, mdt_body_only);
1074 EXPORT_SYMBOL(RQF_MDS_REINT_LINK);
1076 const struct req_format RQF_MDS_REINT_RENAME =
1077 DEFINE_REQ_FMT0("MDS_REINT_RENAME", mds_reint_rename_client,
1078 mds_last_unlink_server);
1079 EXPORT_SYMBOL(RQF_MDS_REINT_RENAME);
1081 const struct req_format RQF_MDS_REINT_SETATTR =
1082 DEFINE_REQ_FMT0("MDS_REINT_SETATTR",
1083 mds_reint_setattr_client, mds_setattr_server);
1084 EXPORT_SYMBOL(RQF_MDS_REINT_SETATTR);
1086 const struct req_format RQF_MDS_REINT_SETXATTR =
1087 DEFINE_REQ_FMT0("MDS_REINT_SETXATTR",
1088 mds_reint_setxattr_client, mdt_body_only);
1089 EXPORT_SYMBOL(RQF_MDS_REINT_SETXATTR);
1091 const struct req_format RQF_MDS_CONNECT =
1092 DEFINE_REQ_FMT0("MDS_CONNECT",
1093 obd_connect_client, obd_connect_server);
1094 EXPORT_SYMBOL(RQF_MDS_CONNECT);
1096 const struct req_format RQF_MDS_DISCONNECT =
1097 DEFINE_REQ_FMT0("MDS_DISCONNECT", empty, empty);
1098 EXPORT_SYMBOL(RQF_MDS_DISCONNECT);
1100 const struct req_format RQF_MDS_GET_INFO =
1101 DEFINE_REQ_FMT0("MDS_GET_INFO", mds_getinfo_client,
1102 mds_getinfo_server);
1103 EXPORT_SYMBOL(RQF_MDS_GET_INFO);
1105 const struct req_format RQF_LDLM_ENQUEUE =
1106 DEFINE_REQ_FMT0("LDLM_ENQUEUE",
1107 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1108 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE);
1110 const struct req_format RQF_LDLM_ENQUEUE_LVB =
1111 DEFINE_REQ_FMT0("LDLM_ENQUEUE_LVB",
1112 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1113 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE_LVB);
1115 const struct req_format RQF_LDLM_CONVERT =
1116 DEFINE_REQ_FMT0("LDLM_CONVERT",
1117 ldlm_enqueue_client, ldlm_enqueue_server);
1118 EXPORT_SYMBOL(RQF_LDLM_CONVERT);
1120 const struct req_format RQF_LDLM_CANCEL =
1121 DEFINE_REQ_FMT0("LDLM_CANCEL", ldlm_enqueue_client, empty);
1122 EXPORT_SYMBOL(RQF_LDLM_CANCEL);
1124 const struct req_format RQF_LDLM_CALLBACK =
1125 DEFINE_REQ_FMT0("LDLM_CALLBACK", ldlm_enqueue_client, empty);
1126 EXPORT_SYMBOL(RQF_LDLM_CALLBACK);
1128 const struct req_format RQF_LDLM_CP_CALLBACK =
1129 DEFINE_REQ_FMT0("LDLM_CP_CALLBACK", ldlm_cp_callback_client, empty);
1130 EXPORT_SYMBOL(RQF_LDLM_CP_CALLBACK);
1132 const struct req_format RQF_LDLM_BL_CALLBACK =
1133 DEFINE_REQ_FMT0("LDLM_BL_CALLBACK", ldlm_enqueue_client, empty);
1134 EXPORT_SYMBOL(RQF_LDLM_BL_CALLBACK);
1136 const struct req_format RQF_LDLM_GL_CALLBACK =
1137 DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_enqueue_client,
1138 ldlm_gl_callback_server);
1139 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK);
1141 const struct req_format RQF_LDLM_INTENT =
1142 DEFINE_REQ_FMT0("LDLM_INTENT",
1143 ldlm_intent_client, ldlm_intent_server);
1144 EXPORT_SYMBOL(RQF_LDLM_INTENT);
1146 const struct req_format RQF_LDLM_INTENT_GETATTR =
1147 DEFINE_REQ_FMT0("LDLM_INTENT_GETATTR",
1148 ldlm_intent_getattr_client, ldlm_intent_getattr_server);
1149 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETATTR);
1151 const struct req_format RQF_LDLM_INTENT_OPEN =
1152 DEFINE_REQ_FMT0("LDLM_INTENT_OPEN",
1153 ldlm_intent_open_client, ldlm_intent_open_server);
1154 EXPORT_SYMBOL(RQF_LDLM_INTENT_OPEN);
1156 const struct req_format RQF_LDLM_INTENT_CREATE =
1157 DEFINE_REQ_FMT0("LDLM_INTENT_CREATE",
1158 ldlm_intent_create_client, ldlm_intent_getattr_server);
1159 EXPORT_SYMBOL(RQF_LDLM_INTENT_CREATE);
1161 const struct req_format RQF_LDLM_INTENT_UNLINK =
1162 DEFINE_REQ_FMT0("LDLM_INTENT_UNLINK",
1163 ldlm_intent_unlink_client, ldlm_intent_server);
1164 EXPORT_SYMBOL(RQF_LDLM_INTENT_UNLINK);
1166 const struct req_format RQF_MDS_CLOSE =
1167 DEFINE_REQ_FMT0("MDS_CLOSE",
1168 mdt_close_client, mds_last_unlink_server);
1169 EXPORT_SYMBOL(RQF_MDS_CLOSE);
1171 const struct req_format RQF_MDS_PIN =
1172 DEFINE_REQ_FMT0("MDS_PIN",
1173 mdt_body_capa, mdt_body_only);
1174 EXPORT_SYMBOL(RQF_MDS_PIN);
1176 const struct req_format RQF_MDS_UNPIN =
1177 DEFINE_REQ_FMT0("MDS_UNPIN", mdt_body_only, empty);
1178 EXPORT_SYMBOL(RQF_MDS_UNPIN);
1180 const struct req_format RQF_MDS_DONE_WRITING =
1181 DEFINE_REQ_FMT0("MDS_DONE_WRITING",
1182 mdt_close_client, mdt_body_only);
1183 EXPORT_SYMBOL(RQF_MDS_DONE_WRITING);
1185 const struct req_format RQF_MDS_READPAGE =
1186 DEFINE_REQ_FMT0("MDS_READPAGE",
1187 mdt_body_capa, mdt_body_only);
1188 EXPORT_SYMBOL(RQF_MDS_READPAGE);
1190 /* This is for split */
1191 const struct req_format RQF_MDS_WRITEPAGE =
1192 DEFINE_REQ_FMT0("MDS_WRITEPAGE",
1193 mdt_body_capa, mdt_body_only);
1194 EXPORT_SYMBOL(RQF_MDS_WRITEPAGE);
1196 const struct req_format RQF_MDS_IS_SUBDIR =
1197 DEFINE_REQ_FMT0("MDS_IS_SUBDIR",
1198 mdt_body_only, mdt_body_only);
1199 EXPORT_SYMBOL(RQF_MDS_IS_SUBDIR);
1201 const struct req_format RQF_LLOG_CATINFO =
1202 DEFINE_REQ_FMT0("LLOG_CATINFO",
1203 llog_catinfo_client, llog_catinfo_server);
1204 EXPORT_SYMBOL(RQF_LLOG_CATINFO);
1206 const struct req_format RQF_LLOG_ORIGIN_HANDLE_CREATE =
1207 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_CREATE",
1208 llog_origin_handle_create_client, llogd_body_only);
1209 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_CREATE);
1211 const struct req_format RQF_LLOG_ORIGIN_HANDLE_DESTROY =
1212 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_DESTROY",
1213 llogd_body_only, llogd_body_only);
1214 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1216 const struct req_format RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK =
1217 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_NEXT_BLOCK",
1218 llogd_body_only, llog_origin_handle_next_block_server);
1219 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1221 const struct req_format RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK =
1222 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_PREV_BLOCK",
1223 llogd_body_only, llog_origin_handle_next_block_server);
1224 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1226 const struct req_format RQF_LLOG_ORIGIN_HANDLE_READ_HEADER =
1227 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_READ_HEADER",
1228 llogd_body_only, llog_log_hdr_only);
1229 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1231 const struct req_format RQF_LLOG_ORIGIN_CONNECT =
1232 DEFINE_REQ_FMT0("LLOG_ORIGIN_CONNECT", llogd_conn_body_only, empty);
1233 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_CONNECT);
1235 const struct req_format RQF_OST_CONNECT =
1236 DEFINE_REQ_FMT0("OST_CONNECT",
1237 obd_connect_client, obd_connect_server);
1238 EXPORT_SYMBOL(RQF_OST_CONNECT);
1240 const struct req_format RQF_OST_DISCONNECT =
1241 DEFINE_REQ_FMT0("OST_DISCONNECT", empty, empty);
1242 EXPORT_SYMBOL(RQF_OST_DISCONNECT);
1244 const struct req_format RQF_OST_GETATTR =
1245 DEFINE_REQ_FMT0("OST_GETATTR", ost_body_capa, ost_body_only);
1246 EXPORT_SYMBOL(RQF_OST_GETATTR);
1248 const struct req_format RQF_OST_SETATTR =
1249 DEFINE_REQ_FMT0("OST_SETATTR", ost_body_capa, ost_body_only);
1250 EXPORT_SYMBOL(RQF_OST_SETATTR);
1252 const struct req_format RQF_OST_CREATE =
1253 DEFINE_REQ_FMT0("OST_CREATE", ost_body_only, ost_body_only);
1254 EXPORT_SYMBOL(RQF_OST_CREATE);
1256 const struct req_format RQF_OST_PUNCH =
1257 DEFINE_REQ_FMT0("OST_PUNCH", ost_body_capa, ost_body_only);
1258 EXPORT_SYMBOL(RQF_OST_PUNCH);
1260 const struct req_format RQF_OST_SYNC =
1261 DEFINE_REQ_FMT0("OST_SYNC", ost_body_capa, ost_body_only);
1262 EXPORT_SYMBOL(RQF_OST_SYNC);
1264 const struct req_format RQF_OST_DESTROY =
1265 DEFINE_REQ_FMT0("OST_DESTROY", ost_destroy_client, ost_body_only);
1266 EXPORT_SYMBOL(RQF_OST_DESTROY);
1268 const struct req_format RQF_OST_BRW_READ =
1269 DEFINE_REQ_FMT0("OST_BRW_READ", ost_brw_client, ost_brw_read_server);
1270 EXPORT_SYMBOL(RQF_OST_BRW_READ);
1272 const struct req_format RQF_OST_BRW_WRITE =
1273 DEFINE_REQ_FMT0("OST_BRW_WRITE", ost_brw_client, ost_brw_write_server);
1274 EXPORT_SYMBOL(RQF_OST_BRW_WRITE);
1276 const struct req_format RQF_OST_STATFS =
1277 DEFINE_REQ_FMT0("OST_STATFS", empty, obd_statfs_server);
1278 EXPORT_SYMBOL(RQF_OST_STATFS);
1280 const struct req_format RQF_OST_SET_GRANT_INFO =
1281 DEFINE_REQ_FMT0("OST_SET_GRANT_INFO", ost_grant_shrink_client,
1283 EXPORT_SYMBOL(RQF_OST_SET_GRANT_INFO);
1285 const struct req_format RQF_OST_GET_INFO_GENERIC =
1286 DEFINE_REQ_FMT0("OST_GET_INFO", ost_get_info_generic_client,
1287 ost_get_info_generic_server);
1288 EXPORT_SYMBOL(RQF_OST_GET_INFO_GENERIC);
1290 const struct req_format RQF_OST_GET_INFO_LAST_ID =
1291 DEFINE_REQ_FMT0("OST_GET_INFO_LAST_ID", ost_get_info_generic_client,
1292 ost_get_last_id_server);
1293 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_ID);
1295 const struct req_format RQF_OST_GET_INFO_FIEMAP =
1296 DEFINE_REQ_FMT0("OST_GET_INFO_FIEMAP", ost_get_fiemap_client,
1297 ost_get_fiemap_server);
1298 EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP);
1301 #if !defined(__REQ_LAYOUT_USER__)
1303 /* Convenience macro */
1304 #define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1307 * Initializes the capsule abstraction by computing and setting the \a rf_idx
1308 * field of RQFs and the \a rmf_offset field of RMFs.
1310 int req_layout_init(void)
1315 struct req_format *rf = NULL;
1317 for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
1318 rf = (struct req_format *)req_formats[i];
1320 for (j = 0; j < RCL_NR; ++j) {
1321 LASSERT(rf->rf_fields[j].nr <= REQ_MAX_FIELD_NR);
1322 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
1323 struct req_msg_field *field;
1325 field = (typeof(field))rf->rf_fields[j].d[k];
1326 LASSERT(!(field->rmf_flags & RMF_F_STRUCT_ARRAY)
1327 || field->rmf_size > 0);
1328 LASSERT(field->rmf_offset[i][j] == 0);
1330 * k + 1 to detect unused format/field
1333 field->rmf_offset[i][j] = k + 1;
1339 EXPORT_SYMBOL(req_layout_init);
1341 void req_layout_fini(void)
1344 EXPORT_SYMBOL(req_layout_fini);
1347 * Initializes the expected sizes of each RMF in a \a pill (\a rc_area) to -1.
1349 * Actual/expected field sizes are set elsewhere in functions in this file:
1350 * req_capsule_init(), req_capsule_server_pack(), req_capsule_set_size() and
1351 * req_capsule_msg_size(). The \a rc_area information is used by.
1352 * ptlrpc_request_set_replen().
1354 void req_capsule_init_area(struct req_capsule *pill)
1358 for (i = 0; i < ARRAY_SIZE(pill->rc_area[RCL_CLIENT]); i++) {
1359 pill->rc_area[RCL_CLIENT][i] = -1;
1360 pill->rc_area[RCL_SERVER][i] = -1;
1363 EXPORT_SYMBOL(req_capsule_init_area);
1366 * Initialize a pill.
1368 * The \a location indicates whether the caller is executing on the client side
1369 * (RCL_CLIENT) or server side (RCL_SERVER)..
1371 void req_capsule_init(struct req_capsule *pill,
1372 struct ptlrpc_request *req,
1373 enum req_location location)
1375 LASSERT(location == RCL_SERVER || location == RCL_CLIENT);
1378 * Today all capsules are embedded in ptlrpc_request structs,
1379 * but just in case that ever isn't the case, we don't reach
1380 * into req unless req != NULL and pill is the one embedded in
1383 * The req->rq_pill_init flag makes it safe to initialize a pill
1384 * twice, which might happen in the OST paths as a result of the
1385 * high-priority RPC queue getting peeked at before ost_handle()
1386 * handles an OST RPC.
1388 if (req != NULL && pill == &req->rq_pill && req->rq_pill_init)
1391 memset(pill, 0, sizeof *pill);
1393 pill->rc_loc = location;
1394 req_capsule_init_area(pill);
1396 if (req != NULL && pill == &req->rq_pill)
1397 req->rq_pill_init = 1;
1399 EXPORT_SYMBOL(req_capsule_init);
1401 void req_capsule_fini(struct req_capsule *pill)
1404 EXPORT_SYMBOL(req_capsule_fini);
1406 static int __req_format_is_sane(const struct req_format *fmt)
1409 0 <= fmt->rf_idx && fmt->rf_idx < ARRAY_SIZE(req_formats) &&
1410 req_formats[fmt->rf_idx] == fmt;
1413 static struct lustre_msg *__req_msg(const struct req_capsule *pill,
1414 enum req_location loc)
1416 struct ptlrpc_request *req;
1419 return loc == RCL_CLIENT ? req->rq_reqmsg : req->rq_repmsg;
1423 * Set the format (\a fmt) of a \a pill; format changes are not allowed here
1424 * (see req_capsule_extend()).
1426 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt)
1428 LASSERT(pill->rc_fmt == NULL || pill->rc_fmt == fmt);
1429 LASSERT(__req_format_is_sane(fmt));
1433 EXPORT_SYMBOL(req_capsule_set);
1436 * Fills in any parts of the \a rc_area of a \a pill that haven't been filled in
1439 * \a rc_area is an array of REQ_MAX_FIELD_NR elements, used to store sizes of
1440 * variable-sized fields. The field sizes come from the declared \a rmf_size
1441 * field of a \a pill's \a rc_fmt's RMF's.
1443 int req_capsule_filled_sizes(struct req_capsule *pill,
1444 enum req_location loc)
1446 const struct req_format *fmt = pill->rc_fmt;
1449 LASSERT(fmt != NULL);
1451 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1452 if (pill->rc_area[loc][i] == -1) {
1453 pill->rc_area[loc][i] =
1454 fmt->rf_fields[loc].d[i]->rmf_size;
1455 if (pill->rc_area[loc][i] == -1) {
1457 * Skip the following fields.
1459 * If this LASSERT() trips then you're missing a
1460 * call to req_capsule_set_size().
1462 LASSERT(loc != RCL_SERVER);
1469 EXPORT_SYMBOL(req_capsule_filled_sizes);
1472 * Capsule equivalent of lustre_pack_request() and lustre_pack_reply().
1474 * This function uses the \a pill's \a rc_area as filled in by
1475 * req_capsule_set_size() or req_capsule_filled_sizes() (the latter is called by
1478 int req_capsule_server_pack(struct req_capsule *pill)
1480 const struct req_format *fmt;
1484 LASSERT(pill->rc_loc == RCL_SERVER);
1486 LASSERT(fmt != NULL);
1488 count = req_capsule_filled_sizes(pill, RCL_SERVER);
1489 rc = lustre_pack_reply(pill->rc_req, count,
1490 pill->rc_area[RCL_SERVER], NULL);
1492 DEBUG_REQ(D_ERROR, pill->rc_req,
1493 "Cannot pack %d fields in format `%s': ",
1494 count, fmt->rf_name);
1498 EXPORT_SYMBOL(req_capsule_server_pack);
1501 * Returns the PTLRPC request or reply (\a loc) buffer offset of a \a pill
1502 * corresponding to the given RMF (\a field).
1504 static int __req_capsule_offset(const struct req_capsule *pill,
1505 const struct req_msg_field *field,
1506 enum req_location loc)
1510 offset = field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1511 LASSERTF(offset > 0, "%s:%s, off=%d, loc=%d\n",
1512 pill->rc_fmt->rf_name,
1513 field->rmf_name, offset, loc);
1516 LASSERT(0 <= offset && offset < REQ_MAX_FIELD_NR);
1521 * Helper for __req_capsule_get(); swabs value / array of values and/or dumps
1526 swabber_dumper_helper(struct req_capsule *pill,
1527 const struct req_msg_field *field,
1528 enum req_location loc,
1530 void *value, int len, int dump, void (*swabber)( void *))
1536 int inout = loc == RCL_CLIENT;
1538 swabber = swabber ?: field->rmf_swabber;
1540 if (ptlrpc_buf_need_swab(pill->rc_req, inout, offset) &&
1541 swabber != NULL && value != NULL)
1546 if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY)) {
1547 if (dump && field->rmf_dumper) {
1548 CDEBUG(D_RPCTRACE, "Dump of %sfield %s follows\n",
1549 do_swab ? "unswabbed " : "", field->rmf_name);
1550 field->rmf_dumper(value);
1555 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1557 CDEBUG(D_RPCTRACE, "Dump of swabbed field %s "
1558 "follows\n", field->rmf_name);
1559 field->rmf_dumper(value);
1566 * We're swabbing an array; swabber() swabs a single array element, so
1567 * swab every element.
1569 LASSERT((len % field->rmf_size) == 0);
1570 for (p = value, i = 0, n = len / field->rmf_size;
1572 i++, p += field->rmf_size) {
1573 if (dump && field->rmf_dumper) {
1574 CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, "
1575 "element %d follows\n",
1576 do_swab ? "unswabbed " : "", field->rmf_name, i);
1577 field->rmf_dumper(p);
1582 if (dump && field->rmf_dumper) {
1583 CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, "
1584 "element %d follows\n", field->rmf_name, i);
1585 field->rmf_dumper(value);
1589 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1593 * Returns the pointer to a PTLRPC request or reply (\a loc) buffer of a \a pill
1594 * corresponding to the given RMF (\a field).
1596 * The buffer will be swabbed using the given \a swabber. If \a swabber == NULL
1597 * then the \a rmf_swabber from the RMF will be used. Soon there will be no
1598 * calls to __req_capsule_get() with a non-NULL \a swabber; \a swabber will then
1599 * be removed. Fields with the \a RMF_F_STRUCT_ARRAY flag set will have each
1600 * element of the array swabbed.
1602 static void *__req_capsule_get(struct req_capsule *pill,
1603 const struct req_msg_field *field,
1604 enum req_location loc,
1605 void (*swabber)( void *),
1608 const struct req_format *fmt;
1609 struct lustre_msg *msg;
1614 void *(*getter)(struct lustre_msg *m, int n, int minlen);
1616 static const char *rcl_names[RCL_NR] = {
1617 [RCL_CLIENT] = "client",
1618 [RCL_SERVER] = "server"
1621 LASSERT(pill != NULL);
1622 LASSERT(pill != LP_POISON);
1624 LASSERT(fmt != NULL);
1625 LASSERT(fmt != LP_POISON);
1626 LASSERT(__req_format_is_sane(fmt));
1628 offset = __req_capsule_offset(pill, field, loc);
1630 msg = __req_msg(pill, loc);
1631 LASSERT(msg != NULL);
1633 getter = (field->rmf_flags & RMF_F_STRING) ?
1634 (typeof(getter))lustre_msg_string : lustre_msg_buf;
1636 if (field->rmf_flags & RMF_F_STRUCT_ARRAY) {
1638 * We've already asserted that field->rmf_size > 0 in
1639 * req_layout_init().
1641 len = lustre_msg_buflen(msg, offset);
1642 if ((len % field->rmf_size) != 0) {
1643 CERROR("%s: array field size mismatch "
1644 "%d modulo %d != 0 (%d)\n",
1645 field->rmf_name, len, field->rmf_size, loc);
1648 } else if (pill->rc_area[loc][offset] != -1) {
1649 len = pill->rc_area[loc][offset];
1651 len = max(field->rmf_size, 0);
1653 value = getter(msg, offset, len);
1655 if (value == NULL) {
1656 DEBUG_REQ(D_ERROR, pill->rc_req,
1657 "Wrong buffer for field `%s' (%d of %d) "
1658 "in format `%s': %d vs. %d (%s)\n",
1659 field->rmf_name, offset, lustre_msg_bufcount(msg),
1660 fmt->rf_name, lustre_msg_buflen(msg, offset), len,
1663 swabber_dumper_helper(pill, field, loc, offset, value, len,
1671 * Dump a request and/or reply
1673 void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
1675 const struct req_format *fmt;
1676 const struct req_msg_field *field;
1682 DEBUG_REQ(D_RPCTRACE, pill->rc_req, "BEGIN REQ CAPSULE DUMP\n");
1683 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1684 field = FMT_FIELD(fmt, loc, i);
1685 if (field->rmf_dumper == NULL) {
1687 * FIXME Add a default hex dumper for fields that don't
1688 * have a specific dumper
1690 len = req_capsule_get_size(pill, field, loc);
1691 CDEBUG(D_RPCTRACE, "Field %s has no dumper function;"
1692 "field size is %d\n", field->rmf_name, len);
1694 /* It's the dumping side-effect that we're interested in */
1695 (void) __req_capsule_get(pill, field, loc, NULL, 1);
1698 CDEBUG(D_RPCTRACE, "END REQ CAPSULE DUMP\n");
1704 void req_capsule_client_dump(struct req_capsule *pill)
1706 __req_capsule_dump(pill, RCL_CLIENT);
1708 EXPORT_SYMBOL(req_capsule_client_dump);
1713 void req_capsule_server_dump(struct req_capsule *pill)
1715 __req_capsule_dump(pill, RCL_SERVER);
1717 EXPORT_SYMBOL(req_capsule_server_dump);
1720 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC request
1721 * buffer corresponding to the given RMF (\a field) of a \a pill.
1723 void *req_capsule_client_get(struct req_capsule *pill,
1724 const struct req_msg_field *field)
1726 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1728 EXPORT_SYMBOL(req_capsule_client_get);
1731 * Same as req_capsule_client_get(), but with a \a swabber argument.
1733 * Currently unused; will be removed when req_capsule_server_swab_get() is
1736 void *req_capsule_client_swab_get(struct req_capsule *pill,
1737 const struct req_msg_field *field,
1738 void (*swabber)(void* ))
1740 return __req_capsule_get(pill, field, RCL_CLIENT, swabber, 0);
1742 EXPORT_SYMBOL(req_capsule_client_swab_get);
1745 * Utility that combines req_capsule_set_size() and req_capsule_client_get().
1747 * First the \a pill's request \a field's size is set (\a rc_area) using
1748 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1751 void *req_capsule_client_sized_get(struct req_capsule *pill,
1752 const struct req_msg_field *field,
1755 req_capsule_set_size(pill, field, RCL_CLIENT, len);
1756 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1758 EXPORT_SYMBOL(req_capsule_client_sized_get);
1761 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC reply
1762 * buffer corresponding to the given RMF (\a field) of a \a pill.
1764 void *req_capsule_server_get(struct req_capsule *pill,
1765 const struct req_msg_field *field)
1767 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1769 EXPORT_SYMBOL(req_capsule_server_get);
1772 * Same as req_capsule_server_get(), but with a \a swabber argument.
1774 * Ideally all swabbing should be done pursuant to RMF definitions, with no
1775 * swabbing done outside this capsule abstraction.
1777 void *req_capsule_server_swab_get(struct req_capsule *pill,
1778 const struct req_msg_field *field,
1781 return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
1783 EXPORT_SYMBOL(req_capsule_server_swab_get);
1786 * Utility that combines req_capsule_set_size() and req_capsule_server_get().
1788 * First the \a pill's request \a field's size is set (\a rc_area) using
1789 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1792 void *req_capsule_server_sized_get(struct req_capsule *pill,
1793 const struct req_msg_field *field,
1796 req_capsule_set_size(pill, field, RCL_SERVER, len);
1797 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1799 EXPORT_SYMBOL(req_capsule_server_sized_get);
1802 * Returns the buffer of a \a pill corresponding to the given \a field from the
1803 * request (if the caller is executing on the server-side) or reply (if the
1804 * caller is executing on the client-side).
1806 * This function convienient for use is code that could be executed on the
1807 * client and server alike.
1809 const void *req_capsule_other_get(struct req_capsule *pill,
1810 const struct req_msg_field *field)
1812 return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL, 0);
1814 EXPORT_SYMBOL(req_capsule_other_get);
1817 * Set the size of the PTLRPC request/reply (\a loc) buffer for the given \a
1818 * field of the given \a pill.
1820 * This function must be used when constructing variable sized fields of a
1823 void req_capsule_set_size(struct req_capsule *pill,
1824 const struct req_msg_field *field,
1825 enum req_location loc, int size)
1827 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1829 if ((size != field->rmf_size) &&
1830 (field->rmf_size != -1) &&
1831 !(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
1833 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1834 (size % field->rmf_size != 0)) {
1835 CERROR("%s: array field size mismatch "
1836 "%d %% %d != 0 (%d)\n",
1837 field->rmf_name, size, field->rmf_size, loc);
1839 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1840 size < field->rmf_size) {
1841 CERROR("%s: field size mismatch %d != %d (%d)\n",
1842 field->rmf_name, size, field->rmf_size, loc);
1847 pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size;
1849 EXPORT_SYMBOL(req_capsule_set_size);
1852 * Return the actual PTLRPC buffer length of a request or reply (\a loc)
1853 * for the given \a pill's given \a field.
1855 * NB: this function doesn't correspond with req_capsule_set_size(), which
1856 * actually sets the size in pill.rc_area[loc][offset], but this function
1857 * returns the message buflen[offset], maybe we should use another name.
1859 int req_capsule_get_size(const struct req_capsule *pill,
1860 const struct req_msg_field *field,
1861 enum req_location loc)
1863 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1865 return lustre_msg_buflen(__req_msg(pill, loc),
1866 __req_capsule_offset(pill, field, loc));
1868 EXPORT_SYMBOL(req_capsule_get_size);
1871 * Wrapper around lustre_msg_size() that returns the PTLRPC size needed for the
1872 * given \a pill's request or reply (\a loc) given the field size recorded in
1873 * the \a pill's rc_area.
1875 * See also req_capsule_set_size().
1877 int req_capsule_msg_size(struct req_capsule *pill, enum req_location loc)
1879 return lustre_msg_size(pill->rc_req->rq_import->imp_msg_magic,
1880 pill->rc_fmt->rf_fields[loc].nr,
1881 pill->rc_area[loc]);
1885 * While req_capsule_msg_size() computes the size of a PTLRPC request or reply
1886 * (\a loc) given a \a pill's \a rc_area, this function computes the size of a
1887 * PTLRPC request or reply given only an RQF (\a fmt).
1889 * This function should not be used for formats which contain variable size
1892 int req_capsule_fmt_size(__u32 magic, const struct req_format *fmt,
1893 enum req_location loc)
1898 * This function should probably LASSERT() that fmt has no fields with
1899 * RMF_F_STRUCT_ARRAY in rmf_flags, since we can't know here how many
1900 * elements in the array there will ultimately be, but then, we could
1901 * assume that there will be at least one element, and that's just what
1904 size = lustre_msg_hdr_size(magic, fmt->rf_fields[loc].nr);
1908 for (; i < fmt->rf_fields[loc].nr; ++i)
1909 if (fmt->rf_fields[loc].d[i]->rmf_size != -1)
1910 size += cfs_size_round(fmt->rf_fields[loc].d[i]->
1916 * Changes the format of an RPC.
1918 * The pill must already have been initialized, which means that it already has
1919 * a request format. The new format \a fmt must be an extension of the pill's
1920 * old format. Specifically: the new format must have as many request and reply
1921 * fields as the old one, and all fields shared by the old and new format must
1922 * be at least as large in the new format.
1924 * The new format's fields may be of different "type" than the old format, but
1925 * only for fields that are "opaque" blobs: fields which have a) have no
1926 * \a rmf_swabber, b) \a rmf_flags == 0 or RMF_F_NO_SIZE_CHECK, and c) \a
1927 * rmf_size == -1 or \a rmf_flags == RMF_F_NO_SIZE_CHECK. For example,
1928 * OBD_SET_INFO has a key field and an opaque value field that gets interpreted
1929 * according to the key field. When the value, according to the key, contains a
1930 * structure (or array thereof) to be swabbed, the format should be changed to
1931 * one where the value field has \a rmf_size/rmf_flags/rmf_swabber set
1934 void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
1939 const struct req_format *old;
1941 LASSERT(pill->rc_fmt != NULL);
1942 LASSERT(__req_format_is_sane(fmt));
1946 * Sanity checking...
1948 for (i = 0; i < RCL_NR; ++i) {
1949 LASSERT(fmt->rf_fields[i].nr >= old->rf_fields[i].nr);
1950 for (j = 0; j < old->rf_fields[i].nr - 1; ++j) {
1951 const struct req_msg_field *ofield = FMT_FIELD(old, i, j);
1953 /* "opaque" fields can be transmogrified */
1954 if (ofield->rmf_swabber == NULL &&
1955 (ofield->rmf_flags & ~RMF_F_NO_SIZE_CHECK) == 0 &&
1956 (ofield->rmf_size == -1 ||
1957 ofield->rmf_flags == RMF_F_NO_SIZE_CHECK))
1959 LASSERT(FMT_FIELD(fmt, i, j) == FMT_FIELD(old, i, j));
1962 * Last field in old format can be shorter than in new.
1964 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
1965 FMT_FIELD(old, i, j)->rmf_size);
1970 EXPORT_SYMBOL(req_capsule_extend);
1973 * This function returns a non-zero value if the given \a field is present in
1974 * the format (\a rc_fmt) of \a pill's PTLRPC request or reply (\a loc), else it
1977 int req_capsule_has_field(const struct req_capsule *pill,
1978 const struct req_msg_field *field,
1979 enum req_location loc)
1981 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1983 return field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1985 EXPORT_SYMBOL(req_capsule_has_field);
1988 * Returns a non-zero value if the given \a field is present in the given \a
1989 * pill's PTLRPC request or reply (\a loc), else it returns 0.
1991 int req_capsule_field_present(const struct req_capsule *pill,
1992 const struct req_msg_field *field,
1993 enum req_location loc)
1997 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1998 LASSERT(req_capsule_has_field(pill, field, loc));
2000 offset = __req_capsule_offset(pill, field, loc);
2001 return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
2003 EXPORT_SYMBOL(req_capsule_field_present);
2006 * This function shrinks the size of the _buffer_ of the \a pill's PTLRPC
2007 * request or reply (\a loc).
2009 * This is not the opposite of req_capsule_extend().
2011 void req_capsule_shrink(struct req_capsule *pill,
2012 const struct req_msg_field *field,
2013 unsigned int newlen,
2014 enum req_location loc)
2016 const struct req_format *fmt;
2017 struct lustre_msg *msg;
2022 LASSERT(fmt != NULL);
2023 LASSERT(__req_format_is_sane(fmt));
2024 LASSERT(req_capsule_has_field(pill, field, loc));
2025 LASSERT(req_capsule_field_present(pill, field, loc));
2027 offset = __req_capsule_offset(pill, field, loc);
2029 msg = __req_msg(pill, loc);
2030 len = lustre_msg_buflen(msg, offset);
2031 LASSERTF(newlen <= len, "%s:%s, oldlen=%d, newlen=%d\n",
2032 fmt->rf_name, field->rmf_name, len, newlen);
2034 if (loc == RCL_CLIENT)
2035 pill->rc_req->rq_reqlen = lustre_shrink_msg(msg, offset, newlen,
2038 pill->rc_req->rq_replen = lustre_shrink_msg(msg, offset, newlen,
2041 EXPORT_SYMBOL(req_capsule_shrink);
2043 /* __REQ_LAYOUT_USER__ */