Whamcloud - gitweb
- tagging RC_CURRENT
[fs/lustre-release.git] / lustre / utils / wirecheck.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #include <stdio.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
7 #include <liblustre.h>
8 #include <linux/lustre_lib.h>
9 #include <linux/lustre_idl.h>
10
11 #define BLANK_LINE()                                            \
12 do {                                                            \
13         printf("\n");                                           \
14 } while(0)
15
16 #define COMMENT(c)                                              \
17 do {                                                            \
18         printf("        /* "c" */\n");                          \
19 } while(0)
20
21 #define STRINGIFY(a) #a
22
23 #define CHECK_DEFINE(a)                                         \
24 do {                                                            \
25         printf("        LASSERTF("#a" == "STRINGIFY(a)          \
26                ",\" found %%lld\\n\",\n                 "       \
27                "(long long)"#a");\n");   \
28 } while(0)
29
30 #define CHECK_VALUE(a)                                          \
31 do {                                                            \
32         printf("        LASSERTF("#a                            \
33                " == %d, \" found %%lld\\n\",\n                 "\
34                "(long long)"#a");\n",a);\
35 } while(0)
36
37 #define CHECK_MEMBER_OFFSET(s,m)                                \
38 do {                                                            \
39         CHECK_VALUE(offsetof(struct s, m));                     \
40 } while(0)
41
42 #define CHECK_MEMBER_SIZEOF(s,m)                                \
43 do {                                                            \
44         CHECK_VALUE((int)sizeof(((struct s *)0)->m));           \
45 } while(0)
46
47 #define CHECK_MEMBER(s,m)                                       \
48 do {                                                            \
49         CHECK_MEMBER_OFFSET(s, m);                              \
50                 CHECK_MEMBER_SIZEOF(s, m);                      \
51 } while(0)
52
53 #define CHECK_STRUCT(s)                                         \
54 do {                                                            \
55         COMMENT("Checks for struct "#s);                        \
56                 CHECK_VALUE((int)sizeof(struct s));             \
57 } while(0)
58
59
60
61 void check1(void)
62 {
63 #define VALUE 1234567
64
65         CHECK_VALUE(VALUE);
66         CHECK_DEFINE(VALUE);
67 }
68
69 void
70 check_lustre_handle(void)
71 {
72         BLANK_LINE();
73         CHECK_STRUCT(lustre_handle);
74         CHECK_MEMBER(lustre_handle, cookie);
75 }
76
77 void
78 check_lustre_msg(void)
79 {
80         BLANK_LINE();
81         CHECK_STRUCT(lustre_msg);
82         CHECK_MEMBER(lustre_msg, handle);
83         CHECK_MEMBER(lustre_msg, magic);
84         CHECK_MEMBER(lustre_msg, type);
85         CHECK_MEMBER(lustre_msg, version);
86         CHECK_MEMBER(lustre_msg, opc);
87         CHECK_MEMBER(lustre_msg, last_xid);
88         CHECK_MEMBER(lustre_msg, last_committed);
89         CHECK_MEMBER(lustre_msg, transno);
90         CHECK_MEMBER(lustre_msg, status);
91         CHECK_MEMBER(lustre_msg, flags);
92         CHECK_MEMBER(lustre_msg, bufcount);
93         CHECK_MEMBER(lustre_msg, buflens[7]);
94 }
95
96 void
97 check_obdo(void)
98 {
99         BLANK_LINE();
100         CHECK_STRUCT(obdo);
101         CHECK_MEMBER(obdo, o_id);
102         CHECK_MEMBER(obdo, o_gr);
103         CHECK_MEMBER(obdo, o_atime);
104         CHECK_MEMBER(obdo, o_mtime);
105         CHECK_MEMBER(obdo, o_ctime);
106         CHECK_MEMBER(obdo, o_size);
107         CHECK_MEMBER(obdo, o_blocks);
108         CHECK_MEMBER(obdo, o_grant);
109         CHECK_MEMBER(obdo, o_blksize);
110         CHECK_MEMBER(obdo, o_mode);
111         CHECK_MEMBER(obdo, o_uid);
112         CHECK_MEMBER(obdo, o_gid);
113         CHECK_MEMBER(obdo, o_flags);
114         CHECK_MEMBER(obdo, o_nlink);
115         CHECK_MEMBER(obdo, o_generation);
116         CHECK_MEMBER(obdo, o_valid);
117         CHECK_MEMBER(obdo, o_misc);
118         CHECK_MEMBER(obdo, o_easize);
119         CHECK_MEMBER(obdo, o_inline);
120
121         CHECK_VALUE(OBD_MD_FLID);
122         CHECK_VALUE(OBD_MD_FLATIME);
123         CHECK_VALUE(OBD_MD_FLMTIME);
124         CHECK_VALUE(OBD_MD_FLCTIME);
125         CHECK_VALUE(OBD_MD_FLSIZE);
126         CHECK_VALUE(OBD_MD_FLBLOCKS);
127         CHECK_VALUE(OBD_MD_FLBLKSZ);
128         CHECK_VALUE(OBD_MD_FLMODE);
129         CHECK_VALUE(OBD_MD_FLTYPE);
130         CHECK_VALUE(OBD_MD_FLUID);
131         CHECK_VALUE(OBD_MD_FLGID);
132         CHECK_VALUE(OBD_MD_FLFLAGS);
133         CHECK_VALUE(OBD_MD_FLNLINK);
134         CHECK_VALUE(OBD_MD_FLGENER);
135         CHECK_VALUE(OBD_MD_FLINLINE);
136         CHECK_VALUE(OBD_MD_FLRDEV);
137         CHECK_VALUE(OBD_MD_FLEASIZE);
138         CHECK_VALUE(OBD_MD_LINKNAME);
139         CHECK_VALUE(OBD_MD_FLHANDLE);
140         CHECK_VALUE(OBD_MD_FLCKSUM);
141         CHECK_VALUE(OBD_MD_FLQOS);
142         CHECK_VALUE(OBD_MD_FLOSCOPQ);
143         CHECK_VALUE(OBD_MD_FLCOOKIE);
144         CHECK_VALUE(OBD_MD_FLGROUP);
145
146         CHECK_VALUE(OBD_FL_INLINEDATA);
147         CHECK_VALUE(OBD_FL_OBDMDEXISTS);
148         CHECK_VALUE(OBD_FL_DELORPHAN);
149         CHECK_VALUE(OBD_FL_NORPC);
150         CHECK_VALUE(OBD_FL_IDONLY);
151         CHECK_VALUE(OBD_FL_RECREATE_OBJS);
152 }
153
154 void
155 check_lov_mds_md_v1(void)
156 {
157         BLANK_LINE();
158         CHECK_STRUCT(lov_mds_md_v1);
159         CHECK_MEMBER(lov_mds_md_v1, lmm_magic);
160         CHECK_MEMBER(lov_mds_md_v1, lmm_pattern);
161         CHECK_MEMBER(lov_mds_md_v1, lmm_object_id);
162         CHECK_MEMBER(lov_mds_md_v1, lmm_object_gr);
163         CHECK_MEMBER(lov_mds_md_v1, lmm_stripe_size);
164         CHECK_MEMBER(lov_mds_md_v1, lmm_stripe_count);
165         CHECK_MEMBER(lov_mds_md_v1, lmm_objects);
166
167         BLANK_LINE();
168         CHECK_STRUCT(lov_ost_data_v1);
169         CHECK_MEMBER(lov_ost_data_v1, l_object_id);
170         CHECK_MEMBER(lov_ost_data_v1, l_object_gr);
171         CHECK_MEMBER(lov_ost_data_v1, l_ost_gen);
172         CHECK_MEMBER(lov_ost_data_v1, l_ost_idx);
173
174         CHECK_VALUE(LOV_MAGIC_V0);
175         CHECK_VALUE(LOV_MAGIC_V1);
176
177         CHECK_VALUE(LOV_PATTERN_RAID0);
178         CHECK_VALUE(LOV_PATTERN_RAID1);
179 }
180
181 void
182 check_obd_statfs(void)
183 {
184         BLANK_LINE();
185         CHECK_STRUCT(obd_statfs);
186         CHECK_MEMBER(obd_statfs, os_type);
187         CHECK_MEMBER(obd_statfs, os_blocks);
188         CHECK_MEMBER(obd_statfs, os_bfree);
189         CHECK_MEMBER(obd_statfs, os_bavail);
190         CHECK_MEMBER(obd_statfs, os_ffree);
191         CHECK_MEMBER(obd_statfs, os_fsid);
192         CHECK_MEMBER(obd_statfs, os_bsize);
193         CHECK_MEMBER(obd_statfs, os_namelen);
194         CHECK_MEMBER(obd_statfs, os_spare);
195 }
196
197 void
198 check_obd_ioobj(void)
199 {
200         BLANK_LINE();
201         CHECK_STRUCT(obd_ioobj);
202         CHECK_MEMBER(obd_ioobj, ioo_id);
203         CHECK_MEMBER(obd_ioobj, ioo_gr);
204         CHECK_MEMBER(obd_ioobj, ioo_type);
205         CHECK_MEMBER(obd_ioobj, ioo_bufcnt);
206 }
207
208 void
209 check_niobuf_remote(void)
210 {
211         BLANK_LINE();
212         CHECK_STRUCT(niobuf_remote);
213         CHECK_MEMBER(niobuf_remote, offset);
214         CHECK_MEMBER(niobuf_remote, len);
215         CHECK_MEMBER(niobuf_remote, flags);
216
217         CHECK_VALUE(OBD_BRW_READ);
218         CHECK_VALUE(OBD_BRW_WRITE);
219         CHECK_VALUE(OBD_BRW_SYNC);
220         CHECK_VALUE(OBD_BRW_FROM_GRANT);
221 }
222
223 void
224 check_ost_body(void)
225 {
226         BLANK_LINE();
227         CHECK_STRUCT(ost_body);
228         CHECK_MEMBER(ost_body, oa);
229 }
230
231 void
232 check_ll_fid(void)
233 {
234         BLANK_LINE();
235         CHECK_STRUCT(ll_fid);
236         CHECK_MEMBER(ll_fid, id);
237         CHECK_MEMBER(ll_fid, generation);
238         CHECK_MEMBER(ll_fid, f_type);
239 }
240
241 void
242 check_mds_status_req(void)
243 {
244         BLANK_LINE();
245         CHECK_STRUCT(mds_status_req);
246         CHECK_MEMBER(mds_status_req, flags);
247         CHECK_MEMBER(mds_status_req, repbuf);
248 }
249
250 void
251 check_mds_body(void)
252 {
253         BLANK_LINE();
254         CHECK_STRUCT(mds_body);
255         CHECK_MEMBER(mds_body, fid1);
256         CHECK_MEMBER(mds_body, fid2);
257         CHECK_MEMBER(mds_body, handle);
258         CHECK_MEMBER(mds_body, size);
259         CHECK_MEMBER(mds_body, blocks);
260         CHECK_MEMBER(mds_body, io_epoch);
261         CHECK_MEMBER(mds_body, ino);
262         CHECK_MEMBER(mds_body, valid);
263         CHECK_MEMBER(mds_body, fsuid);
264         CHECK_MEMBER(mds_body, fsgid);
265         CHECK_MEMBER(mds_body, capability);
266         CHECK_MEMBER(mds_body, mode);
267         CHECK_MEMBER(mds_body, uid);
268         CHECK_MEMBER(mds_body, gid);
269         CHECK_MEMBER(mds_body, mtime);
270         CHECK_MEMBER(mds_body, ctime);
271         CHECK_MEMBER(mds_body, atime);
272         CHECK_MEMBER(mds_body, flags);
273         CHECK_MEMBER(mds_body, rdev);
274         CHECK_MEMBER(mds_body, nlink);
275         CHECK_MEMBER(mds_body, generation);
276         CHECK_MEMBER(mds_body, suppgid);
277         CHECK_MEMBER(mds_body, eadatasize);
278
279         CHECK_VALUE(FMODE_READ);
280         CHECK_VALUE(FMODE_WRITE);
281         CHECK_VALUE(FMODE_EXEC);
282         CHECK_VALUE(MDS_OPEN_CREAT);
283         CHECK_VALUE(MDS_OPEN_EXCL);
284         CHECK_VALUE(MDS_OPEN_TRUNC);
285         CHECK_VALUE(MDS_OPEN_APPEND);
286         CHECK_VALUE(MDS_OPEN_SYNC);
287         CHECK_VALUE(MDS_OPEN_DIRECTORY);
288         CHECK_VALUE(MDS_OPEN_DELAY_CREATE);
289         CHECK_VALUE(MDS_OPEN_HAS_EA);
290 }
291
292 void
293 check_mds_rec_setattr(void)
294 {
295         BLANK_LINE();
296         CHECK_STRUCT(mds_rec_setattr);
297         CHECK_MEMBER(mds_rec_setattr, sa_opcode);
298         CHECK_MEMBER(mds_rec_setattr, sa_fsuid);
299         CHECK_MEMBER(mds_rec_setattr, sa_fsgid);
300         CHECK_MEMBER(mds_rec_setattr, sa_cap);
301         CHECK_MEMBER(mds_rec_setattr, sa_suppgid);
302         CHECK_MEMBER(mds_rec_setattr, sa_valid);
303         CHECK_MEMBER(mds_rec_setattr, sa_fid);
304         CHECK_MEMBER(mds_rec_setattr, sa_mode);
305         CHECK_MEMBER(mds_rec_setattr, sa_uid);
306         CHECK_MEMBER(mds_rec_setattr, sa_gid);
307         CHECK_MEMBER(mds_rec_setattr, sa_attr_flags);
308         CHECK_MEMBER(mds_rec_setattr, sa_size);
309         CHECK_MEMBER(mds_rec_setattr, sa_atime);
310         CHECK_MEMBER(mds_rec_setattr, sa_mtime);
311         CHECK_MEMBER(mds_rec_setattr, sa_ctime);
312 }
313
314 void
315 check_mds_rec_create(void)
316 {
317         BLANK_LINE();
318         CHECK_STRUCT(mds_rec_create);
319         CHECK_MEMBER(mds_rec_create, cr_opcode);
320         CHECK_MEMBER(mds_rec_create, cr_fsuid);
321         CHECK_MEMBER(mds_rec_create, cr_fsgid);
322         CHECK_MEMBER(mds_rec_create, cr_cap);
323         CHECK_MEMBER(mds_rec_create, cr_flags);
324         CHECK_MEMBER(mds_rec_create, cr_mode);
325         CHECK_MEMBER(mds_rec_create, cr_fid);
326         CHECK_MEMBER(mds_rec_create, cr_replayfid);
327         CHECK_MEMBER(mds_rec_create, cr_time);
328         CHECK_MEMBER(mds_rec_create, cr_rdev);
329         CHECK_MEMBER(mds_rec_create, cr_suppgid);
330 }
331
332 void
333 check_mds_rec_link(void)
334 {
335         BLANK_LINE();
336         CHECK_STRUCT(mds_rec_link);
337         CHECK_MEMBER(mds_rec_link, lk_opcode);
338         CHECK_MEMBER(mds_rec_link, lk_fsuid);
339         CHECK_MEMBER(mds_rec_link, lk_fsgid);
340         CHECK_MEMBER(mds_rec_link, lk_cap);
341         CHECK_MEMBER(mds_rec_link, lk_suppgid1);
342         CHECK_MEMBER(mds_rec_link, lk_suppgid2);
343         CHECK_MEMBER(mds_rec_link, lk_fid1);
344         CHECK_MEMBER(mds_rec_link, lk_fid2);
345         CHECK_MEMBER(mds_rec_link, lk_time);
346 }
347
348 void
349 check_mds_rec_unlink(void)
350 {
351         BLANK_LINE();
352         CHECK_STRUCT(mds_rec_unlink);
353         CHECK_MEMBER(mds_rec_unlink, ul_opcode);
354         CHECK_MEMBER(mds_rec_unlink, ul_fsuid);
355         CHECK_MEMBER(mds_rec_unlink, ul_fsgid);
356         CHECK_MEMBER(mds_rec_unlink, ul_cap);
357         CHECK_MEMBER(mds_rec_unlink, ul_suppgid);
358         CHECK_MEMBER(mds_rec_unlink, ul_mode);
359         CHECK_MEMBER(mds_rec_unlink, ul_fid1);
360         CHECK_MEMBER(mds_rec_unlink, ul_fid2);
361         CHECK_MEMBER(mds_rec_unlink, ul_time);
362 }
363
364 void
365 check_mds_rec_rename(void)
366 {
367         BLANK_LINE();
368         CHECK_STRUCT(mds_rec_rename);
369         CHECK_MEMBER(mds_rec_rename, rn_opcode);
370         CHECK_MEMBER(mds_rec_rename, rn_fsuid);
371         CHECK_MEMBER(mds_rec_rename, rn_fsgid);
372         CHECK_MEMBER(mds_rec_rename, rn_cap);
373         CHECK_MEMBER(mds_rec_rename, rn_suppgid1);
374         CHECK_MEMBER(mds_rec_rename, rn_suppgid2);
375         CHECK_MEMBER(mds_rec_rename, rn_fid1);
376         CHECK_MEMBER(mds_rec_rename, rn_fid2);
377         CHECK_MEMBER(mds_rec_rename, rn_time);
378 }
379
380 void
381 check_lov_desc(void)
382 {
383         BLANK_LINE();
384         CHECK_STRUCT(lov_desc);
385         CHECK_MEMBER(lov_desc, ld_tgt_count);
386         CHECK_MEMBER(lov_desc, ld_active_tgt_count);
387         CHECK_MEMBER(lov_desc, ld_default_stripe_count);
388         CHECK_MEMBER(lov_desc, ld_pattern);
389         CHECK_MEMBER(lov_desc, ld_default_stripe_size);
390         CHECK_MEMBER(lov_desc, ld_default_stripe_offset);
391         CHECK_MEMBER(lov_desc, ld_uuid);
392 }
393
394 void
395 check_ldlm_res_id(void)
396 {
397         BLANK_LINE();
398         CHECK_STRUCT(ldlm_res_id);
399         CHECK_MEMBER(ldlm_res_id, name[RES_NAME_SIZE]);
400 }
401
402 void
403 check_ldlm_extent(void)
404 {
405         BLANK_LINE();
406         CHECK_STRUCT(ldlm_extent);
407         CHECK_MEMBER(ldlm_extent, start);
408         CHECK_MEMBER(ldlm_extent, end);
409         CHECK_MEMBER(ldlm_extent, gid);
410 }
411
412 void
413 check_ldlm_flock(void)
414 {
415         BLANK_LINE();
416         CHECK_STRUCT(ldlm_flock);
417         CHECK_MEMBER(ldlm_flock, start);
418         CHECK_MEMBER(ldlm_flock, end);
419         CHECK_MEMBER(ldlm_flock, pid);
420         CHECK_MEMBER(ldlm_flock, blocking_pid);
421         CHECK_MEMBER(ldlm_flock, blocking_export);
422 }
423
424 void
425 check_ldlm_intent(void)
426 {
427         BLANK_LINE();
428         CHECK_STRUCT(ldlm_intent);
429         CHECK_MEMBER(ldlm_intent, opc);
430 }
431
432 void
433 check_ldlm_resource_desc(void)
434 {
435         BLANK_LINE();
436         CHECK_STRUCT(ldlm_resource_desc);
437         CHECK_MEMBER(ldlm_resource_desc, lr_type);
438         CHECK_MEMBER(ldlm_resource_desc, lr_name);
439 }
440
441 void
442 check_ldlm_lock_desc(void)
443 {
444         BLANK_LINE();
445         CHECK_STRUCT(ldlm_lock_desc);
446         CHECK_MEMBER(ldlm_lock_desc, l_resource);
447         CHECK_MEMBER(ldlm_lock_desc, l_req_mode);
448         CHECK_MEMBER(ldlm_lock_desc, l_granted_mode);
449         CHECK_MEMBER(ldlm_lock_desc, l_policy_data);
450 }
451
452 void
453 check_ldlm_request(void)
454 {
455         BLANK_LINE();
456         CHECK_STRUCT(ldlm_request);
457         CHECK_MEMBER(ldlm_request, lock_flags);
458         CHECK_MEMBER(ldlm_request, lock_desc);
459         CHECK_MEMBER(ldlm_request, lock_handle1);
460         CHECK_MEMBER(ldlm_request, lock_handle2);
461 }
462
463 void
464 check_ldlm_reply(void)
465 {
466         BLANK_LINE();
467         CHECK_STRUCT(ldlm_reply);
468         CHECK_MEMBER(ldlm_reply, lock_flags);
469         CHECK_MEMBER(ldlm_request, lock_desc);
470         CHECK_MEMBER(ldlm_reply, lock_handle);
471         CHECK_MEMBER(ldlm_reply, lock_policy_res1);
472         CHECK_MEMBER(ldlm_reply, lock_policy_res2);
473 }
474
475 void
476 check_ldlm_lvb(void)
477 {
478         BLANK_LINE();
479         CHECK_STRUCT(ost_lvb);
480         CHECK_MEMBER(ost_lvb, lvb_size);
481         CHECK_MEMBER(ost_lvb, lvb_mtime);
482         CHECK_MEMBER(ost_lvb, lvb_atime);
483         CHECK_MEMBER(ost_lvb, lvb_ctime);
484         CHECK_MEMBER(ost_lvb, lvb_blocks);
485 }
486
487 void
488 check_ptlbd_op(void)
489 {
490         BLANK_LINE();
491         CHECK_STRUCT(ptlbd_op);
492         CHECK_MEMBER(ptlbd_op, op_cmd);
493         CHECK_MEMBER(ptlbd_op, op_lun);
494         CHECK_MEMBER(ptlbd_op, op_niob_cnt);
495         CHECK_MEMBER(ptlbd_op, op__padding);
496         CHECK_MEMBER(ptlbd_op, op_block_cnt);
497 }
498
499 void
500 check_ptlbd_niob(void)
501 {
502         BLANK_LINE();
503         CHECK_STRUCT(ptlbd_niob);
504         CHECK_MEMBER(ptlbd_niob, n_xid);
505         CHECK_MEMBER(ptlbd_niob, n_block_nr);
506         CHECK_MEMBER(ptlbd_niob, n_offset);
507         CHECK_MEMBER(ptlbd_niob, n_length);
508 }
509
510 void
511 check_ptlbd_rsp(void)
512 {
513         BLANK_LINE();
514         CHECK_STRUCT(ptlbd_rsp);
515         CHECK_MEMBER(ptlbd_rsp, r_status);
516         CHECK_MEMBER(ptlbd_rsp, r_error_cnt);
517 }
518
519 void
520 check_llog_logid(void)
521 {
522         BLANK_LINE();
523         CHECK_STRUCT(llog_logid);
524         CHECK_MEMBER(llog_logid, lgl_oid);
525         CHECK_MEMBER(llog_logid, lgl_ogr);
526         CHECK_MEMBER(llog_logid, lgl_ogen);
527
528         CHECK_VALUE(OST_SZ_REC);
529         CHECK_VALUE(OST_RAID1_REC);
530         CHECK_VALUE(MDS_UNLINK_REC);
531         CHECK_VALUE(OBD_CFG_REC);
532         CHECK_VALUE(PTL_CFG_REC);
533         CHECK_VALUE(LLOG_GEN_REC);
534         CHECK_VALUE(LLOG_HDR_MAGIC);
535         CHECK_VALUE(LLOG_LOGID_MAGIC);
536 }
537
538 void
539 check_llog_catid(void)
540 {
541         BLANK_LINE();
542         CHECK_STRUCT(llog_catid);
543         CHECK_MEMBER(llog_catid, lci_logid);
544 }
545
546 void
547 check_llog_rec_hdr(void)
548 {
549         BLANK_LINE();
550         CHECK_STRUCT(llog_rec_hdr);
551         CHECK_MEMBER(llog_rec_hdr, lrh_len);
552         CHECK_MEMBER(llog_rec_hdr, lrh_index);
553         CHECK_MEMBER(llog_rec_hdr, lrh_type);
554 }
555
556 void
557 check_llog_rec_tail(void)
558 {
559         BLANK_LINE();
560         CHECK_STRUCT(llog_rec_tail);
561         CHECK_MEMBER(llog_rec_tail, lrt_len);
562         CHECK_MEMBER(llog_rec_tail, lrt_index);
563 }
564
565 void
566 check_llog_logid_rec(void)
567 {
568         BLANK_LINE();
569         CHECK_STRUCT(llog_logid_rec);
570         CHECK_MEMBER(llog_logid_rec, lid_hdr);
571         CHECK_MEMBER(llog_logid_rec, lid_id);
572         CHECK_MEMBER(llog_logid_rec, lid_tail);
573 }
574
575 void
576 check_llog_create_rec(void)
577 {
578         BLANK_LINE();
579         CHECK_STRUCT(llog_create_rec);
580         CHECK_MEMBER(llog_create_rec, lcr_hdr);
581         CHECK_MEMBER(llog_create_rec, lcr_fid);
582         CHECK_MEMBER(llog_create_rec, lcr_oid);
583         CHECK_MEMBER(llog_create_rec, lcr_ogen);
584 }
585
586 void
587 check_llog_orphan_rec(void)
588 {
589         BLANK_LINE();
590         CHECK_STRUCT(llog_orphan_rec);
591         CHECK_MEMBER(llog_orphan_rec, lor_hdr);
592         CHECK_MEMBER(llog_orphan_rec, lor_oid);
593         CHECK_MEMBER(llog_orphan_rec, lor_ogen);
594         CHECK_MEMBER(llog_orphan_rec, lor_tail);
595 }
596
597 void
598 check_llog_unlink_rec(void)
599 {
600         BLANK_LINE();
601         CHECK_STRUCT(llog_unlink_rec);
602         CHECK_MEMBER(llog_unlink_rec, lur_hdr);
603         CHECK_MEMBER(llog_unlink_rec, lur_oid);
604         CHECK_MEMBER(llog_unlink_rec, lur_ogen);
605         CHECK_MEMBER(llog_unlink_rec, lur_tail);
606 }
607
608 void
609 check_llog_size_change_rec(void)
610 {
611         BLANK_LINE();
612         CHECK_STRUCT(llog_size_change_rec);
613         CHECK_MEMBER(llog_size_change_rec, lsc_hdr);
614         CHECK_MEMBER(llog_size_change_rec, lsc_fid);
615         CHECK_MEMBER(llog_size_change_rec, lsc_io_epoch);
616         CHECK_MEMBER(llog_size_change_rec, lsc_tail);
617 }
618
619 void
620 check_llog_gen(void)
621 {
622         BLANK_LINE();
623         CHECK_STRUCT(llog_gen);
624         CHECK_MEMBER(llog_gen, mnt_cnt);
625         CHECK_MEMBER(llog_gen, conn_cnt);
626 }
627
628 void
629 check_llog_gen_rec(void)
630 {
631         BLANK_LINE();
632         CHECK_STRUCT(llog_gen_rec);
633         CHECK_MEMBER(llog_gen_rec, lgr_hdr);
634         CHECK_MEMBER(llog_gen_rec, lgr_gen);
635         CHECK_MEMBER(llog_gen_rec, lgr_tail);
636 }
637
638 void
639 check_llog_log_hdr(void)
640 {
641         BLANK_LINE();
642         CHECK_STRUCT(llog_log_hdr);
643         CHECK_MEMBER(llog_log_hdr, llh_hdr);
644         CHECK_MEMBER(llog_log_hdr, llh_timestamp);
645         CHECK_MEMBER(llog_log_hdr, llh_count);
646         CHECK_MEMBER(llog_log_hdr, llh_bitmap_offset);
647         CHECK_MEMBER(llog_log_hdr, llh_size);
648         CHECK_MEMBER(llog_log_hdr, llh_flags);
649         CHECK_MEMBER(llog_log_hdr, llh_cat_idx);
650         CHECK_MEMBER(llog_log_hdr, llh_tgtuuid);
651         CHECK_MEMBER(llog_log_hdr, llh_reserved);
652         CHECK_MEMBER(llog_log_hdr, llh_bitmap);
653         CHECK_MEMBER(llog_log_hdr, llh_tail);
654 }
655
656 void
657 check_llog_cookie(void)
658 {
659         BLANK_LINE();
660         CHECK_STRUCT(llog_cookie);
661         CHECK_MEMBER(llog_cookie, lgc_lgl);
662         CHECK_MEMBER(llog_cookie, lgc_subsys);
663         CHECK_MEMBER(llog_cookie, lgc_index);
664 }
665
666 void
667 check_llogd_body(void)
668 {
669         BLANK_LINE();
670         CHECK_STRUCT(llogd_body);
671         CHECK_MEMBER(llogd_body, lgd_logid);
672         CHECK_MEMBER(llogd_body, lgd_ctxt_idx);
673         CHECK_MEMBER(llogd_body, lgd_llh_flags);
674         CHECK_MEMBER(llogd_body, lgd_index);
675         CHECK_MEMBER(llogd_body, lgd_saved_index);
676         CHECK_MEMBER(llogd_body, lgd_len);
677         CHECK_MEMBER(llogd_body, lgd_cur_offset);
678
679         CHECK_VALUE(LLOG_ORIGIN_HANDLE_CREATE);
680         CHECK_VALUE(LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
681         CHECK_VALUE(LLOG_ORIGIN_HANDLE_READ_HEADER);
682         CHECK_VALUE(LLOG_ORIGIN_HANDLE_WRITE_REC);
683         CHECK_VALUE(LLOG_ORIGIN_HANDLE_CLOSE);
684         CHECK_VALUE(LLOG_ORIGIN_CONNECT);
685         CHECK_VALUE(LLOG_CATINFO);
686 }
687
688 void
689 check_llogd_conn_body(void)
690 {
691         BLANK_LINE();
692         CHECK_STRUCT(llogd_conn_body);
693         CHECK_MEMBER(llogd_conn_body, lgdc_gen);
694         CHECK_MEMBER(llogd_conn_body, lgdc_logid);
695         CHECK_MEMBER(llogd_conn_body, lgdc_ctxt_idx);
696 }
697
698 void
699 system_string (char *cmdline, char *str, int len)
700 {
701         int   fds[2];
702         int   rc;
703         pid_t pid;
704
705         rc = pipe(fds);
706         if (rc != 0)
707                 abort();
708
709         pid = fork();
710         if (pid == 0) {
711                 /* child */
712                 int   fd = fileno(stdout);
713
714                 rc = dup2(fds[1], fd);
715                 if (rc != fd)
716                         abort();
717
718                 exit(system(cmdline));
719                 /* notreached */
720         } else if ((int)pid < 0) {
721                 abort();
722         } else {
723                 FILE *f = fdopen(fds[0], "r");
724
725                 if (f == NULL)
726                         abort();
727
728                 close(fds[1]);
729
730                 if (fgets(str, len, f) == NULL)
731                         abort();
732
733                 if (waitpid(pid, &rc, 0) != pid)
734                         abort();
735
736                 if (!WIFEXITED(rc) || WEXITSTATUS(rc) != 0)
737                         abort();
738
739                 if (strnlen(str, len) == len)
740                         str[len - 1] = 0;
741
742                 if (str[strlen(str) - 1] == '\n')
743                         str[strlen(str) - 1] = 0;
744
745                 fclose(f);
746         }
747 }
748
749 int
750 main(int argc, char **argv)
751 {
752         char unameinfo[80];
753         char gccinfo[80];
754
755         system_string("uname -a", unameinfo, sizeof(unameinfo));
756         system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
757
758         printf ("void lustre_assert_wire_constants(void)\n"
759                 "{\n"
760                 "        /* Wire protocol assertions generated by 'wirecheck'\n"
761                 "         * running on %s\n"
762                 "         * with %s */\n"
763                 "\n", unameinfo, gccinfo);
764
765         BLANK_LINE ();
766
767         COMMENT("Constants...");
768         CHECK_DEFINE(PTLRPC_MSG_MAGIC);
769         CHECK_DEFINE(PTLRPC_MSG_VERSION);
770
771         CHECK_VALUE(PTL_RPC_MSG_REQUEST);
772         CHECK_VALUE(PTL_RPC_MSG_ERR);
773         CHECK_VALUE(PTL_RPC_MSG_REPLY);
774
775         CHECK_VALUE(MSG_LAST_REPLAY);
776         CHECK_VALUE(MSG_RESENT);
777         CHECK_VALUE(MSG_REPLAY);
778
779         CHECK_VALUE(MSG_CONNECT_RECOVERING);
780         CHECK_VALUE(MSG_CONNECT_RECONNECT);
781         CHECK_VALUE(MSG_CONNECT_REPLAYABLE);
782
783         CHECK_VALUE(OST_REPLY);
784         CHECK_VALUE(OST_GETATTR);
785         CHECK_VALUE(OST_SETATTR);
786         CHECK_VALUE(OST_READ);
787         CHECK_VALUE(OST_WRITE);
788         CHECK_VALUE(OST_CREATE);
789         CHECK_VALUE(OST_DESTROY);
790         CHECK_VALUE(OST_GET_INFO);
791         CHECK_VALUE(OST_CONNECT);
792         CHECK_VALUE(OST_DISCONNECT);
793         CHECK_VALUE(OST_PUNCH);
794         CHECK_VALUE(OST_OPEN);
795         CHECK_VALUE(OST_CLOSE);
796         CHECK_VALUE(OST_STATFS);
797         CHECK_VALUE(OST_SAN_READ);
798         CHECK_VALUE(OST_SAN_WRITE);
799         CHECK_VALUE(OST_SYNC);
800         CHECK_VALUE(OST_LAST_OPC);
801
802         CHECK_DEFINE(OBD_OBJECT_EOF);
803
804         CHECK_VALUE(OST_REQ_HAS_OA1);
805
806         CHECK_VALUE(MDS_GETATTR);
807         CHECK_VALUE(MDS_GETATTR_NAME);
808         CHECK_VALUE(MDS_CLOSE);
809         CHECK_VALUE(MDS_REINT);
810         CHECK_VALUE(MDS_READPAGE);
811         CHECK_VALUE(MDS_CONNECT);
812         CHECK_VALUE(MDS_DISCONNECT);
813         CHECK_VALUE(MDS_GETSTATUS);
814         CHECK_VALUE(MDS_STATFS);
815         CHECK_VALUE(MDS_PIN);
816         CHECK_VALUE(MDS_UNPIN);
817         CHECK_VALUE(MDS_SYNC);
818         CHECK_VALUE(MDS_DONE_WRITING);
819         CHECK_VALUE(MDS_LAST_OPC);
820
821         CHECK_VALUE(REINT_SETATTR);
822         CHECK_VALUE(REINT_CREATE);
823         CHECK_VALUE(REINT_LINK);
824         CHECK_VALUE(REINT_UNLINK);
825         CHECK_VALUE(REINT_RENAME);
826         CHECK_VALUE(REINT_OPEN);
827         CHECK_VALUE(REINT_MAX);
828
829         CHECK_VALUE(DISP_IT_EXECD);
830         CHECK_VALUE(DISP_LOOKUP_EXECD);
831         CHECK_VALUE(DISP_LOOKUP_NEG);
832         CHECK_VALUE(DISP_LOOKUP_POS);
833         CHECK_VALUE(DISP_OPEN_CREATE);
834         CHECK_VALUE(DISP_OPEN_OPEN);
835
836         CHECK_VALUE(MDS_STATUS_CONN);
837         CHECK_VALUE(MDS_STATUS_LOV);
838
839         CHECK_VALUE(MDS_OPEN_HAS_EA);
840
841         CHECK_VALUE(LDLM_ENQUEUE);
842         CHECK_VALUE(LDLM_CONVERT);
843         CHECK_VALUE(LDLM_CANCEL);
844         CHECK_VALUE(LDLM_BL_CALLBACK);
845         CHECK_VALUE(LDLM_CP_CALLBACK);
846         CHECK_VALUE(LDLM_LAST_OPC);
847
848         CHECK_VALUE(LCK_EX);
849         CHECK_VALUE(LCK_PW);
850         CHECK_VALUE(LCK_PR);
851         CHECK_VALUE(LCK_CW);
852         CHECK_VALUE(LCK_CR);
853         CHECK_VALUE(LCK_NL);
854
855         CHECK_VALUE(PTLBD_QUERY);
856         CHECK_VALUE(PTLBD_READ);
857         CHECK_VALUE(PTLBD_WRITE);
858         CHECK_VALUE(PTLBD_FLUSH);
859         CHECK_VALUE(PTLBD_CONNECT);
860         CHECK_VALUE(PTLBD_DISCONNECT);
861         CHECK_VALUE(PTLBD_LAST_OPC);
862
863         CHECK_VALUE(MGMT_CONNECT);
864         CHECK_VALUE(MGMT_DISCONNECT);
865         CHECK_VALUE(MGMT_EXCEPTION);
866
867         CHECK_VALUE(OBD_PING);
868         CHECK_VALUE(OBD_LOG_CANCEL);
869         CHECK_VALUE(OBD_LAST_OPC);
870
871         COMMENT("Sizes and Offsets");
872         BLANK_LINE();
873         check_lustre_handle();
874         check_lustre_msg();
875         check_obdo();
876         check_lov_mds_md_v1();
877         check_obd_statfs();
878         check_obd_ioobj();
879         check_niobuf_remote();
880         check_ost_body();
881         check_ll_fid();
882         check_mds_status_req();
883         check_mds_body();
884         check_mds_rec_setattr();
885         check_mds_rec_create();
886         check_mds_rec_link();
887         check_mds_rec_unlink();
888         check_mds_rec_rename();
889         check_lov_desc();
890         check_ldlm_res_id();
891         check_ldlm_extent();
892         check_ldlm_flock();
893         check_ldlm_intent();
894         check_ldlm_resource_desc();
895         check_ldlm_lock_desc();
896         check_ldlm_request();
897         check_ldlm_reply();
898         check_ldlm_lvb();
899         check_ptlbd_op();
900         check_ptlbd_niob();
901         check_ptlbd_rsp();
902         check_llog_logid();
903         check_llog_catid();
904         check_llog_rec_hdr();
905         check_llog_rec_tail();
906         check_llog_logid_rec();
907         check_llog_create_rec();
908         check_llog_orphan_rec();
909         check_llog_unlink_rec();
910         check_llog_size_change_rec();
911         check_llog_gen();
912         check_llog_gen_rec();
913         check_llog_log_hdr();
914         check_llog_cookie();
915         check_llogd_body();
916         check_llogd_conn_body();
917
918         printf("}\n\n");
919
920         return(0);
921 }