1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/layout.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Nikita Danilov <nikita@clusterfs.com>
43 * This file contains the "capsule/pill" abstraction layered above PTLRPC.
45 * Every struct ptlrpc_request contains a "pill", which points to a description
46 * of the format that the request conforms to.
49 #if !defined(__REQ_LAYOUT_USER__)
52 # define EXPORT_SYMTAB
54 #define DEBUG_SUBSYSTEM S_RPC
57 #include <linux/module.h>
59 # include <liblustre.h>
62 /* LUSTRE_VERSION_CODE */
63 #include <lustre_ver.h>
65 #include <obd_support.h>
66 /* lustre_swab_mdt_body */
67 #include <lustre/lustre_idl.h>
68 /* obd2cli_tgt() (required by DEBUG_REQ()) */
71 /* __REQ_LAYOUT_USER__ */
73 /* struct ptlrpc_request, lustre_msg* */
74 #include <lustre_req_layout.h>
75 #include <lustre_acl.h>
76 #include <lustre_debug.h>
79 * RQFs (see below) refer to two struct req_msg_field arrays describing the
80 * client request and server reply, respectively.
82 /* empty set of fields... for suitable definition of emptiness. */
83 static const struct req_msg_field *empty[] = {
87 static const struct req_msg_field *mgs_target_info_only[] = {
92 static const struct req_msg_field *mgs_set_info[] = {
97 static const struct req_msg_field *log_cancel_client[] = {
102 static const struct req_msg_field *mdt_body_only[] = {
107 static const struct req_msg_field *mdt_body_capa[] = {
113 static const struct req_msg_field *quotactl_only[] = {
117 static const struct req_msg_field *quota_adjust_qunit_only[] = {
119 &RMF_QUOTA_ADJUST_QUNIT
122 static const struct req_msg_field *qunit_data_only[] = {
127 static const struct req_msg_field *mdt_close_client[] = {
134 static const struct req_msg_field *obd_statfs_server[] = {
139 static const struct req_msg_field *seq_query_client[] = {
145 static const struct req_msg_field *seq_query_server[] = {
150 static const struct req_msg_field *fld_query_client[] = {
156 static const struct req_msg_field *fld_query_server[] = {
161 static const struct req_msg_field *mds_getattr_name_client[] = {
168 static const struct req_msg_field *mds_reint_client[] = {
173 static const struct req_msg_field *mds_reint_create_client[] = {
180 static const struct req_msg_field *mds_reint_create_slave_client[] = {
189 static const struct req_msg_field *mds_reint_create_rmt_acl_client[] = {
198 static const struct req_msg_field *mds_reint_create_sym_client[] = {
207 static const struct req_msg_field *mds_reint_open_client[] = {
216 static const struct req_msg_field *mds_reint_open_server[] = {
225 static const struct req_msg_field *mds_reint_unlink_client[] = {
233 static const struct req_msg_field *mds_reint_link_client[] = {
242 static const struct req_msg_field *mds_reint_rename_client[] = {
252 static const struct req_msg_field *mds_last_unlink_server[] = {
261 static const struct req_msg_field *mds_reint_setattr_client[] = {
271 static const struct req_msg_field *mds_reint_setxattr_client[] = {
279 static const struct req_msg_field *obd_connect_client[] = {
287 static const struct req_msg_field *obd_connect_server[] = {
292 static const struct req_msg_field *obd_set_info_client[] = {
298 static const struct req_msg_field *ost_grant_shrink_client[] = {
304 static const struct req_msg_field *mds_getinfo_client[] = {
310 static const struct req_msg_field *mds_getinfo_server[] = {
315 static const struct req_msg_field *ldlm_enqueue_client[] = {
320 static const struct req_msg_field *ldlm_enqueue_server[] = {
325 static const struct req_msg_field *ldlm_enqueue_lvb_server[] = {
331 static const struct req_msg_field *ldlm_cp_callback_client[] = {
337 static const struct req_msg_field *ldlm_gl_callback_server[] = {
342 static const struct req_msg_field *ldlm_intent_client[] = {
349 static const struct req_msg_field *ldlm_intent_server[] = {
357 static const struct req_msg_field *ldlm_intent_open_server[] = {
367 static const struct req_msg_field *ldlm_intent_getattr_client[] = {
371 &RMF_MDT_BODY, /* coincides with mds_getattr_name_client[] */
376 static const struct req_msg_field *ldlm_intent_getattr_server[] = {
385 static const struct req_msg_field *ldlm_intent_create_client[] = {
389 &RMF_REC_REINT, /* coincides with mds_reint_create_client[] */
395 static const struct req_msg_field *ldlm_intent_open_client[] = {
399 &RMF_REC_REINT, /* coincides with mds_reint_open_client[] */
406 static const struct req_msg_field *ldlm_intent_unlink_client[] = {
410 &RMF_REC_REINT, /* coincides with mds_reint_unlink_client[] */
415 static const struct req_msg_field *mds_getxattr_client[] = {
423 static const struct req_msg_field *mds_getxattr_server[] = {
429 static const struct req_msg_field *mds_getattr_server[] = {
438 static const struct req_msg_field *mds_setattr_server[] = {
447 static const struct req_msg_field *llog_catinfo_client[] = {
453 static const struct req_msg_field *llog_catinfo_server[] = {
458 static const struct req_msg_field *llog_origin_handle_create_client[] = {
464 static const struct req_msg_field *llogd_body_only[] = {
469 static const struct req_msg_field *llog_log_hdr_only[] = {
474 static const struct req_msg_field *llogd_conn_body_only[] = {
479 static const struct req_msg_field *llog_origin_handle_next_block_server[] = {
485 static const struct req_msg_field *ost_body_only[] = {
490 static const struct req_msg_field *ost_body_capa[] = {
496 static const struct req_msg_field *ost_destroy_client[] = {
504 static const struct req_msg_field *ost_brw_client[] = {
512 static const struct req_msg_field *ost_brw_server[] = {
518 static const struct req_msg_field *ost_get_info_generic_server[] = {
523 static const struct req_msg_field *ost_get_info_generic_client[] = {
528 static const struct req_msg_field *ost_get_last_id_server[] = {
533 static const struct req_msg_field *ost_get_fiemap_client[] = {
539 static const struct req_msg_field *ost_get_fiemap_server[] = {
544 static const struct req_format *req_formats[] = {
558 &RQF_MDS_GETATTR_NAME,
567 &RQF_MDS_DONE_WRITING,
569 &RQF_MDS_REINT_CREATE,
570 &RQF_MDS_REINT_CREATE_RMT_ACL,
571 &RQF_MDS_REINT_CREATE_SLAVE,
572 &RQF_MDS_REINT_CREATE_SYM,
574 &RQF_MDS_REINT_UNLINK,
576 &RQF_MDS_REINT_RENAME,
577 &RQF_MDS_REINT_SETATTR,
578 &RQF_MDS_REINT_SETXATTR,
581 &RQF_MDS_QUOTA_DQACQ,
587 &RQF_OST_QUOTA_ADJUST_QUNIT,
596 &RQF_OST_SET_GRANT_INFO,
597 &RQF_OST_GET_INFO_GENERIC,
598 &RQF_OST_GET_INFO_LAST_ID,
599 &RQF_OST_GET_INFO_FIEMAP,
601 &RQF_LDLM_ENQUEUE_LVB,
605 &RQF_LDLM_CP_CALLBACK,
606 &RQF_LDLM_BL_CALLBACK,
607 &RQF_LDLM_GL_CALLBACK,
609 &RQF_LDLM_INTENT_GETATTR,
610 &RQF_LDLM_INTENT_OPEN,
611 &RQF_LDLM_INTENT_CREATE,
612 &RQF_LDLM_INTENT_UNLINK,
615 &RQF_LLOG_ORIGIN_HANDLE_CREATE,
616 &RQF_LLOG_ORIGIN_HANDLE_DESTROY,
617 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK,
618 &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK,
619 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER,
620 &RQF_LLOG_ORIGIN_CONNECT
623 struct req_msg_field {
625 const char *rmf_name;
627 * Field length. (-1) means "variable length". If the
628 * \a RMF_F_STRUCT_ARRAY flag is set the field is also variable-length,
629 * but the actual size must be a whole multiple of \a rmf_size.
632 void (*rmf_swabber)(void *);
633 void (*rmf_dumper)(void *);
634 int rmf_offset[ARRAY_SIZE(req_formats)][RCL_NR];
639 * The field is a string, must be NUL-terminated.
641 RMF_F_STRING = 1 << 0,
643 * The field's buffer size need not match the declared \a rmf_size.
645 RMF_F_NO_SIZE_CHECK = 1 << 1,
647 * The field's buffer size must be a whole multiple of the declared \a
648 * rmf_size and the \a rmf_swabber function must work on the declared \a
649 * rmf_size worth of bytes.
651 RMF_F_STRUCT_ARRAY = 1 << 2
659 #define DEFINE_MSGF(name, flags, size, swabber, dumper) { \
660 .rmf_name = (name), \
661 .rmf_flags = (flags), \
662 .rmf_size = (size), \
663 .rmf_swabber = (void (*)(void*))(swabber), \
664 .rmf_dumper = (void (*)(void*))(dumper) \
667 const struct req_msg_field RMF_GENERIC_DATA =
668 DEFINE_MSGF("generic_data", 0,
670 EXPORT_SYMBOL(RMF_GENERIC_DATA);
672 const struct req_msg_field RMF_MGS_TARGET_INFO =
673 DEFINE_MSGF("mgs_target_info", 0,
674 sizeof(struct mgs_target_info),
675 lustre_swab_mgs_target_info, NULL);
676 EXPORT_SYMBOL(RMF_MGS_TARGET_INFO);
678 const struct req_msg_field RMF_MGS_SEND_PARAM =
679 DEFINE_MSGF("mgs_send_param", 0,
680 sizeof(struct mgs_send_param),
682 EXPORT_SYMBOL(RMF_MGS_SEND_PARAM);
684 const struct req_msg_field RMF_SETINFO_VAL =
685 DEFINE_MSGF("setinfo_val", 0, -1, NULL, NULL);
686 EXPORT_SYMBOL(RMF_SETINFO_VAL);
688 const struct req_msg_field RMF_GETINFO_KEY =
689 DEFINE_MSGF("getinfo_key", 0, -1, NULL, NULL);
690 EXPORT_SYMBOL(RMF_GETINFO_KEY);
692 const struct req_msg_field RMF_GETINFO_VALLEN =
693 DEFINE_MSGF("getinfo_vallen", 0,
694 sizeof(__u32), lustre_swab_generic_32s, NULL);
695 EXPORT_SYMBOL(RMF_GETINFO_VALLEN);
697 const struct req_msg_field RMF_GETINFO_VAL =
698 DEFINE_MSGF("getinfo_val", 0, -1, NULL, NULL);
699 EXPORT_SYMBOL(RMF_GETINFO_VAL);
701 const struct req_msg_field RMF_SEQ_OPC =
702 DEFINE_MSGF("seq_query_opc", 0,
703 sizeof(__u32), lustre_swab_generic_32s, NULL);
704 EXPORT_SYMBOL(RMF_SEQ_OPC);
706 const struct req_msg_field RMF_SEQ_RANGE =
707 DEFINE_MSGF("seq_query_range", 0,
708 sizeof(struct lu_seq_range),
709 lustre_swab_lu_seq_range, NULL);
710 EXPORT_SYMBOL(RMF_SEQ_RANGE);
712 const struct req_msg_field RMF_FLD_OPC =
713 DEFINE_MSGF("fld_query_opc", 0,
714 sizeof(__u32), lustre_swab_generic_32s, NULL);
715 EXPORT_SYMBOL(RMF_FLD_OPC);
717 const struct req_msg_field RMF_FLD_MDFLD =
718 DEFINE_MSGF("fld_query_mdfld", 0,
719 sizeof(struct lu_seq_range),
720 lustre_swab_lu_seq_range, NULL);
721 EXPORT_SYMBOL(RMF_FLD_MDFLD);
723 const struct req_msg_field RMF_MDT_BODY =
724 DEFINE_MSGF("mdt_body", 0,
725 sizeof(struct mdt_body), lustre_swab_mdt_body, NULL);
726 EXPORT_SYMBOL(RMF_MDT_BODY);
728 const struct req_msg_field RMF_OBD_QUOTACTL =
729 DEFINE_MSGF("obd_quotactl", 0,
730 sizeof(struct obd_quotactl),
731 lustre_swab_obd_quotactl, NULL);
732 EXPORT_SYMBOL(RMF_OBD_QUOTACTL);
734 const struct req_msg_field RMF_QUOTA_ADJUST_QUNIT =
735 DEFINE_MSGF("quota_adjust_qunit", 0,
736 sizeof(struct quota_adjust_qunit),
737 lustre_swab_quota_adjust_qunit, NULL);
738 EXPORT_SYMBOL(RMF_QUOTA_ADJUST_QUNIT);
740 const struct req_msg_field RMF_QUNIT_DATA =
741 DEFINE_MSGF("qunit_data", 0,
742 sizeof(struct qunit_data), lustre_swab_qdata, NULL);
743 EXPORT_SYMBOL(RMF_QUNIT_DATA);
745 const struct req_msg_field RMF_MDT_EPOCH =
746 DEFINE_MSGF("mdt_ioepoch", 0,
747 sizeof(struct mdt_ioepoch), lustre_swab_mdt_ioepoch, NULL);
748 EXPORT_SYMBOL(RMF_MDT_EPOCH);
750 const struct req_msg_field RMF_PTLRPC_BODY =
751 DEFINE_MSGF("ptlrpc_body", 0,
752 sizeof(struct ptlrpc_body), lustre_swab_ptlrpc_body, NULL);
753 EXPORT_SYMBOL(RMF_PTLRPC_BODY);
755 const struct req_msg_field RMF_OBD_STATFS =
756 DEFINE_MSGF("obd_statfs", 0,
757 sizeof(struct obd_statfs), lustre_swab_obd_statfs, NULL);
758 EXPORT_SYMBOL(RMF_OBD_STATFS);
760 const struct req_msg_field RMF_SETINFO_KEY =
761 DEFINE_MSGF("setinfo_key", 0, -1, NULL, NULL);
762 EXPORT_SYMBOL(RMF_SETINFO_KEY);
764 const struct req_msg_field RMF_NAME =
765 DEFINE_MSGF("name", RMF_F_STRING, -1, NULL, NULL);
766 EXPORT_SYMBOL(RMF_NAME);
768 const struct req_msg_field RMF_SYMTGT =
769 DEFINE_MSGF("symtgt", RMF_F_STRING, -1, NULL, NULL);
770 EXPORT_SYMBOL(RMF_SYMTGT);
772 const struct req_msg_field RMF_TGTUUID =
773 DEFINE_MSGF("tgtuuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
775 EXPORT_SYMBOL(RMF_TGTUUID);
777 const struct req_msg_field RMF_CLUUID =
778 DEFINE_MSGF("cluuid", RMF_F_STRING, sizeof(struct obd_uuid) - 1, NULL,
780 EXPORT_SYMBOL(RMF_CLUUID);
782 const struct req_msg_field RMF_STRING =
783 DEFINE_MSGF("string", RMF_F_STRING, -1, NULL, NULL);
784 EXPORT_SYMBOL(RMF_STRING);
786 const struct req_msg_field RMF_LLOGD_BODY =
787 DEFINE_MSGF("llogd_body", 0,
788 sizeof(struct llogd_body), lustre_swab_llogd_body, NULL);
789 EXPORT_SYMBOL(RMF_LLOGD_BODY);
791 const struct req_msg_field RMF_LLOG_LOG_HDR =
792 DEFINE_MSGF("llog_log_hdr", 0,
793 sizeof(struct llog_log_hdr), lustre_swab_llog_hdr, NULL);
794 EXPORT_SYMBOL(RMF_LLOG_LOG_HDR);
796 const struct req_msg_field RMF_LLOGD_CONN_BODY =
797 DEFINE_MSGF("llogd_conn_body", 0,
798 sizeof(struct llogd_conn_body),
799 lustre_swab_llogd_conn_body, NULL);
800 EXPORT_SYMBOL(RMF_LLOGD_CONN_BODY);
803 * connection handle received in MDS_CONNECT request.
805 * No swabbing needed because struct lustre_handle contains only a 64-bit cookie
806 * that the client does not interpret at all.
808 const struct req_msg_field RMF_CONN =
809 DEFINE_MSGF("conn", 0, sizeof(struct lustre_handle), NULL, NULL);
810 EXPORT_SYMBOL(RMF_CONN);
812 const struct req_msg_field RMF_CONNECT_DATA =
814 RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */,
815 sizeof(struct obd_connect_data), lustre_swab_connect, NULL);
816 EXPORT_SYMBOL(RMF_CONNECT_DATA);
818 const struct req_msg_field RMF_DLM_REQ =
819 DEFINE_MSGF("dlm_req", RMF_F_NO_SIZE_CHECK /* ldlm_request_bufsize */,
820 sizeof(struct ldlm_request),
821 lustre_swab_ldlm_request, NULL);
822 EXPORT_SYMBOL(RMF_DLM_REQ);
824 const struct req_msg_field RMF_DLM_REP =
825 DEFINE_MSGF("dlm_rep", 0,
826 sizeof(struct ldlm_reply), lustre_swab_ldlm_reply, NULL);
827 EXPORT_SYMBOL(RMF_DLM_REP);
829 const struct req_msg_field RMF_LDLM_INTENT =
830 DEFINE_MSGF("ldlm_intent", 0,
831 sizeof(struct ldlm_intent), lustre_swab_ldlm_intent, NULL);
832 EXPORT_SYMBOL(RMF_LDLM_INTENT);
834 const struct req_msg_field RMF_DLM_LVB =
835 DEFINE_MSGF("dlm_lvb", 0, sizeof(struct ost_lvb), lustre_swab_ost_lvb,
837 EXPORT_SYMBOL(RMF_DLM_LVB);
839 const struct req_msg_field RMF_MDT_MD =
840 DEFINE_MSGF("mdt_md", RMF_F_NO_SIZE_CHECK, MIN_MD_SIZE, NULL, NULL);
841 EXPORT_SYMBOL(RMF_MDT_MD);
843 const struct req_msg_field RMF_REC_REINT =
844 DEFINE_MSGF("rec_reint", 0, sizeof(struct mdt_rec_reint),
845 lustre_swab_mdt_rec_reint, NULL);
846 EXPORT_SYMBOL(RMF_REC_REINT);
848 /* FIXME: this length should be defined as a macro */
849 const struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1,
851 EXPORT_SYMBOL(RMF_EADATA);
853 const struct req_msg_field RMF_ACL =
854 DEFINE_MSGF("acl", RMF_F_NO_SIZE_CHECK,
855 LUSTRE_POSIX_ACL_MAX_SIZE, NULL, NULL);
856 EXPORT_SYMBOL(RMF_ACL);
858 /* FIXME: this should be made to use RMF_F_STRUCT_ARRAY */
859 const struct req_msg_field RMF_LOGCOOKIES =
860 DEFINE_MSGF("logcookies", RMF_F_NO_SIZE_CHECK /* multiple cookies */,
861 sizeof(struct llog_cookie), NULL, NULL);
862 EXPORT_SYMBOL(RMF_LOGCOOKIES);
864 const struct req_msg_field RMF_CAPA1 =
865 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
866 lustre_swab_lustre_capa, NULL);
867 EXPORT_SYMBOL(RMF_CAPA1);
869 const struct req_msg_field RMF_CAPA2 =
870 DEFINE_MSGF("capa", 0, sizeof(struct lustre_capa),
871 lustre_swab_lustre_capa, NULL);
872 EXPORT_SYMBOL(RMF_CAPA2);
877 const struct req_msg_field RMF_OST_BODY =
878 DEFINE_MSGF("ost_body", 0,
879 sizeof(struct ost_body), lustre_swab_ost_body, dump_ost_body);
880 EXPORT_SYMBOL(RMF_OST_BODY);
882 const struct req_msg_field RMF_OBD_IOOBJ =
883 DEFINE_MSGF("obd_ioobj", RMF_F_STRUCT_ARRAY,
884 sizeof(struct obd_ioobj), lustre_swab_obd_ioobj, dump_ioo);
885 EXPORT_SYMBOL(RMF_OBD_IOOBJ);
887 const struct req_msg_field RMF_NIOBUF_REMOTE =
888 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY,
889 sizeof(struct niobuf_remote), lustre_swab_niobuf_remote,
891 EXPORT_SYMBOL(RMF_NIOBUF_REMOTE);
893 const struct req_msg_field RMF_RCS =
894 DEFINE_MSGF("niobuf_remote", RMF_F_STRUCT_ARRAY, sizeof(__u32),
895 lustre_swab_generic_32s, dump_rcs);
896 EXPORT_SYMBOL(RMF_RCS);
898 const struct req_msg_field RMF_OBD_ID =
899 DEFINE_MSGF("obd_id", 0,
900 sizeof(obd_id), lustre_swab_ost_last_id, NULL);
901 EXPORT_SYMBOL(RMF_OBD_ID);
903 const struct req_msg_field RMF_FIEMAP_KEY =
904 DEFINE_MSGF("fiemap", 0, sizeof(struct ll_fiemap_info_key),
905 lustre_swab_fiemap, NULL);
906 EXPORT_SYMBOL(RMF_FIEMAP_KEY);
908 const struct req_msg_field RMF_FIEMAP_VAL =
909 DEFINE_MSGF("fiemap", 0, -1, lustre_swab_fiemap, NULL);
910 EXPORT_SYMBOL(RMF_FIEMAP_VAL);
921 const struct req_msg_field **d;
925 #define DEFINE_REQ_FMT(name, client, client_nr, server, server_nr) { \
939 #define DEFINE_REQ_FMT0(name, client, server) \
940 DEFINE_REQ_FMT(name, client, ARRAY_SIZE(client), server, ARRAY_SIZE(server))
942 const struct req_format RQF_OBD_PING =
943 DEFINE_REQ_FMT0("OBD_PING", empty, empty);
944 EXPORT_SYMBOL(RQF_OBD_PING);
946 const struct req_format RQF_OBD_SET_INFO =
947 DEFINE_REQ_FMT0("OBD_SET_INFO", obd_set_info_client, empty);
948 EXPORT_SYMBOL(RQF_OBD_SET_INFO);
950 const struct req_format RQF_SEC_CTX =
951 DEFINE_REQ_FMT0("SEC_CTX", empty, empty);
952 EXPORT_SYMBOL(RQF_SEC_CTX);
954 const struct req_format RQF_MGS_TARGET_REG =
955 DEFINE_REQ_FMT0("MGS_TARGET_REG", mgs_target_info_only,
956 mgs_target_info_only);
957 EXPORT_SYMBOL(RQF_MGS_TARGET_REG);
959 const struct req_format RQF_MGS_SET_INFO =
960 DEFINE_REQ_FMT0("MGS_SET_INFO", mgs_set_info,
962 EXPORT_SYMBOL(RQF_MGS_SET_INFO);
964 const struct req_format RQF_SEQ_QUERY =
965 DEFINE_REQ_FMT0("SEQ_QUERY", seq_query_client, seq_query_server);
966 EXPORT_SYMBOL(RQF_SEQ_QUERY);
968 const struct req_format RQF_FLD_QUERY =
969 DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
970 EXPORT_SYMBOL(RQF_FLD_QUERY);
972 const struct req_format RQF_LOG_CANCEL =
973 DEFINE_REQ_FMT0("OBD_LOG_CANCEL", log_cancel_client, empty);
974 EXPORT_SYMBOL(RQF_LOG_CANCEL);
976 const struct req_format RQF_MDS_QUOTACHECK =
977 DEFINE_REQ_FMT0("MDS_QUOTACHECK", quotactl_only, empty);
978 EXPORT_SYMBOL(RQF_MDS_QUOTACHECK);
980 const struct req_format RQF_OST_QUOTACHECK =
981 DEFINE_REQ_FMT0("OST_QUOTACHECK", quotactl_only, empty);
982 EXPORT_SYMBOL(RQF_OST_QUOTACHECK);
984 const struct req_format RQF_MDS_QUOTACTL =
985 DEFINE_REQ_FMT0("MDS_QUOTACTL", quotactl_only, quotactl_only);
986 EXPORT_SYMBOL(RQF_MDS_QUOTACTL);
988 const struct req_format RQF_OST_QUOTACTL =
989 DEFINE_REQ_FMT0("OST_QUOTACTL", quotactl_only, quotactl_only);
990 EXPORT_SYMBOL(RQF_OST_QUOTACTL);
992 const struct req_format RQF_OST_QUOTA_ADJUST_QUNIT =
993 DEFINE_REQ_FMT0("OST_QUOTA_ADJUST_QUNIT", quota_adjust_qunit_only,
994 quota_adjust_qunit_only);
995 EXPORT_SYMBOL(RQF_OST_QUOTA_ADJUST_QUNIT);
997 const struct req_format RQF_QC_CALLBACK =
998 DEFINE_REQ_FMT0("QC_CALLBACK", quotactl_only, empty);
999 EXPORT_SYMBOL(RQF_QC_CALLBACK);
1001 const struct req_format RQF_MDS_QUOTA_DQACQ =
1002 DEFINE_REQ_FMT0("MDS_QUOTA_DQACQ", qunit_data_only, qunit_data_only);
1003 EXPORT_SYMBOL(RQF_MDS_QUOTA_DQACQ);
1005 const struct req_format RQF_MDS_GETSTATUS =
1006 DEFINE_REQ_FMT0("MDS_GETSTATUS", mdt_body_only, mdt_body_capa);
1007 EXPORT_SYMBOL(RQF_MDS_GETSTATUS);
1009 const struct req_format RQF_MDS_STATFS =
1010 DEFINE_REQ_FMT0("MDS_STATFS", empty, obd_statfs_server);
1011 EXPORT_SYMBOL(RQF_MDS_STATFS);
1013 const struct req_format RQF_MDS_SYNC =
1014 DEFINE_REQ_FMT0("MDS_SYNC", mdt_body_capa, mdt_body_only);
1015 EXPORT_SYMBOL(RQF_MDS_SYNC);
1017 const struct req_format RQF_MDS_GETATTR =
1018 DEFINE_REQ_FMT0("MDS_GETATTR", mdt_body_capa, mds_getattr_server);
1019 EXPORT_SYMBOL(RQF_MDS_GETATTR);
1021 const struct req_format RQF_MDS_GETXATTR =
1022 DEFINE_REQ_FMT0("MDS_GETXATTR",
1023 mds_getxattr_client, mds_getxattr_server);
1024 EXPORT_SYMBOL(RQF_MDS_GETXATTR);
1026 const struct req_format RQF_MDS_GETATTR_NAME =
1027 DEFINE_REQ_FMT0("MDS_GETATTR_NAME",
1028 mds_getattr_name_client, mds_getattr_server);
1029 EXPORT_SYMBOL(RQF_MDS_GETATTR_NAME);
1031 const struct req_format RQF_MDS_REINT =
1032 DEFINE_REQ_FMT0("MDS_REINT", mds_reint_client, mdt_body_only);
1033 EXPORT_SYMBOL(RQF_MDS_REINT);
1035 const struct req_format RQF_MDS_REINT_CREATE =
1036 DEFINE_REQ_FMT0("MDS_REINT_CREATE",
1037 mds_reint_create_client, mdt_body_capa);
1038 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE);
1040 const struct req_format RQF_MDS_REINT_CREATE_RMT_ACL =
1041 DEFINE_REQ_FMT0("MDS_REINT_CREATE_RMT_ACL",
1042 mds_reint_create_rmt_acl_client, mdt_body_capa);
1043 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_RMT_ACL);
1045 const struct req_format RQF_MDS_REINT_CREATE_SLAVE =
1046 DEFINE_REQ_FMT0("MDS_REINT_CREATE_EA",
1047 mds_reint_create_slave_client, mdt_body_capa);
1048 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SLAVE);
1050 const struct req_format RQF_MDS_REINT_CREATE_SYM =
1051 DEFINE_REQ_FMT0("MDS_REINT_CREATE_SYM",
1052 mds_reint_create_sym_client, mdt_body_capa);
1053 EXPORT_SYMBOL(RQF_MDS_REINT_CREATE_SYM);
1055 const struct req_format RQF_MDS_REINT_OPEN =
1056 DEFINE_REQ_FMT0("MDS_REINT_OPEN",
1057 mds_reint_open_client, mds_reint_open_server);
1058 EXPORT_SYMBOL(RQF_MDS_REINT_OPEN);
1060 const struct req_format RQF_MDS_REINT_UNLINK =
1061 DEFINE_REQ_FMT0("MDS_REINT_UNLINK", mds_reint_unlink_client,
1062 mds_last_unlink_server);
1063 EXPORT_SYMBOL(RQF_MDS_REINT_UNLINK);
1065 const struct req_format RQF_MDS_REINT_LINK =
1066 DEFINE_REQ_FMT0("MDS_REINT_LINK",
1067 mds_reint_link_client, mdt_body_only);
1068 EXPORT_SYMBOL(RQF_MDS_REINT_LINK);
1070 const struct req_format RQF_MDS_REINT_RENAME =
1071 DEFINE_REQ_FMT0("MDS_REINT_RENAME", mds_reint_rename_client,
1072 mds_last_unlink_server);
1073 EXPORT_SYMBOL(RQF_MDS_REINT_RENAME);
1075 const struct req_format RQF_MDS_REINT_SETATTR =
1076 DEFINE_REQ_FMT0("MDS_REINT_SETATTR",
1077 mds_reint_setattr_client, mds_setattr_server);
1078 EXPORT_SYMBOL(RQF_MDS_REINT_SETATTR);
1080 const struct req_format RQF_MDS_REINT_SETXATTR =
1081 DEFINE_REQ_FMT0("MDS_REINT_SETXATTR",
1082 mds_reint_setxattr_client, mdt_body_only);
1083 EXPORT_SYMBOL(RQF_MDS_REINT_SETXATTR);
1085 const struct req_format RQF_MDS_CONNECT =
1086 DEFINE_REQ_FMT0("MDS_CONNECT",
1087 obd_connect_client, obd_connect_server);
1088 EXPORT_SYMBOL(RQF_MDS_CONNECT);
1090 const struct req_format RQF_MDS_DISCONNECT =
1091 DEFINE_REQ_FMT0("MDS_DISCONNECT", empty, empty);
1092 EXPORT_SYMBOL(RQF_MDS_DISCONNECT);
1094 const struct req_format RQF_MDS_GET_INFO =
1095 DEFINE_REQ_FMT0("MDS_GET_INFO", mds_getinfo_client,
1096 mds_getinfo_server);
1097 EXPORT_SYMBOL(RQF_MDS_GET_INFO);
1099 const struct req_format RQF_LDLM_ENQUEUE =
1100 DEFINE_REQ_FMT0("LDLM_ENQUEUE",
1101 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1102 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE);
1104 const struct req_format RQF_LDLM_ENQUEUE_LVB =
1105 DEFINE_REQ_FMT0("LDLM_ENQUEUE_LVB",
1106 ldlm_enqueue_client, ldlm_enqueue_lvb_server);
1107 EXPORT_SYMBOL(RQF_LDLM_ENQUEUE_LVB);
1109 const struct req_format RQF_LDLM_CONVERT =
1110 DEFINE_REQ_FMT0("LDLM_CONVERT",
1111 ldlm_enqueue_client, ldlm_enqueue_server);
1112 EXPORT_SYMBOL(RQF_LDLM_CONVERT);
1114 const struct req_format RQF_LDLM_CANCEL =
1115 DEFINE_REQ_FMT0("LDLM_CANCEL", ldlm_enqueue_client, empty);
1116 EXPORT_SYMBOL(RQF_LDLM_CANCEL);
1118 const struct req_format RQF_LDLM_CALLBACK =
1119 DEFINE_REQ_FMT0("LDLM_CALLBACK", ldlm_enqueue_client, empty);
1120 EXPORT_SYMBOL(RQF_LDLM_CALLBACK);
1122 const struct req_format RQF_LDLM_CP_CALLBACK =
1123 DEFINE_REQ_FMT0("LDLM_CP_CALLBACK", ldlm_cp_callback_client, empty);
1124 EXPORT_SYMBOL(RQF_LDLM_CP_CALLBACK);
1126 const struct req_format RQF_LDLM_BL_CALLBACK =
1127 DEFINE_REQ_FMT0("LDLM_BL_CALLBACK", ldlm_enqueue_client, empty);
1128 EXPORT_SYMBOL(RQF_LDLM_BL_CALLBACK);
1130 const struct req_format RQF_LDLM_GL_CALLBACK =
1131 DEFINE_REQ_FMT0("LDLM_GL_CALLBACK", ldlm_enqueue_client,
1132 ldlm_gl_callback_server);
1133 EXPORT_SYMBOL(RQF_LDLM_GL_CALLBACK);
1135 const struct req_format RQF_LDLM_INTENT =
1136 DEFINE_REQ_FMT0("LDLM_INTENT",
1137 ldlm_intent_client, ldlm_intent_server);
1138 EXPORT_SYMBOL(RQF_LDLM_INTENT);
1140 const struct req_format RQF_LDLM_INTENT_GETATTR =
1141 DEFINE_REQ_FMT0("LDLM_INTENT_GETATTR",
1142 ldlm_intent_getattr_client, ldlm_intent_getattr_server);
1143 EXPORT_SYMBOL(RQF_LDLM_INTENT_GETATTR);
1145 const struct req_format RQF_LDLM_INTENT_OPEN =
1146 DEFINE_REQ_FMT0("LDLM_INTENT_OPEN",
1147 ldlm_intent_open_client, ldlm_intent_open_server);
1148 EXPORT_SYMBOL(RQF_LDLM_INTENT_OPEN);
1150 const struct req_format RQF_LDLM_INTENT_CREATE =
1151 DEFINE_REQ_FMT0("LDLM_INTENT_CREATE",
1152 ldlm_intent_create_client, ldlm_intent_getattr_server);
1153 EXPORT_SYMBOL(RQF_LDLM_INTENT_CREATE);
1155 const struct req_format RQF_LDLM_INTENT_UNLINK =
1156 DEFINE_REQ_FMT0("LDLM_INTENT_UNLINK",
1157 ldlm_intent_unlink_client, ldlm_intent_server);
1158 EXPORT_SYMBOL(RQF_LDLM_INTENT_UNLINK);
1160 const struct req_format RQF_MDS_CLOSE =
1161 DEFINE_REQ_FMT0("MDS_CLOSE",
1162 mdt_close_client, mds_last_unlink_server);
1163 EXPORT_SYMBOL(RQF_MDS_CLOSE);
1165 const struct req_format RQF_MDS_PIN =
1166 DEFINE_REQ_FMT0("MDS_PIN",
1167 mdt_body_capa, mdt_body_only);
1168 EXPORT_SYMBOL(RQF_MDS_PIN);
1170 const struct req_format RQF_MDS_UNPIN =
1171 DEFINE_REQ_FMT0("MDS_UNPIN", mdt_body_only, empty);
1172 EXPORT_SYMBOL(RQF_MDS_UNPIN);
1174 const struct req_format RQF_MDS_DONE_WRITING =
1175 DEFINE_REQ_FMT0("MDS_DONE_WRITING",
1176 mdt_close_client, mdt_body_only);
1177 EXPORT_SYMBOL(RQF_MDS_DONE_WRITING);
1179 const struct req_format RQF_MDS_READPAGE =
1180 DEFINE_REQ_FMT0("MDS_READPAGE",
1181 mdt_body_capa, mdt_body_only);
1182 EXPORT_SYMBOL(RQF_MDS_READPAGE);
1184 /* This is for split */
1185 const struct req_format RQF_MDS_WRITEPAGE =
1186 DEFINE_REQ_FMT0("MDS_WRITEPAGE",
1187 mdt_body_capa, mdt_body_only);
1188 EXPORT_SYMBOL(RQF_MDS_WRITEPAGE);
1190 const struct req_format RQF_MDS_IS_SUBDIR =
1191 DEFINE_REQ_FMT0("MDS_IS_SUBDIR",
1192 mdt_body_only, mdt_body_only);
1193 EXPORT_SYMBOL(RQF_MDS_IS_SUBDIR);
1195 const struct req_format RQF_LLOG_CATINFO =
1196 DEFINE_REQ_FMT0("LLOG_CATINFO",
1197 llog_catinfo_client, llog_catinfo_server);
1198 EXPORT_SYMBOL(RQF_LLOG_CATINFO);
1200 const struct req_format RQF_LLOG_ORIGIN_HANDLE_CREATE =
1201 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_CREATE",
1202 llog_origin_handle_create_client, llogd_body_only);
1203 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_CREATE);
1205 const struct req_format RQF_LLOG_ORIGIN_HANDLE_DESTROY =
1206 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_DESTROY",
1207 llogd_body_only, llogd_body_only);
1208 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1210 const struct req_format RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK =
1211 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_NEXT_BLOCK",
1212 llogd_body_only, llog_origin_handle_next_block_server);
1213 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1215 const struct req_format RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK =
1216 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_PREV_BLOCK",
1217 llogd_body_only, llog_origin_handle_next_block_server);
1218 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1220 const struct req_format RQF_LLOG_ORIGIN_HANDLE_READ_HEADER =
1221 DEFINE_REQ_FMT0("LLOG_ORIGIN_HANDLE_READ_HEADER",
1222 llogd_body_only, llog_log_hdr_only);
1223 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1225 const struct req_format RQF_LLOG_ORIGIN_CONNECT =
1226 DEFINE_REQ_FMT0("LLOG_ORIGIN_CONNECT", llogd_conn_body_only, empty);
1227 EXPORT_SYMBOL(RQF_LLOG_ORIGIN_CONNECT);
1229 const struct req_format RQF_OST_CONNECT =
1230 DEFINE_REQ_FMT0("OST_CONNECT",
1231 obd_connect_client, obd_connect_server);
1232 EXPORT_SYMBOL(RQF_OST_CONNECT);
1234 const struct req_format RQF_OST_DISCONNECT =
1235 DEFINE_REQ_FMT0("OST_DISCONNECT", empty, empty);
1236 EXPORT_SYMBOL(RQF_OST_DISCONNECT);
1238 const struct req_format RQF_OST_GETATTR =
1239 DEFINE_REQ_FMT0("OST_GETATTR", ost_body_capa, ost_body_only);
1240 EXPORT_SYMBOL(RQF_OST_GETATTR);
1242 const struct req_format RQF_OST_SETATTR =
1243 DEFINE_REQ_FMT0("OST_SETATTR", ost_body_capa, ost_body_only);
1244 EXPORT_SYMBOL(RQF_OST_SETATTR);
1246 const struct req_format RQF_OST_CREATE =
1247 DEFINE_REQ_FMT0("OST_CREATE", ost_body_only, ost_body_only);
1248 EXPORT_SYMBOL(RQF_OST_CREATE);
1250 const struct req_format RQF_OST_PUNCH =
1251 DEFINE_REQ_FMT0("OST_PUNCH", ost_body_capa, ost_body_only);
1252 EXPORT_SYMBOL(RQF_OST_PUNCH);
1254 const struct req_format RQF_OST_SYNC =
1255 DEFINE_REQ_FMT0("OST_SYNC", ost_body_capa, ost_body_only);
1256 EXPORT_SYMBOL(RQF_OST_SYNC);
1258 const struct req_format RQF_OST_DESTROY =
1259 DEFINE_REQ_FMT0("OST_DESTROY", ost_destroy_client, ost_body_only);
1260 EXPORT_SYMBOL(RQF_OST_DESTROY);
1262 const struct req_format RQF_OST_BRW =
1263 DEFINE_REQ_FMT0("OST_BRW", ost_brw_client, ost_brw_server);
1264 EXPORT_SYMBOL(RQF_OST_BRW);
1266 const struct req_format RQF_OST_STATFS =
1267 DEFINE_REQ_FMT0("OST_STATFS", empty, obd_statfs_server);
1268 EXPORT_SYMBOL(RQF_OST_STATFS);
1270 const struct req_format RQF_OST_SET_GRANT_INFO =
1271 DEFINE_REQ_FMT0("OST_SET_GRANT_INFO", ost_grant_shrink_client,
1273 EXPORT_SYMBOL(RQF_OST_SET_GRANT_INFO);
1275 const struct req_format RQF_OST_GET_INFO_GENERIC =
1276 DEFINE_REQ_FMT0("OST_GET_INFO", ost_get_info_generic_client,
1277 ost_get_info_generic_server);
1278 EXPORT_SYMBOL(RQF_OST_GET_INFO_GENERIC);
1280 const struct req_format RQF_OST_GET_INFO_LAST_ID =
1281 DEFINE_REQ_FMT0("OST_GET_INFO_LAST_ID", ost_get_info_generic_client,
1282 ost_get_last_id_server);
1283 EXPORT_SYMBOL(RQF_OST_GET_INFO_LAST_ID);
1285 const struct req_format RQF_OST_GET_INFO_FIEMAP =
1286 DEFINE_REQ_FMT0("OST_GET_INFO_FIEMAP", ost_get_fiemap_client,
1287 ost_get_fiemap_server);
1288 EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP);
1291 #if !defined(__REQ_LAYOUT_USER__)
1293 /* Convenience macro */
1294 #define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1297 * Initializes the capsule abstraction by computing and setting the \a rf_idx
1298 * field of RQFs and the \a rmf_offset field of RMFs.
1300 int req_layout_init(void)
1305 struct req_format *rf = NULL;
1307 for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
1308 rf = (struct req_format *)req_formats[i];
1310 for (j = 0; j < RCL_NR; ++j) {
1311 LASSERT(rf->rf_fields[j].nr <= REQ_MAX_FIELD_NR);
1312 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
1313 struct req_msg_field *field;
1315 field = (typeof(field))rf->rf_fields[j].d[k];
1316 LASSERT(!(field->rmf_flags & RMF_F_STRUCT_ARRAY)
1317 || field->rmf_size > 0);
1318 LASSERT(field->rmf_offset[i][j] == 0);
1320 * k + 1 to detect unused format/field
1323 field->rmf_offset[i][j] = k + 1;
1329 EXPORT_SYMBOL(req_layout_init);
1331 void req_layout_fini(void)
1334 EXPORT_SYMBOL(req_layout_fini);
1337 * Initializes the expected sizes of each RMF in a \a pill (\a rc_area) to -1.
1339 * Actual/expected field sizes are set elsewhere in functions in this file:
1340 * req_capsule_init(), req_capsule_server_pack(), req_capsule_set_size() and
1341 * req_capsule_msg_size(). The \a rc_area information is used by.
1342 * ptlrpc_request_set_replen().
1344 void req_capsule_init_area(struct req_capsule *pill)
1348 for (i = 0; i < ARRAY_SIZE(pill->rc_area[RCL_CLIENT]); i++) {
1349 pill->rc_area[RCL_CLIENT][i] = -1;
1350 pill->rc_area[RCL_SERVER][i] = -1;
1353 EXPORT_SYMBOL(req_capsule_init_area);
1356 * Initialize a pill.
1358 * The \a location indicates whether the caller is executing on the client side
1359 * (RCL_CLIENT) or server side (RCL_SERVER)..
1361 void req_capsule_init(struct req_capsule *pill,
1362 struct ptlrpc_request *req,
1363 enum req_location location)
1365 LASSERT(location == RCL_SERVER || location == RCL_CLIENT);
1368 * Today all capsules are embedded in ptlrpc_request structs,
1369 * but just in case that ever isn't the case, we don't reach
1370 * into req unless req != NULL and pill is the one embedded in
1373 * The req->rq_pill_init flag makes it safe to initialize a pill
1374 * twice, which might happen in the OST paths as a result of the
1375 * high-priority RPC queue getting peeked at before ost_handle()
1376 * handles an OST RPC.
1378 if (req != NULL && pill == &req->rq_pill && req->rq_pill_init)
1381 memset(pill, 0, sizeof *pill);
1383 pill->rc_loc = location;
1384 req_capsule_init_area(pill);
1386 if (req != NULL && pill == &req->rq_pill)
1387 req->rq_pill_init = 1;
1389 EXPORT_SYMBOL(req_capsule_init);
1391 void req_capsule_fini(struct req_capsule *pill)
1394 EXPORT_SYMBOL(req_capsule_fini);
1396 static int __req_format_is_sane(const struct req_format *fmt)
1399 0 <= fmt->rf_idx && fmt->rf_idx < ARRAY_SIZE(req_formats) &&
1400 req_formats[fmt->rf_idx] == fmt;
1403 static struct lustre_msg *__req_msg(const struct req_capsule *pill,
1404 enum req_location loc)
1406 struct ptlrpc_request *req;
1409 return loc == RCL_CLIENT ? req->rq_reqmsg : req->rq_repmsg;
1413 * Set the format (\a fmt) of a \a pill; format changes are not allowed here
1414 * (see req_capsule_extend()).
1416 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt)
1418 LASSERT(pill->rc_fmt == NULL || pill->rc_fmt == fmt);
1419 LASSERT(__req_format_is_sane(fmt));
1423 EXPORT_SYMBOL(req_capsule_set);
1426 * Fills in any parts of the \a rc_area of a \a pill that haven't been filled in
1429 * \a rc_area is an array of REQ_MAX_FIELD_NR elements, used to store sizes of
1430 * variable-sized fields. The field sizes come from the declared \a rmf_size
1431 * field of a \a pill's \a rc_fmt's RMF's.
1433 int req_capsule_filled_sizes(struct req_capsule *pill,
1434 enum req_location loc)
1436 const struct req_format *fmt = pill->rc_fmt;
1439 LASSERT(fmt != NULL);
1441 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1442 if (pill->rc_area[loc][i] == -1) {
1443 pill->rc_area[loc][i] =
1444 fmt->rf_fields[loc].d[i]->rmf_size;
1445 if (pill->rc_area[loc][i] == -1) {
1447 * Skip the following fields.
1449 * If this LASSERT() trips then you're missing a
1450 * call to req_capsule_set_size().
1452 LASSERT(loc != RCL_SERVER);
1459 EXPORT_SYMBOL(req_capsule_filled_sizes);
1462 * Capsule equivalent of lustre_pack_request() and lustre_pack_reply().
1464 * This function uses the \a pill's \a rc_area as filled in by
1465 * req_capsule_set_size() or req_capsule_filled_sizes() (the latter is called by
1468 int req_capsule_server_pack(struct req_capsule *pill)
1470 const struct req_format *fmt;
1474 LASSERT(pill->rc_loc == RCL_SERVER);
1476 LASSERT(fmt != NULL);
1478 count = req_capsule_filled_sizes(pill, RCL_SERVER);
1479 rc = lustre_pack_reply(pill->rc_req, count,
1480 pill->rc_area[RCL_SERVER], NULL);
1482 DEBUG_REQ(D_ERROR, pill->rc_req,
1483 "Cannot pack %d fields in format `%s': ",
1484 count, fmt->rf_name);
1488 EXPORT_SYMBOL(req_capsule_server_pack);
1491 * Returns the PTLRPC request or reply (\a loc) buffer offset of a \a pill
1492 * corresponding to the given RMF (\a field).
1494 static int __req_capsule_offset(const struct req_capsule *pill,
1495 const struct req_msg_field *field,
1496 enum req_location loc)
1500 offset = field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1501 LASSERTF(offset > 0, "%s:%s, off=%d, loc=%d\n",
1502 pill->rc_fmt->rf_name,
1503 field->rmf_name, offset, loc);
1506 LASSERT(0 <= offset && offset < REQ_MAX_FIELD_NR);
1511 * Helper for __req_capsule_get(); swabs value / array of values and/or dumps
1516 swabber_dumper_helper(struct req_capsule *pill,
1517 const struct req_msg_field *field,
1518 enum req_location loc,
1520 void *value, int len, int dump, void (*swabber)( void *))
1526 int inout = loc == RCL_CLIENT;
1528 swabber = swabber ?: field->rmf_swabber;
1530 if (ptlrpc_buf_need_swab(pill->rc_req, inout, offset) &&
1531 swabber != NULL && value != NULL)
1536 if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY)) {
1537 if (dump && field->rmf_dumper) {
1538 CDEBUG(D_RPCTRACE, "Dump of %sfield %s follows\n",
1539 do_swab ? "unswabbed " : "", field->rmf_name);
1540 field->rmf_dumper(value);
1545 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1547 CDEBUG(D_RPCTRACE, "Dump of swabbed field %s "
1548 "follows\n", field->rmf_name);
1549 field->rmf_dumper(value);
1556 * We're swabbing an array; swabber() swabs a single array element, so
1557 * swab every element.
1559 LASSERT((len % field->rmf_size) == 0);
1560 for (p = value, i = 0, n = len / field->rmf_size;
1562 i++, p += field->rmf_size) {
1563 if (dump && field->rmf_dumper) {
1564 CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, "
1565 "element %d follows\n",
1566 do_swab ? "unswabbed " : "", field->rmf_name, i);
1567 field->rmf_dumper(p);
1572 if (dump && field->rmf_dumper) {
1573 CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, "
1574 "element %d follows\n", field->rmf_name, i);
1575 field->rmf_dumper(value);
1579 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1583 * Returns the pointer to a PTLRPC request or reply (\a loc) buffer of a \a pill
1584 * corresponding to the given RMF (\a field).
1586 * The buffer will be swabbed using the given \a swabber. If \a swabber == NULL
1587 * then the \a rmf_swabber from the RMF will be used. Soon there will be no
1588 * calls to __req_capsule_get() with a non-NULL \a swabber; \a swabber will then
1589 * be removed. Fields with the \a RMF_F_STRUCT_ARRAY flag set will have each
1590 * element of the array swabbed.
1592 static void *__req_capsule_get(struct req_capsule *pill,
1593 const struct req_msg_field *field,
1594 enum req_location loc,
1595 void (*swabber)( void *),
1598 const struct req_format *fmt;
1599 struct lustre_msg *msg;
1604 void *(*getter)(struct lustre_msg *m, int n, int minlen);
1606 static const char *rcl_names[RCL_NR] = {
1607 [RCL_CLIENT] = "client",
1608 [RCL_SERVER] = "server"
1611 LASSERT(pill != NULL);
1612 LASSERT(pill != LP_POISON);
1614 LASSERT(fmt != NULL);
1615 LASSERT(fmt != LP_POISON);
1616 LASSERT(__req_format_is_sane(fmt));
1618 offset = __req_capsule_offset(pill, field, loc);
1620 msg = __req_msg(pill, loc);
1621 LASSERT(msg != NULL);
1623 getter = (field->rmf_flags & RMF_F_STRING) ?
1624 (typeof(getter))lustre_msg_string : lustre_msg_buf;
1626 if (field->rmf_flags & RMF_F_STRUCT_ARRAY) {
1628 * We've already asserted that field->rmf_size > 0 in
1629 * req_layout_init().
1631 len = lustre_msg_buflen(msg, offset);
1632 if ((len % field->rmf_size) != 0) {
1633 CERROR("%s: array field size mismatch "
1634 "%d modulo %d != 0 (%d)\n",
1635 field->rmf_name, len, field->rmf_size, loc);
1638 } else if (pill->rc_area[loc][offset] != -1) {
1639 len = pill->rc_area[loc][offset];
1641 len = max(field->rmf_size, 0);
1643 value = getter(msg, offset, len);
1645 if (value == NULL) {
1646 DEBUG_REQ(D_ERROR, pill->rc_req,
1647 "Wrong buffer for field `%s' (%d of %d) "
1648 "in format `%s': %d vs. %d (%s)\n",
1649 field->rmf_name, offset, lustre_msg_bufcount(msg),
1650 fmt->rf_name, lustre_msg_buflen(msg, offset), len,
1653 swabber_dumper_helper(pill, field, loc, offset, value, len,
1661 * Dump a request and/or reply
1663 void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
1665 const struct req_format *fmt;
1666 const struct req_msg_field *field;
1672 DEBUG_REQ(D_RPCTRACE, pill->rc_req, "BEGIN REQ CAPSULE DUMP\n");
1673 for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
1674 field = FMT_FIELD(fmt, loc, i);
1675 if (field->rmf_dumper == NULL) {
1677 * FIXME Add a default hex dumper for fields that don't
1678 * have a specific dumper
1680 len = req_capsule_get_size(pill, field, loc);
1681 CDEBUG(D_RPCTRACE, "Field %s has no dumper function;"
1682 "field size is %d\n", field->rmf_name, len);
1684 /* It's the dumping side-effect that we're interested in */
1685 (void) __req_capsule_get(pill, field, loc, NULL, 1);
1688 CDEBUG(D_RPCTRACE, "END REQ CAPSULE DUMP\n");
1694 void req_capsule_client_dump(struct req_capsule *pill)
1696 __req_capsule_dump(pill, RCL_CLIENT);
1698 EXPORT_SYMBOL(req_capsule_client_dump);
1703 void req_capsule_server_dump(struct req_capsule *pill)
1705 __req_capsule_dump(pill, RCL_SERVER);
1707 EXPORT_SYMBOL(req_capsule_server_dump);
1710 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC request
1711 * buffer corresponding to the given RMF (\a field) of a \a pill.
1713 void *req_capsule_client_get(struct req_capsule *pill,
1714 const struct req_msg_field *field)
1716 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1718 EXPORT_SYMBOL(req_capsule_client_get);
1721 * Same as req_capsule_client_get(), but with a \a swabber argument.
1723 * Currently unused; will be removed when req_capsule_server_swab_get() is
1726 void *req_capsule_client_swab_get(struct req_capsule *pill,
1727 const struct req_msg_field *field,
1728 void (*swabber)(void* ))
1730 return __req_capsule_get(pill, field, RCL_CLIENT, swabber, 0);
1732 EXPORT_SYMBOL(req_capsule_client_swab_get);
1735 * Utility that combines req_capsule_set_size() and req_capsule_client_get().
1737 * First the \a pill's request \a field's size is set (\a rc_area) using
1738 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1741 void *req_capsule_client_sized_get(struct req_capsule *pill,
1742 const struct req_msg_field *field,
1745 req_capsule_set_size(pill, field, RCL_CLIENT, len);
1746 return __req_capsule_get(pill, field, RCL_CLIENT, NULL, 0);
1748 EXPORT_SYMBOL(req_capsule_client_sized_get);
1751 * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC reply
1752 * buffer corresponding to the given RMF (\a field) of a \a pill.
1754 void *req_capsule_server_get(struct req_capsule *pill,
1755 const struct req_msg_field *field)
1757 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1759 EXPORT_SYMBOL(req_capsule_server_get);
1762 * Same as req_capsule_server_get(), but with a \a swabber argument.
1764 * Ideally all swabbing should be done pursuant to RMF definitions, with no
1765 * swabbing done outside this capsule abstraction.
1767 void *req_capsule_server_swab_get(struct req_capsule *pill,
1768 const struct req_msg_field *field,
1771 return __req_capsule_get(pill, field, RCL_SERVER, swabber, 0);
1773 EXPORT_SYMBOL(req_capsule_server_swab_get);
1776 * Utility that combines req_capsule_set_size() and req_capsule_server_get().
1778 * First the \a pill's request \a field's size is set (\a rc_area) using
1779 * req_capsule_set_size() with the given \a len. Then the actual buffer is
1782 void *req_capsule_server_sized_get(struct req_capsule *pill,
1783 const struct req_msg_field *field,
1786 req_capsule_set_size(pill, field, RCL_SERVER, len);
1787 return __req_capsule_get(pill, field, RCL_SERVER, NULL, 0);
1789 EXPORT_SYMBOL(req_capsule_server_sized_get);
1792 * Returns the buffer of a \a pill corresponding to the given \a field from the
1793 * request (if the caller is executing on the server-side) or reply (if the
1794 * caller is executing on the client-side).
1796 * This function convienient for use is code that could be executed on the
1797 * client and server alike.
1799 const void *req_capsule_other_get(struct req_capsule *pill,
1800 const struct req_msg_field *field)
1802 return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL, 0);
1804 EXPORT_SYMBOL(req_capsule_other_get);
1807 * Set the size of the PTLRPC request/reply (\a loc) buffer for the given \a
1808 * field of the given \a pill.
1810 * This function must be used when constructing variable sized fields of a
1813 void req_capsule_set_size(struct req_capsule *pill,
1814 const struct req_msg_field *field,
1815 enum req_location loc, int size)
1817 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1819 if ((size != field->rmf_size) &&
1820 (field->rmf_size != -1) &&
1821 !(field->rmf_flags & RMF_F_NO_SIZE_CHECK) &&
1823 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1824 (size % field->rmf_size != 0)) {
1825 CERROR("%s: array field size mismatch "
1826 "%d %% %d != 0 (%d)\n",
1827 field->rmf_name, size, field->rmf_size, loc);
1829 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
1830 size < field->rmf_size) {
1831 CERROR("%s: field size mismatch %d != %d (%d)\n",
1832 field->rmf_name, size, field->rmf_size, loc);
1837 pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size;
1839 EXPORT_SYMBOL(req_capsule_set_size);
1842 * Return the actual PTLRPC buffer length of a request or reply (\a loc)
1843 * for the given \a pill's given \a field.
1845 * NB: this function doesn't correspond with req_capsule_set_size(), which
1846 * actually sets the size in pill.rc_area[loc][offset], but this function
1847 * returns the message buflen[offset], maybe we should use another name.
1849 int req_capsule_get_size(const struct req_capsule *pill,
1850 const struct req_msg_field *field,
1851 enum req_location loc)
1853 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1855 return lustre_msg_buflen(__req_msg(pill, loc),
1856 __req_capsule_offset(pill, field, loc));
1858 EXPORT_SYMBOL(req_capsule_get_size);
1861 * Wrapper around lustre_msg_size() that returns the PTLRPC size needed for the
1862 * given \a pill's request or reply (\a loc) given the field size recorded in
1863 * the \a pill's rc_area.
1865 * See also req_capsule_set_size().
1867 int req_capsule_msg_size(struct req_capsule *pill, enum req_location loc)
1869 return lustre_msg_size(pill->rc_req->rq_import->imp_msg_magic,
1870 pill->rc_fmt->rf_fields[loc].nr,
1871 pill->rc_area[loc]);
1875 * While req_capsule_msg_size() computes the size of a PTLRPC request or reply
1876 * (\a loc) given a \a pill's \a rc_area, this function computes the size of a
1877 * PTLRPC request or reply given only an RQF (\a fmt).
1879 * This function should not be used for formats which contain variable size
1882 int req_capsule_fmt_size(__u32 magic, const struct req_format *fmt,
1883 enum req_location loc)
1888 * This function should probably LASSERT() that fmt has no fields with
1889 * RMF_F_STRUCT_ARRAY in rmf_flags, since we can't know here how many
1890 * elements in the array there will ultimately be, but then, we could
1891 * assume that there will be at least one element, and that's just what
1894 size = lustre_msg_hdr_size(magic, fmt->rf_fields[loc].nr);
1898 for (; i < fmt->rf_fields[loc].nr; ++i)
1899 if (fmt->rf_fields[loc].d[i]->rmf_size != -1)
1900 size += size_round(fmt->rf_fields[loc].d[i]->rmf_size);
1905 * Changes the format of an RPC.
1907 * The pill must already have been initialized, which means that it already has
1908 * a request format. The new format \a fmt must be an extension of the pill's
1909 * old format. Specifically: the new format must have as many request and reply
1910 * fields as the old one, and all fields shared by the old and new format must
1911 * be at least as large in the new format.
1913 * The new format's fields may be of different "type" than the old format, but
1914 * only for fields that are "opaque" blobs: fields which have a) have no
1915 * \a rmf_swabber, b) \a rmf_flags == 0 or RMF_F_NO_SIZE_CHECK, and c) \a
1916 * rmf_size == -1 or \a rmf_flags == RMF_F_NO_SIZE_CHECK. For example,
1917 * OBD_SET_INFO has a key field and an opaque value field that gets interpreted
1918 * according to the key field. When the value, according to the key, contains a
1919 * structure (or array thereof) to be swabbed, the format should be changed to
1920 * one where the value field has \a rmf_size/rmf_flags/rmf_swabber set
1923 void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
1928 const struct req_format *old;
1930 LASSERT(pill->rc_fmt != NULL);
1931 LASSERT(__req_format_is_sane(fmt));
1935 * Sanity checking...
1937 for (i = 0; i < RCL_NR; ++i) {
1938 LASSERT(fmt->rf_fields[i].nr >= old->rf_fields[i].nr);
1939 for (j = 0; j < old->rf_fields[i].nr - 1; ++j) {
1940 const struct req_msg_field *ofield = FMT_FIELD(old, i, j);
1942 /* "opaque" fields can be transmogrified */
1943 if (ofield->rmf_swabber == NULL &&
1944 (ofield->rmf_flags & ~RMF_F_NO_SIZE_CHECK) == 0 &&
1945 (ofield->rmf_size == -1 ||
1946 ofield->rmf_flags == RMF_F_NO_SIZE_CHECK))
1948 LASSERT(FMT_FIELD(fmt, i, j) == FMT_FIELD(old, i, j));
1951 * Last field in old format can be shorter than in new.
1953 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
1954 FMT_FIELD(old, i, j)->rmf_size);
1959 EXPORT_SYMBOL(req_capsule_extend);
1962 * This function returns a non-zero value if the given \a field is present in
1963 * the format (\a rc_fmt) of \a pill's PTLRPC request or reply (\a loc), else it
1966 int req_capsule_has_field(const struct req_capsule *pill,
1967 const struct req_msg_field *field,
1968 enum req_location loc)
1970 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1972 return field->rmf_offset[pill->rc_fmt->rf_idx][loc];
1974 EXPORT_SYMBOL(req_capsule_has_field);
1977 * Returns a non-zero value if the given \a field is present in the given \a
1978 * pill's PTLRPC request or reply (\a loc), else it returns 0.
1980 int req_capsule_field_present(const struct req_capsule *pill,
1981 const struct req_msg_field *field,
1982 enum req_location loc)
1986 LASSERT(loc == RCL_SERVER || loc == RCL_CLIENT);
1987 LASSERT(req_capsule_has_field(pill, field, loc));
1989 offset = __req_capsule_offset(pill, field, loc);
1990 return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
1992 EXPORT_SYMBOL(req_capsule_field_present);
1995 * This function shrinks the size of the _buffer_ of the \a pill's PTLRPC
1996 * request or reply (\a loc).
1998 * This is not the opposite of req_capsule_extend().
2000 void req_capsule_shrink(struct req_capsule *pill,
2001 const struct req_msg_field *field,
2002 unsigned int newlen,
2003 enum req_location loc)
2005 const struct req_format *fmt;
2006 struct lustre_msg *msg;
2011 LASSERT(fmt != NULL);
2012 LASSERT(__req_format_is_sane(fmt));
2013 LASSERT(req_capsule_has_field(pill, field, loc));
2014 LASSERT(req_capsule_field_present(pill, field, loc));
2016 offset = __req_capsule_offset(pill, field, loc);
2018 msg = __req_msg(pill, loc);
2019 len = lustre_msg_buflen(msg, offset);
2020 LASSERTF(newlen <= len, "%s:%s, oldlen=%d, newlen=%d\n",
2021 fmt->rf_name, field->rmf_name, len, newlen);
2023 if (loc == RCL_CLIENT)
2024 pill->rc_req->rq_reqlen = lustre_shrink_msg(msg, offset, newlen,
2027 pill->rc_req->rq_replen = lustre_shrink_msg(msg, offset, newlen,
2030 EXPORT_SYMBOL(req_capsule_shrink);
2032 /* __REQ_LAYOUT_USER__ */