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 (void)
114 CHECK_STRUCT(struct lnet_hdr);
115 CHECK_MEMBER(struct lnet_hdr, dest_nid);
116 CHECK_MEMBER(struct lnet_hdr, src_nid);
117 CHECK_MEMBER(struct lnet_hdr, dest_pid);
118 CHECK_MEMBER(struct lnet_hdr, src_pid);
119 CHECK_MEMBER(struct lnet_hdr, type);
120 CHECK_MEMBER(struct lnet_hdr, payload_length);
121 CHECK_MEMBER(struct lnet_hdr, msg);
125 CHECK_MEMBER(struct lnet_hdr, msg.ack.dst_wmd);
126 CHECK_MEMBER(struct lnet_hdr, msg.ack.match_bits);
127 CHECK_MEMBER(struct lnet_hdr, msg.ack.mlength);
131 CHECK_MEMBER(struct lnet_hdr, msg.put.ack_wmd);
132 CHECK_MEMBER(struct lnet_hdr, msg.put.match_bits);
133 CHECK_MEMBER(struct lnet_hdr, msg.put.hdr_data);
134 CHECK_MEMBER(struct lnet_hdr, msg.put.ptl_index);
135 CHECK_MEMBER(struct lnet_hdr, msg.put.offset);
139 CHECK_MEMBER(struct lnet_hdr, msg.get.return_wmd);
140 CHECK_MEMBER(struct lnet_hdr, msg.get.match_bits);
141 CHECK_MEMBER(struct lnet_hdr, msg.get.ptl_index);
142 CHECK_MEMBER(struct lnet_hdr, msg.get.src_offset);
143 CHECK_MEMBER(struct lnet_hdr, msg.get.sink_length);
147 CHECK_MEMBER(struct lnet_hdr, msg.reply.dst_wmd);
151 CHECK_MEMBER(struct lnet_hdr, msg.hello.incarnation);
152 CHECK_MEMBER(struct lnet_hdr, 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_unused);
172 check_lnet_ping_info(void)
175 COMMENT("Checks for struct lnet_ping_info and related constants");
177 CHECK_DEFINE(LNET_PROTO_PING_MAGIC);
178 CHECK_VALUE(LNET_PING_FEAT_INVAL);
179 CHECK_VALUE(LNET_PING_FEAT_BASE);
180 CHECK_VALUE(LNET_PING_FEAT_NI_STATUS);
181 CHECK_VALUE(LNET_PING_FEAT_RTE_DISABLED);
182 CHECK_VALUE(LNET_PING_FEAT_MULTI_RAIL);
183 CHECK_VALUE(LNET_PING_FEAT_DISCOVERY);
184 CHECK_VALUE(LNET_PING_FEAT_BITS);
186 CHECK_STRUCT(struct lnet_ping_info);
187 CHECK_MEMBER(struct lnet_ping_info, pi_magic);
188 CHECK_MEMBER(struct lnet_ping_info, pi_features);
189 CHECK_MEMBER(struct lnet_ping_info, pi_pid);
190 CHECK_MEMBER(struct lnet_ping_info, pi_nnis);
191 CHECK_MEMBER(struct lnet_ping_info, pi_ni);
195 system_string(char *cmdline, char *str, int len)
208 int fd = fileno(stdout);
210 rc = dup2(fds[1], fd);
214 exit(system(cmdline));
216 } else if ((int)pid < 0) {
219 FILE *f = fdopen (fds[0], "r");
226 if (fgets(str, len, f) == NULL)
229 if (waitpid(pid, &rc, 0) != pid)
232 if (!WIFEXITED(rc) ||
233 WEXITSTATUS(rc) != 0)
236 if (strnlen(str, len) == len)
239 if (str[strlen(str) - 1] == '\n')
240 str[strlen(str) - 1] = 0;
247 main (int argc, char **argv)
252 system_string("uname -a", unameinfo, sizeof(unameinfo));
253 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
255 printf ("void lnet_assert_wire_constants (void)\n"
257 " /* Wire protocol assertions generated by 'wirecheck'\n"
260 "\n", unameinfo, gccinfo);
264 COMMENT ("Constants...");
266 CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
268 CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
269 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
270 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
272 CHECK_VALUE (LNET_MSG_ACK);
273 CHECK_VALUE (LNET_MSG_PUT);
274 CHECK_VALUE (LNET_MSG_GET);
275 CHECK_VALUE (LNET_MSG_REPLY);
276 CHECK_VALUE (LNET_MSG_HELLO);
278 check_lnet_handle_wire();
279 check_lnet_magicversion();
281 check_lnet_ni_status();
282 check_lnet_ping_info();