1 #include <ccan/tdb/tdb.h>
2 #include <ccan/grab_file/grab_file.h>
3 #include <ccan/hash/hash.h>
4 #include <ccan/talloc/talloc.h>
5 #include <ccan/str_talloc/str_talloc.h>
6 #include <ccan/str/str.h>
7 #include <ccan/list/list.h>
12 #include <sys/types.h>
20 #define STRINGIFY2(x) #x
21 #define STRINGIFY(x) STRINGIFY2(x)
23 /* Avoid mod by zero */
24 static unsigned int total_keys = 1;
26 /* #define DEBUG_DEPS 1 */
28 /* Traversals block transactions in the current implementation. */
29 #define TRAVERSALS_TAKE_TRANSACTION_LOCK 1
34 static struct pipe *pipes;
35 static int backoff_fd = -1;
37 static void __attribute__((noreturn)) fail(const char *filename,
44 fprintf(stderr, "%s:%u: FAIL: ", filename, line);
45 vfprintf(stderr, fmt, ap);
46 fprintf(stderr, "\n");
52 #define try(expr, expect) \
55 if (ret != (expect)) \
56 fail(filename[file], i+1, \
57 STRINGIFY(expr) "= %i", ret); \
60 /* Try or imitate results. */
61 #define unreliable(expr, expect, force, undo) \
64 if (ret != expect) { \
65 fprintf(stderr, "%s:%u: %s gave %i not %i", \
66 filename[file], i+1, STRINGIFY(expr), \
75 static bool key_eq(TDB_DATA a, TDB_DATA b)
77 if (a.dsize != b.dsize)
79 return memcmp(a.dptr, b.dptr, a.dsize) == 0;
82 /* This is based on the hash algorithm from gdbm */
83 static unsigned int hash_key(TDB_DATA *key)
85 uint32_t value; /* Used to compute the hash value. */
86 uint32_t i; /* Used to cycle through random values. */
88 /* Set the initial value from the key size. */
89 for (value = 0x238F13AF ^ key->dsize, i=0; i < key->dsize; i++)
90 value = (value + (key->dptr[i] << (i*5 % 24)));
92 return (1103515243 * value + 12345);
98 OP_TDB_LOCKALL_UNMARK,
99 OP_TDB_LOCKALL_NONBLOCK,
102 OP_TDB_LOCKALL_READ_NONBLOCK,
103 OP_TDB_UNLOCKALL_READ,
105 OP_TDB_CHAINLOCK_NONBLOCK,
106 OP_TDB_CHAINLOCK_MARK,
107 OP_TDB_CHAINLOCK_UNMARK,
109 OP_TDB_CHAINLOCK_READ,
110 OP_TDB_CHAINUNLOCK_READ,
117 OP_TDB_TRANSACTION_START,
118 OP_TDB_TRANSACTION_CANCEL,
119 OP_TDB_TRANSACTION_COMMIT,
120 OP_TDB_TRAVERSE_READ_START,
121 OP_TDB_TRAVERSE_START,
124 OP_TDB_TRAVERSE_END_EARLY,
138 /* Who is waiting for us? */
139 struct list_head post;
140 /* What are we waiting for? */
141 struct list_head pre;
143 /* If I'm part of a group (traverse/transaction) where is
144 * start? (Otherwise, 0) */
145 unsigned int group_start;
148 int flag; /* open and store */
149 struct { /* append */
153 /* transaction/traverse start/chainlock */
154 unsigned int group_len;
163 static unsigned char hex_char(const char *filename, unsigned int line, char c)
166 if (c >= 'A' && c <= 'F')
168 if (c >= '0' && c <= '9')
170 fail(filename, line, "invalid hex character '%c'", c);
173 /* TDB data is <size>:<%02x>* */
174 static TDB_DATA make_tdb_data(const void *ctx,
175 const char *filename, unsigned int line,
182 if (streq(word, "NULL"))
185 data.dsize = atoi(word);
186 data.dptr = talloc_array(ctx, unsigned char, data.dsize);
187 p = strchr(word, ':');
189 fail(filename, line, "invalid tdb data '%s'", word);
191 for (i = 0; i < data.dsize; i++)
192 data.dptr[i] = hex_char(filename, line, p[i*2])*16
193 + hex_char(filename, line, p[i*2+1]);
198 static void add_op(const char *filename, struct op **op, unsigned int i,
199 unsigned int seqnum, enum op_type type)
202 *op = talloc_realloc(NULL, *op, struct op, i+1);
205 new->seqnum = seqnum;
207 new->group_start = 0;
210 static void op_add_nothing(const char *filename,
211 struct op op[], unsigned int op_num, char *words[])
214 fail(filename, op_num+1, "Expected no arguments");
215 op[op_num].key = tdb_null;
218 static void op_add_key(const char *filename,
219 struct op op[], unsigned int op_num, char *words[])
221 if (words[2] == NULL || words[3])
222 fail(filename, op_num+1, "Expected just a key");
224 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
228 static void op_add_key_ret(const char *filename,
229 struct op op[], unsigned int op_num, char *words[])
231 if (!words[2] || !words[3] || !words[4] || words[5]
232 || !streq(words[3], "="))
233 fail(filename, op_num+1, "Expected <key> = <ret>");
234 op[op_num].ret = atoi(words[4]);
235 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
236 /* May only be a unique key if it fails */
237 if (op[op_num].ret != 0)
241 static void op_add_key_data(const char *filename,
242 struct op op[], unsigned int op_num, char *words[])
244 if (!words[2] || !words[3] || !words[4] || words[5]
245 || !streq(words[3], "="))
246 fail(filename, op_num+1, "Expected <key> = <data>");
247 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
248 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[4]);
249 /* May only be a unique key if it fails */
250 if (!op[op_num].data.dptr)
254 /* We don't record the keys or data for a traverse, as we don't use them. */
255 static void op_add_traverse(const char *filename,
256 struct op op[], unsigned int op_num, char *words[])
258 if (!words[2] || !words[3] || !words[4] || words[5]
259 || !streq(words[3], "="))
260 fail(filename, op_num+1, "Expected <key> = <data>");
261 op[op_num].key = tdb_null;
264 /* Full traverse info is useful for debugging, but changing it to
265 * "traversefn" without the data makes the traces *much* smaller! */
266 static void op_add_traversefn(const char *filename,
267 struct op op[], unsigned int op_num, char *words[])
270 fail(filename, op_num+1, "Expected no values");
271 op[op_num].key = tdb_null;
274 /* <seqnum> tdb_store <rec> <rec> <flag> = <ret> */
275 static void op_add_store(const char *filename,
276 struct op op[], unsigned int op_num, char *words[])
278 if (!words[2] || !words[3] || !words[4] || !words[5] || !words[6]
279 || words[7] || !streq(words[5], "="))
280 fail(filename, op_num+1, "Expect <key> <data> <flag> = <ret>");
282 op[op_num].flag = strtoul(words[4], NULL, 0);
283 op[op_num].ret = atoi(words[6]);
284 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
285 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[3]);
289 /* <seqnum> tdb_append <rec> <rec> = <rec> */
290 static void op_add_append(const char *filename,
291 struct op op[], unsigned int op_num, char *words[])
293 if (!words[2] || !words[3] || !words[4] || !words[5] || words[6]
294 || !streq(words[4], "="))
295 fail(filename, op_num+1, "Expect <key> <data> = <rec>");
297 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
298 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[3]);
300 op[op_num].append.post
301 = make_tdb_data(op, filename, op_num+1, words[5]);
303 /* By subtraction, figure out what previous data was. */
304 op[op_num].append.pre.dptr = op[op_num].append.post.dptr;
305 op[op_num].append.pre.dsize
306 = op[op_num].append.post.dsize - op[op_num].data.dsize;
310 /* <seqnum> tdb_get_seqnum = <ret> */
311 static void op_add_seqnum(const char *filename,
312 struct op op[], unsigned int op_num, char *words[])
314 if (!words[2] || !words[3] || words[4] || !streq(words[2], "="))
315 fail(filename, op_num+1, "Expect = <ret>");
317 op[op_num].key = tdb_null;
318 op[op_num].ret = atoi(words[3]);
321 static void op_add_traverse_start(const char *filename,
323 unsigned int op_num, char *words[])
326 fail(filename, op_num+1, "Expect no arguments");
328 op[op_num].key = tdb_null;
329 op[op_num].group_len = 0;
332 static void op_add_transaction(const char *filename, struct op op[],
333 unsigned int op_num, char *words[])
336 fail(filename, op_num+1, "Expect no arguments");
338 op[op_num].key = tdb_null;
339 op[op_num].group_len = 0;
342 static void op_add_chainlock(const char *filename,
343 struct op op[], unsigned int op_num, char *words[])
345 if (words[2] == NULL || words[3])
346 fail(filename, op_num+1, "Expected just a key");
348 /* A chainlock key isn't a key in the normal sense; it doesn't
349 * have to be in the db at all. Also, we don't want to hash this op. */
350 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[2]);
351 op[op_num].key = tdb_null;
352 op[op_num].group_len = 0;
355 static void op_add_chainlock_ret(const char *filename,
356 struct op op[], unsigned int op_num,
359 if (!words[2] || !words[3] || !words[4] || words[5]
360 || !streq(words[3], "="))
361 fail(filename, op_num+1, "Expected <key> = <ret>");
362 op[op_num].ret = atoi(words[4]);
363 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[2]);
364 op[op_num].key = tdb_null;
365 op[op_num].group_len = 0;
369 static int op_find_start(struct op op[], unsigned int op_num, enum op_type type)
373 for (i = op_num-1; i > 0; i--) {
374 if (op[i].type == type && !op[i].group_len)
380 static void op_analyze_transaction(const char *filename,
381 struct op op[], unsigned int op_num,
384 unsigned int start, i;
386 op[op_num].key = tdb_null;
389 fail(filename, op_num+1, "Expect no arguments");
391 start = op_find_start(op, op_num, OP_TDB_TRANSACTION_START);
393 fail(filename, op_num+1, "no transaction start found");
395 op[start].group_len = op_num - start;
397 /* This rolls in nested transactions. I think that's right. */
398 for (i = start; i <= op_num; i++)
399 op[i].group_start = start;
402 /* We treat chainlocks a lot like transactions, even though that's overkill */
403 static void op_analyze_chainlock(const char *filename,
404 struct op op[], unsigned int op_num,
407 unsigned int i, start;
409 if (words[2] == NULL || words[3])
410 fail(filename, op_num+1, "Expected just a key");
412 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[2]);
413 op[op_num].key = tdb_null;
416 start = op_find_start(op, op_num, OP_TDB_CHAINLOCK);
418 start = op_find_start(op, op_num, OP_TDB_CHAINLOCK_READ);
420 fail(filename, op_num+1, "no initial chainlock found");
422 /* FIXME: We'd have to do something clever to make this work
424 if (!key_eq(op[start].data, op[op_num].data))
425 fail(filename, op_num+1, "nested chainlock calls?");
427 op[start].group_len = op_num - start;
428 for (i = start; i <= op_num; i++)
429 op[i].group_start = start;
432 static void op_analyze_traverse(const char *filename,
433 struct op op[], unsigned int op_num,
438 op[op_num].key = tdb_null;
440 /* = %u means traverse function terminated. */
442 if (!streq(words[2], "=") || !words[3] || words[4])
443 fail(filename, op_num+1, "expect = <num>");
444 op[op_num].ret = atoi(words[3]);
448 start = op_find_start(op, op_num, OP_TDB_TRAVERSE_START);
450 start = op_find_start(op, op_num, OP_TDB_TRAVERSE_READ_START);
452 fail(filename, op_num+1, "no traversal start found");
454 op[start].group_len = op_num - start;
456 /* Don't roll in nested traverse/chainlock */
457 for (i = start; i <= op_num; i++)
458 if (!op[i].group_start)
459 op[i].group_start = start;
462 /* Keep -Wmissing-declarations happy: */
463 const struct op_table *
464 find_keyword (register const char *str, register unsigned int len);
466 #include "keywords.c"
469 /* We can have more than one */
470 struct list_node pre_list;
471 struct list_node post_list;
472 struct op_desc needs;
473 struct op_desc prereq;
476 static void check_deps(const char *filename, struct op op[], unsigned int num)
481 for (i = 1; i < num; i++)
482 if (!list_empty(&op[i].pre))
483 fail(filename, i+1, "Still has dependencies");
487 static void dump_pre(char *filename[], struct op *op[],
488 unsigned int file, unsigned int i)
492 printf("%s:%u (%u) still waiting for:\n", filename[file], i+1,
494 list_for_each(&op[file][i].pre, dep, pre_list)
495 printf(" %s:%u (%u)\n",
496 filename[dep->prereq.file], dep->prereq.op_num+1,
497 op[dep->prereq.file][dep->prereq.op_num].seqnum);
498 check_deps(filename[file], op[file], i);
501 /* We simply read/write pointers, since we all are children. */
502 static bool do_pre(struct tdb_context *tdb,
503 char *filename[], struct op *op[],
504 unsigned int file, int pre_fd, unsigned int i,
507 while (!list_empty(&op[file][i].pre)) {
511 printf("%s:%u:waiting for pre\n", filename[file], i+1);
518 while (read(pre_fd, &dep, sizeof(dep)) != sizeof(dep)) {
519 if (errno == EINTR) {
521 struct op_desc desc = { file,i };
522 warnx("%s:%u:avoiding deadlock",
523 filename[file], i+1);
524 if (write(backoff_fd, &desc,
525 sizeof(desc)) != sizeof(desc))
526 err(1, "writing backoff_fd");
529 dump_pre(filename, op, file, i);
532 errx(1, "Reading from pipe");
537 printf("%s:%u:got pre %u from %s:%u\n", filename[file], i+1,
538 dep->needs.op_num+1, filename[dep->prereq.file],
539 dep->prereq.op_num+1);
542 /* This could be any op, not just this one. */
548 static void do_post(char *filename[], struct op *op[],
549 unsigned int file, unsigned int i)
553 list_for_each(&op[file][i].post, dep, post_list) {
555 printf("%s:%u:sending to file %s:%u\n", filename[file], i+1,
556 filename[dep->needs.file], dep->needs.op_num+1);
558 if (write(pipes[dep->needs.file].fd[1], &dep, sizeof(dep))
560 err(1, "%s:%u failed to tell file %s",
561 filename[file], i+1, filename[dep->needs.file]);
565 static int get_len(TDB_DATA key, TDB_DATA data, void *private_data)
570 static unsigned run_ops(struct tdb_context *tdb,
575 unsigned int start, unsigned int stop,
578 struct traverse_info {
587 /* More complex. Just do whatever's they did at the n'th entry. */
588 static int nontrivial_traverse(struct tdb_context *tdb,
589 TDB_DATA key, TDB_DATA data,
592 struct traverse_info *tinfo = _tinfo;
593 unsigned int trav_len = tinfo->op[tinfo->file][tinfo->start].group_len;
594 bool avoid_deadlock = false;
596 if (tinfo->i == tinfo->start + trav_len) {
597 /* This can happen if traverse expects to be empty. */
600 fail(tinfo->filename[tinfo->file], tinfo->start + 1,
601 "traverse did not terminate");
604 if (tinfo->op[tinfo->file][tinfo->i].type != OP_TDB_TRAVERSE)
605 fail(tinfo->filename[tinfo->file], tinfo->start + 1,
606 "%s:%u:traverse terminated early");
608 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
609 avoid_deadlock = true;
612 /* Run any normal ops. */
613 tinfo->i = run_ops(tdb, tinfo->pre_fd, tinfo->filename, tinfo->op,
614 tinfo->file, tinfo->i+1, tinfo->start + trav_len,
617 /* We backed off, or we hit OP_TDB_TRAVERSE_END/EARLY. */
618 if (tinfo->op[tinfo->file][tinfo->i].type != OP_TDB_TRAVERSE)
624 static unsigned op_traverse(struct tdb_context *tdb,
628 int (*traversefn)(struct tdb_context *,
629 tdb_traverse_func, void *),
633 struct traverse_info tinfo = { op, filename, file, pre_fd,
636 traversefn(tdb, nontrivial_traverse, &tinfo);
638 /* Traversing in wrong order can have strange effects: eg. if
639 * original traverse went A (delete A), B, we might do B
640 * (delete A). So if we have ops left over, we do it now. */
641 while (tinfo.i != start + op[file][start].group_len) {
642 if (op[file][tinfo.i].type == OP_TDB_TRAVERSE
643 || op[file][tinfo.i].type == OP_TDB_TRAVERSE_END_EARLY)
646 tinfo.i = run_ops(tdb, pre_fd, filename, op, file,
648 start + op[file][start].group_len,
655 static void break_out(int sig)
659 static __attribute__((noinline))
660 unsigned run_ops(struct tdb_context *tdb,
665 unsigned int start, unsigned int stop,
671 sa.sa_handler = break_out;
674 sigaction(SIGALRM, &sa, NULL);
675 for (i = start; i < stop; i++) {
676 if (!do_pre(tdb, filename, op, file, pre_fd, i, backoff))
679 switch (op[file][i].type) {
681 try(tdb_lockall(tdb), op[file][i].ret);
683 case OP_TDB_LOCKALL_MARK:
684 try(tdb_lockall_mark(tdb), op[file][i].ret);
686 case OP_TDB_LOCKALL_UNMARK:
687 try(tdb_lockall_unmark(tdb), op[file][i].ret);
689 case OP_TDB_LOCKALL_NONBLOCK:
690 unreliable(tdb_lockall_nonblock(tdb), op[file][i].ret,
691 tdb_lockall(tdb), tdb_unlockall(tdb));
693 case OP_TDB_UNLOCKALL:
694 try(tdb_unlockall(tdb), op[file][i].ret);
696 case OP_TDB_LOCKALL_READ:
697 try(tdb_lockall_read(tdb), op[file][i].ret);
699 case OP_TDB_LOCKALL_READ_NONBLOCK:
700 unreliable(tdb_lockall_read_nonblock(tdb),
702 tdb_lockall_read(tdb),
703 tdb_unlockall_read(tdb));
705 case OP_TDB_UNLOCKALL_READ:
706 try(tdb_unlockall_read(tdb), op[file][i].ret);
708 case OP_TDB_CHAINLOCK:
709 try(tdb_chainlock(tdb, op[file][i].key),
712 case OP_TDB_CHAINLOCK_NONBLOCK:
713 unreliable(tdb_chainlock_nonblock(tdb, op[file][i].key),
715 tdb_chainlock(tdb, op[file][i].key),
716 tdb_chainunlock(tdb, op[file][i].key));
718 case OP_TDB_CHAINLOCK_MARK:
719 try(tdb_chainlock_mark(tdb, op[file][i].key),
722 case OP_TDB_CHAINLOCK_UNMARK:
723 try(tdb_chainlock_unmark(tdb, op[file][i].key),
726 case OP_TDB_CHAINUNLOCK:
727 try(tdb_chainunlock(tdb, op[file][i].key),
730 case OP_TDB_CHAINLOCK_READ:
731 try(tdb_chainlock_read(tdb, op[file][i].key),
734 case OP_TDB_CHAINUNLOCK_READ:
735 try(tdb_chainunlock_read(tdb, op[file][i].key),
738 case OP_TDB_PARSE_RECORD:
739 try(tdb_parse_record(tdb, op[file][i].key, get_len,
744 try(tdb_exists(tdb, op[file][i].key), op[file][i].ret);
747 try(tdb_store(tdb, op[file][i].key, op[file][i].data,
752 try(tdb_append(tdb, op[file][i].key, op[file][i].data),
755 case OP_TDB_GET_SEQNUM:
756 try(tdb_get_seqnum(tdb), op[file][i].ret);
758 case OP_TDB_WIPE_ALL:
759 try(tdb_wipe_all(tdb), op[file][i].ret);
761 case OP_TDB_TRANSACTION_START:
762 try(tdb_transaction_start(tdb), op[file][i].ret);
764 case OP_TDB_TRANSACTION_CANCEL:
765 try(tdb_transaction_cancel(tdb), op[file][i].ret);
767 case OP_TDB_TRANSACTION_COMMIT:
768 try(tdb_transaction_commit(tdb), op[file][i].ret);
770 case OP_TDB_TRAVERSE_READ_START:
771 i = op_traverse(tdb, pre_fd, filename, file,
772 tdb_traverse_read, op, i);
774 case OP_TDB_TRAVERSE_START:
775 i = op_traverse(tdb, pre_fd, filename, file,
776 tdb_traverse, op, i);
778 case OP_TDB_TRAVERSE:
779 case OP_TDB_TRAVERSE_END_EARLY:
780 /* Terminate: we're in a traverse, and we've
783 case OP_TDB_TRAVERSE_END:
784 fail(filename[file], i+1, "unexpected end traverse");
785 /* FIXME: These must be treated like traverse. */
786 case OP_TDB_FIRSTKEY:
787 if (!key_eq(tdb_firstkey(tdb), op[file][i].data))
788 fail(filename[file], i+1, "bad firstkey");
791 if (!key_eq(tdb_nextkey(tdb, op[file][i].key),
793 fail(filename[file], i+1, "bad nextkey");
796 TDB_DATA f = tdb_fetch(tdb, op[file][i].key);
797 if (!key_eq(f, op[file][i].data))
798 fail(filename[file], i+1, "bad fetch %u",
803 try(tdb_delete(tdb, op[file][i].key), op[file][i].ret);
806 do_post(filename, op, file, i);
811 /* tdbtorture, in particular, can do a tdb_close with a transaction in
813 static struct op *maybe_cancel_transaction(const char *filename,
814 struct op *op, unsigned int *num)
816 unsigned int start = op_find_start(op, *num, OP_TDB_TRANSACTION_START);
819 char *words[] = { "<unknown>", "tdb_close", NULL };
820 add_op(filename, &op, *num, op[start].seqnum,
821 OP_TDB_TRANSACTION_CANCEL);
822 op_analyze_transaction(filename, op, *num, words);
828 static struct op *load_tracefile(const char *filename, unsigned int *num,
829 unsigned int *hashsize,
830 unsigned int *tdb_flags,
831 unsigned int *open_flags)
834 struct op *op = talloc_array(NULL, struct op, 1);
839 file = grab_file(NULL, filename, NULL);
841 err(1, "Reading %s", filename);
843 lines = strsplit(file, file, "\n", NULL);
845 errx(1, "%s is empty", filename);
847 words = strsplit(lines, lines[0], " ", NULL);
848 if (!streq(words[1], "tdb_open"))
849 fail(filename, 1, "does not start with tdb_open");
851 *hashsize = atoi(words[2]);
852 *tdb_flags = strtoul(words[3], NULL, 0);
853 *open_flags = strtoul(words[4], NULL, 0);
855 for (i = 1; lines[i]; i++) {
856 const struct op_table *opt;
858 words = strsplit(lines, lines[i], " ", NULL);
859 if (!words[0] || !words[1])
860 fail(filename, i+1, "Expected seqnum number and op");
862 opt = find_keyword(words[1], strlen(words[1]));
864 if (streq(words[1], "tdb_close")) {
867 "lines after tdb_close");
870 return maybe_cancel_transaction(filename,
873 fail(filename, i+1, "Unknown operation '%s'", words[1]);
876 add_op(filename, &op, i, atoi(words[0]), opt->type);
877 opt->enhance_op(filename, op, i, words);
880 fprintf(stderr, "%s:%u:last operation is not tdb_close: incomplete?",
884 return maybe_cancel_transaction(filename, op, num);
887 /* We remember all the keys we've ever seen, and who has them. */
890 unsigned int num_users;
891 struct op_desc *user;
894 static const TDB_DATA must_not_exist;
895 static const TDB_DATA must_exist;
896 static const TDB_DATA not_exists_or_empty;
898 /* NULL means doesn't care if it exists or not, &must_exist means
899 * it must exist but we don't care what, &must_not_exist means it must
900 * not exist, otherwise the data it needs. */
901 static const TDB_DATA *needs(const struct op *op)
904 /* FIXME: Pull forward deps, since we can deadlock */
905 case OP_TDB_CHAINLOCK:
906 case OP_TDB_CHAINLOCK_NONBLOCK:
907 case OP_TDB_CHAINLOCK_MARK:
908 case OP_TDB_CHAINLOCK_UNMARK:
909 case OP_TDB_CHAINUNLOCK:
910 case OP_TDB_CHAINLOCK_READ:
911 case OP_TDB_CHAINUNLOCK_READ:
915 if (op->append.pre.dsize == 0)
916 return ¬_exists_or_empty;
917 return &op->append.pre;
920 if (op->flag == TDB_INSERT) {
924 return &must_not_exist;
925 } else if (op->flag == TDB_MODIFY) {
927 return &must_not_exist;
931 /* No flags? Don't care */
938 return &must_not_exist;
940 case OP_TDB_PARSE_RECORD:
942 return &must_not_exist;
945 /* FIXME: handle these. */
946 case OP_TDB_WIPE_ALL:
947 case OP_TDB_FIRSTKEY:
949 case OP_TDB_GET_SEQNUM:
950 case OP_TDB_TRAVERSE:
951 case OP_TDB_TRANSACTION_COMMIT:
952 case OP_TDB_TRANSACTION_CANCEL:
953 case OP_TDB_TRANSACTION_START:
958 return &must_not_exist;
963 return &must_not_exist;
967 errx(1, "Unexpected op type %i", op->type);
972 static bool starts_transaction(const struct op *op)
974 return op->type == OP_TDB_TRANSACTION_START;
977 static bool in_transaction(const struct op op[], unsigned int i)
979 return op[i].group_start && starts_transaction(&op[op[i].group_start]);
982 static bool successful_transaction(const struct op *op)
984 return starts_transaction(op)
985 && op[op->group_len].type == OP_TDB_TRANSACTION_COMMIT;
988 static bool starts_traverse(const struct op *op)
990 return op->type == OP_TDB_TRAVERSE_START
991 || op->type == OP_TDB_TRAVERSE_READ_START;
994 static bool in_traverse(const struct op op[], unsigned int i)
996 return op[i].group_start && starts_traverse(&op[op[i].group_start]);
999 static bool starts_chainlock(const struct op *op)
1001 return op->type == OP_TDB_CHAINLOCK_READ
1002 || op->type == OP_TDB_CHAINLOCK;
1005 static bool in_chainlock(const struct op op[], unsigned int i)
1007 return op[i].group_start && starts_chainlock(&op[op[i].group_start]);
1010 /* What's the data after this op? pre if nothing changed. */
1011 static const TDB_DATA *gives(const TDB_DATA *key, const TDB_DATA *pre,
1012 const struct op *op)
1014 if (starts_transaction(op) || starts_chainlock(op)) {
1017 /* Cancelled transactions don't change anything. */
1018 if (op[op->group_len].type == OP_TDB_TRANSACTION_CANCEL)
1020 assert(op[op->group_len].type == OP_TDB_TRANSACTION_COMMIT
1021 || op[op->group_len].type == OP_TDB_CHAINUNLOCK_READ
1022 || op[op->group_len].type == OP_TDB_CHAINUNLOCK);
1024 for (i = 1; i < op->group_len; i++) {
1025 /* This skips nested transactions, too */
1026 if (key_eq(op[i].key, *key))
1027 pre = gives(key, pre, &op[i]);
1032 /* Failed ops don't change state of db. */
1036 if (op->type == OP_TDB_DELETE || op->type == OP_TDB_WIPE_ALL)
1039 if (op->type == OP_TDB_APPEND)
1040 return &op->append.post;
1042 if (op->type == OP_TDB_STORE)
1048 static struct keyinfo *hash_ops(struct op *op[], unsigned int num_ops[],
1051 unsigned int i, j, h;
1052 struct keyinfo *hash;
1054 hash = talloc_zero_array(op[0], struct keyinfo, total_keys*2);
1055 for (i = 0; i < num; i++) {
1056 for (j = 1; j < num_ops[i]; j++) {
1057 /* We can't do this on allocation, due to realloc. */
1058 list_head_init(&op[i][j].post);
1059 list_head_init(&op[i][j].pre);
1061 if (!op[i][j].key.dptr)
1064 h = hash_key(&op[i][j].key) % (total_keys * 2);
1065 while (!key_eq(hash[h].key, op[i][j].key)) {
1066 if (!hash[h].key.dptr) {
1067 hash[h].key = op[i][j].key;
1070 h = (h + 1) % (total_keys * 2);
1072 /* Might as well save some memory if we can. */
1073 if (op[i][j].key.dptr != hash[h].key.dptr) {
1074 talloc_free(op[i][j].key.dptr);
1075 op[i][j].key.dptr = hash[h].key.dptr;
1077 hash[h].user = talloc_realloc(hash, hash[h].user,
1079 hash[h].num_users+1);
1081 /* If it's in a transaction, it's the transaction which
1082 * matters from an analysis POV. */
1083 if (in_transaction(op[i], j)
1084 || in_chainlock(op[i], j)) {
1085 unsigned start = op[i][j].group_start;
1087 /* Don't include twice. */
1088 if (hash[h].num_users
1089 && hash[h].user[hash[h].num_users-1].file
1091 && hash[h].user[hash[h].num_users-1].op_num
1095 hash[h].user[hash[h].num_users].op_num = start;
1097 hash[h].user[hash[h].num_users].op_num = j;
1098 hash[h].user[hash[h].num_users].file = i;
1099 hash[h].num_users++;
1106 static bool satisfies(const TDB_DATA *key, const TDB_DATA *data,
1107 const struct op *op)
1109 const TDB_DATA *need = NULL;
1111 if (starts_transaction(op) || starts_chainlock(op)) {
1114 /* Look through for an op in this transaction which
1115 * needs this key. */
1116 for (i = 1; i < op->group_len; i++) {
1117 if (key_eq(op[i].key, *key)) {
1118 need = needs(&op[i]);
1119 /* tdb_exists() is special: there might be
1120 * something in the transaction with more
1121 * specific requirements. Other ops don't have
1122 * specific requirements (eg. store or delete),
1123 * but they change the value so we can't get
1124 * more information from future ops. */
1125 if (op[i].type != OP_TDB_EXISTS)
1132 /* Don't need anything? Cool. */
1136 /* This should be tdb_null or a real value. */
1137 assert(data != &must_exist);
1138 assert(data != &must_not_exist);
1139 assert(data != ¬_exists_or_empty);
1141 /* Must not exist? data must not exist. */
1142 if (need == &must_not_exist)
1143 return data == &tdb_null;
1146 if (need == &must_exist)
1147 return data != &tdb_null;
1149 /* Either noexist or empty. */
1150 if (need == ¬_exists_or_empty)
1151 return data->dsize == 0;
1153 /* Needs something specific. */
1154 return key_eq(*data, *need);
1157 static void move_to_front(struct op_desc res[], unsigned off, unsigned elem)
1160 struct op_desc tmp = res[elem];
1161 memmove(res + off + 1, res + off, (elem - off)*sizeof(res[0]));
1166 static void restore_to_pos(struct op_desc res[], unsigned off, unsigned elem)
1169 struct op_desc tmp = res[off];
1170 memmove(res + off, res + off + 1, (elem - off)*sizeof(res[0]));
1175 static bool sort_deps(char *filename[], struct op *op[],
1176 struct op_desc res[],
1177 unsigned off, unsigned num,
1178 const TDB_DATA *key, const TDB_DATA *data,
1179 unsigned num_files, unsigned fuzz)
1181 unsigned int i, files_done;
1183 bool done[num_files];
1185 /* None left? We're sorted. */
1189 /* Does this make sequence number go backwards? Allow a little fuzz. */
1191 int seqnum1 = op[res[off-1].file][res[off-1].op_num].seqnum;
1192 int seqnum2 = op[res[off].file][res[off].op_num].seqnum;
1194 if (seqnum1 - seqnum2 > (int)fuzz) {
1196 printf("Seqnum jump too far (%u -> %u)\n",
1203 memset(done, 0, sizeof(done));
1205 /* Since ops within a trace file are ordered, we just need to figure
1206 * out which file to try next. Since we don't take into account
1207 * inter-key relationships (which exist by virtue of trace file order),
1208 * we minimize the chance of harm by trying to keep in seqnum order. */
1209 for (files_done = 0, i = off; i < num && files_done < num_files; i++) {
1210 if (done[res[i].file])
1213 this_op = &op[res[i].file][res[i].op_num];
1215 /* Is what we have good enough for this op? */
1216 if (satisfies(key, data, this_op)) {
1217 move_to_front(res, off, i);
1218 if (sort_deps(filename, op, res, off+1, num,
1219 key, gives(key, data, this_op),
1222 restore_to_pos(res, off, i);
1224 done[res[i].file] = true;
1228 /* No combination worked. */
1232 static void check_dep_sorting(struct op_desc user[], unsigned num_users,
1237 unsigned minima[num_files];
1239 memset(minima, 0, sizeof(minima));
1240 for (i = 0; i < num_users; i++) {
1241 assert(minima[user[i].file] < user[i].op_num);
1242 minima[user[i].file] = user[i].op_num;
1247 /* All these ops happen on the same key. Which comes first?
1249 * This can happen both because read ops or failed write ops don't
1250 * change sequence number, and also due to race since we access the
1251 * number unlocked (the race can cause less detectable ordering problems,
1252 * in which case we'll deadlock and report: fix manually in that case).
1254 static void figure_deps(char *filename[], struct op *op[],
1255 const TDB_DATA *key, struct op_desc user[],
1256 unsigned num_users, unsigned num_files)
1258 /* We assume database starts empty. */
1259 const struct TDB_DATA *data = &tdb_null;
1262 /* We prefer to keep strict seqnum order if possible: it's the
1263 * most likely. We get more lax if that fails. */
1264 for (fuzz = 0; fuzz < 100; fuzz = (fuzz + 1)*2) {
1265 if (sort_deps(filename, op, user, 0, num_users, key, data,
1271 fail(filename[user[0].file], user[0].op_num+1,
1272 "Could not resolve inter-dependencies");
1274 check_dep_sorting(user, num_users, num_files);
1277 static void sort_ops(struct keyinfo hash[], char *filename[], struct op *op[],
1282 /* Gcc nexted function extension. How cool is this? */
1283 int compare_seqnum(const void *_a, const void *_b)
1285 const struct op_desc *a = _a, *b = _b;
1287 /* First, maintain order within any trace file. */
1288 if (a->file == b->file)
1289 return a->op_num - b->op_num;
1291 /* Otherwise, arrange by seqnum order. */
1292 if (op[a->file][a->op_num].seqnum !=
1293 op[b->file][b->op_num].seqnum)
1294 return op[a->file][a->op_num].seqnum
1295 - op[b->file][b->op_num].seqnum;
1297 /* Cancelled transactions are assumed to happen first. */
1298 if (starts_transaction(&op[a->file][a->op_num])
1299 && !successful_transaction(&op[a->file][a->op_num]))
1301 if (starts_transaction(&op[b->file][b->op_num])
1302 && !successful_transaction(&op[b->file][b->op_num]))
1309 /* Now sort into seqnum order. */
1310 for (h = 0; h < total_keys * 2; h++) {
1311 struct op_desc *user = hash[h].user;
1313 qsort(user, hash[h].num_users, sizeof(user[0]), compare_seqnum);
1314 figure_deps(filename, op, &hash[h].key, user, hash[h].num_users,
1319 static int destroy_depend(struct depend *dep)
1321 list_del(&dep->pre_list);
1322 list_del(&dep->post_list);
1326 static void add_dependency(void *ctx,
1329 const struct op_desc *needs,
1330 const struct op_desc *prereq)
1334 /* We don't depend on ourselves. */
1335 if (needs->file == prereq->file) {
1336 assert(prereq->op_num < needs->op_num);
1341 printf("%s:%u: depends on %s:%u\n",
1342 filename[needs->file], needs->op_num+1,
1343 filename[prereq->file], prereq->op_num+1);
1346 dep = talloc(ctx, struct depend);
1347 dep->needs = *needs;
1348 dep->prereq = *prereq;
1350 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1351 /* If something in a traverse depends on something in another
1352 * traverse/transaction, it creates a dependency between the
1354 if ((in_traverse(op[prereq->file], prereq->op_num)
1355 && (starts_transaction(&op[needs->file][needs->op_num])
1356 || starts_traverse(&op[needs->file][needs->op_num])))
1357 || (in_traverse(op[needs->file], needs->op_num)
1358 && (starts_transaction(&op[prereq->file][prereq->op_num])
1359 || starts_traverse(&op[prereq->file][prereq->op_num])))) {
1362 /* We are satisfied by end of group. */
1363 start = op[prereq->file][prereq->op_num].group_start;
1364 dep->prereq.op_num = start + op[prereq->file][start].group_len;
1365 /* And we need that done by start of our group. */
1366 dep->needs.op_num = op[needs->file][needs->op_num].group_start;
1369 /* There is also this case:
1370 * <traverse> <read foo> ...
1371 * <transaction> ... </transaction> <create foo>
1372 * Where if we start the traverse then wait, we could block
1373 * the transaction and deadlock.
1375 * We try to address this by ensuring that where seqnum indicates it's
1376 * possible, we wait for <create foo> before *starting* traverse.
1378 else if (in_traverse(op[needs->file], needs->op_num)) {
1379 struct op *need = &op[needs->file][needs->op_num];
1380 if (op[needs->file][need->group_start].seqnum >
1381 op[prereq->file][prereq->op_num].seqnum) {
1382 dep->needs.op_num = need->group_start;
1387 /* If you depend on a transaction or chainlock, you actually
1388 * depend on it ending. */
1389 if (starts_transaction(&op[prereq->file][dep->prereq.op_num])
1390 || starts_chainlock(&op[prereq->file][dep->prereq.op_num])) {
1392 += op[dep->prereq.file][dep->prereq.op_num].group_len;
1394 printf("-> Actually end of transaction %s:%u\n",
1395 filename[dep->prereq->file], dep->prereq->op_num+1);
1398 /* We should never create a dependency from middle of
1400 assert(!in_transaction(op[prereq->file], dep->prereq.op_num)
1401 || op[prereq->file][dep->prereq.op_num].type
1402 == OP_TDB_TRANSACTION_COMMIT
1403 || op[prereq->file][dep->prereq.op_num].type
1404 == OP_TDB_TRANSACTION_CANCEL);
1406 list_add(&op[dep->prereq.file][dep->prereq.op_num].post,
1408 list_add(&op[dep->needs.file][dep->needs.op_num].pre,
1410 talloc_set_destructor(dep, destroy_depend);
1413 static bool changes_db(const TDB_DATA *key, const struct op *op)
1415 return gives(key, NULL, op) != NULL;
1418 static void depend_on_previous(struct op *op[],
1421 struct op_desc user[],
1431 if (prev == i - 1) {
1432 /* Just depend on previous. */
1433 add_dependency(NULL, op, filename, &user[i], &user[prev]);
1437 /* We have to wait for the readers. Find last one in *each* file. */
1438 memset(deps, 0, sizeof(deps));
1439 deps[user[i].file] = true;
1440 for (j = i - 1; j > prev; j--) {
1441 if (!deps[user[j].file]) {
1442 add_dependency(NULL, op, filename, &user[i], &user[j]);
1443 deps[user[j].file] = true;
1448 /* This is simple, but not complete. We don't take into account
1449 * indirect dependencies. */
1450 static void optimize_dependencies(struct op *op[], unsigned int num_ops[],
1455 /* There can only be one real dependency on each file */
1456 for (i = 0; i < num; i++) {
1457 for (j = 1; j < num_ops[i]; j++) {
1458 struct depend *dep, *next;
1459 struct depend *prev[num];
1461 memset(prev, 0, sizeof(prev));
1463 list_for_each_safe(&op[i][j].pre, dep, next, pre_list) {
1464 if (!prev[dep->prereq.file]) {
1465 prev[dep->prereq.file] = dep;
1468 if (prev[dep->prereq.file]->prereq.op_num
1469 < dep->prereq.op_num) {
1470 talloc_free(prev[dep->prereq.file]);
1471 prev[dep->prereq.file] = dep;
1478 for (i = 0; i < num; i++) {
1481 for (j = 0; j < num; j++)
1484 for (j = 1; j < num_ops[i]; j++) {
1485 struct depend *dep, *next;
1487 list_for_each_safe(&op[i][j].pre, dep, next, pre_list) {
1488 if (deps[dep->prereq.file]
1489 >= (int)dep->prereq.op_num)
1492 deps[dep->prereq.file]
1493 = dep->prereq.op_num;
1499 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1500 /* Force an order among the traversals, so they don't deadlock (as much) */
1501 static void make_traverse_depends(char *filename[],
1502 struct op *op[], unsigned int num_ops[],
1505 unsigned int i, num_traversals = 0;
1507 struct op_desc *desc;
1509 /* Sort by which one runs first. */
1510 int compare_traverse_desc(const void *_a, const void *_b)
1512 const struct op_desc *da = _a, *db = _b;
1513 const struct op *a = &op[da->file][da->op_num],
1514 *b = &op[db->file][db->op_num];
1516 if (a->seqnum != b->seqnum)
1517 return a->seqnum - b->seqnum;
1519 /* If they have same seqnum, it means one didn't make any
1520 * changes. Thus sort by end in that case. */
1521 return a[a->group_len].seqnum - b[b->group_len].seqnum;
1524 desc = talloc_array(NULL, struct op_desc, 1);
1527 for (i = 0; i < num; i++) {
1528 for (j = 1; j < num_ops[i]; j++) {
1529 /* Traverse start (ignore those in
1530 * transactions; they're already covered by
1531 * transaction dependencies). */
1532 if (starts_traverse(&op[i][j])
1533 && !in_transaction(op[i], j)) {
1534 desc = talloc_realloc(NULL, desc,
1537 desc[num_traversals].file = i;
1538 desc[num_traversals].op_num = j;
1543 qsort(desc, num_traversals, sizeof(desc[0]), compare_traverse_desc);
1545 for (i = 1; i < num_traversals; i++) {
1546 const struct op *prev = &op[desc[i-1].file][desc[i-1].op_num];
1547 const struct op *curr = &op[desc[i].file][desc[i].op_num];
1549 /* Read traverses don't depend on each other (read lock). */
1550 if (prev->type == OP_TDB_TRAVERSE_READ_START
1551 && curr->type == OP_TDB_TRAVERSE_READ_START)
1554 /* Only make dependency if it's clear. */
1555 if (compare_traverse_desc(&desc[i], &desc[i-1])) {
1556 /* i depends on end of traverse i-1. */
1557 struct op_desc end = desc[i-1];
1558 end.op_num += prev->group_len;
1559 add_dependency(NULL, op, filename, &desc[i], &end);
1565 static void set_nonblock(int fd)
1567 if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK) != 0)
1568 err(1, "Setting pipe nonblocking");
1571 static bool handle_backoff(struct op *op[], int fd)
1573 struct op_desc desc;
1574 bool handled = false;
1576 /* Sloppy coding: we assume PIPEBUF never fills. */
1577 while (read(fd, &desc, sizeof(desc)) != -1) {
1580 for (i = desc.op_num; i > 0; i--) {
1581 if (op[desc.file][i].type == OP_TDB_TRAVERSE) {
1582 /* We insert a fake end here. */
1583 op[desc.file][i].type
1584 = OP_TDB_TRAVERSE_END_EARLY;
1586 } else if (starts_traverse(&op[desc.file][i])) {
1587 unsigned int start = i;
1588 struct op tmp = op[desc.file][i];
1589 /* Move the ops outside traverse. */
1590 memmove(&op[desc.file][i],
1591 &op[desc.file][i+1],
1592 (desc.op_num-i-1) * sizeof(op[0][0]));
1593 op[desc.file][desc.op_num] = tmp;
1594 while (op[desc.file][i].group_start == start) {
1595 op[desc.file][i++].group_start
1605 #else /* !TRAVERSALS_TAKE_TRANSACTION_LOCK */
1606 static bool handle_backoff(struct op *op[], int fd)
1612 static void derive_dependencies(char *filename[],
1613 struct op *op[], unsigned int num_ops[],
1616 struct keyinfo *hash;
1619 /* Create hash table for faster key lookup. */
1620 hash = hash_ops(op, num_ops, num);
1622 /* Sort them by sequence number. */
1623 sort_ops(hash, filename, op, num);
1625 /* Create dependencies back to the last change, rather than
1626 * creating false dependencies by naively making each one
1627 * depend on the previous. This has two purposes: it makes
1628 * later optimization simpler, and it also avoids deadlock with
1629 * same sequence number ops inside traversals (if one
1630 * traversal doesn't write anything, two ops can have the same
1631 * sequence number yet we can create a traversal dependency
1632 * the other way). */
1633 for (h = 0; h < total_keys * 2; h++) {
1636 if (hash[h].num_users < 2)
1639 for (i = 0; i < hash[h].num_users; i++) {
1640 if (changes_db(&hash[h].key, &op[hash[h].user[i].file]
1641 [hash[h].user[i].op_num])) {
1642 depend_on_previous(op, filename, num,
1643 hash[h].user, i, prev);
1645 } else if (prev >= 0)
1646 add_dependency(hash, op, filename,
1648 &hash[h].user[prev]);
1652 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1653 make_traverse_depends(filename, op, num_ops, num);
1656 optimize_dependencies(op, num_ops, num);
1659 static struct timeval run_test(char *argv[],
1660 unsigned int num_ops[],
1661 unsigned int hashsize[],
1662 unsigned int tdb_flags[],
1663 unsigned int open_flags[],
1668 struct timeval start, end, diff;
1671 for (i = 0; argv[i+2]; i++) {
1672 struct tdb_context *tdb;
1677 err(1, "fork failed");
1680 tdb = tdb_open_ex(argv[1], hashsize[i],
1681 tdb_flags[i]|TDB_NOSYNC,
1682 open_flags[i], 0600, NULL, hash_key);
1684 err(1, "Opening tdb %s", argv[1]);
1686 /* This catches parent exiting. */
1687 if (read(fds[0], &c, 1) != 1)
1689 run_ops(tdb, pipes[i].fd[0], argv+2, op, i, 1,
1691 check_deps(argv[2+i], op[i], num_ops[i]);
1698 /* Let everything settle. */
1701 printf("Starting run...");
1703 gettimeofday(&start, NULL);
1704 /* Tell them all to go! Any write of sufficient length will do. */
1705 if (write(fds[1], hashsize, i) != i)
1706 err(1, "Writing to wakeup pipe");
1708 for (i = 0; argv[i + 2]; i++) {
1711 if (!WIFEXITED(status)) {
1712 warnx("Child died with signal %i", WTERMSIG(status));
1714 } else if (WEXITSTATUS(status) != 0)
1715 /* Assume child spat out error. */
1721 gettimeofday(&end, NULL);
1724 if (end.tv_usec < start.tv_usec) {
1725 end.tv_usec += 1000000;
1728 diff.tv_sec = end.tv_sec - start.tv_sec;
1729 diff.tv_usec = end.tv_usec - start.tv_usec;
1733 int main(int argc, char *argv[])
1735 struct timeval diff;
1736 unsigned int i, num_ops[argc], hashsize[argc], tdb_flags[argc], open_flags[argc];
1737 struct op *op[argc];
1741 errx(1, "Usage: %s <tdbfile> <tracefile>...", argv[0]);
1743 pipes = talloc_array(NULL, struct pipe, argc - 1);
1744 for (i = 0; i < argc - 2; i++) {
1745 printf("Loading tracefile %s...", argv[2+i]);
1747 op[i] = load_tracefile(argv[2+i], &num_ops[i], &hashsize[i],
1748 &tdb_flags[i], &open_flags[i]);
1749 if (pipe(pipes[i].fd) != 0)
1750 err(1, "creating pipe");
1754 printf("Calculating inter-dependencies...");
1756 derive_dependencies(argv+2, op, num_ops, i);
1759 /* Don't fork for single arg case: simple debugging. */
1761 struct tdb_context *tdb;
1762 tdb = tdb_open_ex(argv[1], hashsize[0], tdb_flags[0]|TDB_NOSYNC,
1763 open_flags[0], 0600, NULL, hash_key);
1764 printf("Single threaded run...");
1767 run_ops(tdb, pipes[0].fd[0], argv+2, op, 0, 1, num_ops[0],
1769 check_deps(argv[2], op[0], num_ops[0]);
1776 err(1, "creating pipe");
1778 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1779 if (pipe(pipes[argc-2].fd) != 0)
1780 err(1, "creating pipe");
1781 backoff_fd = pipes[argc-2].fd[1];
1782 set_nonblock(pipes[argc-2].fd[1]);
1783 set_nonblock(pipes[argc-2].fd[0]);
1787 diff = run_test(argv, num_ops, hashsize, tdb_flags, open_flags,
1789 } while (handle_backoff(op, pipes[argc-2].fd[0]));
1791 printf("Time replaying: %lu usec\n",
1792 diff.tv_sec * 1000000UL + diff.tv_usec);