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.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/ptlrpc/layout.c
40 * Lustre Metadata Target (mdt) request handler
42 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * This file contains the "capsule/pill" abstraction layered above PTLRPC.
47 * Every struct ptlrpc_request contains a "pill", which points to a description
48 * of the format that the request conforms to.
51 #if !defined(__REQ_LAYOUT_USER__)
54 # define EXPORT_SYMTAB
56 #define DEBUG_SUBSYSTEM S_RPC
59 #include <linux/module.h>
61 # include <liblustre.h>
64 /* LUSTRE_VERSION_CODE */
65 #include <lustre_ver.h>
67 #include <obd_support.h>
68 /* lustre_swab_mdt_body */
69 #include <lustre/lustre_idl.h>
70 /* obd2cli_tgt() (required by DEBUG_REQ()) */
73 /* __REQ_LAYOUT_USER__ */
75 /* struct ptlrpc_request, lustre_msg* */
76 #include <lustre_req_layout.h>
77 #include <lustre_acl.h>
78 #include <lustre_debug.h>
81 * RQFs (see below) refer to two struct req_msg_field arrays describing the
82 * client request and server reply, respectively.
84 /* empty set of fields... for suitable definition of emptiness. */
85 static const struct req_msg_field *empty[] = {
89 static const struct req_msg_field *mgs_target_info_only[] = {
94 static const struct req_msg_field *mgs_set_info[] = {
99 static const struct req_msg_field *mgs_config_read_client[] = {
104 static const struct req_msg_field *mgs_config_read_server[] = {
109 static const struct req_msg_field *log_cancel_client[] = {
114 static const struct req_msg_field *mdt_body_only[] = {
119 static const struct req_msg_field *mdt_body_capa[] = {
125 static const struct req_msg_field *quotactl_only[] = {
129 static const struct req_msg_field *quota_adjust_qunit_only[] = {
131 &RMF_QUOTA_ADJUST_QUNIT
134 static const struct req_msg_field *qunit_data_only[] = {
139 static const struct req_msg_field *mdt_close_client[] = {
146 static const struct req_msg_field *obd_statfs_server[] = {
151 static const struct req_msg_field *seq_query_client[] = {
157 static const struct req_msg_field *seq_query_server[] = {
162 static const struct req_msg_field *fld_query_client[] = {
168 static const struct req_msg_field *fld_query_server[] = {
173 static const struct req_msg_field *mds_getattr_name_client[] = {
180 static const struct req_msg_field *mds_reint_client[] = {
185 static const struct req_msg_field *mds_reint_create_client[] = {
192 static const struct req_msg_field *mds_reint_create_slave_client[] = {
201 static const struct req_msg_field *mds_reint_create_rmt_acl_client[] = {
210 static const struct req_msg_field *mds_reint_create_sym_client[] = {
219 static const struct req_msg_field *mds_reint_open_client[] = {
228 static const struct req_msg_field *mds_reint_open_server[] = {
237 static const struct req_msg_field *mds_reint_unlink_client[] = {
245 static const struct req_msg_field *mds_reint_link_client[] = {
254 static const struct req_msg_field *mds_reint_rename_client[] = {
264 static const struct req_msg_field *mds_last_unlink_server[] = {
273 static const struct req_msg_field *mds_reint_setattr_client[] = {
283 static const struct req_msg_field *mds_reint_setxattr_client[] = {
291 static const struct req_msg_field *obd_connect_client[] = {
299 static const struct req_msg_field *obd_connect_server[] = {
304 static const struct req_msg_field *obd_set_info_client[] = {
310 static const struct req_msg_field *ost_grant_shrink_client[] = {
316 static const struct req_msg_field *mds_getinfo_client[] = {
322 static const struct req_msg_field *mds_getinfo_server[] = {
327 static const struct req_msg_field *ldlm_enqueue_client[] = {
332 static const struct req_msg_field *ldlm_enqueue_server[] = {
337 static const struct req_msg_field *ldlm_enqueue_lvb_server[] = {
343 static const struct req_msg_field *ldlm_cp_callback_client[] = {
349 static const struct req_msg_field *ldlm_gl_callback_server[] = {
354 static const struct req_msg_field *ldlm_intent_client[] = {
361 static const struct req_msg_field *ldlm_intent_server[] = {
369 static const struct req_msg_field *ldlm_intent_open_server[] = {
379 static const struct req_msg_field *ldlm_intent_getattr_client[] = {
383 &RMF_MDT_BODY, /* coincides with mds_getattr_name_client[] */
388 static const struct req_msg_field *ldlm_intent_getattr_server[] = {
397 static const struct req_msg_field *ldlm_intent_create_client[] = {
401 &RMF_REC_REINT, /* coincides with mds_reint_create_client[] */
407 static const struct req_msg_field *ldlm_intent_open_client[] = {
411 &RMF_REC_REINT, /* coincides with mds_reint_open_client[] */
418 static const struct req_msg_field *ldlm_intent_unlink_client[] = {
422 &RMF_REC_REINT, /* coincides with mds_reint_unlink_client[] */
427 static const struct req_msg_field *mds_getxattr_client[] = {
435 static const struct req_msg_field *mds_getxattr_server[] = {
441 static const struct req_msg_field *mds_getattr_server[] = {
450 static const struct req_msg_field *mds_setattr_server[] = {
459 static const struct req_msg_field *llog_catinfo_client[] = {
465 static const struct req_msg_field *llog_catinfo_server[] = {
470 static const struct req_msg_field *llog_origin_handle_create_client[] = {
476 static const struct req_msg_field *llogd_body_only[] = {
481 static const struct req_msg_field *llog_log_hdr_only[] = {
486 static const struct req_msg_field *llogd_conn_body_only[] = {
491 static const struct req_msg_field *llog_origin_handle_next_block_server[] = {
497 static const struct req_msg_field *ost_body_only[] = {
502 static const struct req_msg_field *ost_body_capa[] = {
508 static const struct req_msg_field *ost_destroy_client[] = {
516 static const struct req_msg_field *ost_brw_client[] = {
524 static const struct req_msg_field *ost_brw_read_server[] = {
529 static const struct req_msg_field *ost_brw_write_server[] = {
535 static const struct req_msg_field *ost_get_info_generic_server[] = {
540 static const struct req_msg_field *ost_get_info_generic_client[] = {
545 static const struct req_msg_field *ost_get_last_id_server[] = {
550 static const struct req_msg_field *ost_get_fiemap_client[] = {
556 static const struct req_msg_field *ost_get_fiemap_server[] = {
561 static struct req_format *req_formats[] = {
567 &RQF_MGS_CONFIG_READ,
576 &RQF_MDS_GETATTR_NAME,
585 &RQF_MDS_DONE_WRITING,
587 &RQF_MDS_REINT_CREATE,
588 &RQF_MDS_REINT_CREATE_RMT_ACL,
589 &RQF_MDS_REINT_CREATE_SLAVE,
590 &RQF_MDS_REINT_CREATE_SYM,
592 &RQF_MDS_REINT_UNLINK,
594 &RQF_MDS_REINT_RENAME,
595 &RQF_MDS_REINT_SETATTR,
596 &RQF_MDS_REINT_SETXATTR,
599 &RQF_MDS_QUOTA_DQACQ,
605 &RQF_OST_QUOTA_ADJUST_QUNIT,
615 &RQF_OST_SET_GRANT_INFO,
616 &RQF_OST_GET_INFO_GENERIC,
617 &RQF_OST_GET_INFO_LAST_ID,
618 &RQF_OST_GET_INFO_FIEMAP,
620 &RQF_LDLM_ENQUEUE_LVB,
624 &RQF_LDLM_CP_CALLBACK,
625 &RQF_LDLM_BL_CALLBACK,
626 &RQF_LDLM_GL_CALLBACK,
628 &RQF_LDLM_INTENT_GETATTR,
629 &RQF_LDLM_INTENT_OPEN,
630 &RQF_LDLM_INTENT_CREATE,
631 &RQF_LDLM_INTENT_UNLINK,
634 &RQF_LLOG_ORIGIN_HANDLE_CREATE,
635 &RQF_LLOG_ORIGIN_HANDLE_DESTROY,
636 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK,
637 &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK,
638 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER,
639 &RQF_LLOG_ORIGIN_CONNECT
642 struct req_msg_field {
643 const __u32 rmf_flags;
644 const char *rmf_name;
646 * Field length. (-1) means "variable length". If the
647 * \a RMF_F_STRUCT_ARRAY flag is set the field is also variable-length,
648 * but the actual size must be a whole multiple of \a rmf_size.
651 void (*rmf_swabber)(void *);
652 void (*rmf_dumper)(void *);
653 int rmf_offset[ARRAY_SIZE(req_formats)][RCL_NR];
658 * The field is a string, must be NUL-terminated.
660 RMF_F_STRING = 1 << 0,
662 * The field's buffer size need not match the declared \a rmf_size.
664 RMF_F_NO_SIZE_CHECK = 1 << 1,
666 * The field's buffer size must be a whole multiple of the declared \a
667 * rmf_size and the \a rmf_swabber function must work on the declared \a
668 * rmf_size worth of bytes.
670 RMF_F_STRUCT_ARRAY = 1 << 2
678 #define DEFINE_MSGF(name, flags, size, swabber, dumper) { \
679 .rmf_name = (name), \
680 .rmf_flags = (flags), \
681 .rmf_size = (size), \
682 .rmf_swabber = (void (*)(void*))(swabber), \
683 .rmf_dumper = (void (*)(void*))(dumper) \
686 struct req_msg_field RMF_GENERIC_DATA =
687 DEFINE_MSGF("generic_data", 0,
689 EXPORT_SYMBOL(RMF_GENERIC_DATA);
691 struct req_msg_field RMF_MGS_TARGET_INFO =
692 DEFINE_MSGF("mgs_target_info", 0,
693 sizeof(struct mgs_target_info),
694 lustre_swab_mgs_target_info, NULL);
695 EXPORT_SYMBOL(RMF_MGS_TARGET_INFO);
697 struct req_msg_field RMF_MGS_SEND_PARAM =
698 DEFINE_MSGF("mgs_send_param", 0,
699 sizeof(struct mgs_send_param),
701 EXPORT_SYMBOL(RMF_MGS_SEND_PARAM);
703 struct req_msg_field RMF_MGS_CONFIG_BODY =
704 DEFINE_MSGF("mgs_config_read request", 0,
705 sizeof(struct mgs_config_body),
706 lustre_swab_mgs_config_body, NULL);
707 EXPORT_SYMBOL(RMF_MGS_CONFIG_BODY);
709 struct req_msg_field RMF_MGS_CONFIG_RES =
710 DEFINE_MSGF("mgs_config_read reply ", 0,
711 sizeof(struct mgs_config_res),
712 lustre_swab_mgs_config_res, NULL);
713 EXPORT_SYMBOL(RMF_MGS_CONFIG_RES);
715 struct req_msg_field RMF_U32 =
716 DEFINE_MSGF("generic u32", 0,
717 sizeof(__u32), lustre_swab_generic_32s, NULL);
718 EXPORT_SYMBOL(RMF_U32);
720 struct req_msg_field RMF_SETINFO_VAL =
721 DEFINE_MSGF("setinfo_val", 0, -1, NULL, NULL);
722 EXPORT_SYMBOL(RMF_SETINFO_VAL);
724 struct req_msg_field RMF_GETINFO_KEY =
725 DEFINE_MSGF("getinfo_key", 0, -1, NULL, NULL);
726 EXPORT_SYMBOL(RMF_GETINFO_KEY);
728 struct req_msg_field RMF_GETINFO_VALLEN =
729 DEFINE_MSGF("getinfo_vallen", 0,
730 sizeof(__u32), lustre_swab_generic_32s, NULL);
731 EXPORT_SYMBOL(RMF_GETINFO_VALLEN);
733 struct req_msg_field RMF_GETINFO_VAL =
734 DEFINE_MSGF("getinfo_val", 0, -1, NULL, NULL);
735 EXPORT_SYMBOL(RMF_GETINFO_VAL);
737 struct req_msg_field RMF_SEQ_OPC =
738 DEFINE_MSGF("seq_query_opc", 0,
739 sizeof(__u32), lustre_swab_generic_32s, NULL);
740 EXPORT_SYMBOL(RMF_SEQ_OPC);
742 struct req_msg_field RMF_SEQ_RANGE =
743 DEFINE_MSGF("seq_query_range", 0,
744 sizeof(struct lu_seq_range),
745 lustre_swab_lu_seq_range, NULL);
746 EXPORT_SYMBOL(RMF_SEQ_RANGE);
748 struct req_msg_field RMF_FLD_OPC =
749 DEFINE_MSGF("fld_query_opc", 0,
750 sizeof(__u32), lustre_swab_generic_32s, NULL);
751 EXPORT_SYMBOL(RMF_FLD_OPC);
753 struct req_msg_field RMF_FLD_MDFLD =
754 DEFINE_MSGF("fld_query_mdfld", 0,
755 sizeof(struct lu_seq_range),
756 lustre_swab_lu_seq_range, NULL);
757 EXPORT_SYMBOL(RMF_FLD_MDFLD);
759 struct req_msg_field RMF_MDT_BODY =
760 DEFINE_MSGF("mdt_body", 0,
761 sizeof(struct mdt_body), lustre_swab_mdt_body, NULL);
762 EXPORT_SYMBOL(RMF_MDT_BODY);
764 struct req_msg_field RMF_OBD_QUOTACTL =
765 DEFINE_MSGF("obd_quotactl", 0,
766 sizeof(struct obd_quotactl),
767 lustre_swab_obd_quotactl, NULL);
768 EXPORT_SYMBOL(RMF_OBD_QUOTACTL);
770 struct req_msg_field RMF_QUOTA_ADJUST_QUNIT =
771 DEFINE_MSGF("quota_adjust_qunit", 0,
772 sizeof(struct quota_adjust_qunit),
773 lustre_swab_quota_adjust_qunit, NULL);
774 EXPORT_SYMBOL(RMF_QUOTA_ADJUST_QUNIT);
776 struct req_msg_field RMF_QUNIT_DATA =
777 DEFINE_MSGF("qunit_data", 0,
778 sizeof(struct qunit_data), lustre_swab_qdata, NULL);
779 EXPORT_SYMBOL(RMF_QUNIT_DATA);
781 struct req_msg_field RMF_MDT_EPOCH =
782 DEFINE_MSGF("mdt_ioepoch", 0,
783 sizeof(struct mdt_ioepoch), lustre_swab_mdt_ioepoch, NULL);
784 EXPORT_SYMBOL(RMF_MDT_EPOCH);
786 struct req_msg_field RMF_PTLRPC_BODY =
787 DEFINE_MSGF("ptlrpc_body", 0,
788 sizeof(struct ptlrpc_body), lustre_swab_ptlrpc_body, NULL);
789 EXPORT_SYMBOL(RMF_PTLRPC_BODY);
791 struct req_msg_field RMF_OBD_STATFS =
792 DEFINE_MSGF("obd_statfs", 0,
793 sizeof(struct obd_statfs), lustre_swab_obd_statfs, NULL);
794 EXPORT_SYMBOL(RMF_OBD_STATFS);
796 struct req_msg_field RMF_SETINFO_KEY =
797 DEFINE_MSGF("setinfo_key", 0, -1, NULL, NULL);
798 EXPORT_SYMBOL(RMF_SETINFO_KEY);
800 struct req_msg_field RMF_NAME =
801 DEFINE_MSGF("name", RMF_F_STRING, -1, NULL, NULL);
802 EXPORT_SYMBOL(RMF_NAME);
804 struct req_msg_field RMF_SYMTGT =
805 DEFINE_MSGF("symtgt", RMF_F_STRING, -1, NULL, NULL);
806 EXPORT_SYMBOL(RMF_SYMTGT);
808 struct req_msg_field RMF_TGTUUID =
809 DEFINE_MSGF("tgtuuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
811 EXPORT_SYMBOL(RMF_TGTUUID);
813 struct req_msg_field RMF_CLUUID =
814 DEFINE_MSGF("cluuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
816 EXPORT_SYMBOL(RMF_CLUUID);
818 struct req_msg_field RMF_STRING =
819 DEFINE_MSGF("string", RMF_F_STRING, -1, NULL, NULL);
820 EXPORT_SYMBOL(RMF_STRING);
822 struct req_msg_field RMF_LLOGD_BODY =
823 DEFINE_MSGF("llogd_body", 0,
824 sizeof(struct llogd_body), lustre_swab_llogd_body, NULL);
825 EXPORT_SYMBOL(RMF_LLOGD_BODY);
827 struct req_msg_field RMF_LLOG_LOG_HDR =
828 DEFINE_MSGF("llog_log_hdr", 0,
829 sizeof(struct llog_log_hdr), lustre_swab_llog_hdr, NULL);
830 EXPORT_SYMBOL(RMF_LLOG_LOG_HDR);
832 struct req_msg_field RMF_LLOGD_CONN_BODY =
833 DEFINE_MSGF("llogd_conn_body", 0,
834 sizeof(struct llogd_conn_body),
835 lustre_swab_llogd_conn_body, NULL);
836 EXPORT_SYMBOL(RMF_LLOGD_CONN_BODY);
839 * connection handle received in MDS_CONNECT request.
841 * No swabbing needed because struct lustre_handle contains only a 64-bit cookie
842 * that the client does not interpret at all.
844 struct req_msg_field RMF_CONN =
845 DEFINE_MSGF("conn", 0, sizeof(struct lustre_handle), NULL, NULL);
846 EXPORT_SYMBOL(RMF_CONN);
848 struct req_msg_field RMF_CONNECT_DATA =
850 RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */,
851 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 0, 0)
852 sizeof(struct obd_connect_data),
854 /* For interoperability with 1.8 and 2.0 clients/servers.
855 * The RPC verification code allows larger RPC buffers, but not
856 * smaller buffers. Until we no longer need to keep compatibility
857 * with older servers/clients we can only check that the buffer
858 * size is at least as large as obd_connect_data_v1. That is not
859 * not in itself harmful, since the chance of just corrupting this
860 * field is low. See JIRA LU-16 for details. */
861 sizeof(struct obd_connect_data_v1),
863 lustre_swab_connect, NULL);
864 EXPORT_SYMBOL(RMF_CONNECT_DATA);
866 struct req_msg_field RMF_DLM_REQ =
867 DEFINE_MSGF("dlm_req", RMF_F_NO_SIZE_CHECK /* ldlm_request_bufsize */,
868 sizeof(struct ldlm_request),
869 lustre_swab_ldlm_request, NULL);
870 EXPORT_SYMBOL(RMF_DLM_REQ);
872 struct req_msg_field RMF_DLM_REP =
873 DEFINE_MSGF("dlm_rep", 0,
874 sizeof(struct ldlm_reply), lustre_swab_ldlm_reply, NULL);
875 EXPORT_SYMBOL(RMF_DLM_REP);
877 struct req_msg_field RMF_LDLM_INTENT =
878 DEFINE_MSGF("ldlm_intent", 0,
879 sizeof(struct ldlm_intent), lustre_swab_ldlm_intent, NULL);
880 EXPORT_SYMBOL(RMF_LDLM_INTENT);
882 struct req_msg_field RMF_DLM_LVB =
883 DEFINE_MSGF("dlm_lvb", 0, sizeof(struct ost_lvb), lustre_swab_ost_lvb,
885 EXPORT_SYMBOL(RMF_DLM_LVB);
887 struct req_msg_field RMF_MDT_MD =
888 DEFINE_MSGF("mdt_md", RMF_F_NO_SIZE_CHECK, MIN_MD_SIZE, NULL, NULL);
889 EXPORT_SYMBOL(RMF_MDT_MD);
891 struct req_msg_field RMF_REC_REINT =
892 DEFINE_MSGF("rec_reint", 0, sizeof(struct mdt_rec_reint),
893 lustre_swab_mdt_rec_reint, NULL);
894 EXPORT_SYMBOL(RMF_REC_REINT);
896 /* FIXME: this length should be defined as a macro */
897 struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1,
899 EXPORT_SYMBOL(RMF_EADATA);
901 struct req_msg_field RMF_ACL =
902 DEFINE_MSGF("acl", RMF_F_NO_SIZE_CHECK,
903 LUSTRE_POSIX_ACL_MAX_SIZE, NULL, NULL);
904 EXPORT_SYMBOL(RMF_ACL);
906 /* FIXME: this should be made to use RMF_F_STRUCT_ARRAY */
907 struct req_msg_field RMF_LOGCOOKIES =
908 DEFINE_MSGF("logcookies", RMF_F_NO_SIZE_CHECK /* multiple cookies */,
909 sizeof(struct llog_cookie), NULL, NULL);
910 EXPORT_SYMBOL(RMF_LOGCOOKIES);
912 struct req_msg_field RMF_CAPA1 =
913 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
914 lustre_swab_lustre_capa, NULL);
915 EXPORT_SYMBOL(RMF_CAPA1);
917 struct req_msg_field RMF_CAPA2 =
918 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
919 lustre_swab_lustre_capa, NULL);
920 EXPORT_SYMBOL(RMF_CAPA2);
925 struct req_msg_field RMF_OST_BODY =
926 DEFINE_MSGF("ost_body", 0,
927 sizeof(struct ost_body), lustre_swab_ost_body, dump_ost_body);
928 EXPORT_SYMBOL(RMF_OST_BODY);
930 struct req_msg_field RMF_OBD_IOOBJ =
931 DEFINE_MSGF("obd_ioobj", RMF_F_STRUCT_ARRAY,
932 sizeof(struct obd_ioobj), lustre_swab_obd_ioobj, dump_ioo);
933 EXPORT_SYMBOL(RMF_OBD_IOOBJ);
935 struct req_msg_field RMF_NIOBUF_REMOTE =
936 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY,
937 sizeof(struct niobuf_remote), lustre_swab_niobuf_remote,
939 EXPORT_SYMBOL(RMF_NIOBUF_REMOTE);
941 struct req_msg_field RMF_RCS =
942 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY, sizeof(__u32),
943 lustre_swab_generic_32s, dump_rcs);
944 EXPORT_SYMBOL(RMF_RCS);
946 struct req_msg_field RMF_OBD_ID =
947 DEFINE_MSGF("obd_id", 0,
948 sizeof(obd_id), lustre_swab_ost_last_id, NULL);
949 EXPORT_SYMBOL(RMF_OBD_ID);
951 struct req_msg_field RMF_FIEMAP_KEY =
952 DEFINE_MSGF("fiemap", 0, sizeof(struct ll_fiemap_info_key),
953 lustre_swab_fiemap, NULL);
954 EXPORT_SYMBOL(RMF_FIEMAP_KEY);
956 struct req_msg_field RMF_FIEMAP_VAL =
957 DEFINE_MSGF("fiemap", 0, -1, lustre_swab_fiemap, NULL);
958 EXPORT_SYMBOL(RMF_FIEMAP_VAL);
969 const struct req_msg_field **d;
973 #define DEFINE_REQ_FMT(name, client, client_nr, server, server_nr) { \
987 #define DEFINE_REQ_FMT0(name, client, server) \
988 DEFINE_REQ_FMT(name, client, ARRAY_SIZE(client), server, ARRAY_SIZE(server))
990 struct req_format RQF_OBD_PING =
991 DEFINE_REQ_FMT0("OBD_PING", empty, empty);
992 EXPORT_SYMBOL(RQF_OBD_PING);
994 struct req_format RQF_OBD_SET_INFO =
995 DEFINE_REQ_FMT0("OBD_SET_INFO", obd_set_info_client, empty);
996 EXPORT_SYMBOL(RQF_OBD_SET_INFO);
998 struct req_format RQF_SEC_CTX =
999 DEFINE_REQ_FMT0("SEC_CTX", empty, empty);
1000 EXPORT_SYMBOL(RQF_SEC_CTX);
1002 struct req_format RQF_MGS_TARGET_REG =
1003 DEFINE_REQ_FMT0("MGS_TARGET_REG", mgs_target_info_only,
1004 mgs_target_info_only);
1005 EXPORT_SYMBOL(RQF_MGS_TARGET_REG);
1007 struct req_format RQF_MGS_SET_INFO =
1008 DEFINE_REQ_FMT0("MGS_SET_INFO", mgs_set_info,
1010 EXPORT_SYMBOL(RQF_MGS_SET_INFO);
1012 struct req_format RQF_MGS_CONFIG_READ =
1013 DEFINE_REQ_FMT0("MGS_CONFIG_READ", mgs_config_read_client,
1014 mgs_config_read_server);
1015 EXPORT_SYMBOL(RQF_MGS_CONFIG_READ);
1017 struct req_format RQF_SEQ_QUERY =
1018 DEFINE_REQ_FMT0("SEQ_QUERY", seq_query_client, seq_query_server);
1019 EXPORT_SYMBOL(RQF_SEQ_QUERY);
1021 struct req_format RQF_FLD_QUERY =
1022 DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
1023 EXPORT_SYMBOL(RQF_FLD_QUERY);
1025 struct req_format RQF_LOG_CANCEL =
1026 DEFINE_REQ_FMT0("OBD_LOG_CANCEL", log_cancel_client, empty);
1027 EXPORT_SYMBOL(RQF_LOG_CANCEL);
1029 struct req_format RQF_MDS_QUOTACHECK =
1030 DEFINE_REQ_FMT0("MDS_QUOTACHECK", quotactl_only, empty);
1031 EXPORT_SYMBOL(RQF_MDS_QUOTACHECK);
1033 struct req_format RQF_OST_QUOTACHECK =
1034 DEFINE_REQ_FMT0("OST_QUOTACHECK", quotactl_only, empty);
1035 EXPORT_SYMBOL(RQF_OST_QUOTACHECK);
1037 struct req_format RQF_MDS_QUOTACTL =
1038 DEFINE_REQ_FMT0("MDS_QUOTACTL", quotactl_only, quotactl_only);
1039 EXPORT_SYMBOL(RQF_MDS_QUOTACTL);
1041 struct req_format RQF_OST_QUOTACTL =
1042 DEFINE_REQ_FMT0("OST_QUOTACTL", quotactl_only, quotactl_only);
1043 EXPORT_SYMBOL(RQF_OST_QUOTACTL);
1045 struct req_format RQF_OST_QUOTA_ADJUST_QUNIT =
1046 DEFINE_REQ_FMT0("OST_QUOTA_ADJUST_QUNIT", quota_adjust_qunit_only,
1047 quota_adjust_qunit_only);
1048 EXPORT_SYMBOL(RQF_OST_QUOTA_ADJUST_QUNIT);
1050 struct req_format RQF_QC_CALLBACK =
1051 DEFINE_REQ_FMT0("QC_CALLBACK", quotactl_only, empty);
1052 EXPORT_SYMBOL(RQF_QC_CALLBACK);
1054 struct req_format RQF_MDS_QUOTA_DQACQ =
1055 DEFINE_REQ_FMT0("MDS_QUOTA_DQACQ", qunit_data_only, qunit_data_only);
1056 EXPORT_SYMBOL(RQF_MDS_QUOTA_DQACQ);
1058 struct req_format RQF_MDS_GETSTATUS =
1059 DEFINE_REQ_FMT0("MDS_GETSTATUS", mdt_body_only, mdt_body_capa);
1060 EXPORT_SYMBOL(RQF_MDS_GETSTATUS);
1062 struct req_format RQF_MDS_STATFS =
1063 DEFINE_REQ_FMT0("MDS_STATFS", empty, obd_statfs_server);
1064 EXPORT_SYMBOL(RQF_MDS_STATFS);
1066 struct req_format RQF_MDS_SYNC =
1067 DEFINE_REQ_FMT0("MDS_SYNC", mdt_body_capa, mdt_body_only);
1068 EXPORT_SYMBOL(RQF_MDS_SYNC);
1070 struct req_format RQF_MDS_GETATTR =
1071 DEFINE_REQ_FMT0("MDS_GETATTR", mdt_body_capa, mds_getattr_server);
1072 EXPORT_SYMBOL(RQF_MDS_GETATTR);
1074 struct req_format RQF_MDS_GETXATTR =
1075 DEFINE_REQ_FMT0("MDS_GETXATTR",
1076 mds_getxattr_client, mds_getxattr_server);
1077 EXPORT_SYMBOL(RQF_MDS_GETXATTR);
1079 struct req_format RQF_MDS_GETATTR_NAME =
1080 DEFINE_REQ_FMT0("MDS_GETATTR_NAME",
1081 mds_getattr_name_client, mds_getattr_server);
1082 EXPORT_SYMBOL(RQF_MDS_GETATTR_NAME);
1084 struct req_format RQF_MDS_REINT =
1085 DEFINE_REQ_FMT0("MDS_REINT", mds_reint_client, mdt_body_only);
1086 EXPORT_SYMBOL(RQF_MDS_REINT);
1088 struct req_format RQF_MDS_REINT_CREATE =
1089 DEFINE_REQ_FMT0("MDS_REINT_CREATE",
1090 mds_reint_create_client, mdt_body_capa);
1091 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE);
1093 struct req_format RQF_MDS_REINT_CREATE_RMT_ACL =
1094 DEFINE_REQ_FMT0("MDS_REINT_CREATE_RMT_ACL",
1095 mds_reint_create_rmt_acl_client, mdt_body_capa);
1096 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_RMT_ACL);
1098 struct req_format RQF_MDS_REINT_CREATE_SLAVE =
1099 DEFINE_REQ_FMT0("MDS_REINT_CREATE_EA",
1100 mds_reint_create_slave_client, mdt_body_capa);
1101 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SLAVE);
1103 struct req_format RQF_MDS_REINT_CREATE_SYM =
1104 DEFINE_REQ_FMT0("MDS_REINT_CREATE_SYM",
1105 mds_reint_create_sym_client, mdt_body_capa);
1106 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SYM);
1108 struct req_format RQF_MDS_REINT_OPEN =
1109 DEFINE_REQ_FMT0("MDS_REINT_OPEN",
1110 mds_reint_open_client, mds_reint_open_server);
1111 EXPORT_SYMBOL(RQF_MDS_REINT_OPEN);
1113 struct req_format RQF_MDS_REINT_UNLINK =
1114 DEFINE_REQ_FMT0("MDS_REINT_UNLINK", mds_reint_unlink_client,
1115 mds_last_unlink_server);
1116 EXPORT_SYMBOL(RQF_MDS_REINT_UNLINK);
1118 struct req_format RQF_MDS_REINT_LINK =
1119 DEFINE_REQ_FMT0("MDS_REINT_LINK",
1120 mds_reint_link_client, mdt_body_only);
1121 EXPORT_SYMBOL(RQF_MDS_REINT_LINK);
1123 struct req_format RQF_MDS_REINT_RENAME =
1124 DEFINE_REQ_FMT0("MDS_REINT_RENAME", mds_reint_rename_client,
1125 mds_last_unlink_server);
1126 EXPORT_SYMBOL(RQF_MDS_REINT_RENAME);
1128 struct req_format RQF_MDS_REINT_SETATTR =
1129 DEFINE_REQ_FMT0("MDS_REINT_SETATTR",
1130 mds_reint_setattr_client, mds_setattr_server);
1131 EXPORT_SYMBOL(RQF_MDS_REINT_SETATTR);
1133 struct req_format RQF_MDS_REINT_SETXATTR =
1134 DEFINE_REQ_FMT0("MDS_REINT_SETXATTR",
1135 mds_reint_setxattr_client, mdt_body_only);
1136 EXPORT_SYMBOL(RQF_MDS_REINT_SETXATTR);
1138 struct req_format RQF_MDS_CONNECT =
1139 DEFINE_REQ_FMT0("MDS_CONNECT",
1140 obd_connect_client, obd_connect_server);
1141 EXPORT_SYMBOL(RQF_MDS_CONNECT);
1143 struct req_format RQF_MDS_DISCONNECT =
1144 DEFINE_REQ_FMT0("MDS_DISCONNECT", empty, empty);
1145 EXPORT_SYMBOL(RQF_MDS_DISCONNECT);
1147 struct req_format RQF_MDS_GET_INFO =
1148 DEFINE_REQ_FMT0("MDS_GET_INFO", mds_getinfo_client,
1149 mds_getinfo_server);
1150 EXPORT_SYMBOL(RQF_MDS_GET_INFO);
1152 struct req_format RQF_LDLM_ENQUEUE =
1153 DEFINE_REQ_FMT0("LDLM_ENQUEUE",
1154 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1155 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE);
1157 struct req_format RQF_LDLM_ENQUEUE_LVB =
1158 DEFINE_REQ_FMT0("LDLM_ENQUEUE_LVB",
1159 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1160 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE_LVB);
1162 struct req_format RQF_LDLM_CONVERT =
1163 DEFINE_REQ_FMT0("LDLM_CONVERT",
1164 ldlm_enqueue_client, ldlm_enqueue_server);
1165 EXPORT_SYMBOL(RQF_LDLM_CONVERT);
1167 struct req_format RQF_LDLM_CANCEL =
1168 DEFINE_REQ_FMT0("LDLM_CANCEL", ldlm_enqueue_client, empty);
1169 EXPORT_SYMBOL(RQF_LDLM_CANCEL);
1171 struct req_format RQF_LDLM_CALLBACK =
1172 DEFINE_REQ_FMT0("LDLM_CALLBACK", ldlm_enqueue_client, empty);
1173 EXPORT_SYMBOL(RQF_LDLM_CALLBACK);
1175 struct req_format RQF_LDLM_CP_CALLBACK =
1176 DEFINE_REQ_FMT0("LDLM_CP_CALLBACK", ldlm_cp_callback_client, empty);
1177 EXPORT_SYMBOL(RQF_LDLM_CP_CALLBACK);
1179 struct req_format RQF_LDLM_BL_CALLBACK =
1180 DEFINE_REQ_FMT0("LDLM_BL_CALLBACK", ldlm_enqueue_client, empty);
1181 EXPORT_SYMBOL(RQF_LDLM_BL_CALLBACK);
1183 struct req_format RQF_LDLM_GL_CALLBACK =
1184 DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_enqueue_client,
1185 ldlm_gl_callback_server);
1186 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK);
1188 struct req_format RQF_LDLM_INTENT =
1189 DEFINE_REQ_FMT0("LDLM_INTENT",
1190 ldlm_intent_client, ldlm_intent_server);
1191 EXPORT_SYMBOL(RQF_LDLM_INTENT);
1193 struct req_format RQF_LDLM_INTENT_GETATTR =
1194 DEFINE_REQ_FMT0("LDLM_INTENT_GETATTR",
1195 ldlm_intent_getattr_client, ldlm_intent_getattr_server);
1196 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETATTR);
1198 struct req_format RQF_LDLM_INTENT_OPEN =
1199 DEFINE_REQ_FMT0("LDLM_INTENT_OPEN",
1200 ldlm_intent_open_client, ldlm_intent_open_server);
1201 EXPORT_SYMBOL(RQF_LDLM_INTENT_OPEN);
1203 struct req_format RQF_LDLM_INTENT_CREATE =
1204 DEFINE_REQ_FMT0("LDLM_INTENT_CREATE",
1205 ldlm_intent_create_client, ldlm_intent_getattr_server);
1206 EXPORT_SYMBOL(RQF_LDLM_INTENT_CREATE);
1208 struct req_format RQF_LDLM_INTENT_UNLINK =
1209 DEFINE_REQ_FMT0("LDLM_INTENT_UNLINK",
1210 ldlm_intent_unlink_client, ldlm_intent_server);
1211 EXPORT_SYMBOL(RQF_LDLM_INTENT_UNLINK);
1213 struct req_format RQF_MDS_CLOSE =
1214 DEFINE_REQ_FMT0("MDS_CLOSE",
1215 mdt_close_client, mds_last_unlink_server);
1216 EXPORT_SYMBOL(RQF_MDS_CLOSE);
1218 struct req_format RQF_MDS_PIN =
1219 DEFINE_REQ_FMT0("MDS_PIN",
1220 mdt_body_capa, mdt_body_only);
1221 EXPORT_SYMBOL(RQF_MDS_PIN);
1223 struct req_format RQF_MDS_UNPIN =
1224 DEFINE_REQ_FMT0("MDS_UNPIN", mdt_body_only, empty);
1225 EXPORT_SYMBOL(RQF_MDS_UNPIN);
1227 struct req_format RQF_MDS_DONE_WRITING =
1228 DEFINE_REQ_FMT0("MDS_DONE_WRITING",
1229 mdt_close_client, mdt_body_only);
1230 EXPORT_SYMBOL(RQF_MDS_DONE_WRITING);
1232 struct req_format RQF_MDS_READPAGE =
1233 DEFINE_REQ_FMT0("MDS_READPAGE",
1234 mdt_body_capa, mdt_body_only);
1235 EXPORT_SYMBOL(RQF_MDS_READPAGE);
1237 /* This is for split */
1238 struct req_format RQF_MDS_WRITEPAGE =
1239 DEFINE_REQ_FMT0("MDS_WRITEPAGE",
1240 mdt_body_capa, mdt_body_only);
1241 EXPORT_SYMBOL(RQF_MDS_WRITEPAGE);
1243 struct req_format RQF_MDS_IS_SUBDIR =
1244 DEFINE_REQ_FMT0("MDS_IS_SUBDIR",
1245 mdt_body_only, mdt_body_only);
1246 EXPORT_SYMBOL(RQF_MDS_IS_SUBDIR);
1248 struct req_format RQF_LLOG_CATINFO =
1249 DEFINE_REQ_FMT0("LLOG_CATINFO",
1250 llog_catinfo_client, llog_catinfo_server);
1251 EXPORT_SYMBOL(RQF_LLOG_CATINFO);
1253 struct req_format RQF_LLOG_ORIGIN_HANDLE_CREATE =
1254 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_CREATE",
1255 llog_origin_handle_create_client, llogd_body_only);
1256 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_CREATE);
1258 struct req_format RQF_LLOG_ORIGIN_HANDLE_DESTROY =
1259 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_DESTROY",
1260 llogd_body_only, llogd_body_only);
1261 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1263 struct req_format RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK =
1264 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_NEXT_BLOCK",
1265 llogd_body_only, llog_origin_handle_next_block_server);
1266 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1268 struct req_format RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK =
1269 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_PREV_BLOCK",
1270 llogd_body_only, llog_origin_handle_next_block_server);
1271 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1273 struct req_format RQF_LLOG_ORIGIN_HANDLE_READ_HEADER =
1274 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_READ_HEADER",
1275 llogd_body_only, llog_log_hdr_only);
1276 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1278 struct req_format RQF_LLOG_ORIGIN_CONNECT =
1279 DEFINE_REQ_FMT0("LLOG_ORIGIN_CONNECT", llogd_conn_body_only, empty);
1280 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_CONNECT);
1282 struct req_format RQF_OST_CONNECT =
1283 DEFINE_REQ_FMT0("OST_CONNECT",
1284 obd_connect_client, obd_connect_server);
1285 EXPORT_SYMBOL(RQF_OST_CONNECT);
1287 struct req_format RQF_OST_DISCONNECT =
1288 DEFINE_REQ_FMT0("OST_DISCONNECT", empty, empty);
1289 EXPORT_SYMBOL(RQF_OST_DISCONNECT);
1291 struct req_format RQF_OST_GETATTR =
1292 DEFINE_REQ_FMT0("OST_GETATTR", ost_body_capa, ost_body_only);
1293 EXPORT_SYMBOL(RQF_OST_GETATTR);
1295 struct req_format RQF_OST_SETATTR =
1296 DEFINE_REQ_FMT0("OST_SETATTR", ost_body_capa, ost_body_only);
1297 EXPORT_SYMBOL(RQF_OST_SETATTR);
1299 struct req_format RQF_OST_CREATE =
1300 DEFINE_REQ_FMT0("OST_CREATE", ost_body_only, ost_body_only);
1301 EXPORT_SYMBOL(RQF_OST_CREATE);
1303 struct req_format RQF_OST_PUNCH =
1304 DEFINE_REQ_FMT0("OST_PUNCH", ost_body_capa, ost_body_only);
1305 EXPORT_SYMBOL(RQF_OST_PUNCH);
1307 struct req_format RQF_OST_SYNC =
1308 DEFINE_REQ_FMT0("OST_SYNC", ost_body_capa, ost_body_only);
1309 EXPORT_SYMBOL(RQF_OST_SYNC);
1311 struct req_format RQF_OST_DESTROY =
1312 DEFINE_REQ_FMT0("OST_DESTROY", ost_destroy_client, ost_body_only);
1313 EXPORT_SYMBOL(RQF_OST_DESTROY);
1315 struct req_format RQF_OST_BRW_READ =
1316 DEFINE_REQ_FMT0("OST_BRW_READ", ost_brw_client, ost_brw_read_server);
1317 EXPORT_SYMBOL(RQF_OST_BRW_READ);
1319 struct req_format RQF_OST_BRW_WRITE =
1320 DEFINE_REQ_FMT0("OST_BRW_WRITE", ost_brw_client, ost_brw_write_server);
1321 EXPORT_SYMBOL(RQF_OST_BRW_WRITE);
1323 struct req_format RQF_OST_STATFS =
1324 DEFINE_REQ_FMT0("OST_STATFS", empty, obd_statfs_server);
1325 EXPORT_SYMBOL(RQF_OST_STATFS);
1327 struct req_format RQF_OST_SET_GRANT_INFO =
1328 DEFINE_REQ_FMT0("OST_SET_GRANT_INFO", ost_grant_shrink_client,
1330 EXPORT_SYMBOL(RQF_OST_SET_GRANT_INFO);
1332 struct req_format RQF_OST_GET_INFO_GENERIC =
1333 DEFINE_REQ_FMT0("OST_GET_INFO", ost_get_info_generic_client,
1334 ost_get_info_generic_server);
1335 EXPORT_SYMBOL(RQF_OST_GET_INFO_GENERIC);
1337 struct req_format RQF_OST_GET_INFO_LAST_ID =
1338 DEFINE_REQ_FMT0("OST_GET_INFO_LAST_ID", ost_get_info_generic_client,
1339 ost_get_last_id_server);
1340 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_ID);
1342 struct req_format RQF_OST_GET_INFO_FIEMAP =
1343 DEFINE_REQ_FMT0("OST_GET_INFO_FIEMAP", ost_get_fiemap_client,
1344 ost_get_fiemap_server);
1345 EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP);
1348 #if !defined(__REQ_LAYOUT_USER__)
1350 /* Convenience macro */
1351 #define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1354 * Initializes the capsule abstraction by computing and setting the \a rf_idx
1355 * field of RQFs and the \a rmf_offset field of RMFs.
1357 int req_layout_init(void)
1362 struct req_format *rf = NULL;
1364 for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
1365 rf = req_formats[i];
1367 for (j = 0; j < RCL_NR; ++j) {
1368 LASSERT(rf->rf_fields[j].nr <= REQ_MAX_FIELD_NR);
1369 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
1370 struct req_msg_field *field;
1372 field = (typeof(field))rf->rf_fields[j].d[k];
1373 LASSERT(!(field->rmf_flags & RMF_F_STRUCT_ARRAY)
1374 || field->rmf_size > 0);
1375 LASSERT(field->rmf_offset[i][j] == 0);
1377 * k + 1 to detect unused format/field
1380 field->rmf_offset[i][j] = k + 1;
1386 EXPORT_SYMBOL(req_layout_init);
1388 void req_layout_fini(void)
1391 EXPORT_SYMBOL(req_layout_fini);
1394 * Initializes the expected sizes of each RMF in a \a pill (\a rc_area) to -1.
1396 * Actual/expected field sizes are set elsewhere in functions in this file:
1397 * req_capsule_init(), req_capsule_server_pack(), req_capsule_set_size() and
1398 * req_capsule_msg_size(). The \a rc_area information is used by.
1399 * ptlrpc_request_set_replen().
1401 void req_capsule_init_area(struct req_capsule *pill)
1405 for (i = 0; i < ARRAY_SIZE(pill->rc_area[RCL_CLIENT]); i++) {
1406 pill->rc_area[RCL_CLIENT][i] = -1;
1407 pill->rc_area[RCL_SERVER][i] = -1;
1410 EXPORT_SYMBOL(req_capsule_init_area);
1413 * Initialize a pill.
1415 * The \a location indicates whether the caller is executing on the client side
1416 * (RCL_CLIENT) or server side (RCL_SERVER)..
1418 void req_capsule_init(struct req_capsule *pill,
1419 struct ptlrpc_request *req,
1420 enum req_location location)
1422 LASSERT(location == RCL_SERVER || location == RCL_CLIENT);
1425 * Today all capsules are embedded in ptlrpc_request structs,
1426 * but just in case that ever isn't the case, we don't reach
1427 * into req unless req != NULL and pill is the one embedded in
1430 * The req->rq_pill_init flag makes it safe to initialize a pill
1431 * twice, which might happen in the OST paths as a result of the
1432 * high-priority RPC queue getting peeked at before ost_handle()
1433 * handles an OST RPC.
1435 if (req != NULL && pill == &req->rq_pill && req->rq_pill_init)
1438 memset(pill, 0, sizeof *pill);
1440 pill->rc_loc = location;
1441 req_capsule_init_area(pill);
1443 if (req != NULL && pill == &req->rq_pill)
1444 req->rq_pill_init = 1;
1446 EXPORT_SYMBOL(req_capsule_init);
1448 void req_capsule_fini(struct req_capsule *pill)
1451 EXPORT_SYMBOL(req_capsule_fini);
1453 static int __req_format_is_sane(const struct req_format *fmt)
1456 0 <= fmt->rf_idx && fmt->rf_idx < ARRAY_SIZE(req_formats) &&
1457 req_formats[fmt->rf_idx] == fmt;
1460 static struct lustre_msg *__req_msg(const struct req_capsule *pill,
1461 enum req_location loc)
1463 struct ptlrpc_request *req;
1466 return loc == RCL_CLIENT ? req->rq_reqmsg : req->rq_repmsg;
1470 * Set the format (\a fmt) of a \a pill; format changes are not allowed here
1471 * (see req_capsule_extend()).
1473 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt)
1475 LASSERT(pill->rc_fmt == NULL || pill->rc_fmt == fmt);
1476 LASSERT(__req_format_is_sane(fmt));
1480 EXPORT_SYMBOL(req_capsule_set);
1483 * Fills in any parts of the \a rc_area of a \a pill that haven't been filled in
1486 * \a rc_area is an array of REQ_MAX_FIELD_NR elements, used to store sizes of
1487 * variable-sized fields. The field sizes come from the declared \a rmf_size
1488 * field of a \a pill's \a rc_fmt's RMF's.
1490 int req_capsule_filled_sizes(struct req_capsule *pill,
1491 enum req_location loc)
1493 const struct req_format *fmt = pill->rc_fmt;
1496 LASSERT(fmt != NULL);
1498 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1499 if (pill->rc_area[loc][i] == -1) {
1500 pill->rc_area[loc][i] =
1501 fmt->rf_fields[loc].d[i]->rmf_size;
1502 if (pill->rc_area[loc][i] == -1) {
1504 * Skip the following fields.
1506 * If this LASSERT() trips then you're missing a
1507 * call to req_capsule_set_size().
1509 LASSERT(loc != RCL_SERVER);
1516 EXPORT_SYMBOL(req_capsule_filled_sizes);
1519 * Capsule equivalent of lustre_pack_request() and lustre_pack_reply().
1521 * This function uses the \a pill's \a rc_area as filled in by
1522 * req_capsule_set_size() or req_capsule_filled_sizes() (the latter is called by
1525 int req_capsule_server_pack(struct req_capsule *pill)
1527 const struct req_format *fmt;
1531 LASSERT(pill->rc_loc == RCL_SERVER);
1533 LASSERT(fmt != NULL);
1535 count = req_capsule_filled_sizes(pill, RCL_SERVER);
1536 rc = lustre_pack_reply(pill->rc_req, count,
1537 pill->rc_area[RCL_SERVER], NULL);
1539 DEBUG_REQ(D_ERROR, pill->rc_req,
1540 "Cannot pack %d fields in format `%s': ",
1541 count, fmt->rf_name);
1545 EXPORT_SYMBOL(req_capsule_server_pack);
1548 * Returns the PTLRPC request or reply (\a loc) buffer offset of a \a pill
1549 * corresponding to the given RMF (\a field).
1551 static int __req_capsule_offset(const struct req_capsule *pill,
1552 const struct req_msg_field *field,
1553 enum req_location loc)
1557 offset = field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1558 LASSERTF(offset > 0, "%s:%s, off=%d, loc=%d\n",
1559 pill->rc_fmt->rf_name,
1560 field->rmf_name, offset, loc);
1563 LASSERT(0 <= offset && offset < REQ_MAX_FIELD_NR);
1568 * Helper for __req_capsule_get(); swabs value / array of values and/or dumps
1573 swabber_dumper_helper(struct req_capsule *pill,
1574 const struct req_msg_field *field,
1575 enum req_location loc,
1577 void *value, int len, int dump, void (*swabber)( void *))
1583 int inout = loc == RCL_CLIENT;
1585 swabber = swabber ?: field->rmf_swabber;
1587 if (ptlrpc_buf_need_swab(pill->rc_req, inout, offset) &&
1588 swabber != NULL && value != NULL)
1593 if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY)) {
1594 if (dump && field->rmf_dumper) {
1595 CDEBUG(D_RPCTRACE, "Dump of %sfield %s follows\n",
1596 do_swab ? "unswabbed " : "", field->rmf_name);
1597 field->rmf_dumper(value);
1602 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1604 CDEBUG(D_RPCTRACE, "Dump of swabbed field %s "
1605 "follows\n", field->rmf_name);
1606 field->rmf_dumper(value);
1613 * We're swabbing an array; swabber() swabs a single array element, so
1614 * swab every element.
1616 LASSERT((len % field->rmf_size) == 0);
1617 for (p = value, i = 0, n = len / field->rmf_size;
1619 i++, p += field->rmf_size) {
1620 if (dump && field->rmf_dumper) {
1621 CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, "
1622 "element %d follows\n",
1623 do_swab ? "unswabbed " : "", field->rmf_name, i);
1624 field->rmf_dumper(p);
1629 if (dump && field->rmf_dumper) {
1630 CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, "
1631 "element %d follows\n", field->rmf_name, i);
1632 field->rmf_dumper(value);
1636 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1640 * Returns the pointer to a PTLRPC request or reply (\a loc) buffer of a \a pill
1641 * corresponding to the given RMF (\a field).
1643 * The buffer will be swabbed using the given \a swabber. If \a swabber == NULL
1644 * then the \a rmf_swabber from the RMF will be used. Soon there will be no
1645 * calls to __req_capsule_get() with a non-NULL \a swabber; \a swabber will then
1646 * be removed. Fields with the \a RMF_F_STRUCT_ARRAY flag set will have each
1647 * element of the array swabbed.
1649 static void *__req_capsule_get(struct req_capsule *pill,
1650 const struct req_msg_field *field,
1651 enum req_location loc,
1652 void (*swabber)( void *),
1655 const struct req_format *fmt;
1656 struct lustre_msg *msg;
1661 void *(*getter)(struct lustre_msg *m, int n, int minlen);
1663 static const char *rcl_names[RCL_NR] = {
1664 [RCL_CLIENT] = "client",
1665 [RCL_SERVER] = "server"
1668 LASSERT(pill != NULL);
1669 LASSERT(pill != LP_POISON);
1671 LASSERT(fmt != NULL);
1672 LASSERT(fmt != LP_POISON);
1673 LASSERT(__req_format_is_sane(fmt));
1675 offset = __req_capsule_offset(pill, field, loc);
1677 msg = __req_msg(pill, loc);
1678 LASSERT(msg != NULL);
1680 getter = (field->rmf_flags & RMF_F_STRING) ?
1681 (typeof(getter))lustre_msg_string : lustre_msg_buf;
1683 if (field->rmf_flags & RMF_F_STRUCT_ARRAY) {
1685 * We've already asserted that field->rmf_size > 0 in
1686 * req_layout_init().
1688 len = lustre_msg_buflen(msg, offset);
1689 if ((len % field->rmf_size) != 0) {
1690 CERROR("%s: array field size mismatch "
1691 "%d modulo %d != 0 (%d)\n",
1692 field->rmf_name, len, field->rmf_size, loc);
1695 } else if (pill->rc_area[loc][offset] != -1) {
1696 len = pill->rc_area[loc][offset];
1698 len = max(field->rmf_size, 0);
1700 value = getter(msg, offset, len);
1702 if (value == NULL) {
1703 DEBUG_REQ(D_ERROR, pill->rc_req,
1704 "Wrong buffer for field `%s' (%d of %d) "
1705 "in format `%s': %d vs. %d (%s)\n",
1706 field->rmf_name, offset, lustre_msg_bufcount(msg),
1707 fmt->rf_name, lustre_msg_buflen(msg, offset), len,
1710 swabber_dumper_helper(pill, field, loc, offset, value, len,
1718 * Dump a request and/or reply
1720 void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
1722 const struct req_format *fmt;
1723 const struct req_msg_field *field;
1729 DEBUG_REQ(D_RPCTRACE, pill->rc_req, "BEGIN REQ CAPSULE DUMP\n");
1730 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1731 field = FMT_FIELD(fmt, loc, i);
1732 if (field->rmf_dumper == NULL) {
1734 * FIXME Add a default hex dumper for fields that don't
1735 * have a specific dumper
1737 len = req_capsule_get_size(pill, field, loc);
1738 CDEBUG(D_RPCTRACE, "Field %s has no dumper function;"
1739 "field size is %d\n", field->rmf_name, len);
1741 /* It's the dumping side-effect that we're interested in */
1742 (void) __req_capsule_get(pill, field, loc, NULL, 1);
1745 CDEBUG(D_RPCTRACE, "END REQ CAPSULE DUMP\n");
1751 void req_capsule_client_dump(struct req_capsule *pill)
1753 __req_capsule_dump(pill, RCL_CLIENT);
1755 EXPORT_SYMBOL(req_capsule_client_dump);
1760 void req_capsule_server_dump(struct req_capsule *pill)
1762 __req_capsule_dump(pill, RCL_SERVER);
1764 EXPORT_SYMBOL(req_capsule_server_dump);
1767 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC request
1768 * buffer corresponding to the given RMF (\a field) of a \a pill.
1770 void *req_capsule_client_get(struct req_capsule *pill,
1771 const struct req_msg_field *field)
1773 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1775 EXPORT_SYMBOL(req_capsule_client_get);
1778 * Same as req_capsule_client_get(), but with a \a swabber argument.
1780 * Currently unused; will be removed when req_capsule_server_swab_get() is
1783 void *req_capsule_client_swab_get(struct req_capsule *pill,
1784 const struct req_msg_field *field,
1785 void (*swabber)(void* ))
1787 return __req_capsule_get(pill, field, RCL_CLIENT, swabber, 0);
1789 EXPORT_SYMBOL(req_capsule_client_swab_get);
1792 * Utility that combines req_capsule_set_size() and req_capsule_client_get().
1794 * First the \a pill's request \a field's size is set (\a rc_area) using
1795 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1798 void *req_capsule_client_sized_get(struct req_capsule *pill,
1799 const struct req_msg_field *field,
1802 req_capsule_set_size(pill, field, RCL_CLIENT, len);
1803 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1805 EXPORT_SYMBOL(req_capsule_client_sized_get);
1808 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC reply
1809 * buffer corresponding to the given RMF (\a field) of a \a pill.
1811 void *req_capsule_server_get(struct req_capsule *pill,
1812 const struct req_msg_field *field)
1814 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1816 EXPORT_SYMBOL(req_capsule_server_get);
1819 * Same as req_capsule_server_get(), but with a \a swabber argument.
1821 * Ideally all swabbing should be done pursuant to RMF definitions, with no
1822 * swabbing done outside this capsule abstraction.
1824 void *req_capsule_server_swab_get(struct req_capsule *pill,
1825 const struct req_msg_field *field,
1828 return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
1830 EXPORT_SYMBOL(req_capsule_server_swab_get);
1833 * Utility that combines req_capsule_set_size() and req_capsule_server_get().
1835 * First the \a pill's request \a field's size is set (\a rc_area) using
1836 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1839 void *req_capsule_server_sized_get(struct req_capsule *pill,
1840 const struct req_msg_field *field,
1843 req_capsule_set_size(pill, field, RCL_SERVER, len);
1844 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1846 EXPORT_SYMBOL(req_capsule_server_sized_get);
1849 * Returns the buffer of a \a pill corresponding to the given \a field from the
1850 * request (if the caller is executing on the server-side) or reply (if the
1851 * caller is executing on the client-side).
1853 * This function convienient for use is code that could be executed on the
1854 * client and server alike.
1856 const void *req_capsule_other_get(struct req_capsule *pill,
1857 const struct req_msg_field *field)
1859 return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL, 0);
1861 EXPORT_SYMBOL(req_capsule_other_get);
1864 * Set the size of the PTLRPC request/reply (\a loc) buffer for the given \a
1865 * field of the given \a pill.
1867 * This function must be used when constructing variable sized fields of a
1870 void req_capsule_set_size(struct req_capsule *pill,
1871 const struct req_msg_field *field,
1872 enum req_location loc, int size)
1874 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1876 if ((size != field->rmf_size) &&
1877 (field->rmf_size != -1) &&
1878 !(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
1880 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1881 (size % field->rmf_size != 0)) {
1882 CERROR("%s: array field size mismatch "
1883 "%d %% %d != 0 (%d)\n",
1884 field->rmf_name, size, field->rmf_size, loc);
1886 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1887 size < field->rmf_size) {
1888 CERROR("%s: field size mismatch %d != %d (%d)\n",
1889 field->rmf_name, size, field->rmf_size, loc);
1894 pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size;
1896 EXPORT_SYMBOL(req_capsule_set_size);
1899 * Return the actual PTLRPC buffer length of a request or reply (\a loc)
1900 * for the given \a pill's given \a field.
1902 * NB: this function doesn't correspond with req_capsule_set_size(), which
1903 * actually sets the size in pill.rc_area[loc][offset], but this function
1904 * returns the message buflen[offset], maybe we should use another name.
1906 int req_capsule_get_size(const struct req_capsule *pill,
1907 const struct req_msg_field *field,
1908 enum req_location loc)
1910 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1912 return lustre_msg_buflen(__req_msg(pill, loc),
1913 __req_capsule_offset(pill, field, loc));
1915 EXPORT_SYMBOL(req_capsule_get_size);
1918 * Wrapper around lustre_msg_size() that returns the PTLRPC size needed for the
1919 * given \a pill's request or reply (\a loc) given the field size recorded in
1920 * the \a pill's rc_area.
1922 * See also req_capsule_set_size().
1924 int req_capsule_msg_size(struct req_capsule *pill, enum req_location loc)
1926 return lustre_msg_size(pill->rc_req->rq_import->imp_msg_magic,
1927 pill->rc_fmt->rf_fields[loc].nr,
1928 pill->rc_area[loc]);
1932 * While req_capsule_msg_size() computes the size of a PTLRPC request or reply
1933 * (\a loc) given a \a pill's \a rc_area, this function computes the size of a
1934 * PTLRPC request or reply given only an RQF (\a fmt).
1936 * This function should not be used for formats which contain variable size
1939 int req_capsule_fmt_size(__u32 magic, const struct req_format *fmt,
1940 enum req_location loc)
1945 * This function should probably LASSERT() that fmt has no fields with
1946 * RMF_F_STRUCT_ARRAY in rmf_flags, since we can't know here how many
1947 * elements in the array there will ultimately be, but then, we could
1948 * assume that there will be at least one element, and that's just what
1951 size = lustre_msg_hdr_size(magic, fmt->rf_fields[loc].nr);
1955 for (; i < fmt->rf_fields[loc].nr; ++i)
1956 if (fmt->rf_fields[loc].d[i]->rmf_size != -1)
1957 size += cfs_size_round(fmt->rf_fields[loc].d[i]->
1963 * Changes the format of an RPC.
1965 * The pill must already have been initialized, which means that it already has
1966 * a request format. The new format \a fmt must be an extension of the pill's
1967 * old format. Specifically: the new format must have as many request and reply
1968 * fields as the old one, and all fields shared by the old and new format must
1969 * be at least as large in the new format.
1971 * The new format's fields may be of different "type" than the old format, but
1972 * only for fields that are "opaque" blobs: fields which have a) have no
1973 * \a rmf_swabber, b) \a rmf_flags == 0 or RMF_F_NO_SIZE_CHECK, and c) \a
1974 * rmf_size == -1 or \a rmf_flags == RMF_F_NO_SIZE_CHECK. For example,
1975 * OBD_SET_INFO has a key field and an opaque value field that gets interpreted
1976 * according to the key field. When the value, according to the key, contains a
1977 * structure (or array thereof) to be swabbed, the format should be changed to
1978 * one where the value field has \a rmf_size/rmf_flags/rmf_swabber set
1981 void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
1986 const struct req_format *old;
1988 LASSERT(pill->rc_fmt != NULL);
1989 LASSERT(__req_format_is_sane(fmt));
1993 * Sanity checking...
1995 for (i = 0; i < RCL_NR; ++i) {
1996 LASSERT(fmt->rf_fields[i].nr >= old->rf_fields[i].nr);
1997 for (j = 0; j < old->rf_fields[i].nr - 1; ++j) {
1998 const struct req_msg_field *ofield = FMT_FIELD(old, i, j);
2000 /* "opaque" fields can be transmogrified */
2001 if (ofield->rmf_swabber == NULL &&
2002 (ofield->rmf_flags & ~RMF_F_NO_SIZE_CHECK) == 0 &&
2003 (ofield->rmf_size == -1 ||
2004 ofield->rmf_flags == RMF_F_NO_SIZE_CHECK))
2006 LASSERT(FMT_FIELD(fmt, i, j) == FMT_FIELD(old, i, j));
2009 * Last field in old format can be shorter than in new.
2011 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
2012 FMT_FIELD(old, i, j)->rmf_size);
2017 EXPORT_SYMBOL(req_capsule_extend);
2020 * This function returns a non-zero value if the given \a field is present in
2021 * the format (\a rc_fmt) of \a pill's PTLRPC request or reply (\a loc), else it
2024 int req_capsule_has_field(const struct req_capsule *pill,
2025 const struct req_msg_field *field,
2026 enum req_location loc)
2028 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2030 return field->rmf_offset[pill->rc_fmt->rf_idx][loc];
2032 EXPORT_SYMBOL(req_capsule_has_field);
2035 * Returns a non-zero value if the given \a field is present in the given \a
2036 * pill's PTLRPC request or reply (\a loc), else it returns 0.
2038 int req_capsule_field_present(const struct req_capsule *pill,
2039 const struct req_msg_field *field,
2040 enum req_location loc)
2044 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
2045 LASSERT(req_capsule_has_field(pill, field, loc));
2047 offset = __req_capsule_offset(pill, field, loc);
2048 return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
2050 EXPORT_SYMBOL(req_capsule_field_present);
2053 * This function shrinks the size of the _buffer_ of the \a pill's PTLRPC
2054 * request or reply (\a loc).
2056 * This is not the opposite of req_capsule_extend().
2058 void req_capsule_shrink(struct req_capsule *pill,
2059 const struct req_msg_field *field,
2060 unsigned int newlen,
2061 enum req_location loc)
2063 const struct req_format *fmt;
2064 struct lustre_msg *msg;
2069 LASSERT(fmt != NULL);
2070 LASSERT(__req_format_is_sane(fmt));
2071 LASSERT(req_capsule_has_field(pill, field, loc));
2072 LASSERT(req_capsule_field_present(pill, field, loc));
2074 offset = __req_capsule_offset(pill, field, loc);
2076 msg = __req_msg(pill, loc);
2077 len = lustre_msg_buflen(msg, offset);
2078 LASSERTF(newlen <= len, "%s:%s, oldlen=%d, newlen=%d\n",
2079 fmt->rf_name, field->rmf_name, len, newlen);
2081 if (loc == RCL_CLIENT)
2082 pill->rc_req->rq_reqlen = lustre_shrink_msg(msg, offset, newlen,
2085 pill->rc_req->rq_replen = lustre_shrink_msg(msg, offset, newlen,
2088 EXPORT_SYMBOL(req_capsule_shrink);
2090 /* __REQ_LAYOUT_USER__ */