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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
42 #include <sys/types.h>
44 #include <linux/lnet/lnet-types.h>
47 #define strnlen(s, i) strlen(s)
50 #define BLANK_LINE() \
57 printf (" /* "c" */\n"); \
60 #define STRINGIFY(a) #a
62 #define CHECK_DEFINE(a) \
64 printf (" BUILD_BUG_ON("#a" != "STRINGIFY(a)");\n"); \
67 #define CHECK_VALUE(a) \
69 printf (" BUILD_BUG_ON("#a" != %d);\n", a); \
72 #define CHECK_MEMBER_OFFSET(s,m) \
74 CHECK_VALUE((int)offsetof(s, m)); \
77 #define CHECK_MEMBER_SIZEOF(s,m) \
79 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
82 #define CHECK_MEMBER(s,m) \
84 CHECK_MEMBER_OFFSET(s, m); \
85 CHECK_MEMBER_SIZEOF(s, m); \
88 #define CHECK_STRUCT(s) \
91 COMMENT ("Checks for struct "#s); \
92 CHECK_VALUE((int)sizeof(s)); \
96 check_lnet_handle_wire(void)
98 CHECK_STRUCT(struct lnet_handle_wire);
99 CHECK_MEMBER(struct lnet_handle_wire, wh_interface_cookie);
100 CHECK_MEMBER(struct lnet_handle_wire, wh_object_cookie);
104 check_lnet_magicversion (void)
106 CHECK_STRUCT(struct lnet_magicversion);
107 CHECK_MEMBER(struct lnet_magicversion, magic);
108 CHECK_MEMBER(struct lnet_magicversion, version_major);
109 CHECK_MEMBER(struct lnet_magicversion, version_minor);
113 check_lnet_hdr (void)
115 CHECK_STRUCT(struct lnet_hdr);
116 CHECK_MEMBER(struct lnet_hdr, dest_nid);
117 CHECK_MEMBER(struct lnet_hdr, src_nid);
118 CHECK_MEMBER(struct lnet_hdr, dest_pid);
119 CHECK_MEMBER(struct lnet_hdr, src_pid);
120 CHECK_MEMBER(struct lnet_hdr, type);
121 CHECK_MEMBER(struct lnet_hdr, payload_length);
122 CHECK_MEMBER(struct lnet_hdr, msg);
126 CHECK_MEMBER(struct lnet_hdr, msg.ack.dst_wmd);
127 CHECK_MEMBER(struct lnet_hdr, msg.ack.match_bits);
128 CHECK_MEMBER(struct lnet_hdr, msg.ack.mlength);
132 CHECK_MEMBER(struct lnet_hdr, msg.put.ack_wmd);
133 CHECK_MEMBER(struct lnet_hdr, msg.put.match_bits);
134 CHECK_MEMBER(struct lnet_hdr, msg.put.hdr_data);
135 CHECK_MEMBER(struct lnet_hdr, msg.put.ptl_index);
136 CHECK_MEMBER(struct lnet_hdr, msg.put.offset);
140 CHECK_MEMBER(struct lnet_hdr, msg.get.return_wmd);
141 CHECK_MEMBER(struct lnet_hdr, msg.get.match_bits);
142 CHECK_MEMBER(struct lnet_hdr, msg.get.ptl_index);
143 CHECK_MEMBER(struct lnet_hdr, msg.get.src_offset);
144 CHECK_MEMBER(struct lnet_hdr, msg.get.sink_length);
148 CHECK_MEMBER(struct lnet_hdr, msg.reply.dst_wmd);
152 CHECK_MEMBER(struct lnet_hdr, msg.hello.incarnation);
153 CHECK_MEMBER(struct lnet_hdr, msg.hello.type);
157 check_lnet_ni_status(void)
160 COMMENT("Checks for struct lnet_ni_status and related constants");
162 CHECK_DEFINE(LNET_NI_STATUS_INVALID);
163 CHECK_DEFINE(LNET_NI_STATUS_UP);
164 CHECK_DEFINE(LNET_NI_STATUS_DOWN);
166 CHECK_STRUCT(struct lnet_ni_status);
167 CHECK_MEMBER(struct lnet_ni_status, ns_nid);
168 CHECK_MEMBER(struct lnet_ni_status, ns_status);
169 CHECK_MEMBER(struct lnet_ni_status, ns_unused);
173 check_lnet_ping_info(void)
176 COMMENT("Checks for struct lnet_ping_info and related constants");
178 CHECK_DEFINE(LNET_PROTO_PING_MAGIC);
179 CHECK_VALUE(LNET_PING_FEAT_INVAL);
180 CHECK_VALUE(LNET_PING_FEAT_BASE);
181 CHECK_VALUE(LNET_PING_FEAT_NI_STATUS);
182 CHECK_VALUE(LNET_PING_FEAT_RTE_DISABLED);
183 CHECK_VALUE(LNET_PING_FEAT_MULTI_RAIL);
184 CHECK_VALUE(LNET_PING_FEAT_DISCOVERY);
185 CHECK_VALUE(LNET_PING_FEAT_BITS);
187 CHECK_STRUCT(struct lnet_ping_info);
188 CHECK_MEMBER(struct lnet_ping_info, pi_magic);
189 CHECK_MEMBER(struct lnet_ping_info, pi_features);
190 CHECK_MEMBER(struct lnet_ping_info, pi_pid);
191 CHECK_MEMBER(struct lnet_ping_info, pi_nnis);
192 CHECK_MEMBER(struct lnet_ping_info, pi_ni);
196 system_string(char *cmdline, char *str, int len)
209 int fd = fileno(stdout);
211 rc = dup2(fds[1], fd);
215 exit(system(cmdline));
217 } else if ((int)pid < 0) {
220 FILE *f = fdopen (fds[0], "r");
227 if (fgets(str, len, f) == NULL)
230 if (waitpid(pid, &rc, 0) != pid)
233 if (!WIFEXITED(rc) ||
234 WEXITSTATUS(rc) != 0)
237 if (strnlen(str, len) == len)
240 if (str[strlen(str) - 1] == '\n')
241 str[strlen(str) - 1] = 0;
248 main (int argc, char **argv)
253 system_string("uname -a", unameinfo, sizeof(unameinfo));
254 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
256 printf ("void lnet_assert_wire_constants (void)\n"
258 " /* Wire protocol assertions generated by 'wirecheck'\n"
261 "\n", unameinfo, gccinfo);
265 COMMENT ("Constants...");
267 CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
269 CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
270 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
271 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
273 CHECK_VALUE (LNET_MSG_ACK);
274 CHECK_VALUE (LNET_MSG_PUT);
275 CHECK_VALUE (LNET_MSG_GET);
276 CHECK_VALUE (LNET_MSG_REPLY);
277 CHECK_VALUE (LNET_MSG_HELLO);
279 check_lnet_handle_wire();
280 check_lnet_magicversion();
282 check_lnet_ni_status();
283 check_lnet_ping_info();