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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/ptlrpc/layout.c
41 * Lustre Metadata Target (mdt) request handler
43 * Author: Nikita Danilov <nikita@clusterfs.com>
46 * This file contains the "capsule/pill" abstraction layered above PTLRPC.
48 * Every struct ptlrpc_request contains a "pill", which points to a description
49 * of the format that the request conforms to.
52 #if !defined(__REQ_LAYOUT_USER__)
55 # define EXPORT_SYMTAB
57 #define DEBUG_SUBSYSTEM S_RPC
60 #include <linux/module.h>
62 # include <liblustre.h>
65 /* LUSTRE_VERSION_CODE */
66 #include <lustre_ver.h>
68 #include <obd_support.h>
69 /* lustre_swab_mdt_body */
70 #include <lustre/lustre_idl.h>
71 /* obd2cli_tgt() (required by DEBUG_REQ()) */
74 /* __REQ_LAYOUT_USER__ */
76 /* struct ptlrpc_request, lustre_msg* */
77 #include <lustre_req_layout.h>
78 #include <lustre_acl.h>
79 #include <lustre_debug.h>
82 * RQFs (see below) refer to two struct req_msg_field arrays describing the
83 * client request and server reply, respectively.
85 /* empty set of fields... for suitable definition of emptiness. */
86 static const struct req_msg_field *empty[] = {
90 static const struct req_msg_field *mgs_target_info_only[] = {
95 static const struct req_msg_field *mgs_set_info[] = {
100 static const struct req_msg_field *mgs_config_read_client[] = {
105 static const struct req_msg_field *mgs_config_read_server[] = {
110 static const struct req_msg_field *log_cancel_client[] = {
115 static const struct req_msg_field *mdt_body_only[] = {
120 static const struct req_msg_field *mdt_body_capa[] = {
126 static const struct req_msg_field *quotactl_only[] = {
130 static const struct req_msg_field *quota_adjust_qunit_only[] = {
132 &RMF_QUOTA_ADJUST_QUNIT
135 static const struct req_msg_field *qunit_data_only[] = {
140 static const struct req_msg_field *mdt_close_client[] = {
147 static const struct req_msg_field *obd_statfs_server[] = {
152 static const struct req_msg_field *seq_query_client[] = {
158 static const struct req_msg_field *seq_query_server[] = {
163 static const struct req_msg_field *fld_query_client[] = {
169 static const struct req_msg_field *fld_query_server[] = {
174 static const struct req_msg_field *mds_getattr_name_client[] = {
181 static const struct req_msg_field *mds_reint_client[] = {
186 static const struct req_msg_field *mds_reint_create_client[] = {
193 static const struct req_msg_field *mds_reint_create_slave_client[] = {
202 static const struct req_msg_field *mds_reint_create_rmt_acl_client[] = {
211 static const struct req_msg_field *mds_reint_create_sym_client[] = {
220 static const struct req_msg_field *mds_reint_open_client[] = {
229 static const struct req_msg_field *mds_reint_open_server[] = {
238 static const struct req_msg_field *mds_reint_unlink_client[] = {
246 static const struct req_msg_field *mds_reint_link_client[] = {
255 static const struct req_msg_field *mds_reint_rename_client[] = {
265 static const struct req_msg_field *mds_last_unlink_server[] = {
274 static const struct req_msg_field *mds_reint_setattr_client[] = {
284 static const struct req_msg_field *mds_reint_setxattr_client[] = {
292 static const struct req_msg_field *obd_connect_client[] = {
300 static const struct req_msg_field *obd_connect_server[] = {
305 static const struct req_msg_field *obd_set_info_client[] = {
311 static const struct req_msg_field *ost_grant_shrink_client[] = {
317 static const struct req_msg_field *mds_getinfo_client[] = {
323 static const struct req_msg_field *mds_getinfo_server[] = {
328 static const struct req_msg_field *ldlm_enqueue_client[] = {
333 static const struct req_msg_field *ldlm_enqueue_server[] = {
338 static const struct req_msg_field *ldlm_enqueue_lvb_server[] = {
344 static const struct req_msg_field *ldlm_cp_callback_client[] = {
350 static const struct req_msg_field *ldlm_gl_callback_server[] = {
355 static const struct req_msg_field *ldlm_intent_client[] = {
362 static const struct req_msg_field *ldlm_intent_server[] = {
370 static const struct req_msg_field *ldlm_intent_open_server[] = {
380 static const struct req_msg_field *ldlm_intent_getattr_client[] = {
384 &RMF_MDT_BODY, /* coincides with mds_getattr_name_client[] */
389 static const struct req_msg_field *ldlm_intent_getattr_server[] = {
398 static const struct req_msg_field *ldlm_intent_create_client[] = {
402 &RMF_REC_REINT, /* coincides with mds_reint_create_client[] */
408 static const struct req_msg_field *ldlm_intent_open_client[] = {
412 &RMF_REC_REINT, /* coincides with mds_reint_open_client[] */
419 static const struct req_msg_field *ldlm_intent_unlink_client[] = {
423 &RMF_REC_REINT, /* coincides with mds_reint_unlink_client[] */
428 static const struct req_msg_field *mds_getxattr_client[] = {
436 static const struct req_msg_field *mds_getxattr_server[] = {
442 static const struct req_msg_field *mds_getattr_server[] = {
451 static const struct req_msg_field *mds_setattr_server[] = {
460 static const struct req_msg_field *llog_catinfo_client[] = {
466 static const struct req_msg_field *llog_catinfo_server[] = {
471 static const struct req_msg_field *llog_origin_handle_create_client[] = {
477 static const struct req_msg_field *llogd_body_only[] = {
482 static const struct req_msg_field *llog_log_hdr_only[] = {
487 static const struct req_msg_field *llogd_conn_body_only[] = {
492 static const struct req_msg_field *llog_origin_handle_next_block_server[] = {
498 static const struct req_msg_field *ost_body_only[] = {
503 static const struct req_msg_field *ost_body_capa[] = {
509 static const struct req_msg_field *ost_destroy_client[] = {
517 static const struct req_msg_field *ost_brw_client[] = {
525 static const struct req_msg_field *ost_brw_read_server[] = {
530 static const struct req_msg_field *ost_brw_write_server[] = {
536 static const struct req_msg_field *ost_get_info_generic_server[] = {
541 static const struct req_msg_field *ost_get_info_generic_client[] = {
546 static const struct req_msg_field *ost_get_last_id_server[] = {
551 static const struct req_msg_field *ost_get_fiemap_client[] = {
557 static const struct req_msg_field *ost_get_fiemap_server[] = {
562 static struct req_format *req_formats[] = {
568 &RQF_MGS_CONFIG_READ,
577 &RQF_MDS_GETATTR_NAME,
586 &RQF_MDS_DONE_WRITING,
588 &RQF_MDS_REINT_CREATE,
589 &RQF_MDS_REINT_CREATE_RMT_ACL,
590 &RQF_MDS_REINT_CREATE_SLAVE,
591 &RQF_MDS_REINT_CREATE_SYM,
593 &RQF_MDS_REINT_UNLINK,
595 &RQF_MDS_REINT_RENAME,
596 &RQF_MDS_REINT_SETATTR,
597 &RQF_MDS_REINT_SETXATTR,
600 &RQF_MDS_QUOTA_DQACQ,
606 &RQF_OST_QUOTA_ADJUST_QUNIT,
616 &RQF_OST_SET_GRANT_INFO,
617 &RQF_OST_GET_INFO_GENERIC,
618 &RQF_OST_GET_INFO_LAST_ID,
619 &RQF_OST_GET_INFO_FIEMAP,
621 &RQF_LDLM_ENQUEUE_LVB,
625 &RQF_LDLM_CP_CALLBACK,
626 &RQF_LDLM_BL_CALLBACK,
627 &RQF_LDLM_GL_CALLBACK,
629 &RQF_LDLM_INTENT_GETATTR,
630 &RQF_LDLM_INTENT_OPEN,
631 &RQF_LDLM_INTENT_CREATE,
632 &RQF_LDLM_INTENT_UNLINK,
635 &RQF_LLOG_ORIGIN_HANDLE_CREATE,
636 &RQF_LLOG_ORIGIN_HANDLE_DESTROY,
637 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK,
638 &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK,
639 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER,
640 &RQF_LLOG_ORIGIN_CONNECT
643 struct req_msg_field {
644 const __u32 rmf_flags;
645 const char *rmf_name;
647 * Field length. (-1) means "variable length". If the
648 * \a RMF_F_STRUCT_ARRAY flag is set the field is also variable-length,
649 * but the actual size must be a whole multiple of \a rmf_size.
652 void (*rmf_swabber)(void *);
653 void (*rmf_dumper)(void *);
654 int rmf_offset[ARRAY_SIZE(req_formats)][RCL_NR];
659 * The field is a string, must be NUL-terminated.
661 RMF_F_STRING = 1 << 0,
663 * The field's buffer size need not match the declared \a rmf_size.
665 RMF_F_NO_SIZE_CHECK = 1 << 1,
667 * The field's buffer size must be a whole multiple of the declared \a
668 * rmf_size and the \a rmf_swabber function must work on the declared \a
669 * rmf_size worth of bytes.
671 RMF_F_STRUCT_ARRAY = 1 << 2
679 #define DEFINE_MSGF(name, flags, size, swabber, dumper) { \
680 .rmf_name = (name), \
681 .rmf_flags = (flags), \
682 .rmf_size = (size), \
683 .rmf_swabber = (void (*)(void*))(swabber), \
684 .rmf_dumper = (void (*)(void*))(dumper) \
687 struct req_msg_field RMF_GENERIC_DATA =
688 DEFINE_MSGF("generic_data", 0,
690 EXPORT_SYMBOL(RMF_GENERIC_DATA);
692 struct req_msg_field RMF_MGS_TARGET_INFO =
693 DEFINE_MSGF("mgs_target_info", 0,
694 sizeof(struct mgs_target_info),
695 lustre_swab_mgs_target_info, NULL);
696 EXPORT_SYMBOL(RMF_MGS_TARGET_INFO);
698 struct req_msg_field RMF_MGS_SEND_PARAM =
699 DEFINE_MSGF("mgs_send_param", 0,
700 sizeof(struct mgs_send_param),
702 EXPORT_SYMBOL(RMF_MGS_SEND_PARAM);
704 struct req_msg_field RMF_MGS_CONFIG_BODY =
705 DEFINE_MSGF("mgs_config_read request", 0,
706 sizeof(struct mgs_config_body),
707 lustre_swab_mgs_config_body, NULL);
708 EXPORT_SYMBOL(RMF_MGS_CONFIG_BODY);
710 struct req_msg_field RMF_MGS_CONFIG_RES =
711 DEFINE_MSGF("mgs_config_read reply ", 0,
712 sizeof(struct mgs_config_res),
713 lustre_swab_mgs_config_res, NULL);
714 EXPORT_SYMBOL(RMF_MGS_CONFIG_RES);
716 struct req_msg_field RMF_U32 =
717 DEFINE_MSGF("generic u32", 0,
718 sizeof(__u32), lustre_swab_generic_32s, NULL);
719 EXPORT_SYMBOL(RMF_U32);
721 struct req_msg_field RMF_SETINFO_VAL =
722 DEFINE_MSGF("setinfo_val", 0, -1, NULL, NULL);
723 EXPORT_SYMBOL(RMF_SETINFO_VAL);
725 struct req_msg_field RMF_GETINFO_KEY =
726 DEFINE_MSGF("getinfo_key", 0, -1, NULL, NULL);
727 EXPORT_SYMBOL(RMF_GETINFO_KEY);
729 struct req_msg_field RMF_GETINFO_VALLEN =
730 DEFINE_MSGF("getinfo_vallen", 0,
731 sizeof(__u32), lustre_swab_generic_32s, NULL);
732 EXPORT_SYMBOL(RMF_GETINFO_VALLEN);
734 struct req_msg_field RMF_GETINFO_VAL =
735 DEFINE_MSGF("getinfo_val", 0, -1, NULL, NULL);
736 EXPORT_SYMBOL(RMF_GETINFO_VAL);
738 struct req_msg_field RMF_SEQ_OPC =
739 DEFINE_MSGF("seq_query_opc", 0,
740 sizeof(__u32), lustre_swab_generic_32s, NULL);
741 EXPORT_SYMBOL(RMF_SEQ_OPC);
743 struct req_msg_field RMF_SEQ_RANGE =
744 DEFINE_MSGF("seq_query_range", 0,
745 sizeof(struct lu_seq_range),
746 lustre_swab_lu_seq_range, NULL);
747 EXPORT_SYMBOL(RMF_SEQ_RANGE);
749 struct req_msg_field RMF_FLD_OPC =
750 DEFINE_MSGF("fld_query_opc", 0,
751 sizeof(__u32), lustre_swab_generic_32s, NULL);
752 EXPORT_SYMBOL(RMF_FLD_OPC);
754 struct req_msg_field RMF_FLD_MDFLD =
755 DEFINE_MSGF("fld_query_mdfld", 0,
756 sizeof(struct lu_seq_range),
757 lustre_swab_lu_seq_range, NULL);
758 EXPORT_SYMBOL(RMF_FLD_MDFLD);
760 struct req_msg_field RMF_MDT_BODY =
761 DEFINE_MSGF("mdt_body", 0,
762 sizeof(struct mdt_body), lustre_swab_mdt_body, NULL);
763 EXPORT_SYMBOL(RMF_MDT_BODY);
765 struct req_msg_field RMF_OBD_QUOTACTL =
766 DEFINE_MSGF("obd_quotactl", 0,
767 sizeof(struct obd_quotactl),
768 lustre_swab_obd_quotactl, NULL);
769 EXPORT_SYMBOL(RMF_OBD_QUOTACTL);
771 struct req_msg_field RMF_QUOTA_ADJUST_QUNIT =
772 DEFINE_MSGF("quota_adjust_qunit", 0,
773 sizeof(struct quota_adjust_qunit),
774 lustre_swab_quota_adjust_qunit, NULL);
775 EXPORT_SYMBOL(RMF_QUOTA_ADJUST_QUNIT);
777 struct req_msg_field RMF_QUNIT_DATA =
778 DEFINE_MSGF("qunit_data", 0,
779 sizeof(struct qunit_data), lustre_swab_qdata, NULL);
780 EXPORT_SYMBOL(RMF_QUNIT_DATA);
782 struct req_msg_field RMF_MDT_EPOCH =
783 DEFINE_MSGF("mdt_ioepoch", 0,
784 sizeof(struct mdt_ioepoch), lustre_swab_mdt_ioepoch, NULL);
785 EXPORT_SYMBOL(RMF_MDT_EPOCH);
787 struct req_msg_field RMF_PTLRPC_BODY =
788 DEFINE_MSGF("ptlrpc_body", 0,
789 sizeof(struct ptlrpc_body), lustre_swab_ptlrpc_body, NULL);
790 EXPORT_SYMBOL(RMF_PTLRPC_BODY);
792 struct req_msg_field RMF_OBD_STATFS =
793 DEFINE_MSGF("obd_statfs", 0,
794 sizeof(struct obd_statfs), lustre_swab_obd_statfs, NULL);
795 EXPORT_SYMBOL(RMF_OBD_STATFS);
797 struct req_msg_field RMF_SETINFO_KEY =
798 DEFINE_MSGF("setinfo_key", 0, -1, NULL, NULL);
799 EXPORT_SYMBOL(RMF_SETINFO_KEY);
801 struct req_msg_field RMF_NAME =
802 DEFINE_MSGF("name", RMF_F_STRING, -1, NULL, NULL);
803 EXPORT_SYMBOL(RMF_NAME);
805 struct req_msg_field RMF_SYMTGT =
806 DEFINE_MSGF("symtgt", RMF_F_STRING, -1, NULL, NULL);
807 EXPORT_SYMBOL(RMF_SYMTGT);
809 struct req_msg_field RMF_TGTUUID =
810 DEFINE_MSGF("tgtuuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
812 EXPORT_SYMBOL(RMF_TGTUUID);
814 struct req_msg_field RMF_CLUUID =
815 DEFINE_MSGF("cluuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
817 EXPORT_SYMBOL(RMF_CLUUID);
819 struct req_msg_field RMF_STRING =
820 DEFINE_MSGF("string", RMF_F_STRING, -1, NULL, NULL);
821 EXPORT_SYMBOL(RMF_STRING);
823 struct req_msg_field RMF_LLOGD_BODY =
824 DEFINE_MSGF("llogd_body", 0,
825 sizeof(struct llogd_body), lustre_swab_llogd_body, NULL);
826 EXPORT_SYMBOL(RMF_LLOGD_BODY);
828 struct req_msg_field RMF_LLOG_LOG_HDR =
829 DEFINE_MSGF("llog_log_hdr", 0,
830 sizeof(struct llog_log_hdr), lustre_swab_llog_hdr, NULL);
831 EXPORT_SYMBOL(RMF_LLOG_LOG_HDR);
833 struct req_msg_field RMF_LLOGD_CONN_BODY =
834 DEFINE_MSGF("llogd_conn_body", 0,
835 sizeof(struct llogd_conn_body),
836 lustre_swab_llogd_conn_body, NULL);
837 EXPORT_SYMBOL(RMF_LLOGD_CONN_BODY);
840 * connection handle received in MDS_CONNECT request.
842 * No swabbing needed because struct lustre_handle contains only a 64-bit cookie
843 * that the client does not interpret at all.
845 struct req_msg_field RMF_CONN =
846 DEFINE_MSGF("conn", 0, sizeof(struct lustre_handle), NULL, NULL);
847 EXPORT_SYMBOL(RMF_CONN);
849 struct req_msg_field RMF_CONNECT_DATA =
851 RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */,
852 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 0, 0)
853 sizeof(struct obd_connect_data),
855 /* For interoperability with 1.8 and 2.0 clients/servers.
856 * The RPC verification code allows larger RPC buffers, but not
857 * smaller buffers. Until we no longer need to keep compatibility
858 * with older servers/clients we can only check that the buffer
859 * size is at least as large as obd_connect_data_v1. That is not
860 * not in itself harmful, since the chance of just corrupting this
861 * field is low. See JIRA LU-16 for details. */
862 sizeof(struct obd_connect_data_v1),
864 lustre_swab_connect, NULL);
865 EXPORT_SYMBOL(RMF_CONNECT_DATA);
867 struct req_msg_field RMF_DLM_REQ =
868 DEFINE_MSGF("dlm_req", RMF_F_NO_SIZE_CHECK /* ldlm_request_bufsize */,
869 sizeof(struct ldlm_request),
870 lustre_swab_ldlm_request, NULL);
871 EXPORT_SYMBOL(RMF_DLM_REQ);
873 struct req_msg_field RMF_DLM_REP =
874 DEFINE_MSGF("dlm_rep", 0,
875 sizeof(struct ldlm_reply), lustre_swab_ldlm_reply, NULL);
876 EXPORT_SYMBOL(RMF_DLM_REP);
878 struct req_msg_field RMF_LDLM_INTENT =
879 DEFINE_MSGF("ldlm_intent", 0,
880 sizeof(struct ldlm_intent), lustre_swab_ldlm_intent, NULL);
881 EXPORT_SYMBOL(RMF_LDLM_INTENT);
883 struct req_msg_field RMF_DLM_LVB =
884 DEFINE_MSGF("dlm_lvb", 0, sizeof(struct ost_lvb), lustre_swab_ost_lvb,
886 EXPORT_SYMBOL(RMF_DLM_LVB);
888 struct req_msg_field RMF_MDT_MD =
889 DEFINE_MSGF("mdt_md", RMF_F_NO_SIZE_CHECK, MIN_MD_SIZE, NULL, NULL);
890 EXPORT_SYMBOL(RMF_MDT_MD);
892 struct req_msg_field RMF_REC_REINT =
893 DEFINE_MSGF("rec_reint", 0, sizeof(struct mdt_rec_reint),
894 lustre_swab_mdt_rec_reint, NULL);
895 EXPORT_SYMBOL(RMF_REC_REINT);
897 /* FIXME: this length should be defined as a macro */
898 struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1,
900 EXPORT_SYMBOL(RMF_EADATA);
902 struct req_msg_field RMF_ACL =
903 DEFINE_MSGF("acl", RMF_F_NO_SIZE_CHECK,
904 LUSTRE_POSIX_ACL_MAX_SIZE, NULL, NULL);
905 EXPORT_SYMBOL(RMF_ACL);
907 /* FIXME: this should be made to use RMF_F_STRUCT_ARRAY */
908 struct req_msg_field RMF_LOGCOOKIES =
909 DEFINE_MSGF("logcookies", RMF_F_NO_SIZE_CHECK /* multiple cookies */,
910 sizeof(struct llog_cookie), NULL, NULL);
911 EXPORT_SYMBOL(RMF_LOGCOOKIES);
913 struct req_msg_field RMF_CAPA1 =
914 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
915 lustre_swab_lustre_capa, NULL);
916 EXPORT_SYMBOL(RMF_CAPA1);
918 struct req_msg_field RMF_CAPA2 =
919 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
920 lustre_swab_lustre_capa, NULL);
921 EXPORT_SYMBOL(RMF_CAPA2);
926 struct req_msg_field RMF_OST_BODY =
927 DEFINE_MSGF("ost_body", 0,
928 sizeof(struct ost_body), lustre_swab_ost_body, dump_ost_body);
929 EXPORT_SYMBOL(RMF_OST_BODY);
931 struct req_msg_field RMF_OBD_IOOBJ =
932 DEFINE_MSGF("obd_ioobj", RMF_F_STRUCT_ARRAY,
933 sizeof(struct obd_ioobj), lustre_swab_obd_ioobj, dump_ioo);
934 EXPORT_SYMBOL(RMF_OBD_IOOBJ);
936 struct req_msg_field RMF_NIOBUF_REMOTE =
937 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY,
938 sizeof(struct niobuf_remote), lustre_swab_niobuf_remote,
940 EXPORT_SYMBOL(RMF_NIOBUF_REMOTE);
942 struct req_msg_field RMF_RCS =
943 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY, sizeof(__u32),
944 lustre_swab_generic_32s, dump_rcs);
945 EXPORT_SYMBOL(RMF_RCS);
947 struct req_msg_field RMF_OBD_ID =
948 DEFINE_MSGF("obd_id", 0,
949 sizeof(obd_id), lustre_swab_ost_last_id, NULL);
950 EXPORT_SYMBOL(RMF_OBD_ID);
952 struct req_msg_field RMF_FIEMAP_KEY =
953 DEFINE_MSGF("fiemap", 0, sizeof(struct ll_fiemap_info_key),
954 lustre_swab_fiemap, NULL);
955 EXPORT_SYMBOL(RMF_FIEMAP_KEY);
957 struct req_msg_field RMF_FIEMAP_VAL =
958 DEFINE_MSGF("fiemap", 0, -1, lustre_swab_fiemap, NULL);
959 EXPORT_SYMBOL(RMF_FIEMAP_VAL);
970 const struct req_msg_field **d;
974 #define DEFINE_REQ_FMT(name, client, client_nr, server, server_nr) { \
988 #define DEFINE_REQ_FMT0(name, client, server) \
989 DEFINE_REQ_FMT(name, client, ARRAY_SIZE(client), server, ARRAY_SIZE(server))
991 struct req_format RQF_OBD_PING =
992 DEFINE_REQ_FMT0("OBD_PING", empty, empty);
993 EXPORT_SYMBOL(RQF_OBD_PING);
995 struct req_format RQF_OBD_SET_INFO =
996 DEFINE_REQ_FMT0("OBD_SET_INFO", obd_set_info_client, empty);
997 EXPORT_SYMBOL(RQF_OBD_SET_INFO);
999 struct req_format RQF_SEC_CTX =
1000 DEFINE_REQ_FMT0("SEC_CTX", empty, empty);
1001 EXPORT_SYMBOL(RQF_SEC_CTX);
1003 struct req_format RQF_MGS_TARGET_REG =
1004 DEFINE_REQ_FMT0("MGS_TARGET_REG", mgs_target_info_only,
1005 mgs_target_info_only);
1006 EXPORT_SYMBOL(RQF_MGS_TARGET_REG);
1008 struct req_format RQF_MGS_SET_INFO =
1009 DEFINE_REQ_FMT0("MGS_SET_INFO", mgs_set_info,
1011 EXPORT_SYMBOL(RQF_MGS_SET_INFO);
1013 struct req_format RQF_MGS_CONFIG_READ =
1014 DEFINE_REQ_FMT0("MGS_CONFIG_READ", mgs_config_read_client,
1015 mgs_config_read_server);
1016 EXPORT_SYMBOL(RQF_MGS_CONFIG_READ);
1018 struct req_format RQF_SEQ_QUERY =
1019 DEFINE_REQ_FMT0("SEQ_QUERY", seq_query_client, seq_query_server);
1020 EXPORT_SYMBOL(RQF_SEQ_QUERY);
1022 struct req_format RQF_FLD_QUERY =
1023 DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
1024 EXPORT_SYMBOL(RQF_FLD_QUERY);
1026 struct req_format RQF_LOG_CANCEL =
1027 DEFINE_REQ_FMT0("OBD_LOG_CANCEL", log_cancel_client, empty);
1028 EXPORT_SYMBOL(RQF_LOG_CANCEL);
1030 struct req_format RQF_MDS_QUOTACHECK =
1031 DEFINE_REQ_FMT0("MDS_QUOTACHECK", quotactl_only, empty);
1032 EXPORT_SYMBOL(RQF_MDS_QUOTACHECK);
1034 struct req_format RQF_OST_QUOTACHECK =
1035 DEFINE_REQ_FMT0("OST_QUOTACHECK", quotactl_only, empty);
1036 EXPORT_SYMBOL(RQF_OST_QUOTACHECK);
1038 struct req_format RQF_MDS_QUOTACTL =
1039 DEFINE_REQ_FMT0("MDS_QUOTACTL", quotactl_only, quotactl_only);
1040 EXPORT_SYMBOL(RQF_MDS_QUOTACTL);
1042 struct req_format RQF_OST_QUOTACTL =
1043 DEFINE_REQ_FMT0("OST_QUOTACTL", quotactl_only, quotactl_only);
1044 EXPORT_SYMBOL(RQF_OST_QUOTACTL);
1046 struct req_format RQF_OST_QUOTA_ADJUST_QUNIT =
1047 DEFINE_REQ_FMT0("OST_QUOTA_ADJUST_QUNIT", quota_adjust_qunit_only,
1048 quota_adjust_qunit_only);
1049 EXPORT_SYMBOL(RQF_OST_QUOTA_ADJUST_QUNIT);
1051 struct req_format RQF_QC_CALLBACK =
1052 DEFINE_REQ_FMT0("QC_CALLBACK", quotactl_only, empty);
1053 EXPORT_SYMBOL(RQF_QC_CALLBACK);
1055 struct req_format RQF_MDS_QUOTA_DQACQ =
1056 DEFINE_REQ_FMT0("MDS_QUOTA_DQACQ", qunit_data_only, qunit_data_only);
1057 EXPORT_SYMBOL(RQF_MDS_QUOTA_DQACQ);
1059 struct req_format RQF_MDS_GETSTATUS =
1060 DEFINE_REQ_FMT0("MDS_GETSTATUS", mdt_body_only, mdt_body_capa);
1061 EXPORT_SYMBOL(RQF_MDS_GETSTATUS);
1063 struct req_format RQF_MDS_STATFS =
1064 DEFINE_REQ_FMT0("MDS_STATFS", empty, obd_statfs_server);
1065 EXPORT_SYMBOL(RQF_MDS_STATFS);
1067 struct req_format RQF_MDS_SYNC =
1068 DEFINE_REQ_FMT0("MDS_SYNC", mdt_body_capa, mdt_body_only);
1069 EXPORT_SYMBOL(RQF_MDS_SYNC);
1071 struct req_format RQF_MDS_GETATTR =
1072 DEFINE_REQ_FMT0("MDS_GETATTR", mdt_body_capa, mds_getattr_server);
1073 EXPORT_SYMBOL(RQF_MDS_GETATTR);
1075 struct req_format RQF_MDS_GETXATTR =
1076 DEFINE_REQ_FMT0("MDS_GETXATTR",
1077 mds_getxattr_client, mds_getxattr_server);
1078 EXPORT_SYMBOL(RQF_MDS_GETXATTR);
1080 struct req_format RQF_MDS_GETATTR_NAME =
1081 DEFINE_REQ_FMT0("MDS_GETATTR_NAME",
1082 mds_getattr_name_client, mds_getattr_server);
1083 EXPORT_SYMBOL(RQF_MDS_GETATTR_NAME);
1085 struct req_format RQF_MDS_REINT =
1086 DEFINE_REQ_FMT0("MDS_REINT", mds_reint_client, mdt_body_only);
1087 EXPORT_SYMBOL(RQF_MDS_REINT);
1089 struct req_format RQF_MDS_REINT_CREATE =
1090 DEFINE_REQ_FMT0("MDS_REINT_CREATE",
1091 mds_reint_create_client, mdt_body_capa);
1092 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE);
1094 struct req_format RQF_MDS_REINT_CREATE_RMT_ACL =
1095 DEFINE_REQ_FMT0("MDS_REINT_CREATE_RMT_ACL",
1096 mds_reint_create_rmt_acl_client, mdt_body_capa);
1097 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_RMT_ACL);
1099 struct req_format RQF_MDS_REINT_CREATE_SLAVE =
1100 DEFINE_REQ_FMT0("MDS_REINT_CREATE_EA",
1101 mds_reint_create_slave_client, mdt_body_capa);
1102 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SLAVE);
1104 struct req_format RQF_MDS_REINT_CREATE_SYM =
1105 DEFINE_REQ_FMT0("MDS_REINT_CREATE_SYM",
1106 mds_reint_create_sym_client, mdt_body_capa);
1107 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SYM);
1109 struct req_format RQF_MDS_REINT_OPEN =
1110 DEFINE_REQ_FMT0("MDS_REINT_OPEN",
1111 mds_reint_open_client, mds_reint_open_server);
1112 EXPORT_SYMBOL(RQF_MDS_REINT_OPEN);
1114 struct req_format RQF_MDS_REINT_UNLINK =
1115 DEFINE_REQ_FMT0("MDS_REINT_UNLINK", mds_reint_unlink_client,
1116 mds_last_unlink_server);
1117 EXPORT_SYMBOL(RQF_MDS_REINT_UNLINK);
1119 struct req_format RQF_MDS_REINT_LINK =
1120 DEFINE_REQ_FMT0("MDS_REINT_LINK",
1121 mds_reint_link_client, mdt_body_only);
1122 EXPORT_SYMBOL(RQF_MDS_REINT_LINK);
1124 struct req_format RQF_MDS_REINT_RENAME =
1125 DEFINE_REQ_FMT0("MDS_REINT_RENAME", mds_reint_rename_client,
1126 mds_last_unlink_server);
1127 EXPORT_SYMBOL(RQF_MDS_REINT_RENAME);
1129 struct req_format RQF_MDS_REINT_SETATTR =
1130 DEFINE_REQ_FMT0("MDS_REINT_SETATTR",
1131 mds_reint_setattr_client, mds_setattr_server);
1132 EXPORT_SYMBOL(RQF_MDS_REINT_SETATTR);
1134 struct req_format RQF_MDS_REINT_SETXATTR =
1135 DEFINE_REQ_FMT0("MDS_REINT_SETXATTR",
1136 mds_reint_setxattr_client, mdt_body_only);
1137 EXPORT_SYMBOL(RQF_MDS_REINT_SETXATTR);
1139 struct req_format RQF_MDS_CONNECT =
1140 DEFINE_REQ_FMT0("MDS_CONNECT",
1141 obd_connect_client, obd_connect_server);
1142 EXPORT_SYMBOL(RQF_MDS_CONNECT);
1144 struct req_format RQF_MDS_DISCONNECT =
1145 DEFINE_REQ_FMT0("MDS_DISCONNECT", empty, empty);
1146 EXPORT_SYMBOL(RQF_MDS_DISCONNECT);
1148 struct req_format RQF_MDS_GET_INFO =
1149 DEFINE_REQ_FMT0("MDS_GET_INFO", mds_getinfo_client,
1150 mds_getinfo_server);
1151 EXPORT_SYMBOL(RQF_MDS_GET_INFO);
1153 struct req_format RQF_LDLM_ENQUEUE =
1154 DEFINE_REQ_FMT0("LDLM_ENQUEUE",
1155 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1156 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE);
1158 struct req_format RQF_LDLM_ENQUEUE_LVB =
1159 DEFINE_REQ_FMT0("LDLM_ENQUEUE_LVB",
1160 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1161 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE_LVB);
1163 struct req_format RQF_LDLM_CONVERT =
1164 DEFINE_REQ_FMT0("LDLM_CONVERT",
1165 ldlm_enqueue_client, ldlm_enqueue_server);
1166 EXPORT_SYMBOL(RQF_LDLM_CONVERT);
1168 struct req_format RQF_LDLM_CANCEL =
1169 DEFINE_REQ_FMT0("LDLM_CANCEL", ldlm_enqueue_client, empty);
1170 EXPORT_SYMBOL(RQF_LDLM_CANCEL);
1172 struct req_format RQF_LDLM_CALLBACK =
1173 DEFINE_REQ_FMT0("LDLM_CALLBACK", ldlm_enqueue_client, empty);
1174 EXPORT_SYMBOL(RQF_LDLM_CALLBACK);
1176 struct req_format RQF_LDLM_CP_CALLBACK =
1177 DEFINE_REQ_FMT0("LDLM_CP_CALLBACK", ldlm_cp_callback_client, empty);
1178 EXPORT_SYMBOL(RQF_LDLM_CP_CALLBACK);
1180 struct req_format RQF_LDLM_BL_CALLBACK =
1181 DEFINE_REQ_FMT0("LDLM_BL_CALLBACK", ldlm_enqueue_client, empty);
1182 EXPORT_SYMBOL(RQF_LDLM_BL_CALLBACK);
1184 struct req_format RQF_LDLM_GL_CALLBACK =
1185 DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_enqueue_client,
1186 ldlm_gl_callback_server);
1187 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK);
1189 struct req_format RQF_LDLM_INTENT =
1190 DEFINE_REQ_FMT0("LDLM_INTENT",
1191 ldlm_intent_client, ldlm_intent_server);
1192 EXPORT_SYMBOL(RQF_LDLM_INTENT);
1194 struct req_format RQF_LDLM_INTENT_GETATTR =
1195 DEFINE_REQ_FMT0("LDLM_INTENT_GETATTR",
1196 ldlm_intent_getattr_client, ldlm_intent_getattr_server);
1197 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETATTR);
1199 struct req_format RQF_LDLM_INTENT_OPEN =
1200 DEFINE_REQ_FMT0("LDLM_INTENT_OPEN",
1201 ldlm_intent_open_client, ldlm_intent_open_server);
1202 EXPORT_SYMBOL(RQF_LDLM_INTENT_OPEN);
1204 struct req_format RQF_LDLM_INTENT_CREATE =
1205 DEFINE_REQ_FMT0("LDLM_INTENT_CREATE",
1206 ldlm_intent_create_client, ldlm_intent_getattr_server);
1207 EXPORT_SYMBOL(RQF_LDLM_INTENT_CREATE);
1209 struct req_format RQF_LDLM_INTENT_UNLINK =
1210 DEFINE_REQ_FMT0("LDLM_INTENT_UNLINK",
1211 ldlm_intent_unlink_client, ldlm_intent_server);
1212 EXPORT_SYMBOL(RQF_LDLM_INTENT_UNLINK);
1214 struct req_format RQF_MDS_CLOSE =
1215 DEFINE_REQ_FMT0("MDS_CLOSE",
1216 mdt_close_client, mds_last_unlink_server);
1217 EXPORT_SYMBOL(RQF_MDS_CLOSE);
1219 struct req_format RQF_MDS_PIN =
1220 DEFINE_REQ_FMT0("MDS_PIN",
1221 mdt_body_capa, mdt_body_only);
1222 EXPORT_SYMBOL(RQF_MDS_PIN);
1224 struct req_format RQF_MDS_UNPIN =
1225 DEFINE_REQ_FMT0("MDS_UNPIN", mdt_body_only, empty);
1226 EXPORT_SYMBOL(RQF_MDS_UNPIN);
1228 struct req_format RQF_MDS_DONE_WRITING =
1229 DEFINE_REQ_FMT0("MDS_DONE_WRITING",
1230 mdt_close_client, mdt_body_only);
1231 EXPORT_SYMBOL(RQF_MDS_DONE_WRITING);
1233 struct req_format RQF_MDS_READPAGE =
1234 DEFINE_REQ_FMT0("MDS_READPAGE",
1235 mdt_body_capa, mdt_body_only);
1236 EXPORT_SYMBOL(RQF_MDS_READPAGE);
1238 /* This is for split */
1239 struct req_format RQF_MDS_WRITEPAGE =
1240 DEFINE_REQ_FMT0("MDS_WRITEPAGE",
1241 mdt_body_capa, mdt_body_only);
1242 EXPORT_SYMBOL(RQF_MDS_WRITEPAGE);
1244 struct req_format RQF_MDS_IS_SUBDIR =
1245 DEFINE_REQ_FMT0("MDS_IS_SUBDIR",
1246 mdt_body_only, mdt_body_only);
1247 EXPORT_SYMBOL(RQF_MDS_IS_SUBDIR);
1249 struct req_format RQF_LLOG_CATINFO =
1250 DEFINE_REQ_FMT0("LLOG_CATINFO",
1251 llog_catinfo_client, llog_catinfo_server);
1252 EXPORT_SYMBOL(RQF_LLOG_CATINFO);
1254 struct req_format RQF_LLOG_ORIGIN_HANDLE_CREATE =
1255 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_CREATE",
1256 llog_origin_handle_create_client, llogd_body_only);
1257 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_CREATE);
1259 struct req_format RQF_LLOG_ORIGIN_HANDLE_DESTROY =
1260 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_DESTROY",
1261 llogd_body_only, llogd_body_only);
1262 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1264 struct req_format RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK =
1265 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_NEXT_BLOCK",
1266 llogd_body_only, llog_origin_handle_next_block_server);
1267 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1269 struct req_format RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK =
1270 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_PREV_BLOCK",
1271 llogd_body_only, llog_origin_handle_next_block_server);
1272 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1274 struct req_format RQF_LLOG_ORIGIN_HANDLE_READ_HEADER =
1275 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_READ_HEADER",
1276 llogd_body_only, llog_log_hdr_only);
1277 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1279 struct req_format RQF_LLOG_ORIGIN_CONNECT =
1280 DEFINE_REQ_FMT0("LLOG_ORIGIN_CONNECT", llogd_conn_body_only, empty);
1281 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_CONNECT);
1283 struct req_format RQF_OST_CONNECT =
1284 DEFINE_REQ_FMT0("OST_CONNECT",
1285 obd_connect_client, obd_connect_server);
1286 EXPORT_SYMBOL(RQF_OST_CONNECT);
1288 struct req_format RQF_OST_DISCONNECT =
1289 DEFINE_REQ_FMT0("OST_DISCONNECT", empty, empty);
1290 EXPORT_SYMBOL(RQF_OST_DISCONNECT);
1292 struct req_format RQF_OST_GETATTR =
1293 DEFINE_REQ_FMT0("OST_GETATTR", ost_body_capa, ost_body_only);
1294 EXPORT_SYMBOL(RQF_OST_GETATTR);
1296 struct req_format RQF_OST_SETATTR =
1297 DEFINE_REQ_FMT0("OST_SETATTR", ost_body_capa, ost_body_only);
1298 EXPORT_SYMBOL(RQF_OST_SETATTR);
1300 struct req_format RQF_OST_CREATE =
1301 DEFINE_REQ_FMT0("OST_CREATE", ost_body_only, ost_body_only);
1302 EXPORT_SYMBOL(RQF_OST_CREATE);
1304 struct req_format RQF_OST_PUNCH =
1305 DEFINE_REQ_FMT0("OST_PUNCH", ost_body_capa, ost_body_only);
1306 EXPORT_SYMBOL(RQF_OST_PUNCH);
1308 struct req_format RQF_OST_SYNC =
1309 DEFINE_REQ_FMT0("OST_SYNC", ost_body_capa, ost_body_only);
1310 EXPORT_SYMBOL(RQF_OST_SYNC);
1312 struct req_format RQF_OST_DESTROY =
1313 DEFINE_REQ_FMT0("OST_DESTROY", ost_destroy_client, ost_body_only);
1314 EXPORT_SYMBOL(RQF_OST_DESTROY);
1316 struct req_format RQF_OST_BRW_READ =
1317 DEFINE_REQ_FMT0("OST_BRW_READ", ost_brw_client, ost_brw_read_server);
1318 EXPORT_SYMBOL(RQF_OST_BRW_READ);
1320 struct req_format RQF_OST_BRW_WRITE =
1321 DEFINE_REQ_FMT0("OST_BRW_WRITE", ost_brw_client, ost_brw_write_server);
1322 EXPORT_SYMBOL(RQF_OST_BRW_WRITE);
1324 struct req_format RQF_OST_STATFS =
1325 DEFINE_REQ_FMT0("OST_STATFS", empty, obd_statfs_server);
1326 EXPORT_SYMBOL(RQF_OST_STATFS);
1328 struct req_format RQF_OST_SET_GRANT_INFO =
1329 DEFINE_REQ_FMT0("OST_SET_GRANT_INFO", ost_grant_shrink_client,
1331 EXPORT_SYMBOL(RQF_OST_SET_GRANT_INFO);
1333 struct req_format RQF_OST_GET_INFO_GENERIC =
1334 DEFINE_REQ_FMT0("OST_GET_INFO", ost_get_info_generic_client,
1335 ost_get_info_generic_server);
1336 EXPORT_SYMBOL(RQF_OST_GET_INFO_GENERIC);
1338 struct req_format RQF_OST_GET_INFO_LAST_ID =
1339 DEFINE_REQ_FMT0("OST_GET_INFO_LAST_ID", ost_get_info_generic_client,
1340 ost_get_last_id_server);
1341 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_ID);
1343 struct req_format RQF_OST_GET_INFO_FIEMAP =
1344 DEFINE_REQ_FMT0("OST_GET_INFO_FIEMAP", ost_get_fiemap_client,
1345 ost_get_fiemap_server);
1346 EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP);
1349 #if !defined(__REQ_LAYOUT_USER__)
1351 /* Convenience macro */
1352 #define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1355 * Initializes the capsule abstraction by computing and setting the \a rf_idx
1356 * field of RQFs and the \a rmf_offset field of RMFs.
1358 int req_layout_init(void)
1363 struct req_format *rf = NULL;
1365 for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
1366 rf = req_formats[i];
1368 for (j = 0; j < RCL_NR; ++j) {
1369 LASSERT(rf->rf_fields[j].nr <= REQ_MAX_FIELD_NR);
1370 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
1371 struct req_msg_field *field;
1373 field = (typeof(field))rf->rf_fields[j].d[k];
1374 LASSERT(!(field->rmf_flags & RMF_F_STRUCT_ARRAY)
1375 || field->rmf_size > 0);
1376 LASSERT(field->rmf_offset[i][j] == 0);
1378 * k + 1 to detect unused format/field
1381 field->rmf_offset[i][j] = k + 1;
1387 EXPORT_SYMBOL(req_layout_init);
1389 void req_layout_fini(void)
1392 EXPORT_SYMBOL(req_layout_fini);
1395 * Initializes the expected sizes of each RMF in a \a pill (\a rc_area) to -1.
1397 * Actual/expected field sizes are set elsewhere in functions in this file:
1398 * req_capsule_init(), req_capsule_server_pack(), req_capsule_set_size() and
1399 * req_capsule_msg_size(). The \a rc_area information is used by.
1400 * ptlrpc_request_set_replen().
1402 void req_capsule_init_area(struct req_capsule *pill)
1406 for (i = 0; i < ARRAY_SIZE(pill->rc_area[RCL_CLIENT]); i++) {
1407 pill->rc_area[RCL_CLIENT][i] = -1;
1408 pill->rc_area[RCL_SERVER][i] = -1;
1411 EXPORT_SYMBOL(req_capsule_init_area);
1414 * Initialize a pill.
1416 * The \a location indicates whether the caller is executing on the client side
1417 * (RCL_CLIENT) or server side (RCL_SERVER)..
1419 void req_capsule_init(struct req_capsule *pill,
1420 struct ptlrpc_request *req,
1421 enum req_location location)
1423 LASSERT(location == RCL_SERVER || location == RCL_CLIENT);
1426 * Today all capsules are embedded in ptlrpc_request structs,
1427 * but just in case that ever isn't the case, we don't reach
1428 * into req unless req != NULL and pill is the one embedded in
1431 * The req->rq_pill_init flag makes it safe to initialize a pill
1432 * twice, which might happen in the OST paths as a result of the
1433 * high-priority RPC queue getting peeked at before ost_handle()
1434 * handles an OST RPC.
1436 if (req != NULL && pill == &req->rq_pill && req->rq_pill_init)
1439 memset(pill, 0, sizeof *pill);
1441 pill->rc_loc = location;
1442 req_capsule_init_area(pill);
1444 if (req != NULL && pill == &req->rq_pill)
1445 req->rq_pill_init = 1;
1447 EXPORT_SYMBOL(req_capsule_init);
1449 void req_capsule_fini(struct req_capsule *pill)
1452 EXPORT_SYMBOL(req_capsule_fini);
1454 static int __req_format_is_sane(const struct req_format *fmt)
1457 0 <= fmt->rf_idx && fmt->rf_idx < ARRAY_SIZE(req_formats) &&
1458 req_formats[fmt->rf_idx] == fmt;
1461 static struct lustre_msg *__req_msg(const struct req_capsule *pill,
1462 enum req_location loc)
1464 struct ptlrpc_request *req;
1467 return loc == RCL_CLIENT ? req->rq_reqmsg : req->rq_repmsg;
1471 * Set the format (\a fmt) of a \a pill; format changes are not allowed here
1472 * (see req_capsule_extend()).
1474 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt)
1476 LASSERT(pill->rc_fmt == NULL || pill->rc_fmt == fmt);
1477 LASSERT(__req_format_is_sane(fmt));
1481 EXPORT_SYMBOL(req_capsule_set);
1484 * Fills in any parts of the \a rc_area of a \a pill that haven't been filled in
1487 * \a rc_area is an array of REQ_MAX_FIELD_NR elements, used to store sizes of
1488 * variable-sized fields. The field sizes come from the declared \a rmf_size
1489 * field of a \a pill's \a rc_fmt's RMF's.
1491 int req_capsule_filled_sizes(struct req_capsule *pill,
1492 enum req_location loc)
1494 const struct req_format *fmt = pill->rc_fmt;
1497 LASSERT(fmt != NULL);
1499 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1500 if (pill->rc_area[loc][i] == -1) {
1501 pill->rc_area[loc][i] =
1502 fmt->rf_fields[loc].d[i]->rmf_size;
1503 if (pill->rc_area[loc][i] == -1) {
1505 * Skip the following fields.
1507 * If this LASSERT() trips then you're missing a
1508 * call to req_capsule_set_size().
1510 LASSERT(loc != RCL_SERVER);
1517 EXPORT_SYMBOL(req_capsule_filled_sizes);
1520 * Capsule equivalent of lustre_pack_request() and lustre_pack_reply().
1522 * This function uses the \a pill's \a rc_area as filled in by
1523 * req_capsule_set_size() or req_capsule_filled_sizes() (the latter is called by
1526 int req_capsule_server_pack(struct req_capsule *pill)
1528 const struct req_format *fmt;
1532 LASSERT(pill->rc_loc == RCL_SERVER);
1534 LASSERT(fmt != NULL);
1536 count = req_capsule_filled_sizes(pill, RCL_SERVER);
1537 rc = lustre_pack_reply(pill->rc_req, count,
1538 pill->rc_area[RCL_SERVER], NULL);
1540 DEBUG_REQ(D_ERROR, pill->rc_req,
1541 "Cannot pack %d fields in format `%s': ",
1542 count, fmt->rf_name);
1546 EXPORT_SYMBOL(req_capsule_server_pack);
1549 * Returns the PTLRPC request or reply (\a loc) buffer offset of a \a pill
1550 * corresponding to the given RMF (\a field).
1552 static int __req_capsule_offset(const struct req_capsule *pill,
1553 const struct req_msg_field *field,
1554 enum req_location loc)
1558 offset = field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1559 LASSERTF(offset > 0, "%s:%s, off=%d, loc=%d\n",
1560 pill->rc_fmt->rf_name,
1561 field->rmf_name, offset, loc);
1564 LASSERT(0 <= offset && offset < REQ_MAX_FIELD_NR);
1569 * Helper for __req_capsule_get(); swabs value / array of values and/or dumps
1574 swabber_dumper_helper(struct req_capsule *pill,
1575 const struct req_msg_field *field,
1576 enum req_location loc,
1578 void *value, int len, int dump, void (*swabber)( void *))
1584 int inout = loc == RCL_CLIENT;
1586 swabber = swabber ?: field->rmf_swabber;
1588 if (ptlrpc_buf_need_swab(pill->rc_req, inout, offset) &&
1589 swabber != NULL && value != NULL)
1594 if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY)) {
1595 if (dump && field->rmf_dumper) {
1596 CDEBUG(D_RPCTRACE, "Dump of %sfield %s follows\n",
1597 do_swab ? "unswabbed " : "", field->rmf_name);
1598 field->rmf_dumper(value);
1603 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1605 CDEBUG(D_RPCTRACE, "Dump of swabbed field %s "
1606 "follows\n", field->rmf_name);
1607 field->rmf_dumper(value);
1614 * We're swabbing an array; swabber() swabs a single array element, so
1615 * swab every element.
1617 LASSERT((len % field->rmf_size) == 0);
1618 for (p = value, i = 0, n = len / field->rmf_size;
1620 i++, p += field->rmf_size) {
1621 if (dump && field->rmf_dumper) {
1622 CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, "
1623 "element %d follows\n",
1624 do_swab ? "unswabbed " : "", field->rmf_name, i);
1625 field->rmf_dumper(p);
1630 if (dump && field->rmf_dumper) {
1631 CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, "
1632 "element %d follows\n", field->rmf_name, i);
1633 field->rmf_dumper(value);
1637 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1641 * Returns the pointer to a PTLRPC request or reply (\a loc) buffer of a \a pill
1642 * corresponding to the given RMF (\a field).
1644 * The buffer will be swabbed using the given \a swabber. If \a swabber == NULL
1645 * then the \a rmf_swabber from the RMF will be used. Soon there will be no
1646 * calls to __req_capsule_get() with a non-NULL \a swabber; \a swabber will then
1647 * be removed. Fields with the \a RMF_F_STRUCT_ARRAY flag set will have each
1648 * element of the array swabbed.
1650 static void *__req_capsule_get(struct req_capsule *pill,
1651 const struct req_msg_field *field,
1652 enum req_location loc,
1653 void (*swabber)( void *),
1656 const struct req_format *fmt;
1657 struct lustre_msg *msg;
1662 void *(*getter)(struct lustre_msg *m, int n, int minlen);
1664 static const char *rcl_names[RCL_NR] = {
1665 [RCL_CLIENT] = "client",
1666 [RCL_SERVER] = "server"
1669 LASSERT(pill != NULL);
1670 LASSERT(pill != LP_POISON);
1672 LASSERT(fmt != NULL);
1673 LASSERT(fmt != LP_POISON);
1674 LASSERT(__req_format_is_sane(fmt));
1676 offset = __req_capsule_offset(pill, field, loc);
1678 msg = __req_msg(pill, loc);
1679 LASSERT(msg != NULL);
1681 getter = (field->rmf_flags & RMF_F_STRING) ?
1682 (typeof(getter))lustre_msg_string : lustre_msg_buf;
1684 if (field->rmf_flags & RMF_F_STRUCT_ARRAY) {
1686 * We've already asserted that field->rmf_size > 0 in
1687 * req_layout_init().
1689 len = lustre_msg_buflen(msg, offset);
1690 if ((len % field->rmf_size) != 0) {
1691 CERROR("%s: array field size mismatch "
1692 "%d modulo %d != 0 (%d)\n",
1693 field->rmf_name, len, field->rmf_size, loc);
1696 } else if (pill->rc_area[loc][offset] != -1) {
1697 len = pill->rc_area[loc][offset];
1699 len = max(field->rmf_size, 0);
1701 value = getter(msg, offset, len);
1703 if (value == NULL) {
1704 DEBUG_REQ(D_ERROR, pill->rc_req,
1705 "Wrong buffer for field `%s' (%d of %d) "
1706 "in format `%s': %d vs. %d (%s)\n",
1707 field->rmf_name, offset, lustre_msg_bufcount(msg),
1708 fmt->rf_name, lustre_msg_buflen(msg, offset), len,
1711 swabber_dumper_helper(pill, field, loc, offset, value, len,
1719 * Dump a request and/or reply
1721 void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
1723 const struct req_format *fmt;
1724 const struct req_msg_field *field;
1730 DEBUG_REQ(D_RPCTRACE, pill->rc_req, "BEGIN REQ CAPSULE DUMP\n");
1731 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1732 field = FMT_FIELD(fmt, loc, i);
1733 if (field->rmf_dumper == NULL) {
1735 * FIXME Add a default hex dumper for fields that don't
1736 * have a specific dumper
1738 len = req_capsule_get_size(pill, field, loc);
1739 CDEBUG(D_RPCTRACE, "Field %s has no dumper function;"
1740 "field size is %d\n", field->rmf_name, len);
1742 /* It's the dumping side-effect that we're interested in */
1743 (void) __req_capsule_get(pill, field, loc, NULL, 1);
1746 CDEBUG(D_RPCTRACE, "END REQ CAPSULE DUMP\n");
1752 void req_capsule_client_dump(struct req_capsule *pill)
1754 __req_capsule_dump(pill, RCL_CLIENT);
1756 EXPORT_SYMBOL(req_capsule_client_dump);
1761 void req_capsule_server_dump(struct req_capsule *pill)
1763 __req_capsule_dump(pill, RCL_SERVER);
1765 EXPORT_SYMBOL(req_capsule_server_dump);
1768 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC request
1769 * buffer corresponding to the given RMF (\a field) of a \a pill.
1771 void *req_capsule_client_get(struct req_capsule *pill,
1772 const struct req_msg_field *field)
1774 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1776 EXPORT_SYMBOL(req_capsule_client_get);
1779 * Same as req_capsule_client_get(), but with a \a swabber argument.
1781 * Currently unused; will be removed when req_capsule_server_swab_get() is
1784 void *req_capsule_client_swab_get(struct req_capsule *pill,
1785 const struct req_msg_field *field,
1786 void (*swabber)(void* ))
1788 return __req_capsule_get(pill, field, RCL_CLIENT, swabber, 0);
1790 EXPORT_SYMBOL(req_capsule_client_swab_get);
1793 * Utility that combines req_capsule_set_size() and req_capsule_client_get().
1795 * First the \a pill's request \a field's size is set (\a rc_area) using
1796 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1799 void *req_capsule_client_sized_get(struct req_capsule *pill,
1800 const struct req_msg_field *field,
1803 req_capsule_set_size(pill, field, RCL_CLIENT, len);
1804 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1806 EXPORT_SYMBOL(req_capsule_client_sized_get);
1809 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC reply
1810 * buffer corresponding to the given RMF (\a field) of a \a pill.
1812 void *req_capsule_server_get(struct req_capsule *pill,
1813 const struct req_msg_field *field)
1815 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1817 EXPORT_SYMBOL(req_capsule_server_get);
1820 * Same as req_capsule_server_get(), but with a \a swabber argument.
1822 * Ideally all swabbing should be done pursuant to RMF definitions, with no
1823 * swabbing done outside this capsule abstraction.
1825 void *req_capsule_server_swab_get(struct req_capsule *pill,
1826 const struct req_msg_field *field,
1829 return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
1831 EXPORT_SYMBOL(req_capsule_server_swab_get);
1834 * Utility that combines req_capsule_set_size() and req_capsule_server_get().
1836 * First the \a pill's request \a field's size is set (\a rc_area) using
1837 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1840 void *req_capsule_server_sized_get(struct req_capsule *pill,
1841 const struct req_msg_field *field,
1844 req_capsule_set_size(pill, field, RCL_SERVER, len);
1845 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1847 EXPORT_SYMBOL(req_capsule_server_sized_get);
1850 * Returns the buffer of a \a pill corresponding to the given \a field from the
1851 * request (if the caller is executing on the server-side) or reply (if the
1852 * caller is executing on the client-side).
1854 * This function convienient for use is code that could be executed on the
1855 * client and server alike.
1857 const void *req_capsule_other_get(struct req_capsule *pill,
1858 const struct req_msg_field *field)
1860 return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL, 0);
1862 EXPORT_SYMBOL(req_capsule_other_get);
1865 * Set the size of the PTLRPC request/reply (\a loc) buffer for the given \a
1866 * field of the given \a pill.
1868 * This function must be used when constructing variable sized fields of a
1871 void req_capsule_set_size(struct req_capsule *pill,
1872 const struct req_msg_field *field,
1873 enum req_location loc, int size)
1875 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1877 if ((size != field->rmf_size) &&
1878 (field->rmf_size != -1) &&
1879 !(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
1881 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1882 (size % field->rmf_size != 0)) {
1883 CERROR("%s: array field size mismatch "
1884 "%d %% %d != 0 (%d)\n",
1885 field->rmf_name, size, field->rmf_size, loc);
1887 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1888 size < field->rmf_size) {
1889 CERROR("%s: field size mismatch %d != %d (%d)\n",
1890 field->rmf_name, size, field->rmf_size, loc);
1895 pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size;
1897 EXPORT_SYMBOL(req_capsule_set_size);
1900 * Return the actual PTLRPC buffer length of a request or reply (\a loc)
1901 * for the given \a pill's given \a field.
1903 * NB: this function doesn't correspond with req_capsule_set_size(), which
1904 * actually sets the size in pill.rc_area[loc][offset], but this function
1905 * returns the message buflen[offset], maybe we should use another name.
1907 int req_capsule_get_size(const struct req_capsule *pill,
1908 const struct req_msg_field *field,
1909 enum req_location loc)
1911 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1913 return lustre_msg_buflen(__req_msg(pill, loc),
1914 __req_capsule_offset(pill, field, loc));
1916 EXPORT_SYMBOL(req_capsule_get_size);
1919 * Wrapper around lustre_msg_size() that returns the PTLRPC size needed for the
1920 * given \a pill's request or reply (\a loc) given the field size recorded in
1921 * the \a pill's rc_area.
1923 * See also req_capsule_set_size().
1925 int req_capsule_msg_size(struct req_capsule *pill, enum req_location loc)
1927 return lustre_msg_size(pill->rc_req->rq_import->imp_msg_magic,
1928 pill->rc_fmt->rf_fields[loc].nr,
1929 pill->rc_area[loc]);
1933 * While req_capsule_msg_size() computes the size of a PTLRPC request or reply
1934 * (\a loc) given a \a pill's \a rc_area, this function computes the size of a
1935 * PTLRPC request or reply given only an RQF (\a fmt).
1937 * This function should not be used for formats which contain variable size
1940 int req_capsule_fmt_size(__u32 magic, const struct req_format *fmt,
1941 enum req_location loc)
1946 * This function should probably LASSERT() that fmt has no fields with
1947 * RMF_F_STRUCT_ARRAY in rmf_flags, since we can't know here how many
1948 * elements in the array there will ultimately be, but then, we could
1949 * assume that there will be at least one element, and that's just what
1952 size = lustre_msg_hdr_size(magic, fmt->rf_fields[loc].nr);
1956 for (; i < fmt->rf_fields[loc].nr; ++i)
1957 if (fmt->rf_fields[loc].d[i]->rmf_size != -1)
1958 size += cfs_size_round(fmt->rf_fields[loc].d[i]->
1964 * Changes the format of an RPC.
1966 * The pill must already have been initialized, which means that it already has
1967 * a request format. The new format \a fmt must be an extension of the pill's
1968 * old format. Specifically: the new format must have as many request and reply
1969 * fields as the old one, and all fields shared by the old and new format must
1970 * be at least as large in the new format.
1972 * The new format's fields may be of different "type" than the old format, but
1973 * only for fields that are "opaque" blobs: fields which have a) have no
1974 * \a rmf_swabber, b) \a rmf_flags == 0 or RMF_F_NO_SIZE_CHECK, and c) \a
1975 * rmf_size == -1 or \a rmf_flags == RMF_F_NO_SIZE_CHECK. For example,
1976 * OBD_SET_INFO has a key field and an opaque value field that gets interpreted
1977 * according to the key field. When the value, according to the key, contains a
1978 * structure (or array thereof) to be swabbed, the format should be changed to
1979 * one where the value field has \a rmf_size/rmf_flags/rmf_swabber set
1982 void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
1987 const struct req_format *old;
1989 LASSERT(pill->rc_fmt != NULL);
1990 LASSERT(__req_format_is_sane(fmt));
1994 * Sanity checking...
1996 for (i = 0; i < RCL_NR; ++i) {
1997 LASSERT(fmt->rf_fields[i].nr >= old->rf_fields[i].nr);
1998 for (j = 0; j < old->rf_fields[i].nr - 1; ++j) {
1999 const struct req_msg_field *ofield = FMT_FIELD(old, i, j);
2001 /* "opaque" fields can be transmogrified */
2002 if (ofield->rmf_swabber == NULL &&
2003 (ofield->rmf_flags & ~RMF_F_NO_SIZE_CHECK) == 0 &&
2004 (ofield->rmf_size == -1 ||
2005 ofield->rmf_flags == RMF_F_NO_SIZE_CHECK))
2007 LASSERT(FMT_FIELD(fmt, i, j) == FMT_FIELD(old, i, j));
2010 * Last field in old format can be shorter than in new.
2012 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
2013 FMT_FIELD(old, i, j)->rmf_size);
2018 EXPORT_SYMBOL(req_capsule_extend);
2021 * This function returns a non-zero value if the given \a field is present in
2022 * the format (\a rc_fmt) of \a pill's PTLRPC request or reply (\a loc), else it
2025 int req_capsule_has_field(const struct req_capsule *pill,
2026 const struct req_msg_field *field,
2027 enum req_location loc)
2029 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2031 return field->rmf_offset[pill->rc_fmt->rf_idx][loc];
2033 EXPORT_SYMBOL(req_capsule_has_field);
2036 * Returns a non-zero value if the given \a field is present in the given \a
2037 * pill's PTLRPC request or reply (\a loc), else it returns 0.
2039 int req_capsule_field_present(const struct req_capsule *pill,
2040 const struct req_msg_field *field,
2041 enum req_location loc)
2045 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2046 LASSERT(req_capsule_has_field(pill, field, loc));
2048 offset = __req_capsule_offset(pill, field, loc);
2049 return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
2051 EXPORT_SYMBOL(req_capsule_field_present);
2054 * This function shrinks the size of the _buffer_ of the \a pill's PTLRPC
2055 * request or reply (\a loc).
2057 * This is not the opposite of req_capsule_extend().
2059 void req_capsule_shrink(struct req_capsule *pill,
2060 const struct req_msg_field *field,
2061 unsigned int newlen,
2062 enum req_location loc)
2064 const struct req_format *fmt;
2065 struct lustre_msg *msg;
2070 LASSERT(fmt != NULL);
2071 LASSERT(__req_format_is_sane(fmt));
2072 LASSERT(req_capsule_has_field(pill, field, loc));
2073 LASSERT(req_capsule_field_present(pill, field, loc));
2075 offset = __req_capsule_offset(pill, field, loc);
2077 msg = __req_msg(pill, loc);
2078 len = lustre_msg_buflen(msg, offset);
2079 LASSERTF(newlen <= len, "%s:%s, oldlen=%d, newlen=%d\n",
2080 fmt->rf_name, field->rmf_name, len, newlen);
2082 if (loc == RCL_CLIENT)
2083 pill->rc_req->rq_reqlen = lustre_shrink_msg(msg, offset, newlen,
2086 pill->rc_req->rq_replen = lustre_shrink_msg(msg, offset, newlen,
2089 EXPORT_SYMBOL(req_capsule_shrink);
2091 /* __REQ_LAYOUT_USER__ */