1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2014, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
23 #include <sys/types.h>
25 #include <linux/lnet/lnet-types.h>
28 #define strnlen(s, i) strlen(s)
31 #define BLANK_LINE() \
38 printf (" /* "c" */\n"); \
41 #define STRINGIFY(a) #a
43 #define CHECK_BUILD_TEST(a) \
44 printf(" BUILD_BUG_ON("#a");\n")
46 #define CHECK_DEFINE(a) \
48 printf (" BUILD_BUG_ON("#a" != "STRINGIFY(a)");\n"); \
51 #define CHECK_VALUE(a) \
53 printf (" BUILD_BUG_ON("#a" != %d);\n", a); \
56 #define CHECK_MEMBER_OFFSET(s,m) \
58 CHECK_VALUE((int)offsetof(s, m)); \
61 #define CHECK_MEMBER_SIZEOF(s,m) \
63 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
66 #define CHECK_MEMBER_IS_FLEXIBLE(s, m) \
68 CHECK_MEMBER_OFFSET(s, m); \
69 CHECK_BUILD_TEST(offsetof(struct s, m) != sizeof(struct s)); \
72 #define CHECK_MEMBER(s,m) \
74 CHECK_MEMBER_OFFSET(s, m); \
75 CHECK_MEMBER_SIZEOF(s, m); \
78 #define CHECK_STRUCT(s) \
81 COMMENT ("Checks for struct "#s); \
82 CHECK_VALUE((int)sizeof(s)); \
86 check_lnet_handle_wire(void)
88 CHECK_STRUCT(struct lnet_handle_wire);
89 CHECK_MEMBER(struct lnet_handle_wire, wh_interface_cookie);
90 CHECK_MEMBER(struct lnet_handle_wire, wh_object_cookie);
94 check_lnet_magicversion (void)
96 CHECK_STRUCT(struct lnet_magicversion);
97 CHECK_MEMBER(struct lnet_magicversion, magic);
98 CHECK_MEMBER(struct lnet_magicversion, version_major);
99 CHECK_MEMBER(struct lnet_magicversion, version_minor);
103 check_lnet_hdr_nid4(void)
105 CHECK_STRUCT(struct _lnet_hdr_nid4);
106 CHECK_MEMBER(struct _lnet_hdr_nid4, dest_nid);
107 CHECK_MEMBER(struct _lnet_hdr_nid4, src_nid);
108 CHECK_MEMBER(struct _lnet_hdr_nid4, dest_pid);
109 CHECK_MEMBER(struct _lnet_hdr_nid4, src_pid);
110 CHECK_MEMBER(struct _lnet_hdr_nid4, type);
111 CHECK_MEMBER(struct _lnet_hdr_nid4, payload_length);
112 CHECK_MEMBER(struct _lnet_hdr_nid4, msg);
116 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.dst_wmd);
117 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.match_bits);
118 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.mlength);
122 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.ack_wmd);
123 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.match_bits);
124 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.hdr_data);
125 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.ptl_index);
126 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.offset);
130 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.return_wmd);
131 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.match_bits);
132 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.ptl_index);
133 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.src_offset);
134 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.sink_length);
138 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.reply.dst_wmd);
142 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.hello.incarnation);
143 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.hello.type);
147 check_lnet_ni_status(void)
150 COMMENT("Checks for struct lnet_ni_status and related constants");
152 CHECK_DEFINE(LNET_NI_STATUS_INVALID);
153 CHECK_DEFINE(LNET_NI_STATUS_UP);
154 CHECK_DEFINE(LNET_NI_STATUS_DOWN);
156 CHECK_STRUCT(struct lnet_ni_status);
157 CHECK_MEMBER(struct lnet_ni_status, ns_nid);
158 CHECK_MEMBER(struct lnet_ni_status, ns_status);
159 CHECK_MEMBER(struct lnet_ni_status, ns_msg_size);
161 CHECK_STRUCT(struct lnet_ni_large_status);
162 CHECK_MEMBER(struct lnet_ni_large_status, ns_status);
163 CHECK_MEMBER(struct lnet_ni_large_status, ns_nid);
167 check_lnet_ping_info(void)
170 COMMENT("Checks for struct lnet_ping_info and related constants");
172 CHECK_DEFINE(LNET_PROTO_PING_MAGIC);
173 CHECK_VALUE(LNET_PING_FEAT_INVAL);
174 CHECK_VALUE(LNET_PING_FEAT_BASE);
175 CHECK_VALUE(LNET_PING_FEAT_NI_STATUS);
176 CHECK_VALUE(LNET_PING_FEAT_RTE_DISABLED);
177 CHECK_VALUE(LNET_PING_FEAT_MULTI_RAIL);
178 CHECK_VALUE(LNET_PING_FEAT_DISCOVERY);
179 CHECK_VALUE(LNET_PING_FEAT_LARGE_ADDR);
180 CHECK_VALUE(LNET_PING_FEAT_PRIMARY_LARGE);
181 CHECK_VALUE(LNET_PING_FEAT_BITS);
183 CHECK_STRUCT(struct lnet_ping_info);
184 CHECK_MEMBER(struct lnet_ping_info, pi_magic);
185 CHECK_MEMBER(struct lnet_ping_info, pi_features);
186 CHECK_MEMBER(struct lnet_ping_info, pi_pid);
187 CHECK_MEMBER(struct lnet_ping_info, pi_nnis);
188 CHECK_MEMBER_IS_FLEXIBLE(struct lnet_ping_info, pi_ni);
192 system_string(char *cmdline, char *str, int len)
205 int fd = fileno(stdout);
207 rc = dup2(fds[1], fd);
211 exit(system(cmdline));
213 } else if ((int)pid < 0) {
216 FILE *f = fdopen (fds[0], "r");
223 if (fgets(str, len, f) == NULL)
226 if (waitpid(pid, &rc, 0) != pid)
229 if (!WIFEXITED(rc) ||
230 WEXITSTATUS(rc) != 0)
233 if (strnlen(str, len) == len)
236 if (str[strlen(str) - 1] == '\n')
237 str[strlen(str) - 1] = 0;
244 main (int argc, char **argv)
249 system_string("uname -a", unameinfo, sizeof(unameinfo));
250 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
252 printf ("void lnet_assert_wire_constants (void)\n"
254 " /* Wire protocol assertions generated by 'wirecheck'\n"
257 "\n", unameinfo, gccinfo);
261 COMMENT ("Constants...");
263 CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
265 CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
266 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
267 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
269 CHECK_VALUE (LNET_MSG_ACK);
270 CHECK_VALUE (LNET_MSG_PUT);
271 CHECK_VALUE (LNET_MSG_GET);
272 CHECK_VALUE (LNET_MSG_REPLY);
273 CHECK_VALUE (LNET_MSG_HELLO);
275 check_lnet_handle_wire();
276 check_lnet_magicversion();
277 check_lnet_hdr_nid4();
278 check_lnet_ni_status();
279 check_lnet_ping_info();