1 [= AutoGen5 Template h -*- Mode: C -*- =]
2 [= (dne " * " "/* ") =]
4 [= (gpl "lustre" " * ") =]
7 * \file [= (out-name) =]
8 * The flags and collections of flags (masks) for \see struct ldlm_lock.
9 * This file is derived from flag definitions in [=(def-file)=].
10 * The format is defined in the [=(tpl-file)=] template file.
12 * \addtogroup LDLM Lustre Distributed Lock Manager
16 * The flags and collections of flags (masks) for \see struct ldlm_lock.
19 #ifndef LDLM_ALL_FLAGS_MASK
22 ;; Guile is unable to handle 64 bit unsigned ints very easily.
23 ;; BASH does just fine. Construct a shell script to compute the
24 ;; bit masks and echo out the appropriate #defines.
26 (out-push-new "script.sh")
31 fmt='#define LDLM_FL_%-16s 0x%016XULL // bit %2u
32 #define ldlm_is_%-20s LDLM_TEST_FLAG(( _l), 1ULL << %2u)
33 #define ldlm_set_%-20s LDLM_SET_FLAG(( _l), 1ULL << %2u)
34 #define ldlm_clear_%-20s LDLM_CLEAR_FLAG((_l), 1ULL << %2u)\n'
36 tmpfile=[=(base-name)=]-$$.tmp
43 bitno=[=(define temp-txt (get "f-desc"))
45 bitval=$(( 1 << $bitno ))
48 IF (< (string-length temp-txt) 72)=]
49 echo '/**' [= (raw-shell-str temp-txt) =] '*/'[=
52 { fmt -w 74 | sed 's/^/ * /;s/ *$//;$s@$@ */@'
59 dn_name=[= (string-downcase! (string->c-name! (get "f-name"))) =]'(_l)'
60 up_name=[= (string-upcase! (string->c-name! (get "f-name"))) =]
61 printf "$fmt" $up_name $bitval $bitno \
66 (( allbits += bitval ))[=
69 mask_list=${mask_list}[= f-mask =]$'\n'
70 mask_[= f-mask =]=$(( ${mask_[= f-mask =]:-0} + bitval ))[=
77 fmt='\n/** l_flags bits marked as "%s" bits */
78 #define LDLM_FL_%-22s 0x%016XULL\n'
79 printf "$fmt" all_flags ALL_FLAGS_MASK $allbits
81 for f in $(echo "$mask_list" | sort -u)
83 ucf=$(echo $f | tr a-z A-Z)_MASK
85 printf "$fmt" $f $ucf $v
89 rm -f $tmpfile script.sh[=
91 ;; The script is done. Pop off the temporary output, handing
92 ;; it to the shell for evaluation. stdout becomes the output text
99 /** test for ldlm_lock flag bit set */
100 #define LDLM_TEST_FLAG(_l, _b) (((_l)->l_flags & (_b)) != 0)
102 /** multi-bit test: are any of mask bits set? */
103 #define LDLM_HAVE_MASK(_l, _m) (((_l)->l_flags & LDLM_FL_##_m##_MASK) != 0)
105 /** set a ldlm_lock flag bit */
106 #define LDLM_SET_FLAG(_l, _b) ((_l)->l_flags |= (_b))
108 /** clear a ldlm_lock flag bit */
109 #define LDLM_CLEAR_FLAG(_l, _b) ((_l)->l_flags &= ~(_b))
113 #endif /* LDLM_ALL_FLAGS_MASK */
115 (out-push-new (string-append (base-name) "_wshark.c"))
116 (define flags-vals "")
118 (define init-text "")
121 (define down-name "")
124 " dissect_uint32(tvb, offset, pinfo, tree, hf_lustre_ldlm_fl_%s);\n")
127 /* p_id */ &hf_lustre_ldlm_fl_%1$s,
129 /* name */ "LDLM_FL_%2$s",
130 /* abbrev */ "lustre.ldlm_fl_%1$s",
131 /* type */ FT_BOOLEAN,
133 /* strings */ TFS(&lnet_flags_set_truth),
134 /* bitmask */ LDLM_FL_%2$s,
139 [= (define init-fmt (out-pop #t)) \=]
141 * \file [=(out-name)=]
143 * wireshark definitions. This file contains the ldlm lock flag bits
144 * that can be transmitted over the wire. There are many other bits,
145 * but they are not transmitted and not handled here.
152 (if (match-value? = "f-mask" "on_wire") (begin
153 (set! temp-txt (get "f-name"))
154 (set! up-name (string-upcase (string->c-name! temp-txt)))
155 (set! down-name (string-downcase temp-txt))
157 (set! flags-vals (string-append flags-vals (sprintf
158 "\n {LDLM_FL_%-20s \"LDLM_FL_%s\"},"
159 (string-append up-name ",") up-name )))
161 (set! dissect (string-append dissect (sprintf dissect-fmt
164 (set! init-text (string-append init-text (sprintf init-fmt
165 down-name up-name (c-string (get "f-desc")) )))
167 (ag-fprintf 0 "\nstatic int hf_lustre_ldlm_fl_%-20s= -1;"
172 const value_string lustre_ldlm_flags_vals[] = {[= (. flags-vals) =]
176 /* IDL: struct ldlm_reply { */
177 /* IDL: uint32 lock_flags; */
178 /* IDL: uint32 lock_padding; */
179 /* IDL: struct ldlm_lock_desc { */
180 /* IDL: } lock_desc; */
181 /* IDL: struct lustre_handle { */
182 /* IDL: } lock_handle; */
183 /* IDL: uint64 lock_policy_res1; */
184 /* IDL: uint64 lock_policy_res2; */
188 lustre_dissect_element_ldlm_lock_flags(
189 tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_,
190 proto_tree *parent_tree _U_, int hf_index _U_)
192 proto_item *item = NULL;
193 proto_tree *tree = NULL;
196 item = proto_tree_add_item(parent_tree,hf_index, tvb, offset, 4, TRUE);
197 tree = proto_item_add_subtree(item, ett_lustre_ldlm_lock_flags);
201 return' <<- \\_EOF_\n" dissect "_EOF_"
204 #endif /* WSHARK_HEAD */
206 #ifdef WSHARK_INIT_DATA
210 "\n#endif /* WSHARK_INIT_DATA */\n")
216 IF (getenv "TESTING") =][=
218 FOR flag (define len-list "")
221 (define header-name (out-name))
222 (out-push-new (string-append (base-name) ".c"))
224 (for-from 0) (for-by 1) =][=
226 (if (exist? "f-name")
228 (set! temp-str (string-upcase! (get "f-name")))
229 (set! len-list (string-append len-list (c-string
230 (sprintf "%%%us" (- 20 (string-length temp-str))) ) "\n" ))
231 (set! str-list (string-append str-list
232 (c-string temp-str) "\n" ))
235 (set! len-list (string-append len-list "NULL\n"))
236 (set! str-list (string-append str-list "NULL\n"))
244 #include "[=(. header-name)=]"
252 static char const * const fill_fmts[] = {
254 columns --spread=1 -I4 -S, --end=' };' <<_EOF_
258 printf '\nstatic char const * const flag_names[] = {\n'
259 columns --spread=1 -I4 -S, --end=' };' <<_EOF_
262 [= (shell (out-pop #t)) =]
265 print_bits(unsigned long long v)
267 static char const new_line[] = "\n";
268 char const * space_fmt = new_line + 1;
272 if ((v & ~LDLM_FL_ALL_FLAGS_MASK) != 0) {
273 unsigned long long wrong = v & ~LDLM_FL_ALL_FLAGS_MASK;
274 printf("undefined bits: 0x%016llX\n", wrong);
275 v &= LDLM_FL_ALL_FLAGS_MASK;
278 for (ix = 0; v != 0ULL; ix++, v >>= 1) {
279 if ((v & 0x1ULL) == 0)
282 printf(space_fmt, "");
283 if ((++ct & 0x03) == 0)
284 space_fmt = new_line;
286 space_fmt = fill_fmts[ix];
287 fputs(flag_names[ix], stdout);
293 cmd_ldlm_lock_flags(void)
297 unsigned long long v;
298 bool flip_val = false;
301 printf("no argument\n");
309 v = strtoull(p, &e, 0);
312 v = strtoull(p, &e, 16);
313 if ((errno != 0) || (*e != '\0')) {
314 printf("invalid number: %s\n", p);
320 v &= LDLM_FL_ALL_FLAGS_MASK;
326 char * help_ldlm_lock_flags[] = {
328 "flag bit names for ldlm_lock",
330 "The names of the bits that are set in the numeric value are printed.",
334 #ifdef LDLM_FLAGS_PROGRAM
340 usage(int ex_code, char const * msg)
343 FILE * fp = (ex_code == EXIT_SUCCESS) ? stdout : stderr;
344 args = help_ldlm_lock_flags;
346 fprintf(fp, "%s usage error: %s\n", args[0], msg);
347 fprintf(fp, "%s - %s\n", args[0], args[1]);
348 fprintf(fp, "Usage: %s %s\n", args[0], args[2]);
350 char * txt = args[ix++];
353 fprintf(fp, "%s\n", txt);
359 main(int argc, char ** argv)
362 char * av[3] = { argv[0], NULL, NULL };
367 usage(EXIT_FAILURE, "argument missing");
371 char * arg = argv[1];
375 case '-': if (arg[2] == 'h') break;
377 case 'h': usage(EXIT_SUCCESS, NULL);
386 cmd_ldlm_lock_flags();
390 #endif /* LDLM_FLAGS_PROGRAM */
397 * c-file-style: "linux"
398 * indent-tabs-mode: t