4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
41 #include <sys/types.h>
43 #include <linux/lnet/lnet-types.h>
46 #define strnlen(s, i) strlen(s)
49 #define BLANK_LINE() \
56 printf (" /* "c" */\n"); \
59 #define STRINGIFY(a) #a
61 #define CHECK_DEFINE(a) \
63 printf (" BUILD_BUG_ON("#a" != "STRINGIFY(a)");\n"); \
66 #define CHECK_VALUE(a) \
68 printf (" BUILD_BUG_ON("#a" != %d);\n", a); \
71 #define CHECK_MEMBER_OFFSET(s,m) \
73 CHECK_VALUE((int)offsetof(s, m)); \
76 #define CHECK_MEMBER_SIZEOF(s,m) \
78 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
81 #define CHECK_MEMBER(s,m) \
83 CHECK_MEMBER_OFFSET(s, m); \
84 CHECK_MEMBER_SIZEOF(s, m); \
87 #define CHECK_STRUCT(s) \
90 COMMENT ("Checks for struct "#s); \
91 CHECK_VALUE((int)sizeof(s)); \
95 check_lnet_handle_wire(void)
97 CHECK_STRUCT(struct lnet_handle_wire);
98 CHECK_MEMBER(struct lnet_handle_wire, wh_interface_cookie);
99 CHECK_MEMBER(struct lnet_handle_wire, wh_object_cookie);
103 check_lnet_magicversion (void)
105 CHECK_STRUCT(struct lnet_magicversion);
106 CHECK_MEMBER(struct lnet_magicversion, magic);
107 CHECK_MEMBER(struct lnet_magicversion, version_major);
108 CHECK_MEMBER(struct lnet_magicversion, version_minor);
112 check_lnet_hdr_nid4(void)
114 CHECK_STRUCT(struct _lnet_hdr_nid4);
115 CHECK_MEMBER(struct _lnet_hdr_nid4, dest_nid);
116 CHECK_MEMBER(struct _lnet_hdr_nid4, src_nid);
117 CHECK_MEMBER(struct _lnet_hdr_nid4, dest_pid);
118 CHECK_MEMBER(struct _lnet_hdr_nid4, src_pid);
119 CHECK_MEMBER(struct _lnet_hdr_nid4, type);
120 CHECK_MEMBER(struct _lnet_hdr_nid4, payload_length);
121 CHECK_MEMBER(struct _lnet_hdr_nid4, msg);
125 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.dst_wmd);
126 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.match_bits);
127 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.mlength);
131 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.ack_wmd);
132 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.match_bits);
133 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.hdr_data);
134 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.ptl_index);
135 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.offset);
139 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.return_wmd);
140 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.match_bits);
141 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.ptl_index);
142 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.src_offset);
143 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.sink_length);
147 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.reply.dst_wmd);
151 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.hello.incarnation);
152 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.hello.type);
156 check_lnet_ni_status(void)
159 COMMENT("Checks for struct lnet_ni_status and related constants");
161 CHECK_DEFINE(LNET_NI_STATUS_INVALID);
162 CHECK_DEFINE(LNET_NI_STATUS_UP);
163 CHECK_DEFINE(LNET_NI_STATUS_DOWN);
165 CHECK_STRUCT(struct lnet_ni_status);
166 CHECK_MEMBER(struct lnet_ni_status, ns_nid);
167 CHECK_MEMBER(struct lnet_ni_status, ns_status);
168 CHECK_MEMBER(struct lnet_ni_status, ns_msg_size);
170 CHECK_STRUCT(struct lnet_ni_large_status);
171 CHECK_MEMBER(struct lnet_ni_large_status, ns_status);
172 CHECK_MEMBER(struct lnet_ni_large_status, ns_nid);
176 check_lnet_ping_info(void)
179 COMMENT("Checks for struct lnet_ping_info and related constants");
181 CHECK_DEFINE(LNET_PROTO_PING_MAGIC);
182 CHECK_VALUE(LNET_PING_FEAT_INVAL);
183 CHECK_VALUE(LNET_PING_FEAT_BASE);
184 CHECK_VALUE(LNET_PING_FEAT_NI_STATUS);
185 CHECK_VALUE(LNET_PING_FEAT_RTE_DISABLED);
186 CHECK_VALUE(LNET_PING_FEAT_MULTI_RAIL);
187 CHECK_VALUE(LNET_PING_FEAT_DISCOVERY);
188 CHECK_VALUE(LNET_PING_FEAT_LARGE_ADDR);
189 CHECK_VALUE(LNET_PING_FEAT_PRIMARY_LARGE);
190 CHECK_VALUE(LNET_PING_FEAT_BITS);
192 CHECK_STRUCT(struct lnet_ping_info);
193 CHECK_MEMBER(struct lnet_ping_info, pi_magic);
194 CHECK_MEMBER(struct lnet_ping_info, pi_features);
195 CHECK_MEMBER(struct lnet_ping_info, pi_pid);
196 CHECK_MEMBER(struct lnet_ping_info, pi_nnis);
197 CHECK_MEMBER(struct lnet_ping_info, pi_ni);
201 system_string(char *cmdline, char *str, int len)
214 int fd = fileno(stdout);
216 rc = dup2(fds[1], fd);
220 exit(system(cmdline));
222 } else if ((int)pid < 0) {
225 FILE *f = fdopen (fds[0], "r");
232 if (fgets(str, len, f) == NULL)
235 if (waitpid(pid, &rc, 0) != pid)
238 if (!WIFEXITED(rc) ||
239 WEXITSTATUS(rc) != 0)
242 if (strnlen(str, len) == len)
245 if (str[strlen(str) - 1] == '\n')
246 str[strlen(str) - 1] = 0;
253 main (int argc, char **argv)
258 system_string("uname -a", unameinfo, sizeof(unameinfo));
259 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
261 printf ("void lnet_assert_wire_constants (void)\n"
263 " /* Wire protocol assertions generated by 'wirecheck'\n"
266 "\n", unameinfo, gccinfo);
270 COMMENT ("Constants...");
272 CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
274 CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
275 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
276 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
278 CHECK_VALUE (LNET_MSG_ACK);
279 CHECK_VALUE (LNET_MSG_PUT);
280 CHECK_VALUE (LNET_MSG_GET);
281 CHECK_VALUE (LNET_MSG_REPLY);
282 CHECK_VALUE (LNET_MSG_HELLO);
284 check_lnet_handle_wire();
285 check_lnet_magicversion();
286 check_lnet_hdr_nid4();
287 check_lnet_ni_status();
288 check_lnet_ping_info();