4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ptlrpc/layout.c
34 * Lustre Metadata Target (mdt) request handler
36 * Author: Nikita Danilov <nikita@clusterfs.com>
39 * This file contains the "capsule/pill" abstraction layered above PTLRPC.
41 * Every struct ptlrpc_request contains a "pill", which points to a description
42 * of the format that the request conforms to.
45 #define DEBUG_SUBSYSTEM S_RPC
47 #include <linux/module.h>
49 #include <llog_swab.h>
50 #include <lustre_debug.h>
51 #include <lustre_swab.h>
53 #include <obd_support.h>
55 /* struct ptlrpc_request, lustre_msg* */
56 #include <lustre_req_layout.h>
57 #include <lustre_acl.h>
58 #include <lustre_nodemap.h>
61 * RQFs (see below) refer to two struct req_msg_field arrays describing the
62 * client request and server reply, respectively.
64 /* empty set of fields... for suitable definition of emptiness. */
65 static const struct req_msg_field *empty[] = {
69 static const struct req_msg_field *mgs_target_info_only[] = {
74 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 13, 53, 0)
75 static const struct req_msg_field *mgs_set_info[] = {
81 static const struct req_msg_field *mgs_config_read_client[] = {
86 static const struct req_msg_field *mgs_config_read_server[] = {
91 static const struct req_msg_field *mdt_body_only[] = {
96 static const struct req_msg_field *mdt_body_capa[] = {
102 static const struct req_msg_field *quotactl_only[] = {
107 static const struct req_msg_field *quota_body_only[] = {
112 static const struct req_msg_field *ldlm_intent_quota_client[] = {
119 static const struct req_msg_field *ldlm_intent_quota_server[] = {
126 static const struct req_msg_field *mdt_close_client[] = {
133 static const struct req_msg_field *mdt_close_intent_client[] = {
142 static const struct req_msg_field *obd_statfs_server[] = {
147 static const struct req_msg_field *seq_query_client[] = {
153 static const struct req_msg_field *seq_query_server[] = {
158 static const struct req_msg_field *fld_query_client[] = {
164 static const struct req_msg_field *fld_query_server[] = {
169 static const struct req_msg_field *fld_read_client[] = {
174 static const struct req_msg_field *fld_read_server[] = {
179 static const struct req_msg_field *mds_getattr_name_client[] = {
186 static const struct req_msg_field *mds_reint_client[] = {
191 static const struct req_msg_field *mds_reint_create_client[] = {
198 static const struct req_msg_field *mds_reint_create_slave_client[] = {
207 static const struct req_msg_field *mds_reint_create_acl_client[] = {
214 &RMF_FILE_SECCTX_NAME,
219 static const struct req_msg_field *mds_reint_create_sym_client[] = {
226 &RMF_FILE_SECCTX_NAME,
231 static const struct req_msg_field *mds_reint_open_client[] = {
238 &RMF_FILE_SECCTX_NAME,
243 static const struct req_msg_field *mds_reint_open_server[] = {
252 static const struct req_msg_field *mds_reint_unlink_client[] = {
261 static const struct req_msg_field *mds_reint_link_client[] = {
271 static const struct req_msg_field *mds_reint_rename_client[] = {
282 static const struct req_msg_field *mds_reint_migrate_client[] = {
296 static const struct req_msg_field *mds_last_unlink_server[] = {
305 static const struct req_msg_field *mds_reint_setattr_client[] = {
315 static const struct req_msg_field *mds_reint_setxattr_client[] = {
325 static const struct req_msg_field *mds_reint_resync[] = {
331 static const struct req_msg_field *mdt_swap_layouts[] = {
340 static const struct req_msg_field *obd_connect_client[] = {
349 static const struct req_msg_field *obd_connect_server[] = {
354 static const struct req_msg_field *obd_set_info_client[] = {
360 static const struct req_msg_field *ost_grant_shrink_client[] = {
366 static const struct req_msg_field *mds_getinfo_client[] = {
372 static const struct req_msg_field *mds_getinfo_server[] = {
377 static const struct req_msg_field *ldlm_enqueue_client[] = {
382 static const struct req_msg_field *ldlm_enqueue_server[] = {
387 static const struct req_msg_field *ldlm_enqueue_lvb_server[] = {
393 static const struct req_msg_field *ldlm_cp_callback_client[] = {
399 static const struct req_msg_field *ldlm_gl_callback_desc_client[] = {
405 static const struct req_msg_field *ldlm_gl_callback_server[] = {
410 static const struct req_msg_field *ldlm_intent_basic_client[] = {
416 static const struct req_msg_field *ldlm_intent_client[] = {
423 static const struct req_msg_field *ldlm_intent_server[] = {
431 static const struct req_msg_field *ldlm_intent_layout_client[] = {
436 &RMF_EADATA /* for new layout to be set up */
439 static const struct req_msg_field *ldlm_intent_open_server[] = {
451 static const struct req_msg_field *ldlm_intent_getattr_client[] = {
455 &RMF_MDT_BODY, /* coincides with mds_getattr_name_client[] */
458 &RMF_FILE_SECCTX_NAME
461 static const struct req_msg_field *ldlm_intent_getattr_server[] = {
472 static const struct req_msg_field *ldlm_intent_create_client[] = {
476 &RMF_REC_REINT, /* coincides with mds_reint_create_client[] */
480 &RMF_FILE_SECCTX_NAME,
485 static const struct req_msg_field *ldlm_intent_open_client[] = {
489 &RMF_REC_REINT, /* coincides with mds_reint_open_client[] */
494 &RMF_FILE_SECCTX_NAME,
499 static const struct req_msg_field *ldlm_intent_getxattr_client[] = {
508 static const struct req_msg_field *ldlm_intent_getxattr_server[] = {
513 &RMF_ACL, /* for req_capsule_extend/mdt_intent_policy */
519 static const struct req_msg_field *mds_get_root_client[] = {
525 static const struct req_msg_field *mds_getxattr_client[] = {
534 static const struct req_msg_field *mds_getxattr_server[] = {
540 static const struct req_msg_field *mds_getattr_server[] = {
549 static const struct req_msg_field *mds_setattr_server[] = {
558 static const struct req_msg_field *mds_update_client[] = {
560 &RMF_OUT_UPDATE_HEADER,
564 static const struct req_msg_field *mds_update_server[] = {
566 &RMF_OUT_UPDATE_REPLY,
569 static const struct req_msg_field *llog_origin_handle_create_client[] = {
575 static const struct req_msg_field *llogd_body_only[] = {
580 static const struct req_msg_field *llog_log_hdr_only[] = {
585 static const struct req_msg_field *llog_origin_handle_next_block_server[] = {
591 static const struct req_msg_field *obd_idx_read_client[] = {
596 static const struct req_msg_field *obd_idx_read_server[] = {
601 static const struct req_msg_field *ost_body_only[] = {
606 static const struct req_msg_field *ost_body_capa[] = {
612 static const struct req_msg_field *ost_destroy_client[] = {
620 static const struct req_msg_field *ost_brw_client[] = {
629 static const struct req_msg_field *ost_brw_read_server[] = {
635 static const struct req_msg_field *ost_brw_write_server[] = {
641 static const struct req_msg_field *ost_get_info_generic_server[] = {
646 static const struct req_msg_field *ost_get_info_generic_client[] = {
651 static const struct req_msg_field *ost_get_last_id_server[] = {
656 static const struct req_msg_field *ost_get_last_fid_client[] = {
662 static const struct req_msg_field *ost_get_last_fid_server[] = {
667 static const struct req_msg_field *ost_get_fiemap_client[] = {
673 static const struct req_msg_field *ost_ladvise[] = {
676 &RMF_OST_LADVISE_HDR,
680 static const struct req_msg_field *ost_get_fiemap_server[] = {
685 static const struct req_msg_field *mdt_hsm_progress[] = {
688 &RMF_MDS_HSM_PROGRESS,
691 static const struct req_msg_field *mdt_hsm_ct_register[] = {
694 &RMF_MDS_HSM_ARCHIVE,
697 static const struct req_msg_field *mdt_hsm_ct_unregister[] = {
702 static const struct req_msg_field *mdt_hsm_action_server[] = {
705 &RMF_MDS_HSM_CURRENT_ACTION,
708 static const struct req_msg_field *mdt_hsm_state_get_server[] = {
714 static const struct req_msg_field *mdt_hsm_state_set[] = {
721 static const struct req_msg_field *mdt_hsm_request[] = {
724 &RMF_MDS_HSM_REQUEST,
725 &RMF_MDS_HSM_USER_ITEM,
729 static const struct req_msg_field *obd_lfsck_request[] = {
734 static const struct req_msg_field *obd_lfsck_reply[] = {
739 static struct req_format *req_formats[] = {
745 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 13, 53, 0)
748 &RQF_MGS_CONFIG_READ,
759 &RQF_MDS_GETATTR_NAME,
763 &RQF_MDS_CLOSE_INTENT,
766 &RQF_MDS_REINT_CREATE,
767 &RQF_MDS_REINT_CREATE_ACL,
768 &RQF_MDS_REINT_CREATE_SLAVE,
769 &RQF_MDS_REINT_CREATE_SYM,
771 &RQF_MDS_REINT_UNLINK,
773 &RQF_MDS_REINT_RENAME,
774 &RQF_MDS_REINT_MIGRATE,
775 &RQF_MDS_REINT_SETATTR,
776 &RQF_MDS_REINT_SETXATTR,
777 &RQF_MDS_REINT_RESYNC,
779 &RQF_MDS_HSM_PROGRESS,
780 &RQF_MDS_HSM_CT_REGISTER,
781 &RQF_MDS_HSM_CT_UNREGISTER,
782 &RQF_MDS_HSM_STATE_GET,
783 &RQF_MDS_HSM_STATE_SET,
785 &RQF_MDS_HSM_REQUEST,
786 &RQF_MDS_SWAP_LAYOUTS,
800 &RQF_OST_SET_GRANT_INFO,
802 &RQF_OST_GET_INFO_LAST_ID,
803 &RQF_OST_GET_INFO_LAST_FID,
804 &RQF_OST_SET_INFO_LAST_FID,
805 &RQF_OST_GET_INFO_FIEMAP,
808 &RQF_LDLM_ENQUEUE_LVB,
812 &RQF_LDLM_CP_CALLBACK,
813 &RQF_LDLM_BL_CALLBACK,
814 &RQF_LDLM_GL_CALLBACK,
815 &RQF_LDLM_GL_CALLBACK_DESC,
817 &RQF_LDLM_INTENT_BASIC,
818 &RQF_LDLM_INTENT_LAYOUT,
819 &RQF_LDLM_INTENT_GETATTR,
820 &RQF_LDLM_INTENT_OPEN,
821 &RQF_LDLM_INTENT_CREATE,
822 &RQF_LDLM_INTENT_GETXATTR,
823 &RQF_LDLM_INTENT_QUOTA,
825 &RQF_LLOG_ORIGIN_HANDLE_CREATE,
826 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK,
827 &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK,
828 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER,
834 struct req_msg_field {
835 const __u32 rmf_flags;
836 const char *rmf_name;
838 * Field length. (-1) means "variable length". If the
839 * \a RMF_F_STRUCT_ARRAY flag is set the field is also variable-length,
840 * but the actual size must be a whole multiple of \a rmf_size.
843 void (*rmf_swabber)(void *);
844 void (*rmf_dumper)(void *);
845 int rmf_offset[ARRAY_SIZE(req_formats)][RCL_NR];
850 * The field is a string, must be NUL-terminated.
852 RMF_F_STRING = 1 << 0,
854 * The field's buffer size need not match the declared \a rmf_size.
856 RMF_F_NO_SIZE_CHECK = 1 << 1,
858 * The field's buffer size must be a whole multiple of the declared \a
859 * rmf_size and the \a rmf_swabber function must work on the declared \a
860 * rmf_size worth of bytes.
862 RMF_F_STRUCT_ARRAY = 1 << 2
870 #define DEFINE_MSGF(name, flags, size, swabber, dumper) { \
871 .rmf_name = (name), \
872 .rmf_flags = (flags), \
873 .rmf_size = (size), \
874 .rmf_swabber = (void (*)(void*))(swabber), \
875 .rmf_dumper = (void (*)(void*))(dumper) \
878 struct req_msg_field RMF_GENERIC_DATA =
879 DEFINE_MSGF("generic_data", 0,
881 EXPORT_SYMBOL(RMF_GENERIC_DATA);
883 struct req_msg_field RMF_MGS_TARGET_INFO =
884 DEFINE_MSGF("mgs_target_info", 0,
885 sizeof(struct mgs_target_info),
886 lustre_swab_mgs_target_info, NULL);
887 EXPORT_SYMBOL(RMF_MGS_TARGET_INFO);
889 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 13, 53, 0)
890 struct req_msg_field RMF_MGS_SEND_PARAM =
891 DEFINE_MSGF("mgs_send_param", 0,
892 sizeof(struct mgs_send_param),
894 EXPORT_SYMBOL(RMF_MGS_SEND_PARAM);
897 struct req_msg_field RMF_MGS_CONFIG_BODY =
898 DEFINE_MSGF("mgs_config_read request", 0,
899 sizeof(struct mgs_config_body),
900 lustre_swab_mgs_config_body, NULL);
901 EXPORT_SYMBOL(RMF_MGS_CONFIG_BODY);
903 struct req_msg_field RMF_MGS_CONFIG_RES =
904 DEFINE_MSGF("mgs_config_read reply ", 0,
905 sizeof(struct mgs_config_res),
906 lustre_swab_mgs_config_res, NULL);
907 EXPORT_SYMBOL(RMF_MGS_CONFIG_RES);
909 struct req_msg_field RMF_U32 =
910 DEFINE_MSGF("generic u32", RMF_F_STRUCT_ARRAY,
911 sizeof(__u32), lustre_swab_generic_32s, NULL);
912 EXPORT_SYMBOL(RMF_U32);
914 struct req_msg_field RMF_SETINFO_VAL =
915 DEFINE_MSGF("setinfo_val", 0, -1, NULL, NULL);
916 EXPORT_SYMBOL(RMF_SETINFO_VAL);
918 struct req_msg_field RMF_GETINFO_KEY =
919 DEFINE_MSGF("getinfo_key", 0, -1, NULL, NULL);
920 EXPORT_SYMBOL(RMF_GETINFO_KEY);
922 struct req_msg_field RMF_GETINFO_VALLEN =
923 DEFINE_MSGF("getinfo_vallen", 0,
924 sizeof(__u32), lustre_swab_generic_32s, NULL);
925 EXPORT_SYMBOL(RMF_GETINFO_VALLEN);
927 struct req_msg_field RMF_GETINFO_VAL =
928 DEFINE_MSGF("getinfo_val", 0, -1, NULL, NULL);
929 EXPORT_SYMBOL(RMF_GETINFO_VAL);
931 struct req_msg_field RMF_SEQ_OPC =
932 DEFINE_MSGF("seq_query_opc", 0,
933 sizeof(__u32), lustre_swab_generic_32s, NULL);
934 EXPORT_SYMBOL(RMF_SEQ_OPC);
936 struct req_msg_field RMF_SEQ_RANGE =
937 DEFINE_MSGF("seq_query_range", 0,
938 sizeof(struct lu_seq_range),
939 lustre_swab_lu_seq_range, NULL);
940 EXPORT_SYMBOL(RMF_SEQ_RANGE);
942 struct req_msg_field RMF_FLD_OPC =
943 DEFINE_MSGF("fld_query_opc", 0,
944 sizeof(__u32), lustre_swab_generic_32s, NULL);
945 EXPORT_SYMBOL(RMF_FLD_OPC);
947 struct req_msg_field RMF_FLD_MDFLD =
948 DEFINE_MSGF("fld_query_mdfld", 0,
949 sizeof(struct lu_seq_range),
950 lustre_swab_lu_seq_range, NULL);
951 EXPORT_SYMBOL(RMF_FLD_MDFLD);
953 struct req_msg_field RMF_MDT_BODY =
954 DEFINE_MSGF("mdt_body", 0,
955 sizeof(struct mdt_body), lustre_swab_mdt_body, NULL);
956 EXPORT_SYMBOL(RMF_MDT_BODY);
958 struct req_msg_field RMF_OBD_QUOTACTL =
959 DEFINE_MSGF("obd_quotactl", 0,
960 sizeof(struct obd_quotactl),
961 lustre_swab_obd_quotactl, NULL);
962 EXPORT_SYMBOL(RMF_OBD_QUOTACTL);
964 struct req_msg_field RMF_QUOTA_BODY =
965 DEFINE_MSGF("quota_body", 0,
966 sizeof(struct quota_body), lustre_swab_quota_body, NULL);
967 EXPORT_SYMBOL(RMF_QUOTA_BODY);
969 struct req_msg_field RMF_MDT_EPOCH =
970 DEFINE_MSGF("mdt_ioepoch", 0,
971 sizeof(struct mdt_ioepoch), lustre_swab_mdt_ioepoch, NULL);
972 EXPORT_SYMBOL(RMF_MDT_EPOCH);
974 struct req_msg_field RMF_PTLRPC_BODY =
975 DEFINE_MSGF("ptlrpc_body", 0,
976 sizeof(struct ptlrpc_body), lustre_swab_ptlrpc_body, NULL);
977 EXPORT_SYMBOL(RMF_PTLRPC_BODY);
979 struct req_msg_field RMF_CLOSE_DATA =
980 DEFINE_MSGF("data_version", 0,
981 sizeof(struct close_data), lustre_swab_close_data, NULL);
982 EXPORT_SYMBOL(RMF_CLOSE_DATA);
984 struct req_msg_field RMF_OBD_STATFS =
985 DEFINE_MSGF("obd_statfs", 0,
986 sizeof(struct obd_statfs), lustre_swab_obd_statfs, NULL);
987 EXPORT_SYMBOL(RMF_OBD_STATFS);
989 struct req_msg_field RMF_SETINFO_KEY =
990 DEFINE_MSGF("setinfo_key", 0, -1, NULL, NULL);
991 EXPORT_SYMBOL(RMF_SETINFO_KEY);
993 struct req_msg_field RMF_NAME =
994 DEFINE_MSGF("name", RMF_F_STRING, -1, NULL, NULL);
995 EXPORT_SYMBOL(RMF_NAME);
997 struct req_msg_field RMF_SYMTGT =
998 DEFINE_MSGF("symtgt", RMF_F_STRING, -1, NULL, NULL);
999 EXPORT_SYMBOL(RMF_SYMTGT);
1001 struct req_msg_field RMF_TGTUUID =
1002 DEFINE_MSGF("tgtuuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
1004 EXPORT_SYMBOL(RMF_TGTUUID);
1006 struct req_msg_field RMF_CLUUID =
1007 DEFINE_MSGF("cluuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
1009 EXPORT_SYMBOL(RMF_CLUUID);
1011 struct req_msg_field RMF_STRING =
1012 DEFINE_MSGF("string", RMF_F_STRING, -1, NULL, NULL);
1013 EXPORT_SYMBOL(RMF_STRING);
1015 struct req_msg_field RMF_FILE_SECCTX_NAME =
1016 DEFINE_MSGF("file_secctx_name", RMF_F_STRING, -1, NULL, NULL);
1017 EXPORT_SYMBOL(RMF_FILE_SECCTX_NAME);
1019 struct req_msg_field RMF_FILE_SECCTX =
1020 DEFINE_MSGF("file_secctx", RMF_F_NO_SIZE_CHECK, -1, NULL, NULL);
1021 EXPORT_SYMBOL(RMF_FILE_SECCTX);
1023 struct req_msg_field RMF_LLOGD_BODY =
1024 DEFINE_MSGF("llogd_body", 0,
1025 sizeof(struct llogd_body), lustre_swab_llogd_body, NULL);
1026 EXPORT_SYMBOL(RMF_LLOGD_BODY);
1028 struct req_msg_field RMF_LLOG_LOG_HDR =
1029 DEFINE_MSGF("llog_log_hdr", 0,
1030 sizeof(struct llog_log_hdr), lustre_swab_llog_hdr, NULL);
1031 EXPORT_SYMBOL(RMF_LLOG_LOG_HDR);
1033 struct req_msg_field RMF_LLOGD_CONN_BODY =
1034 DEFINE_MSGF("llogd_conn_body", 0,
1035 sizeof(struct llogd_conn_body),
1036 lustre_swab_llogd_conn_body, NULL);
1037 EXPORT_SYMBOL(RMF_LLOGD_CONN_BODY);
1040 * connection handle received in MDS_CONNECT request.
1042 * No swabbing needed because struct lustre_handle contains only a 64-bit cookie
1043 * that the client does not interpret at all.
1045 struct req_msg_field RMF_CONN =
1046 DEFINE_MSGF("conn", 0, sizeof(struct lustre_handle), NULL, NULL);
1047 EXPORT_SYMBOL(RMF_CONN);
1049 struct req_msg_field RMF_CONNECT_DATA =
1050 DEFINE_MSGF("cdata",
1051 RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */,
1052 sizeof(struct obd_connect_data),
1053 lustre_swab_connect, NULL);
1054 EXPORT_SYMBOL(RMF_CONNECT_DATA);
1056 struct req_msg_field RMF_DLM_REQ =
1057 DEFINE_MSGF("dlm_req", RMF_F_NO_SIZE_CHECK /* ldlm_request_bufsize */,
1058 sizeof(struct ldlm_request),
1059 lustre_swab_ldlm_request, NULL);
1060 EXPORT_SYMBOL(RMF_DLM_REQ);
1062 struct req_msg_field RMF_DLM_REP =
1063 DEFINE_MSGF("dlm_rep", 0,
1064 sizeof(struct ldlm_reply), lustre_swab_ldlm_reply, NULL);
1065 EXPORT_SYMBOL(RMF_DLM_REP);
1067 struct req_msg_field RMF_LDLM_INTENT =
1068 DEFINE_MSGF("ldlm_intent", 0,
1069 sizeof(struct ldlm_intent), lustre_swab_ldlm_intent, NULL);
1070 EXPORT_SYMBOL(RMF_LDLM_INTENT);
1072 struct req_msg_field RMF_DLM_LVB =
1073 DEFINE_MSGF("dlm_lvb", 0, -1, NULL, NULL);
1074 EXPORT_SYMBOL(RMF_DLM_LVB);
1076 struct req_msg_field RMF_DLM_GL_DESC =
1077 DEFINE_MSGF("dlm_gl_desc", 0, sizeof(union ldlm_gl_desc), NULL, NULL);
1078 EXPORT_SYMBOL(RMF_DLM_GL_DESC);
1080 struct req_msg_field RMF_MDT_MD =
1081 DEFINE_MSGF("mdt_md", RMF_F_NO_SIZE_CHECK, MIN_MD_SIZE, NULL, NULL);
1082 EXPORT_SYMBOL(RMF_MDT_MD);
1084 struct req_msg_field RMF_DEFAULT_MDT_MD =
1085 DEFINE_MSGF("default_mdt_md", RMF_F_NO_SIZE_CHECK, MIN_MD_SIZE, NULL,
1087 EXPORT_SYMBOL(RMF_DEFAULT_MDT_MD);
1089 struct req_msg_field RMF_REC_REINT =
1090 DEFINE_MSGF("rec_reint", 0, sizeof(struct mdt_rec_reint),
1091 lustre_swab_mdt_rec_reint, NULL);
1092 EXPORT_SYMBOL(RMF_REC_REINT);
1094 /* FIXME: this length should be defined as a macro */
1095 struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1,
1097 EXPORT_SYMBOL(RMF_EADATA);
1099 struct req_msg_field RMF_EAVALS = DEFINE_MSGF("eavals", 0, -1, NULL, NULL);
1100 EXPORT_SYMBOL(RMF_EAVALS);
1102 struct req_msg_field RMF_ACL = DEFINE_MSGF("acl", 0, -1, NULL, NULL);
1103 EXPORT_SYMBOL(RMF_ACL);
1105 /* FIXME: this should be made to use RMF_F_STRUCT_ARRAY */
1106 struct req_msg_field RMF_LOGCOOKIES =
1107 DEFINE_MSGF("logcookies", RMF_F_NO_SIZE_CHECK /* multiple cookies */,
1108 sizeof(struct llog_cookie), NULL, NULL);
1109 EXPORT_SYMBOL(RMF_LOGCOOKIES);
1111 struct req_msg_field RMF_CAPA1 =
1112 DEFINE_MSGF("capa", 0, 0, NULL, NULL);
1113 EXPORT_SYMBOL(RMF_CAPA1);
1115 struct req_msg_field RMF_CAPA2 =
1116 DEFINE_MSGF("capa", 0, 0, NULL, NULL);
1117 EXPORT_SYMBOL(RMF_CAPA2);
1119 struct req_msg_field RMF_LAYOUT_INTENT =
1120 DEFINE_MSGF("layout_intent", 0,
1121 sizeof(struct layout_intent), lustre_swab_layout_intent,
1123 EXPORT_SYMBOL(RMF_LAYOUT_INTENT);
1125 struct req_msg_field RMF_SELINUX_POL =
1126 DEFINE_MSGF("selinux_pol", RMF_F_STRING, -1, NULL, NULL);
1127 EXPORT_SYMBOL(RMF_SELINUX_POL);
1130 * OST request field.
1132 struct req_msg_field RMF_OST_BODY =
1133 DEFINE_MSGF("ost_body", 0,
1134 sizeof(struct ost_body), lustre_swab_ost_body,
1136 EXPORT_SYMBOL(RMF_OST_BODY);
1138 struct req_msg_field RMF_OBD_IOOBJ =
1139 DEFINE_MSGF("obd_ioobj", RMF_F_STRUCT_ARRAY,
1140 sizeof(struct obd_ioobj), lustre_swab_obd_ioobj, dump_ioo);
1141 EXPORT_SYMBOL(RMF_OBD_IOOBJ);
1143 struct req_msg_field RMF_NIOBUF_REMOTE =
1144 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY,
1145 sizeof(struct niobuf_remote), lustre_swab_niobuf_remote,
1147 EXPORT_SYMBOL(RMF_NIOBUF_REMOTE);
1149 struct req_msg_field RMF_NIOBUF_INLINE =
1150 DEFINE_MSGF("niobuf_inline", RMF_F_NO_SIZE_CHECK,
1151 sizeof(struct niobuf_remote), lustre_swab_niobuf_remote,
1153 EXPORT_SYMBOL(RMF_NIOBUF_INLINE);
1155 struct req_msg_field RMF_RCS =
1156 DEFINE_MSGF("niobuf_rcs", RMF_F_STRUCT_ARRAY, sizeof(__u32),
1157 lustre_swab_generic_32s, dump_rcs);
1158 EXPORT_SYMBOL(RMF_RCS);
1160 struct req_msg_field RMF_EAVALS_LENS =
1161 DEFINE_MSGF("eavals_lens", RMF_F_STRUCT_ARRAY, sizeof(__u32),
1162 lustre_swab_generic_32s, NULL);
1163 EXPORT_SYMBOL(RMF_EAVALS_LENS);
1165 struct req_msg_field RMF_OBD_ID =
1166 DEFINE_MSGF("obd_id", 0,
1167 sizeof(__u64), lustre_swab_ost_last_id, NULL);
1168 EXPORT_SYMBOL(RMF_OBD_ID);
1170 struct req_msg_field RMF_FID =
1171 DEFINE_MSGF("fid", 0,
1172 sizeof(struct lu_fid), lustre_swab_lu_fid, NULL);
1173 EXPORT_SYMBOL(RMF_FID);
1175 struct req_msg_field RMF_OST_ID =
1176 DEFINE_MSGF("ost_id", 0,
1177 sizeof(struct ost_id), lustre_swab_ost_id, NULL);
1178 EXPORT_SYMBOL(RMF_OST_ID);
1180 struct req_msg_field RMF_FIEMAP_KEY =
1181 DEFINE_MSGF("fiemap", 0, sizeof(struct ll_fiemap_info_key),
1182 lustre_swab_fiemap, NULL);
1183 EXPORT_SYMBOL(RMF_FIEMAP_KEY);
1185 struct req_msg_field RMF_FIEMAP_VAL =
1186 DEFINE_MSGF("fiemap", 0, -1, lustre_swab_fiemap, NULL);
1187 EXPORT_SYMBOL(RMF_FIEMAP_VAL);
1189 struct req_msg_field RMF_IDX_INFO =
1190 DEFINE_MSGF("idx_info", 0, sizeof(struct idx_info),
1191 lustre_swab_idx_info, NULL);
1192 EXPORT_SYMBOL(RMF_IDX_INFO);
1193 struct req_msg_field RMF_SHORT_IO =
1194 DEFINE_MSGF("short_io", 0, -1, NULL, NULL);
1195 EXPORT_SYMBOL(RMF_SHORT_IO);
1196 struct req_msg_field RMF_HSM_USER_STATE =
1197 DEFINE_MSGF("hsm_user_state", 0, sizeof(struct hsm_user_state),
1198 lustre_swab_hsm_user_state, NULL);
1199 EXPORT_SYMBOL(RMF_HSM_USER_STATE);
1201 struct req_msg_field RMF_HSM_STATE_SET =
1202 DEFINE_MSGF("hsm_state_set", 0, sizeof(struct hsm_state_set),
1203 lustre_swab_hsm_state_set, NULL);
1204 EXPORT_SYMBOL(RMF_HSM_STATE_SET);
1206 struct req_msg_field RMF_MDS_HSM_PROGRESS =
1207 DEFINE_MSGF("hsm_progress", 0, sizeof(struct hsm_progress_kernel),
1208 lustre_swab_hsm_progress_kernel, NULL);
1209 EXPORT_SYMBOL(RMF_MDS_HSM_PROGRESS);
1211 struct req_msg_field RMF_MDS_HSM_CURRENT_ACTION =
1212 DEFINE_MSGF("hsm_current_action", 0, sizeof(struct hsm_current_action),
1213 lustre_swab_hsm_current_action, NULL);
1214 EXPORT_SYMBOL(RMF_MDS_HSM_CURRENT_ACTION);
1216 struct req_msg_field RMF_MDS_HSM_USER_ITEM =
1217 DEFINE_MSGF("hsm_user_item", RMF_F_STRUCT_ARRAY,
1218 sizeof(struct hsm_user_item), lustre_swab_hsm_user_item,
1220 EXPORT_SYMBOL(RMF_MDS_HSM_USER_ITEM);
1222 struct req_msg_field RMF_MDS_HSM_ARCHIVE =
1223 DEFINE_MSGF("hsm_archive", RMF_F_STRUCT_ARRAY,
1224 sizeof(__u32), lustre_swab_generic_32s, NULL);
1225 EXPORT_SYMBOL(RMF_MDS_HSM_ARCHIVE);
1227 struct req_msg_field RMF_MDS_HSM_REQUEST =
1228 DEFINE_MSGF("hsm_request", 0, sizeof(struct hsm_request),
1229 lustre_swab_hsm_request, NULL);
1230 EXPORT_SYMBOL(RMF_MDS_HSM_REQUEST);
1232 struct req_msg_field RMF_OUT_UPDATE = DEFINE_MSGF("object_update", 0, -1,
1233 lustre_swab_object_update_request, NULL);
1234 EXPORT_SYMBOL(RMF_OUT_UPDATE);
1236 struct req_msg_field RMF_OUT_UPDATE_REPLY =
1237 DEFINE_MSGF("object_update_reply", 0, -1,
1238 lustre_swab_object_update_reply, NULL);
1239 EXPORT_SYMBOL(RMF_OUT_UPDATE_REPLY);
1241 struct req_msg_field RMF_SWAP_LAYOUTS =
1242 DEFINE_MSGF("swap_layouts", 0, sizeof(struct mdc_swap_layouts),
1243 lustre_swab_swap_layouts, NULL);
1244 EXPORT_SYMBOL(RMF_SWAP_LAYOUTS);
1246 struct req_msg_field RMF_LFSCK_REQUEST =
1247 DEFINE_MSGF("lfsck_request", 0, sizeof(struct lfsck_request),
1248 lustre_swab_lfsck_request, NULL);
1249 EXPORT_SYMBOL(RMF_LFSCK_REQUEST);
1251 struct req_msg_field RMF_LFSCK_REPLY =
1252 DEFINE_MSGF("lfsck_reply", 0, sizeof(struct lfsck_reply),
1253 lustre_swab_lfsck_reply, NULL);
1254 EXPORT_SYMBOL(RMF_LFSCK_REPLY);
1256 struct req_msg_field RMF_OST_LADVISE_HDR =
1257 DEFINE_MSGF("ladvise_request", 0,
1258 sizeof(struct ladvise_hdr),
1259 lustre_swab_ladvise_hdr, NULL);
1260 EXPORT_SYMBOL(RMF_OST_LADVISE_HDR);
1262 struct req_msg_field RMF_OST_LADVISE =
1263 DEFINE_MSGF("ladvise_request", RMF_F_STRUCT_ARRAY,
1264 sizeof(struct lu_ladvise),
1265 lustre_swab_ladvise, NULL);
1266 EXPORT_SYMBOL(RMF_OST_LADVISE);
1268 struct req_msg_field RMF_OUT_UPDATE_HEADER = DEFINE_MSGF("out_update_header", 0,
1269 -1, lustre_swab_out_update_header, NULL);
1270 EXPORT_SYMBOL(RMF_OUT_UPDATE_HEADER);
1272 struct req_msg_field RMF_OUT_UPDATE_BUF = DEFINE_MSGF("update_buf",
1273 RMF_F_STRUCT_ARRAY, sizeof(struct out_update_buffer),
1274 lustre_swab_out_update_buffer, NULL);
1275 EXPORT_SYMBOL(RMF_OUT_UPDATE_BUF);
1282 const char *rf_name;
1286 const struct req_msg_field **d;
1287 } rf_fields[RCL_NR];
1290 #define DEFINE_REQ_FMT(name, client, client_nr, server, server_nr) { \
1304 #define DEFINE_REQ_FMT0(name, client, server) \
1305 DEFINE_REQ_FMT(name, client, ARRAY_SIZE(client), server, ARRAY_SIZE(server))
1307 struct req_format RQF_OBD_PING =
1308 DEFINE_REQ_FMT0("OBD_PING", empty, empty);
1309 EXPORT_SYMBOL(RQF_OBD_PING);
1311 struct req_format RQF_OBD_SET_INFO =
1312 DEFINE_REQ_FMT0("OBD_SET_INFO", obd_set_info_client, empty);
1313 EXPORT_SYMBOL(RQF_OBD_SET_INFO);
1315 /* Read index file through the network */
1316 struct req_format RQF_OBD_IDX_READ =
1317 DEFINE_REQ_FMT0("OBD_IDX_READ",
1318 obd_idx_read_client, obd_idx_read_server);
1319 EXPORT_SYMBOL(RQF_OBD_IDX_READ);
1321 struct req_format RQF_SEC_CTX =
1322 DEFINE_REQ_FMT0("SEC_CTX", empty, empty);
1323 EXPORT_SYMBOL(RQF_SEC_CTX);
1325 struct req_format RQF_MGS_TARGET_REG =
1326 DEFINE_REQ_FMT0("MGS_TARGET_REG", mgs_target_info_only,
1327 mgs_target_info_only);
1328 EXPORT_SYMBOL(RQF_MGS_TARGET_REG);
1330 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 13, 53, 0)
1331 struct req_format RQF_MGS_SET_INFO =
1332 DEFINE_REQ_FMT0("MGS_SET_INFO", mgs_set_info,
1334 EXPORT_SYMBOL(RQF_MGS_SET_INFO);
1337 struct req_format RQF_MGS_CONFIG_READ =
1338 DEFINE_REQ_FMT0("MGS_CONFIG_READ", mgs_config_read_client,
1339 mgs_config_read_server);
1340 EXPORT_SYMBOL(RQF_MGS_CONFIG_READ);
1342 struct req_format RQF_SEQ_QUERY =
1343 DEFINE_REQ_FMT0("SEQ_QUERY", seq_query_client, seq_query_server);
1344 EXPORT_SYMBOL(RQF_SEQ_QUERY);
1346 struct req_format RQF_FLD_QUERY =
1347 DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
1348 EXPORT_SYMBOL(RQF_FLD_QUERY);
1350 /* The 'fld_read_server' uses 'RMF_GENERIC_DATA' to hold the 'FLD_QUERY'
1351 * RPC reply that is composed of 'struct lu_seq_range_array'. But there
1352 * is not registered swabber function for 'RMF_GENERIC_DATA'. So the RPC
1353 * peers need to handle the RPC reply with fixed little-endian format.
1355 * In theory, we can define new structure with some swabber registered to
1356 * handle the 'FLD_QUERY' RPC reply result automatically. But from the
1357 * implementation view, it is not easy to be done within current "struct
1358 * req_msg_field" framework. Because the sequence range array in the RPC
1359 * reply is not fixed length, instead, its length depends on 'lu_seq_range'
1360 * count, that is unknown when prepare the RPC buffer. Generally, for such
1361 * flexible length RPC usage, there will be a field in the RPC layout to
1362 * indicate the data length. But for the 'FLD_READ' RPC, we have no way to
1363 * do that unless we add new length filed that will broken the on-wire RPC
1364 * protocol and cause interoperability trouble with old peer. */
1365 struct req_format RQF_FLD_READ =
1366 DEFINE_REQ_FMT0("FLD_READ", fld_read_client, fld_read_server);
1367 EXPORT_SYMBOL(RQF_FLD_READ);
1369 struct req_format RQF_MDS_QUOTACTL =
1370 DEFINE_REQ_FMT0("MDS_QUOTACTL", quotactl_only, quotactl_only);
1371 EXPORT_SYMBOL(RQF_MDS_QUOTACTL);
1373 struct req_format RQF_OST_QUOTACTL =
1374 DEFINE_REQ_FMT0("OST_QUOTACTL", quotactl_only, quotactl_only);
1375 EXPORT_SYMBOL(RQF_OST_QUOTACTL);
1377 struct req_format RQF_QUOTA_DQACQ =
1378 DEFINE_REQ_FMT0("QUOTA_DQACQ", quota_body_only, quota_body_only);
1379 EXPORT_SYMBOL(RQF_QUOTA_DQACQ);
1381 struct req_format RQF_LDLM_INTENT_QUOTA =
1382 DEFINE_REQ_FMT0("LDLM_INTENT_QUOTA",
1383 ldlm_intent_quota_client,
1384 ldlm_intent_quota_server);
1385 EXPORT_SYMBOL(RQF_LDLM_INTENT_QUOTA);
1387 struct req_format RQF_MDS_GET_ROOT =
1388 DEFINE_REQ_FMT0("MDS_GET_ROOT", mds_get_root_client, mdt_body_capa);
1389 EXPORT_SYMBOL(RQF_MDS_GET_ROOT);
1391 struct req_format RQF_MDS_STATFS =
1392 DEFINE_REQ_FMT0("MDS_STATFS", empty, obd_statfs_server);
1393 EXPORT_SYMBOL(RQF_MDS_STATFS);
1395 struct req_format RQF_MDS_STATFS_NEW =
1396 DEFINE_REQ_FMT0("MDS_STATFS_NEW", mdt_body_only, obd_statfs_server);
1397 EXPORT_SYMBOL(RQF_MDS_STATFS_NEW);
1399 struct req_format RQF_MDS_SYNC =
1400 DEFINE_REQ_FMT0("MDS_SYNC", mdt_body_capa, mdt_body_only);
1401 EXPORT_SYMBOL(RQF_MDS_SYNC);
1403 struct req_format RQF_MDS_GETATTR =
1404 DEFINE_REQ_FMT0("MDS_GETATTR", mdt_body_capa, mds_getattr_server);
1405 EXPORT_SYMBOL(RQF_MDS_GETATTR);
1407 struct req_format RQF_MDS_GETXATTR =
1408 DEFINE_REQ_FMT0("MDS_GETXATTR",
1409 mds_getxattr_client, mds_getxattr_server);
1410 EXPORT_SYMBOL(RQF_MDS_GETXATTR);
1412 struct req_format RQF_MDS_GETATTR_NAME =
1413 DEFINE_REQ_FMT0("MDS_GETATTR_NAME",
1414 mds_getattr_name_client, mds_getattr_server);
1415 EXPORT_SYMBOL(RQF_MDS_GETATTR_NAME);
1417 struct req_format RQF_MDS_REINT =
1418 DEFINE_REQ_FMT0("MDS_REINT", mds_reint_client, mdt_body_only);
1419 EXPORT_SYMBOL(RQF_MDS_REINT);
1421 struct req_format RQF_MDS_REINT_CREATE =
1422 DEFINE_REQ_FMT0("MDS_REINT_CREATE",
1423 mds_reint_create_client, mdt_body_capa);
1424 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE);
1426 struct req_format RQF_MDS_REINT_CREATE_ACL =
1427 DEFINE_REQ_FMT0("MDS_REINT_CREATE_ACL",
1428 mds_reint_create_acl_client, mdt_body_capa);
1429 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_ACL);
1431 struct req_format RQF_MDS_REINT_CREATE_SLAVE =
1432 DEFINE_REQ_FMT0("MDS_REINT_CREATE_EA",
1433 mds_reint_create_slave_client, mdt_body_capa);
1434 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SLAVE);
1436 struct req_format RQF_MDS_REINT_CREATE_SYM =
1437 DEFINE_REQ_FMT0("MDS_REINT_CREATE_SYM",
1438 mds_reint_create_sym_client, mdt_body_capa);
1439 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SYM);
1441 struct req_format RQF_MDS_REINT_OPEN =
1442 DEFINE_REQ_FMT0("MDS_REINT_OPEN",
1443 mds_reint_open_client, mds_reint_open_server);
1444 EXPORT_SYMBOL(RQF_MDS_REINT_OPEN);
1446 struct req_format RQF_MDS_REINT_UNLINK =
1447 DEFINE_REQ_FMT0("MDS_REINT_UNLINK", mds_reint_unlink_client,
1448 mds_last_unlink_server);
1449 EXPORT_SYMBOL(RQF_MDS_REINT_UNLINK);
1451 struct req_format RQF_MDS_REINT_LINK =
1452 DEFINE_REQ_FMT0("MDS_REINT_LINK",
1453 mds_reint_link_client, mdt_body_only);
1454 EXPORT_SYMBOL(RQF_MDS_REINT_LINK);
1456 struct req_format RQF_MDS_REINT_RENAME =
1457 DEFINE_REQ_FMT0("MDS_REINT_RENAME", mds_reint_rename_client,
1458 mds_last_unlink_server);
1459 EXPORT_SYMBOL(RQF_MDS_REINT_RENAME);
1461 struct req_format RQF_MDS_REINT_MIGRATE =
1462 DEFINE_REQ_FMT0("MDS_REINT_MIGRATE", mds_reint_migrate_client,
1463 mds_last_unlink_server);
1464 EXPORT_SYMBOL(RQF_MDS_REINT_MIGRATE);
1466 struct req_format RQF_MDS_REINT_SETATTR =
1467 DEFINE_REQ_FMT0("MDS_REINT_SETATTR",
1468 mds_reint_setattr_client, mds_setattr_server);
1469 EXPORT_SYMBOL(RQF_MDS_REINT_SETATTR);
1471 struct req_format RQF_MDS_REINT_SETXATTR =
1472 DEFINE_REQ_FMT0("MDS_REINT_SETXATTR",
1473 mds_reint_setxattr_client, mdt_body_only);
1474 EXPORT_SYMBOL(RQF_MDS_REINT_SETXATTR);
1476 struct req_format RQF_MDS_REINT_RESYNC =
1477 DEFINE_REQ_FMT0("MDS_REINT_RESYNC", mds_reint_resync, mdt_body_only);
1478 EXPORT_SYMBOL(RQF_MDS_REINT_RESYNC);
1480 struct req_format RQF_MDS_CONNECT =
1481 DEFINE_REQ_FMT0("MDS_CONNECT",
1482 obd_connect_client, obd_connect_server);
1483 EXPORT_SYMBOL(RQF_MDS_CONNECT);
1485 struct req_format RQF_MDS_DISCONNECT =
1486 DEFINE_REQ_FMT0("MDS_DISCONNECT", empty, empty);
1487 EXPORT_SYMBOL(RQF_MDS_DISCONNECT);
1489 struct req_format RQF_MDS_GET_INFO =
1490 DEFINE_REQ_FMT0("MDS_GET_INFO", mds_getinfo_client,
1491 mds_getinfo_server);
1492 EXPORT_SYMBOL(RQF_MDS_GET_INFO);
1494 struct req_format RQF_OUT_UPDATE =
1495 DEFINE_REQ_FMT0("OUT_UPDATE", mds_update_client,
1497 EXPORT_SYMBOL(RQF_OUT_UPDATE);
1499 struct req_format RQF_LDLM_ENQUEUE =
1500 DEFINE_REQ_FMT0("LDLM_ENQUEUE",
1501 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1502 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE);
1504 struct req_format RQF_LDLM_ENQUEUE_LVB =
1505 DEFINE_REQ_FMT0("LDLM_ENQUEUE_LVB",
1506 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1507 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE_LVB);
1509 struct req_format RQF_LDLM_CONVERT =
1510 DEFINE_REQ_FMT0("LDLM_CONVERT",
1511 ldlm_enqueue_client, ldlm_enqueue_server);
1512 EXPORT_SYMBOL(RQF_LDLM_CONVERT);
1514 struct req_format RQF_LDLM_CANCEL =
1515 DEFINE_REQ_FMT0("LDLM_CANCEL", ldlm_enqueue_client, empty);
1516 EXPORT_SYMBOL(RQF_LDLM_CANCEL);
1518 struct req_format RQF_LDLM_CALLBACK =
1519 DEFINE_REQ_FMT0("LDLM_CALLBACK", ldlm_enqueue_client, empty);
1520 EXPORT_SYMBOL(RQF_LDLM_CALLBACK);
1522 struct req_format RQF_LDLM_CP_CALLBACK =
1523 DEFINE_REQ_FMT0("LDLM_CP_CALLBACK", ldlm_cp_callback_client, empty);
1524 EXPORT_SYMBOL(RQF_LDLM_CP_CALLBACK);
1526 struct req_format RQF_LDLM_BL_CALLBACK =
1527 DEFINE_REQ_FMT0("LDLM_BL_CALLBACK", ldlm_enqueue_client, empty);
1528 EXPORT_SYMBOL(RQF_LDLM_BL_CALLBACK);
1530 struct req_format RQF_LDLM_GL_CALLBACK =
1531 DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_enqueue_client,
1532 ldlm_gl_callback_server);
1533 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK);
1535 struct req_format RQF_LDLM_GL_CALLBACK_DESC =
1536 DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_gl_callback_desc_client,
1537 ldlm_gl_callback_server);
1538 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK_DESC);
1540 struct req_format RQF_LDLM_INTENT_BASIC =
1541 DEFINE_REQ_FMT0("LDLM_INTENT_BASIC",
1542 ldlm_intent_basic_client, ldlm_enqueue_lvb_server);
1543 EXPORT_SYMBOL(RQF_LDLM_INTENT_BASIC);
1545 struct req_format RQF_LDLM_INTENT =
1546 DEFINE_REQ_FMT0("LDLM_INTENT",
1547 ldlm_intent_client, ldlm_intent_server);
1548 EXPORT_SYMBOL(RQF_LDLM_INTENT);
1550 struct req_format RQF_LDLM_INTENT_LAYOUT =
1551 DEFINE_REQ_FMT0("LDLM_INTENT_LAYOUT",
1552 ldlm_intent_layout_client, ldlm_enqueue_lvb_server);
1553 EXPORT_SYMBOL(RQF_LDLM_INTENT_LAYOUT);
1555 struct req_format RQF_LDLM_INTENT_GETATTR =
1556 DEFINE_REQ_FMT0("LDLM_INTENT_GETATTR",
1557 ldlm_intent_getattr_client, ldlm_intent_getattr_server);
1558 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETATTR);
1560 struct req_format RQF_LDLM_INTENT_OPEN =
1561 DEFINE_REQ_FMT0("LDLM_INTENT_OPEN",
1562 ldlm_intent_open_client, ldlm_intent_open_server);
1563 EXPORT_SYMBOL(RQF_LDLM_INTENT_OPEN);
1565 struct req_format RQF_LDLM_INTENT_CREATE =
1566 DEFINE_REQ_FMT0("LDLM_INTENT_CREATE",
1567 ldlm_intent_create_client, ldlm_intent_getattr_server);
1568 EXPORT_SYMBOL(RQF_LDLM_INTENT_CREATE);
1570 struct req_format RQF_LDLM_INTENT_GETXATTR =
1571 DEFINE_REQ_FMT0("LDLM_INTENT_GETXATTR",
1572 ldlm_intent_getxattr_client,
1573 ldlm_intent_getxattr_server);
1574 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETXATTR);
1576 struct req_format RQF_MDS_CLOSE =
1577 DEFINE_REQ_FMT0("MDS_CLOSE",
1578 mdt_close_client, mds_last_unlink_server);
1579 EXPORT_SYMBOL(RQF_MDS_CLOSE);
1581 struct req_format RQF_MDS_CLOSE_INTENT =
1582 DEFINE_REQ_FMT0("MDS_CLOSE_INTENT",
1583 mdt_close_intent_client, mds_last_unlink_server);
1584 EXPORT_SYMBOL(RQF_MDS_CLOSE_INTENT);
1586 struct req_format RQF_MDS_READPAGE =
1587 DEFINE_REQ_FMT0("MDS_READPAGE",
1588 mdt_body_capa, mdt_body_only);
1589 EXPORT_SYMBOL(RQF_MDS_READPAGE);
1591 struct req_format RQF_MDS_HSM_ACTION =
1592 DEFINE_REQ_FMT0("MDS_HSM_ACTION", mdt_body_capa, mdt_hsm_action_server);
1593 EXPORT_SYMBOL(RQF_MDS_HSM_ACTION);
1595 struct req_format RQF_MDS_HSM_PROGRESS =
1596 DEFINE_REQ_FMT0("MDS_HSM_PROGRESS", mdt_hsm_progress, empty);
1597 EXPORT_SYMBOL(RQF_MDS_HSM_PROGRESS);
1599 struct req_format RQF_MDS_HSM_CT_REGISTER =
1600 DEFINE_REQ_FMT0("MDS_HSM_CT_REGISTER", mdt_hsm_ct_register, empty);
1601 EXPORT_SYMBOL(RQF_MDS_HSM_CT_REGISTER);
1603 struct req_format RQF_MDS_HSM_CT_UNREGISTER =
1604 DEFINE_REQ_FMT0("MDS_HSM_CT_UNREGISTER", mdt_hsm_ct_unregister, empty);
1605 EXPORT_SYMBOL(RQF_MDS_HSM_CT_UNREGISTER);
1607 struct req_format RQF_MDS_HSM_STATE_GET =
1608 DEFINE_REQ_FMT0("MDS_HSM_STATE_GET",
1609 mdt_body_capa, mdt_hsm_state_get_server);
1610 EXPORT_SYMBOL(RQF_MDS_HSM_STATE_GET);
1612 struct req_format RQF_MDS_HSM_STATE_SET =
1613 DEFINE_REQ_FMT0("MDS_HSM_STATE_SET", mdt_hsm_state_set, empty);
1614 EXPORT_SYMBOL(RQF_MDS_HSM_STATE_SET);
1616 struct req_format RQF_MDS_HSM_REQUEST =
1617 DEFINE_REQ_FMT0("MDS_HSM_REQUEST", mdt_hsm_request, empty);
1618 EXPORT_SYMBOL(RQF_MDS_HSM_REQUEST);
1620 struct req_format RQF_MDS_SWAP_LAYOUTS =
1621 DEFINE_REQ_FMT0("MDS_SWAP_LAYOUTS",
1622 mdt_swap_layouts, empty);
1623 EXPORT_SYMBOL(RQF_MDS_SWAP_LAYOUTS);
1625 struct req_format RQF_LLOG_ORIGIN_HANDLE_CREATE =
1626 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_CREATE",
1627 llog_origin_handle_create_client, llogd_body_only);
1628 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_CREATE);
1630 struct req_format RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK =
1631 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_NEXT_BLOCK",
1632 llogd_body_only, llog_origin_handle_next_block_server);
1633 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1635 struct req_format RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK =
1636 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_PREV_BLOCK",
1637 llogd_body_only, llog_origin_handle_next_block_server);
1638 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1640 struct req_format RQF_LLOG_ORIGIN_HANDLE_READ_HEADER =
1641 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_READ_HEADER",
1642 llogd_body_only, llog_log_hdr_only);
1643 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1645 struct req_format RQF_CONNECT =
1646 DEFINE_REQ_FMT0("CONNECT", obd_connect_client, obd_connect_server);
1647 EXPORT_SYMBOL(RQF_CONNECT);
1649 struct req_format RQF_OST_CONNECT =
1650 DEFINE_REQ_FMT0("OST_CONNECT",
1651 obd_connect_client, obd_connect_server);
1652 EXPORT_SYMBOL(RQF_OST_CONNECT);
1654 struct req_format RQF_OST_DISCONNECT =
1655 DEFINE_REQ_FMT0("OST_DISCONNECT", empty, empty);
1656 EXPORT_SYMBOL(RQF_OST_DISCONNECT);
1658 struct req_format RQF_OST_GETATTR =
1659 DEFINE_REQ_FMT0("OST_GETATTR", ost_body_capa, ost_body_only);
1660 EXPORT_SYMBOL(RQF_OST_GETATTR);
1662 struct req_format RQF_OST_SETATTR =
1663 DEFINE_REQ_FMT0("OST_SETATTR", ost_body_capa, ost_body_only);
1664 EXPORT_SYMBOL(RQF_OST_SETATTR);
1666 struct req_format RQF_OST_CREATE =
1667 DEFINE_REQ_FMT0("OST_CREATE", ost_body_only, ost_body_only);
1668 EXPORT_SYMBOL(RQF_OST_CREATE);
1670 struct req_format RQF_OST_PUNCH =
1671 DEFINE_REQ_FMT0("OST_PUNCH", ost_body_capa, ost_body_only);
1672 EXPORT_SYMBOL(RQF_OST_PUNCH);
1674 struct req_format RQF_OST_SYNC =
1675 DEFINE_REQ_FMT0("OST_SYNC", ost_body_capa, ost_body_only);
1676 EXPORT_SYMBOL(RQF_OST_SYNC);
1678 struct req_format RQF_OST_DESTROY =
1679 DEFINE_REQ_FMT0("OST_DESTROY", ost_destroy_client, ost_body_only);
1680 EXPORT_SYMBOL(RQF_OST_DESTROY);
1682 struct req_format RQF_OST_BRW_READ =
1683 DEFINE_REQ_FMT0("OST_BRW_READ", ost_brw_client, ost_brw_read_server);
1684 EXPORT_SYMBOL(RQF_OST_BRW_READ);
1686 struct req_format RQF_OST_BRW_WRITE =
1687 DEFINE_REQ_FMT0("OST_BRW_WRITE", ost_brw_client, ost_brw_write_server);
1688 EXPORT_SYMBOL(RQF_OST_BRW_WRITE);
1690 struct req_format RQF_OST_STATFS =
1691 DEFINE_REQ_FMT0("OST_STATFS", empty, obd_statfs_server);
1692 EXPORT_SYMBOL(RQF_OST_STATFS);
1694 struct req_format RQF_OST_SET_GRANT_INFO =
1695 DEFINE_REQ_FMT0("OST_SET_GRANT_INFO", ost_grant_shrink_client,
1697 EXPORT_SYMBOL(RQF_OST_SET_GRANT_INFO);
1699 struct req_format RQF_OST_GET_INFO =
1700 DEFINE_REQ_FMT0("OST_GET_INFO", ost_get_info_generic_client,
1701 ost_get_info_generic_server);
1702 EXPORT_SYMBOL(RQF_OST_GET_INFO);
1704 struct req_format RQF_OST_GET_INFO_LAST_ID =
1705 DEFINE_REQ_FMT0("OST_GET_INFO_LAST_ID", ost_get_info_generic_client,
1706 ost_get_last_id_server);
1707 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_ID);
1709 struct req_format RQF_OST_GET_INFO_LAST_FID =
1710 DEFINE_REQ_FMT0("OST_GET_INFO_LAST_FID", ost_get_last_fid_client,
1711 ost_get_last_fid_server);
1712 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_FID);
1714 struct req_format RQF_OST_SET_INFO_LAST_FID =
1715 DEFINE_REQ_FMT0("OST_SET_INFO_LAST_FID", obd_set_info_client,
1717 EXPORT_SYMBOL(RQF_OST_SET_INFO_LAST_FID);
1719 struct req_format RQF_OST_GET_INFO_FIEMAP =
1720 DEFINE_REQ_FMT0("OST_GET_INFO_FIEMAP", ost_get_fiemap_client,
1721 ost_get_fiemap_server);
1722 EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP);
1724 struct req_format RQF_LFSCK_NOTIFY =
1725 DEFINE_REQ_FMT0("LFSCK_NOTIFY", obd_lfsck_request, empty);
1726 EXPORT_SYMBOL(RQF_LFSCK_NOTIFY);
1728 struct req_format RQF_LFSCK_QUERY =
1729 DEFINE_REQ_FMT0("LFSCK_QUERY", obd_lfsck_request, obd_lfsck_reply);
1730 EXPORT_SYMBOL(RQF_LFSCK_QUERY);
1732 struct req_format RQF_OST_LADVISE =
1733 DEFINE_REQ_FMT0("OST_LADVISE", ost_ladvise, ost_body_only);
1734 EXPORT_SYMBOL(RQF_OST_LADVISE);
1736 /* Convenience macro */
1737 #define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1740 * Initializes the capsule abstraction by computing and setting the \a rf_idx
1741 * field of RQFs and the \a rmf_offset field of RMFs.
1743 int req_layout_init(void)
1748 struct req_format *rf = NULL;
1750 for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
1751 rf = req_formats[i];
1753 for (j = 0; j < RCL_NR; ++j) {
1754 LASSERT(rf->rf_fields[j].nr <= REQ_MAX_FIELD_NR);
1755 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
1756 struct req_msg_field *field;
1758 field = (typeof(field))rf->rf_fields[j].d[k];
1759 LASSERT(!(field->rmf_flags & RMF_F_STRUCT_ARRAY)
1760 || field->rmf_size > 0);
1761 LASSERT(field->rmf_offset[i][j] == 0);
1763 * k + 1 to detect unused format/field
1766 field->rmf_offset[i][j] = k + 1;
1772 EXPORT_SYMBOL(req_layout_init);
1774 void req_layout_fini(void)
1777 EXPORT_SYMBOL(req_layout_fini);
1780 * Initializes the expected sizes of each RMF in a \a pill (\a rc_area) to -1.
1782 * Actual/expected field sizes are set elsewhere in functions in this file:
1783 * req_capsule_init(), req_capsule_server_pack(), req_capsule_set_size() and
1784 * req_capsule_msg_size(). The \a rc_area information is used by.
1785 * ptlrpc_request_set_replen().
1787 void req_capsule_init_area(struct req_capsule *pill)
1791 for (i = 0; i < ARRAY_SIZE(pill->rc_area[RCL_CLIENT]); i++) {
1792 pill->rc_area[RCL_CLIENT][i] = -1;
1793 pill->rc_area[RCL_SERVER][i] = -1;
1796 EXPORT_SYMBOL(req_capsule_init_area);
1799 * Initialize a pill.
1801 * The \a location indicates whether the caller is executing on the client side
1802 * (RCL_CLIENT) or server side (RCL_SERVER)..
1804 void req_capsule_init(struct req_capsule *pill,
1805 struct ptlrpc_request *req,
1806 enum req_location location)
1808 LASSERT(location == RCL_SERVER || location == RCL_CLIENT);
1811 * Today all capsules are embedded in ptlrpc_request structs,
1812 * but just in case that ever isn't the case, we don't reach
1813 * into req unless req != NULL and pill is the one embedded in
1816 * The req->rq_pill_init flag makes it safe to initialize a pill
1817 * twice, which might happen in the OST paths as a result of the
1818 * high-priority RPC queue getting peeked at before ost_handle()
1819 * handles an OST RPC.
1821 if (req != NULL && pill == &req->rq_pill && req->rq_pill_init)
1824 memset(pill, 0, sizeof *pill);
1826 pill->rc_loc = location;
1827 req_capsule_init_area(pill);
1829 if (req != NULL && pill == &req->rq_pill)
1830 req->rq_pill_init = 1;
1832 EXPORT_SYMBOL(req_capsule_init);
1834 void req_capsule_fini(struct req_capsule *pill)
1837 EXPORT_SYMBOL(req_capsule_fini);
1839 static int __req_format_is_sane(const struct req_format *fmt)
1841 return fmt->rf_idx < ARRAY_SIZE(req_formats) &&
1842 req_formats[fmt->rf_idx] == fmt;
1845 static struct lustre_msg *__req_msg(const struct req_capsule *pill,
1846 enum req_location loc)
1848 struct ptlrpc_request *req;
1851 return loc == RCL_CLIENT ? req->rq_reqmsg : req->rq_repmsg;
1855 * Set the format (\a fmt) of a \a pill; format changes are not allowed here
1856 * (see req_capsule_extend()).
1858 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt)
1860 LASSERT(pill->rc_fmt == NULL || pill->rc_fmt == fmt);
1861 LASSERT(__req_format_is_sane(fmt));
1865 EXPORT_SYMBOL(req_capsule_set);
1868 * Fills in any parts of the \a rc_area of a \a pill that haven't been filled in
1871 * \a rc_area is an array of REQ_MAX_FIELD_NR elements, used to store sizes of
1872 * variable-sized fields. The field sizes come from the declared \a rmf_size
1873 * field of a \a pill's \a rc_fmt's RMF's.
1875 size_t req_capsule_filled_sizes(struct req_capsule *pill,
1876 enum req_location loc)
1878 const struct req_format *fmt = pill->rc_fmt;
1881 LASSERT(fmt != NULL);
1883 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1884 if (pill->rc_area[loc][i] == -1) {
1885 pill->rc_area[loc][i] =
1886 fmt->rf_fields[loc].d[i]->rmf_size;
1887 if (pill->rc_area[loc][i] == -1) {
1889 * Skip the following fields.
1891 * If this LASSERT() trips then you're missing a
1892 * call to req_capsule_set_size().
1894 LASSERT(loc != RCL_SERVER);
1901 EXPORT_SYMBOL(req_capsule_filled_sizes);
1904 * Capsule equivalent of lustre_pack_request() and lustre_pack_reply().
1906 * This function uses the \a pill's \a rc_area as filled in by
1907 * req_capsule_set_size() or req_capsule_filled_sizes() (the latter is called by
1910 int req_capsule_server_pack(struct req_capsule *pill)
1912 const struct req_format *fmt;
1916 LASSERT(pill->rc_loc == RCL_SERVER);
1918 LASSERT(fmt != NULL);
1920 count = req_capsule_filled_sizes(pill, RCL_SERVER);
1921 rc = lustre_pack_reply(pill->rc_req, count,
1922 pill->rc_area[RCL_SERVER], NULL);
1924 DEBUG_REQ(D_ERROR, pill->rc_req,
1925 "Cannot pack %d fields in format `%s': ",
1926 count, fmt->rf_name);
1930 EXPORT_SYMBOL(req_capsule_server_pack);
1933 * Returns the PTLRPC request or reply (\a loc) buffer offset of a \a pill
1934 * corresponding to the given RMF (\a field).
1936 __u32 __req_capsule_offset(const struct req_capsule *pill,
1937 const struct req_msg_field *field,
1938 enum req_location loc)
1940 unsigned int offset;
1942 offset = field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1943 LASSERTF(offset > 0, "%s:%s, off=%d, loc=%d\n",
1944 pill->rc_fmt->rf_name,
1945 field->rmf_name, offset, loc);
1948 LASSERT(offset < REQ_MAX_FIELD_NR);
1953 * Helper for __req_capsule_get(); swabs value / array of values and/or dumps
1958 swabber_dumper_helper(struct req_capsule *pill,
1959 const struct req_msg_field *field,
1960 enum req_location loc,
1962 void *value, int len, int dump, void (*swabber)( void *))
1968 int inout = loc == RCL_CLIENT;
1970 swabber = swabber ?: field->rmf_swabber;
1972 if (ptlrpc_buf_need_swab(pill->rc_req, inout, offset) &&
1973 swabber != NULL && value != NULL)
1978 if (!field->rmf_dumper)
1981 if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY)) {
1983 CDEBUG(D_RPCTRACE, "Dump of %sfield %s follows\n",
1984 do_swab ? "unswabbed " : "", field->rmf_name);
1985 field->rmf_dumper(value);
1990 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1992 CDEBUG(D_RPCTRACE, "Dump of swabbed field %s "
1993 "follows\n", field->rmf_name);
1994 field->rmf_dumper(value);
2001 * We're swabbing an array; swabber() swabs a single array element, so
2002 * swab every element.
2004 LASSERT((len % field->rmf_size) == 0);
2005 for (p = value, i = 0, n = len / field->rmf_size;
2007 i++, p += field->rmf_size) {
2009 CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, "
2010 "element %d follows\n",
2011 do_swab ? "unswabbed " : "", field->rmf_name, i);
2012 field->rmf_dumper(p);
2018 CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, "
2019 "element %d follows\n", field->rmf_name, i);
2020 field->rmf_dumper(value);
2024 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
2028 * Returns the pointer to a PTLRPC request or reply (\a loc) buffer of a \a pill
2029 * corresponding to the given RMF (\a field).
2031 * The buffer will be swabbed using the given \a swabber. If \a swabber == NULL
2032 * then the \a rmf_swabber from the RMF will be used. Soon there will be no
2033 * calls to __req_capsule_get() with a non-NULL \a swabber; \a swabber will then
2034 * be removed. Fields with the \a RMF_F_STRUCT_ARRAY flag set will have each
2035 * element of the array swabbed.
2037 static void *__req_capsule_get(struct req_capsule *pill,
2038 const struct req_msg_field *field,
2039 enum req_location loc,
2040 void (*swabber)( void *),
2043 const struct req_format *fmt;
2044 struct lustre_msg *msg;
2049 void *(*getter)(struct lustre_msg *m, __u32 n, __u32 minlen);
2051 static const char *rcl_names[RCL_NR] = {
2052 [RCL_CLIENT] = "client",
2053 [RCL_SERVER] = "server"
2056 LASSERT(pill != NULL);
2057 LASSERT(pill != LP_POISON);
2059 LASSERT(fmt != NULL);
2060 LASSERT(fmt != LP_POISON);
2061 LASSERT(__req_format_is_sane(fmt));
2063 offset = __req_capsule_offset(pill, field, loc);
2065 msg = __req_msg(pill, loc);
2066 LASSERT(msg != NULL);
2068 getter = (field->rmf_flags & RMF_F_STRING) ?
2069 (typeof(getter))lustre_msg_string : lustre_msg_buf;
2071 if (field->rmf_flags & (RMF_F_STRUCT_ARRAY|RMF_F_NO_SIZE_CHECK)) {
2073 * We've already asserted that field->rmf_size > 0 in
2074 * req_layout_init().
2076 len = lustre_msg_buflen(msg, offset);
2077 if (!(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
2078 (len % field->rmf_size) != 0) {
2079 CERROR("%s: array field size mismatch "
2080 "%d modulo %u != 0 (%d)\n",
2081 field->rmf_name, len, field->rmf_size, loc);
2084 } else if (pill->rc_area[loc][offset] != -1) {
2085 len = pill->rc_area[loc][offset];
2087 len = max_t(typeof(field->rmf_size), field->rmf_size, 0);
2089 value = getter(msg, offset, len);
2091 if (value == NULL) {
2092 DEBUG_REQ(D_ERROR, pill->rc_req,
2093 "Wrong buffer for field `%s' (%u of %u) "
2094 "in format `%s': %u vs. %u (%s)\n",
2095 field->rmf_name, offset, lustre_msg_bufcount(msg),
2096 fmt->rf_name, lustre_msg_buflen(msg, offset), len,
2099 swabber_dumper_helper(pill, field, loc, offset, value, len,
2107 * Dump a request and/or reply
2109 void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
2111 const struct req_format *fmt;
2112 const struct req_msg_field *field;
2118 DEBUG_REQ(D_RPCTRACE, pill->rc_req, "BEGIN REQ CAPSULE DUMP\n");
2119 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
2120 field = FMT_FIELD(fmt, loc, i);
2121 if (field->rmf_dumper == NULL) {
2123 * FIXME Add a default hex dumper for fields that don't
2124 * have a specific dumper
2126 len = req_capsule_get_size(pill, field, loc);
2127 CDEBUG(D_RPCTRACE, "Field %s has no dumper function;"
2128 "field size is %u\n", field->rmf_name, len);
2130 /* It's the dumping side-effect that we're interested in */
2131 (void) __req_capsule_get(pill, field, loc, NULL, 1);
2134 CDEBUG(D_RPCTRACE, "END REQ CAPSULE DUMP\n");
2140 void req_capsule_client_dump(struct req_capsule *pill)
2142 __req_capsule_dump(pill, RCL_CLIENT);
2144 EXPORT_SYMBOL(req_capsule_client_dump);
2149 void req_capsule_server_dump(struct req_capsule *pill)
2151 __req_capsule_dump(pill, RCL_SERVER);
2153 EXPORT_SYMBOL(req_capsule_server_dump);
2156 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC request
2157 * buffer corresponding to the given RMF (\a field) of a \a pill.
2159 void *req_capsule_client_get(struct req_capsule *pill,
2160 const struct req_msg_field *field)
2162 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
2164 EXPORT_SYMBOL(req_capsule_client_get);
2167 * Same as req_capsule_client_get(), but with a \a swabber argument.
2169 * Currently unused; will be removed when req_capsule_server_swab_get() is
2172 void *req_capsule_client_swab_get(struct req_capsule *pill,
2173 const struct req_msg_field *field,
2176 return __req_capsule_get(pill, field, RCL_CLIENT, swabber, 0);
2178 EXPORT_SYMBOL(req_capsule_client_swab_get);
2181 * Utility that combines req_capsule_set_size() and req_capsule_client_get().
2183 * First the \a pill's request \a field's size is set (\a rc_area) using
2184 * req_capsule_set_size() with the given \a len. Then the actual buffer is
2187 void *req_capsule_client_sized_get(struct req_capsule *pill,
2188 const struct req_msg_field *field,
2191 req_capsule_set_size(pill, field, RCL_CLIENT, len);
2192 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
2194 EXPORT_SYMBOL(req_capsule_client_sized_get);
2197 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC reply
2198 * buffer corresponding to the given RMF (\a field) of a \a pill.
2200 void *req_capsule_server_get(struct req_capsule *pill,
2201 const struct req_msg_field *field)
2203 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
2205 EXPORT_SYMBOL(req_capsule_server_get);
2208 * Same as req_capsule_server_get(), but with a \a swabber argument.
2210 * Ideally all swabbing should be done pursuant to RMF definitions, with no
2211 * swabbing done outside this capsule abstraction.
2213 void *req_capsule_server_swab_get(struct req_capsule *pill,
2214 const struct req_msg_field *field,
2217 return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
2219 EXPORT_SYMBOL(req_capsule_server_swab_get);
2222 * Utility that combines req_capsule_set_size() and req_capsule_server_get().
2224 * First the \a pill's request \a field's size is set (\a rc_area) using
2225 * req_capsule_set_size() with the given \a len. Then the actual buffer is
2228 void *req_capsule_server_sized_get(struct req_capsule *pill,
2229 const struct req_msg_field *field,
2232 req_capsule_set_size(pill, field, RCL_SERVER, len);
2233 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
2235 EXPORT_SYMBOL(req_capsule_server_sized_get);
2237 void *req_capsule_server_sized_swab_get(struct req_capsule *pill,
2238 const struct req_msg_field *field,
2239 __u32 len, void *swabber)
2241 req_capsule_set_size(pill, field, RCL_SERVER, len);
2242 return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
2244 EXPORT_SYMBOL(req_capsule_server_sized_swab_get);
2247 * Returns the buffer of a \a pill corresponding to the given \a field from the
2248 * request (if the caller is executing on the server-side) or reply (if the
2249 * caller is executing on the client-side).
2251 * This function convienient for use is code that could be executed on the
2252 * client and server alike.
2254 const void *req_capsule_other_get(struct req_capsule *pill,
2255 const struct req_msg_field *field)
2257 return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL, 0);
2259 EXPORT_SYMBOL(req_capsule_other_get);
2262 * Set the size of the PTLRPC request/reply (\a loc) buffer for the given \a
2263 * field of the given \a pill.
2265 * This function must be used when constructing variable sized fields of a
2268 void req_capsule_set_size(struct req_capsule *pill,
2269 const struct req_msg_field *field,
2270 enum req_location loc, __u32 size)
2272 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2274 if ((size != (__u32)field->rmf_size) &&
2275 (field->rmf_size != -1) &&
2276 !(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
2278 __u32 rmf_size = (__u32)field->rmf_size;
2279 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
2280 (size % rmf_size != 0)) {
2281 CERROR("%s: array field size mismatch "
2282 "%u %% %u != 0 (%d)\n",
2283 field->rmf_name, size, rmf_size, loc);
2285 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
2287 CERROR("%s: field size mismatch %u != %u (%d)\n",
2288 field->rmf_name, size, rmf_size, loc);
2293 pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size;
2295 EXPORT_SYMBOL(req_capsule_set_size);
2298 * Return the actual PTLRPC buffer length of a request or reply (\a loc)
2299 * for the given \a pill's given \a field.
2301 * NB: this function doesn't correspond with req_capsule_set_size(), which
2302 * actually sets the size in pill.rc_area[loc][offset], but this function
2303 * returns the message buflen[offset], maybe we should use another name.
2305 __u32 req_capsule_get_size(const struct req_capsule *pill,
2306 const struct req_msg_field *field,
2307 enum req_location loc)
2309 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2311 return lustre_msg_buflen(__req_msg(pill, loc),
2312 __req_capsule_offset(pill, field, loc));
2314 EXPORT_SYMBOL(req_capsule_get_size);
2317 * Wrapper around lustre_msg_size() that returns the PTLRPC size needed for the
2318 * given \a pill's request or reply (\a loc) given the field size recorded in
2319 * the \a pill's rc_area.
2321 * See also req_capsule_set_size().
2323 __u32 req_capsule_msg_size(struct req_capsule *pill, enum req_location loc)
2325 return lustre_msg_size(pill->rc_req->rq_import->imp_msg_magic,
2326 pill->rc_fmt->rf_fields[loc].nr,
2327 pill->rc_area[loc]);
2331 * While req_capsule_msg_size() computes the size of a PTLRPC request or reply
2332 * (\a loc) given a \a pill's \a rc_area, this function computes the size of a
2333 * PTLRPC request or reply given only an RQF (\a fmt).
2335 * This function should not be used for formats which contain variable size
2338 __u32 req_capsule_fmt_size(__u32 magic, const struct req_format *fmt,
2339 enum req_location loc)
2345 * This function should probably LASSERT() that fmt has no fields with
2346 * RMF_F_STRUCT_ARRAY in rmf_flags, since we can't know here how many
2347 * elements in the array there will ultimately be, but then, we could
2348 * assume that there will be at least one element, and that's just what
2351 size = lustre_msg_hdr_size(magic, fmt->rf_fields[loc].nr);
2355 for (; i < fmt->rf_fields[loc].nr; ++i)
2356 if (fmt->rf_fields[loc].d[i]->rmf_size != -1)
2357 size += cfs_size_round(fmt->rf_fields[loc].d[i]->
2361 EXPORT_SYMBOL(req_capsule_fmt_size);
2364 * Changes the format of an RPC.
2366 * The pill must already have been initialized, which means that it already has
2367 * a request format. The new format \a fmt must be an extension of the pill's
2368 * old format. Specifically: the new format must have as many request and reply
2369 * fields as the old one, and all fields shared by the old and new format must
2370 * be at least as large in the new format.
2372 * The new format's fields may be of different "type" than the old format, but
2373 * only for fields that are "opaque" blobs: fields which have a) have no
2374 * \a rmf_swabber, b) \a rmf_flags == 0 or RMF_F_NO_SIZE_CHECK, and c) \a
2375 * rmf_size == -1 or \a rmf_flags == RMF_F_NO_SIZE_CHECK. For example,
2376 * OBD_SET_INFO has a key field and an opaque value field that gets interpreted
2377 * according to the key field. When the value, according to the key, contains a
2378 * structure (or array thereof) to be swabbed, the format should be changed to
2379 * one where the value field has \a rmf_size/rmf_flags/rmf_swabber set
2382 void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
2387 const struct req_format *old;
2389 LASSERT(pill->rc_fmt != NULL);
2390 LASSERT(__req_format_is_sane(fmt));
2394 * Sanity checking...
2396 for (i = 0; i < RCL_NR; ++i) {
2397 LASSERT(fmt->rf_fields[i].nr >= old->rf_fields[i].nr);
2398 for (j = 0; j < old->rf_fields[i].nr - 1; ++j) {
2399 const struct req_msg_field *ofield = FMT_FIELD(old, i, j);
2401 /* "opaque" fields can be transmogrified */
2402 if (ofield->rmf_swabber == NULL &&
2403 (ofield->rmf_flags & ~RMF_F_NO_SIZE_CHECK) == 0 &&
2404 (ofield->rmf_size == -1 ||
2405 ofield->rmf_flags == RMF_F_NO_SIZE_CHECK))
2407 LASSERT(FMT_FIELD(fmt, i, j) == FMT_FIELD(old, i, j));
2410 * Last field in old format can be shorter than in new.
2412 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
2413 FMT_FIELD(old, i, j)->rmf_size);
2418 EXPORT_SYMBOL(req_capsule_extend);
2421 * This function returns a non-zero value if the given \a field is present in
2422 * the format (\a rc_fmt) of \a pill's PTLRPC request or reply (\a loc), else it
2425 int req_capsule_has_field(const struct req_capsule *pill,
2426 const struct req_msg_field *field,
2427 enum req_location loc)
2429 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2431 return field->rmf_offset[pill->rc_fmt->rf_idx][loc];
2433 EXPORT_SYMBOL(req_capsule_has_field);
2436 * Returns a non-zero value if the given \a field is present in the given \a
2437 * pill's PTLRPC request or reply (\a loc), else it returns 0.
2439 int req_capsule_field_present(const struct req_capsule *pill,
2440 const struct req_msg_field *field,
2441 enum req_location loc)
2445 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2446 LASSERT(req_capsule_has_field(pill, field, loc));
2448 offset = __req_capsule_offset(pill, field, loc);
2449 return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
2451 EXPORT_SYMBOL(req_capsule_field_present);
2454 * This function shrinks the size of the _buffer_ of the \a pill's PTLRPC
2455 * request or reply (\a loc).
2457 * This is not the opposite of req_capsule_extend().
2459 void req_capsule_shrink(struct req_capsule *pill,
2460 const struct req_msg_field *field,
2462 enum req_location loc)
2464 const struct req_format *fmt;
2465 struct lustre_msg *msg;
2470 LASSERT(fmt != NULL);
2471 LASSERT(__req_format_is_sane(fmt));
2472 LASSERT(req_capsule_has_field(pill, field, loc));
2473 LASSERT(req_capsule_field_present(pill, field, loc));
2475 offset = __req_capsule_offset(pill, field, loc);
2477 msg = __req_msg(pill, loc);
2478 len = lustre_msg_buflen(msg, offset);
2479 LASSERTF(newlen <= len, "%s:%s, oldlen=%u, newlen=%u\n",
2480 fmt->rf_name, field->rmf_name, len, newlen);
2482 if (loc == RCL_CLIENT)
2483 pill->rc_req->rq_reqlen = lustre_shrink_msg(msg, offset, newlen,
2486 pill->rc_req->rq_replen = lustre_shrink_msg(msg, offset, newlen,
2489 EXPORT_SYMBOL(req_capsule_shrink);
2491 int req_capsule_server_grow(struct req_capsule *pill,
2492 const struct req_msg_field *field,
2495 struct ptlrpc_reply_state *rs = pill->rc_req->rq_reply_state, *nrs;
2500 LASSERT(pill->rc_fmt != NULL);
2501 LASSERT(__req_format_is_sane(pill->rc_fmt));
2502 LASSERT(req_capsule_has_field(pill, field, RCL_SERVER));
2503 LASSERT(req_capsule_field_present(pill, field, RCL_SERVER));
2505 len = req_capsule_get_size(pill, field, RCL_SERVER);
2506 offset = __req_capsule_offset(pill, field, RCL_SERVER);
2507 if ((__u32)pill->rc_req->rq_repbuf_len >=
2508 lustre_packed_msg_size(pill->rc_req->rq_repmsg) - len + newlen)
2509 CERROR("Inplace repack might be done\n");
2511 pill->rc_req->rq_reply_state = NULL;
2512 req_capsule_set_size(pill, field, RCL_SERVER, newlen);
2513 rc = req_capsule_server_pack(pill);
2515 /* put old rs back, the caller will decide what to do */
2516 pill->rc_req->rq_reply_state = rs;
2519 nrs = pill->rc_req->rq_reply_state;
2520 /* Now we need only buffers, copy first chunk */
2521 to = lustre_msg_buf(nrs->rs_msg, 0, 0);
2522 from = lustre_msg_buf(rs->rs_msg, 0, 0);
2523 len = (char *)lustre_msg_buf(rs->rs_msg, offset, 0) - from;
2524 memcpy(to, from, len);
2525 /* check if we have tail and copy it too */
2526 if (rs->rs_msg->lm_bufcount > offset + 1) {
2527 to = lustre_msg_buf(nrs->rs_msg, offset + 1, 0);
2528 from = lustre_msg_buf(rs->rs_msg, offset + 1, 0);
2529 offset = rs->rs_msg->lm_bufcount - 1;
2530 len = (char *)lustre_msg_buf(rs->rs_msg, offset, 0) +
2531 cfs_size_round(rs->rs_msg->lm_buflens[offset]) - from;
2532 memcpy(to, from, len);
2534 /* drop old reply if everything is fine */
2535 if (rs->rs_difficult) {
2539 nrs->rs_difficult = 1;
2540 nrs->rs_no_ack = rs->rs_no_ack;
2541 nrs->rs_convert_lock = rs->rs_convert_lock;
2542 for (i = 0; i < rs->rs_nlocks; i++) {
2543 nrs->rs_locks[i] = rs->rs_locks[i];
2544 nrs->rs_modes[i] = rs->rs_modes[i];
2548 rs->rs_difficult = 0;
2551 ptlrpc_rs_decref(rs);
2554 EXPORT_SYMBOL(req_capsule_server_grow);
2556 int req_check_sepol(struct req_capsule *pill)
2559 #ifdef HAVE_SERVER_SUPPORT
2560 struct obd_export *export;
2561 struct lu_nodemap *nm = NULL;
2562 const char *sepol = NULL;
2563 const char *nm_sepol = NULL;
2568 export = pill->rc_req->rq_export;
2569 if (!export || !exp_connect_sepol(export) ||
2570 !req_capsule_has_field(pill, &RMF_SELINUX_POL, RCL_CLIENT))
2573 if (req_capsule_get_size(pill, &RMF_SELINUX_POL, RCL_CLIENT) == 0)
2576 sepol = req_capsule_client_get(pill, &RMF_SELINUX_POL);
2577 CDEBUG(D_SEC, "retrieved sepol %s\n", sepol);
2581 nm = nodemap_get_from_exp(export);
2582 if (!IS_ERR_OR_NULL(nm)) {
2583 nm_sepol = nodemap_get_sepol(nm);
2584 if (nm_sepol && nm_sepol[0])
2585 if (sepol == NULL ||
2586 strcmp(sepol, nm_sepol) != 0)
2591 if (!IS_ERR_OR_NULL(nm))
2597 EXPORT_SYMBOL(req_check_sepol);