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_PREPARE_COMMIT,
120 OP_TDB_TRANSACTION_COMMIT,
121 OP_TDB_TRAVERSE_READ_START,
122 OP_TDB_TRAVERSE_START,
125 OP_TDB_TRAVERSE_END_EARLY,
139 /* Who is waiting for us? */
140 struct list_head post;
141 /* What are we waiting for? */
142 struct list_head pre;
144 /* If I'm part of a group (traverse/transaction) where is
145 * start? (Otherwise, 0) */
146 unsigned int group_start;
149 int flag; /* open and store */
150 struct { /* append */
154 /* transaction/traverse start/chainlock */
155 unsigned int group_len;
164 static unsigned char hex_char(const char *filename, unsigned int line, char c)
167 if (c >= 'A' && c <= 'F')
169 if (c >= '0' && c <= '9')
171 fail(filename, line, "invalid hex character '%c'", c);
174 /* TDB data is <size>:<%02x>* */
175 static TDB_DATA make_tdb_data(const void *ctx,
176 const char *filename, unsigned int line,
183 if (streq(word, "NULL"))
186 data.dsize = atoi(word);
187 data.dptr = talloc_array(ctx, unsigned char, data.dsize);
188 p = strchr(word, ':');
190 fail(filename, line, "invalid tdb data '%s'", word);
192 for (i = 0; i < data.dsize; i++)
193 data.dptr[i] = hex_char(filename, line, p[i*2])*16
194 + hex_char(filename, line, p[i*2+1]);
199 static void add_op(const char *filename, struct op **op, unsigned int i,
200 unsigned int seqnum, enum op_type type)
203 *op = talloc_realloc(NULL, *op, struct op, i+1);
206 new->seqnum = seqnum;
208 new->group_start = 0;
211 static void op_add_nothing(const char *filename,
212 struct op op[], unsigned int op_num, char *words[])
215 fail(filename, op_num+1, "Expected no arguments");
216 op[op_num].key = tdb_null;
219 static void op_add_key(const char *filename,
220 struct op op[], unsigned int op_num, char *words[])
222 if (words[2] == NULL || words[3])
223 fail(filename, op_num+1, "Expected just a key");
225 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
229 static void op_add_key_ret(const char *filename,
230 struct op op[], unsigned int op_num, char *words[])
232 if (!words[2] || !words[3] || !words[4] || words[5]
233 || !streq(words[3], "="))
234 fail(filename, op_num+1, "Expected <key> = <ret>");
235 op[op_num].ret = atoi(words[4]);
236 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
237 /* May only be a unique key if it fails */
238 if (op[op_num].ret != 0)
242 static void op_add_key_data(const char *filename,
243 struct op op[], unsigned int op_num, char *words[])
245 if (!words[2] || !words[3] || !words[4] || words[5]
246 || !streq(words[3], "="))
247 fail(filename, op_num+1, "Expected <key> = <data>");
248 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
249 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[4]);
250 /* May only be a unique key if it fails */
251 if (!op[op_num].data.dptr)
255 /* We don't record the keys or data for a traverse, as we don't use them. */
256 static void op_add_traverse(const char *filename,
257 struct op op[], unsigned int op_num, char *words[])
259 if (!words[2] || !words[3] || !words[4] || words[5]
260 || !streq(words[3], "="))
261 fail(filename, op_num+1, "Expected <key> = <data>");
262 op[op_num].key = tdb_null;
265 /* Full traverse info is useful for debugging, but changing it to
266 * "traversefn" without the data makes the traces *much* smaller! */
267 static void op_add_traversefn(const char *filename,
268 struct op op[], unsigned int op_num, char *words[])
271 fail(filename, op_num+1, "Expected no values");
272 op[op_num].key = tdb_null;
275 /* <seqnum> tdb_store <rec> <rec> <flag> = <ret> */
276 static void op_add_store(const char *filename,
277 struct op op[], unsigned int op_num, char *words[])
279 if (!words[2] || !words[3] || !words[4] || !words[5] || !words[6]
280 || words[7] || !streq(words[5], "="))
281 fail(filename, op_num+1, "Expect <key> <data> <flag> = <ret>");
283 op[op_num].flag = strtoul(words[4], NULL, 0);
284 op[op_num].ret = atoi(words[6]);
285 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
286 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[3]);
290 /* <seqnum> tdb_append <rec> <rec> = <rec> */
291 static void op_add_append(const char *filename,
292 struct op op[], unsigned int op_num, char *words[])
294 if (!words[2] || !words[3] || !words[4] || !words[5] || words[6]
295 || !streq(words[4], "="))
296 fail(filename, op_num+1, "Expect <key> <data> = <rec>");
298 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
299 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[3]);
301 op[op_num].append.post
302 = make_tdb_data(op, filename, op_num+1, words[5]);
304 /* By subtraction, figure out what previous data was. */
305 op[op_num].append.pre.dptr = op[op_num].append.post.dptr;
306 op[op_num].append.pre.dsize
307 = op[op_num].append.post.dsize - op[op_num].data.dsize;
311 /* <seqnum> tdb_get_seqnum = <ret> */
312 static void op_add_seqnum(const char *filename,
313 struct op op[], unsigned int op_num, char *words[])
315 if (!words[2] || !words[3] || words[4] || !streq(words[2], "="))
316 fail(filename, op_num+1, "Expect = <ret>");
318 op[op_num].key = tdb_null;
319 op[op_num].ret = atoi(words[3]);
322 static void op_add_traverse_start(const char *filename,
324 unsigned int op_num, char *words[])
327 fail(filename, op_num+1, "Expect no arguments");
329 op[op_num].key = tdb_null;
330 op[op_num].group_len = 0;
333 static void op_add_transaction(const char *filename, struct op op[],
334 unsigned int op_num, char *words[])
337 fail(filename, op_num+1, "Expect no arguments");
339 op[op_num].key = tdb_null;
340 op[op_num].group_len = 0;
343 static void op_add_chainlock(const char *filename,
344 struct op op[], unsigned int op_num, char *words[])
346 if (words[2] == NULL || words[3])
347 fail(filename, op_num+1, "Expected just a key");
349 /* A chainlock key isn't a key in the normal sense; it doesn't
350 * have to be in the db at all. Also, we don't want to hash this op. */
351 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[2]);
352 op[op_num].key = tdb_null;
353 op[op_num].group_len = 0;
356 static void op_add_chainlock_ret(const char *filename,
357 struct op op[], unsigned int op_num,
360 if (!words[2] || !words[3] || !words[4] || words[5]
361 || !streq(words[3], "="))
362 fail(filename, op_num+1, "Expected <key> = <ret>");
363 op[op_num].ret = atoi(words[4]);
364 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[2]);
365 op[op_num].key = tdb_null;
366 op[op_num].group_len = 0;
370 static int op_find_start(struct op op[], unsigned int op_num, enum op_type type)
374 for (i = op_num-1; i > 0; i--) {
375 if (op[i].type == type && !op[i].group_len)
381 static void op_analyze_transaction(const char *filename,
382 struct op op[], unsigned int op_num,
385 unsigned int start, i;
387 op[op_num].key = tdb_null;
390 fail(filename, op_num+1, "Expect no arguments");
392 start = op_find_start(op, op_num, OP_TDB_TRANSACTION_START);
394 fail(filename, op_num+1, "no transaction start found");
396 op[start].group_len = op_num - start;
398 /* This rolls in nested transactions. I think that's right. */
399 for (i = start; i <= op_num; i++)
400 op[i].group_start = start;
403 /* We treat chainlocks a lot like transactions, even though that's overkill */
404 static void op_analyze_chainlock(const char *filename,
405 struct op op[], unsigned int op_num,
408 unsigned int i, start;
410 if (words[2] == NULL || words[3])
411 fail(filename, op_num+1, "Expected just a key");
413 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[2]);
414 op[op_num].key = tdb_null;
417 start = op_find_start(op, op_num, OP_TDB_CHAINLOCK);
419 start = op_find_start(op, op_num, OP_TDB_CHAINLOCK_READ);
421 fail(filename, op_num+1, "no initial chainlock found");
423 /* FIXME: We'd have to do something clever to make this work
425 if (!key_eq(op[start].data, op[op_num].data))
426 fail(filename, op_num+1, "nested chainlock calls?");
428 op[start].group_len = op_num - start;
429 for (i = start; i <= op_num; i++)
430 op[i].group_start = start;
433 static void op_analyze_traverse(const char *filename,
434 struct op op[], unsigned int op_num,
439 op[op_num].key = tdb_null;
441 /* = %u means traverse function terminated. */
443 if (!streq(words[2], "=") || !words[3] || words[4])
444 fail(filename, op_num+1, "expect = <num>");
445 op[op_num].ret = atoi(words[3]);
449 start = op_find_start(op, op_num, OP_TDB_TRAVERSE_START);
451 start = op_find_start(op, op_num, OP_TDB_TRAVERSE_READ_START);
453 fail(filename, op_num+1, "no traversal start found");
455 op[start].group_len = op_num - start;
457 /* Don't roll in nested traverse/chainlock */
458 for (i = start; i <= op_num; i++)
459 if (!op[i].group_start)
460 op[i].group_start = start;
463 /* Keep -Wmissing-declarations happy: */
464 const struct op_table *
465 find_keyword (register const char *str, register unsigned int len);
467 #include "keywords.c"
470 /* We can have more than one */
471 struct list_node pre_list;
472 struct list_node post_list;
473 struct op_desc needs;
474 struct op_desc prereq;
477 static void check_deps(const char *filename, struct op op[], unsigned int num)
482 for (i = 1; i < num; i++)
483 if (!list_empty(&op[i].pre))
484 fail(filename, i+1, "Still has dependencies");
488 static void dump_pre(char *filename[], struct op *op[],
489 unsigned int file, unsigned int i)
493 printf("%s:%u (%u) still waiting for:\n", filename[file], i+1,
495 list_for_each(&op[file][i].pre, dep, pre_list)
496 printf(" %s:%u (%u)\n",
497 filename[dep->prereq.file], dep->prereq.op_num+1,
498 op[dep->prereq.file][dep->prereq.op_num].seqnum);
499 check_deps(filename[file], op[file], i);
502 /* We simply read/write pointers, since we all are children. */
503 static bool do_pre(struct tdb_context *tdb,
504 char *filename[], struct op *op[],
505 unsigned int file, int pre_fd, unsigned int i,
508 while (!list_empty(&op[file][i].pre)) {
512 printf("%s:%u:waiting for pre\n", filename[file], i+1);
519 while (read(pre_fd, &dep, sizeof(dep)) != sizeof(dep)) {
520 if (errno == EINTR) {
522 struct op_desc desc = { file,i };
523 warnx("%s:%u:avoiding deadlock",
524 filename[file], i+1);
525 if (write(backoff_fd, &desc,
526 sizeof(desc)) != sizeof(desc))
527 err(1, "writing backoff_fd");
530 dump_pre(filename, op, file, i);
533 errx(1, "Reading from pipe");
538 printf("%s:%u:got pre %u from %s:%u\n", filename[file], i+1,
539 dep->needs.op_num+1, filename[dep->prereq.file],
540 dep->prereq.op_num+1);
543 /* This could be any op, not just this one. */
549 static void do_post(char *filename[], struct op *op[],
550 unsigned int file, unsigned int i)
554 list_for_each(&op[file][i].post, dep, post_list) {
556 printf("%s:%u:sending to file %s:%u\n", filename[file], i+1,
557 filename[dep->needs.file], dep->needs.op_num+1);
559 if (write(pipes[dep->needs.file].fd[1], &dep, sizeof(dep))
561 err(1, "%s:%u failed to tell file %s",
562 filename[file], i+1, filename[dep->needs.file]);
566 static int get_len(TDB_DATA key, TDB_DATA data, void *private_data)
571 static unsigned run_ops(struct tdb_context *tdb,
576 unsigned int start, unsigned int stop,
579 struct traverse_info {
588 /* More complex. Just do whatever's they did at the n'th entry. */
589 static int nontrivial_traverse(struct tdb_context *tdb,
590 TDB_DATA key, TDB_DATA data,
593 struct traverse_info *tinfo = _tinfo;
594 unsigned int trav_len = tinfo->op[tinfo->file][tinfo->start].group_len;
595 bool avoid_deadlock = false;
597 if (tinfo->i == tinfo->start + trav_len) {
598 /* This can happen if traverse expects to be empty. */
601 fail(tinfo->filename[tinfo->file], tinfo->start + 1,
602 "traverse did not terminate");
605 if (tinfo->op[tinfo->file][tinfo->i].type != OP_TDB_TRAVERSE)
606 fail(tinfo->filename[tinfo->file], tinfo->start + 1,
607 "%s:%u:traverse terminated early");
609 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
610 avoid_deadlock = true;
613 /* Run any normal ops. */
614 tinfo->i = run_ops(tdb, tinfo->pre_fd, tinfo->filename, tinfo->op,
615 tinfo->file, tinfo->i+1, tinfo->start + trav_len,
618 /* We backed off, or we hit OP_TDB_TRAVERSE_END/EARLY. */
619 if (tinfo->op[tinfo->file][tinfo->i].type != OP_TDB_TRAVERSE)
625 static unsigned op_traverse(struct tdb_context *tdb,
629 int (*traversefn)(struct tdb_context *,
630 tdb_traverse_func, void *),
634 struct traverse_info tinfo = { op, filename, file, pre_fd,
637 traversefn(tdb, nontrivial_traverse, &tinfo);
639 /* Traversing in wrong order can have strange effects: eg. if
640 * original traverse went A (delete A), B, we might do B
641 * (delete A). So if we have ops left over, we do it now. */
642 while (tinfo.i != start + op[file][start].group_len) {
643 if (op[file][tinfo.i].type == OP_TDB_TRAVERSE
644 || op[file][tinfo.i].type == OP_TDB_TRAVERSE_END_EARLY)
647 tinfo.i = run_ops(tdb, pre_fd, filename, op, file,
649 start + op[file][start].group_len,
656 static void break_out(int sig)
660 static __attribute__((noinline))
661 unsigned run_ops(struct tdb_context *tdb,
666 unsigned int start, unsigned int stop,
672 sa.sa_handler = break_out;
675 sigaction(SIGALRM, &sa, NULL);
676 for (i = start; i < stop; i++) {
677 if (!do_pre(tdb, filename, op, file, pre_fd, i, backoff))
680 switch (op[file][i].type) {
682 try(tdb_lockall(tdb), op[file][i].ret);
684 case OP_TDB_LOCKALL_MARK:
685 try(tdb_lockall_mark(tdb), op[file][i].ret);
687 case OP_TDB_LOCKALL_UNMARK:
688 try(tdb_lockall_unmark(tdb), op[file][i].ret);
690 case OP_TDB_LOCKALL_NONBLOCK:
691 unreliable(tdb_lockall_nonblock(tdb), op[file][i].ret,
692 tdb_lockall(tdb), tdb_unlockall(tdb));
694 case OP_TDB_UNLOCKALL:
695 try(tdb_unlockall(tdb), op[file][i].ret);
697 case OP_TDB_LOCKALL_READ:
698 try(tdb_lockall_read(tdb), op[file][i].ret);
700 case OP_TDB_LOCKALL_READ_NONBLOCK:
701 unreliable(tdb_lockall_read_nonblock(tdb),
703 tdb_lockall_read(tdb),
704 tdb_unlockall_read(tdb));
706 case OP_TDB_UNLOCKALL_READ:
707 try(tdb_unlockall_read(tdb), op[file][i].ret);
709 case OP_TDB_CHAINLOCK:
710 try(tdb_chainlock(tdb, op[file][i].key),
713 case OP_TDB_CHAINLOCK_NONBLOCK:
714 unreliable(tdb_chainlock_nonblock(tdb, op[file][i].key),
716 tdb_chainlock(tdb, op[file][i].key),
717 tdb_chainunlock(tdb, op[file][i].key));
719 case OP_TDB_CHAINLOCK_MARK:
720 try(tdb_chainlock_mark(tdb, op[file][i].key),
723 case OP_TDB_CHAINLOCK_UNMARK:
724 try(tdb_chainlock_unmark(tdb, op[file][i].key),
727 case OP_TDB_CHAINUNLOCK:
728 try(tdb_chainunlock(tdb, op[file][i].key),
731 case OP_TDB_CHAINLOCK_READ:
732 try(tdb_chainlock_read(tdb, op[file][i].key),
735 case OP_TDB_CHAINUNLOCK_READ:
736 try(tdb_chainunlock_read(tdb, op[file][i].key),
739 case OP_TDB_PARSE_RECORD:
740 try(tdb_parse_record(tdb, op[file][i].key, get_len,
745 try(tdb_exists(tdb, op[file][i].key), op[file][i].ret);
748 try(tdb_store(tdb, op[file][i].key, op[file][i].data,
753 try(tdb_append(tdb, op[file][i].key, op[file][i].data),
756 case OP_TDB_GET_SEQNUM:
757 try(tdb_get_seqnum(tdb), op[file][i].ret);
759 case OP_TDB_WIPE_ALL:
760 try(tdb_wipe_all(tdb), op[file][i].ret);
762 case OP_TDB_TRANSACTION_START:
763 try(tdb_transaction_start(tdb), op[file][i].ret);
765 case OP_TDB_TRANSACTION_CANCEL:
766 try(tdb_transaction_cancel(tdb), op[file][i].ret);
768 case OP_TDB_TRANSACTION_PREPARE_COMMIT:
769 try(tdb_transaction_prepare_commit(tdb),
772 case OP_TDB_TRANSACTION_COMMIT:
773 try(tdb_transaction_commit(tdb), op[file][i].ret);
775 case OP_TDB_TRAVERSE_READ_START:
776 i = op_traverse(tdb, pre_fd, filename, file,
777 tdb_traverse_read, op, i);
779 case OP_TDB_TRAVERSE_START:
780 i = op_traverse(tdb, pre_fd, filename, file,
781 tdb_traverse, op, i);
783 case OP_TDB_TRAVERSE:
784 case OP_TDB_TRAVERSE_END_EARLY:
785 /* Terminate: we're in a traverse, and we've
788 case OP_TDB_TRAVERSE_END:
789 fail(filename[file], i+1, "unexpected end traverse");
790 /* FIXME: These must be treated like traverse. */
791 case OP_TDB_FIRSTKEY:
792 if (!key_eq(tdb_firstkey(tdb), op[file][i].data))
793 fail(filename[file], i+1, "bad firstkey");
796 if (!key_eq(tdb_nextkey(tdb, op[file][i].key),
798 fail(filename[file], i+1, "bad nextkey");
801 TDB_DATA f = tdb_fetch(tdb, op[file][i].key);
802 if (!key_eq(f, op[file][i].data))
803 fail(filename[file], i+1, "bad fetch %u",
808 try(tdb_delete(tdb, op[file][i].key), op[file][i].ret);
811 do_post(filename, op, file, i);
816 /* tdbtorture, in particular, can do a tdb_close with a transaction in
818 static struct op *maybe_cancel_transaction(const char *filename,
819 struct op *op, unsigned int *num)
821 unsigned int start = op_find_start(op, *num, OP_TDB_TRANSACTION_START);
824 char *words[] = { "<unknown>", "tdb_close", NULL };
825 add_op(filename, &op, *num, op[start].seqnum,
826 OP_TDB_TRANSACTION_CANCEL);
827 op_analyze_transaction(filename, op, *num, words);
833 static struct op *load_tracefile(const char *filename, unsigned int *num,
834 unsigned int *hashsize,
835 unsigned int *tdb_flags,
836 unsigned int *open_flags)
839 struct op *op = talloc_array(NULL, struct op, 1);
844 file = grab_file(NULL, filename, NULL);
846 err(1, "Reading %s", filename);
848 lines = strsplit(file, file, "\n", NULL);
850 errx(1, "%s is empty", filename);
852 words = strsplit(lines, lines[0], " ", NULL);
853 if (!streq(words[1], "tdb_open"))
854 fail(filename, 1, "does not start with tdb_open");
856 *hashsize = atoi(words[2]);
857 *tdb_flags = strtoul(words[3], NULL, 0);
858 *open_flags = strtoul(words[4], NULL, 0);
860 for (i = 1; lines[i]; i++) {
861 const struct op_table *opt;
863 words = strsplit(lines, lines[i], " ", NULL);
864 if (!words[0] || !words[1])
865 fail(filename, i+1, "Expected seqnum number and op");
867 opt = find_keyword(words[1], strlen(words[1]));
869 if (streq(words[1], "tdb_close")) {
872 "lines after tdb_close");
875 return maybe_cancel_transaction(filename,
878 fail(filename, i+1, "Unknown operation '%s'", words[1]);
881 add_op(filename, &op, i, atoi(words[0]), opt->type);
882 opt->enhance_op(filename, op, i, words);
885 fprintf(stderr, "%s:%u:last operation is not tdb_close: incomplete?",
889 return maybe_cancel_transaction(filename, op, num);
892 /* We remember all the keys we've ever seen, and who has them. */
895 unsigned int num_users;
896 struct op_desc *user;
899 static const TDB_DATA must_not_exist;
900 static const TDB_DATA must_exist;
901 static const TDB_DATA not_exists_or_empty;
903 /* NULL means doesn't care if it exists or not, &must_exist means
904 * it must exist but we don't care what, &must_not_exist means it must
905 * not exist, otherwise the data it needs. */
906 static const TDB_DATA *needs(const struct op *op)
909 /* FIXME: Pull forward deps, since we can deadlock */
910 case OP_TDB_CHAINLOCK:
911 case OP_TDB_CHAINLOCK_NONBLOCK:
912 case OP_TDB_CHAINLOCK_MARK:
913 case OP_TDB_CHAINLOCK_UNMARK:
914 case OP_TDB_CHAINUNLOCK:
915 case OP_TDB_CHAINLOCK_READ:
916 case OP_TDB_CHAINUNLOCK_READ:
920 if (op->append.pre.dsize == 0)
921 return ¬_exists_or_empty;
922 return &op->append.pre;
925 if (op->flag == TDB_INSERT) {
929 return &must_not_exist;
930 } else if (op->flag == TDB_MODIFY) {
932 return &must_not_exist;
936 /* No flags? Don't care */
943 return &must_not_exist;
945 case OP_TDB_PARSE_RECORD:
947 return &must_not_exist;
950 /* FIXME: handle these. */
951 case OP_TDB_WIPE_ALL:
952 case OP_TDB_FIRSTKEY:
954 case OP_TDB_GET_SEQNUM:
955 case OP_TDB_TRAVERSE:
956 case OP_TDB_TRANSACTION_COMMIT:
957 case OP_TDB_TRANSACTION_CANCEL:
958 case OP_TDB_TRANSACTION_START:
963 return &must_not_exist;
968 return &must_not_exist;
972 errx(1, "Unexpected op type %i", op->type);
977 static bool starts_transaction(const struct op *op)
979 return op->type == OP_TDB_TRANSACTION_START;
982 static bool in_transaction(const struct op op[], unsigned int i)
984 return op[i].group_start && starts_transaction(&op[op[i].group_start]);
987 static bool successful_transaction(const struct op *op)
989 return starts_transaction(op)
990 && op[op->group_len].type == OP_TDB_TRANSACTION_COMMIT;
993 static bool starts_traverse(const struct op *op)
995 return op->type == OP_TDB_TRAVERSE_START
996 || op->type == OP_TDB_TRAVERSE_READ_START;
999 static bool in_traverse(const struct op op[], unsigned int i)
1001 return op[i].group_start && starts_traverse(&op[op[i].group_start]);
1004 static bool starts_chainlock(const struct op *op)
1006 return op->type == OP_TDB_CHAINLOCK_READ
1007 || op->type == OP_TDB_CHAINLOCK;
1010 static bool in_chainlock(const struct op op[], unsigned int i)
1012 return op[i].group_start && starts_chainlock(&op[op[i].group_start]);
1015 /* What's the data after this op? pre if nothing changed. */
1016 static const TDB_DATA *gives(const TDB_DATA *key, const TDB_DATA *pre,
1017 const struct op *op)
1019 if (starts_transaction(op) || starts_chainlock(op)) {
1022 /* Cancelled transactions don't change anything. */
1023 if (op[op->group_len].type == OP_TDB_TRANSACTION_CANCEL)
1025 assert(op[op->group_len].type == OP_TDB_TRANSACTION_COMMIT
1026 || op[op->group_len].type == OP_TDB_CHAINUNLOCK_READ
1027 || op[op->group_len].type == OP_TDB_CHAINUNLOCK);
1029 for (i = 1; i < op->group_len; i++) {
1030 /* This skips nested transactions, too */
1031 if (key_eq(op[i].key, *key))
1032 pre = gives(key, pre, &op[i]);
1037 /* Failed ops don't change state of db. */
1041 if (op->type == OP_TDB_DELETE || op->type == OP_TDB_WIPE_ALL)
1044 if (op->type == OP_TDB_APPEND)
1045 return &op->append.post;
1047 if (op->type == OP_TDB_STORE)
1053 static struct keyinfo *hash_ops(struct op *op[], unsigned int num_ops[],
1056 unsigned int i, j, h;
1057 struct keyinfo *hash;
1059 hash = talloc_zero_array(op[0], struct keyinfo, total_keys*2);
1060 for (i = 0; i < num; i++) {
1061 for (j = 1; j < num_ops[i]; j++) {
1062 /* We can't do this on allocation, due to realloc. */
1063 list_head_init(&op[i][j].post);
1064 list_head_init(&op[i][j].pre);
1066 if (!op[i][j].key.dptr)
1069 h = hash_key(&op[i][j].key) % (total_keys * 2);
1070 while (!key_eq(hash[h].key, op[i][j].key)) {
1071 if (!hash[h].key.dptr) {
1072 hash[h].key = op[i][j].key;
1075 h = (h + 1) % (total_keys * 2);
1077 /* Might as well save some memory if we can. */
1078 if (op[i][j].key.dptr != hash[h].key.dptr) {
1079 talloc_free(op[i][j].key.dptr);
1080 op[i][j].key.dptr = hash[h].key.dptr;
1082 hash[h].user = talloc_realloc(hash, hash[h].user,
1084 hash[h].num_users+1);
1086 /* If it's in a transaction, it's the transaction which
1087 * matters from an analysis POV. */
1088 if (in_transaction(op[i], j)
1089 || in_chainlock(op[i], j)) {
1090 unsigned start = op[i][j].group_start;
1092 /* Don't include twice. */
1093 if (hash[h].num_users
1094 && hash[h].user[hash[h].num_users-1].file
1096 && hash[h].user[hash[h].num_users-1].op_num
1100 hash[h].user[hash[h].num_users].op_num = start;
1102 hash[h].user[hash[h].num_users].op_num = j;
1103 hash[h].user[hash[h].num_users].file = i;
1104 hash[h].num_users++;
1111 static bool satisfies(const TDB_DATA *key, const TDB_DATA *data,
1112 const struct op *op)
1114 const TDB_DATA *need = NULL;
1116 if (starts_transaction(op) || starts_chainlock(op)) {
1119 /* Look through for an op in this transaction which
1120 * needs this key. */
1121 for (i = 1; i < op->group_len; i++) {
1122 if (key_eq(op[i].key, *key)) {
1123 need = needs(&op[i]);
1124 /* tdb_exists() is special: there might be
1125 * something in the transaction with more
1126 * specific requirements. Other ops don't have
1127 * specific requirements (eg. store or delete),
1128 * but they change the value so we can't get
1129 * more information from future ops. */
1130 if (op[i].type != OP_TDB_EXISTS)
1137 /* Don't need anything? Cool. */
1141 /* This should be tdb_null or a real value. */
1142 assert(data != &must_exist);
1143 assert(data != &must_not_exist);
1144 assert(data != ¬_exists_or_empty);
1146 /* Must not exist? data must not exist. */
1147 if (need == &must_not_exist)
1148 return data == &tdb_null;
1151 if (need == &must_exist)
1152 return data != &tdb_null;
1154 /* Either noexist or empty. */
1155 if (need == ¬_exists_or_empty)
1156 return data->dsize == 0;
1158 /* Needs something specific. */
1159 return key_eq(*data, *need);
1162 static void move_to_front(struct op_desc res[], unsigned off, unsigned elem)
1165 struct op_desc tmp = res[elem];
1166 memmove(res + off + 1, res + off, (elem - off)*sizeof(res[0]));
1171 static void restore_to_pos(struct op_desc res[], unsigned off, unsigned elem)
1174 struct op_desc tmp = res[off];
1175 memmove(res + off, res + off + 1, (elem - off)*sizeof(res[0]));
1180 static bool sort_deps(char *filename[], struct op *op[],
1181 struct op_desc res[],
1182 unsigned off, unsigned num,
1183 const TDB_DATA *key, const TDB_DATA *data,
1184 unsigned num_files, unsigned fuzz)
1186 unsigned int i, files_done;
1188 bool done[num_files];
1190 /* None left? We're sorted. */
1194 /* Does this make sequence number go backwards? Allow a little fuzz. */
1196 int seqnum1 = op[res[off-1].file][res[off-1].op_num].seqnum;
1197 int seqnum2 = op[res[off].file][res[off].op_num].seqnum;
1199 if (seqnum1 - seqnum2 > (int)fuzz) {
1201 printf("Seqnum jump too far (%u -> %u)\n",
1208 memset(done, 0, sizeof(done));
1210 /* Since ops within a trace file are ordered, we just need to figure
1211 * out which file to try next. Since we don't take into account
1212 * inter-key relationships (which exist by virtue of trace file order),
1213 * we minimize the chance of harm by trying to keep in seqnum order. */
1214 for (files_done = 0, i = off; i < num && files_done < num_files; i++) {
1215 if (done[res[i].file])
1218 this_op = &op[res[i].file][res[i].op_num];
1220 /* Is what we have good enough for this op? */
1221 if (satisfies(key, data, this_op)) {
1222 move_to_front(res, off, i);
1223 if (sort_deps(filename, op, res, off+1, num,
1224 key, gives(key, data, this_op),
1227 restore_to_pos(res, off, i);
1229 done[res[i].file] = true;
1233 /* No combination worked. */
1237 static void check_dep_sorting(struct op_desc user[], unsigned num_users,
1242 unsigned minima[num_files];
1244 memset(minima, 0, sizeof(minima));
1245 for (i = 0; i < num_users; i++) {
1246 assert(minima[user[i].file] < user[i].op_num);
1247 minima[user[i].file] = user[i].op_num;
1252 /* All these ops happen on the same key. Which comes first?
1254 * This can happen both because read ops or failed write ops don't
1255 * change sequence number, and also due to race since we access the
1256 * number unlocked (the race can cause less detectable ordering problems,
1257 * in which case we'll deadlock and report: fix manually in that case).
1259 static void figure_deps(char *filename[], struct op *op[],
1260 const TDB_DATA *key, struct op_desc user[],
1261 unsigned num_users, unsigned num_files)
1263 /* We assume database starts empty. */
1264 const struct TDB_DATA *data = &tdb_null;
1267 /* We prefer to keep strict seqnum order if possible: it's the
1268 * most likely. We get more lax if that fails. */
1269 for (fuzz = 0; fuzz < 100; fuzz = (fuzz + 1)*2) {
1270 if (sort_deps(filename, op, user, 0, num_users, key, data,
1276 fail(filename[user[0].file], user[0].op_num+1,
1277 "Could not resolve inter-dependencies");
1279 check_dep_sorting(user, num_users, num_files);
1282 static void sort_ops(struct keyinfo hash[], char *filename[], struct op *op[],
1287 /* Gcc nexted function extension. How cool is this? */
1288 int compare_seqnum(const void *_a, const void *_b)
1290 const struct op_desc *a = _a, *b = _b;
1292 /* First, maintain order within any trace file. */
1293 if (a->file == b->file)
1294 return a->op_num - b->op_num;
1296 /* Otherwise, arrange by seqnum order. */
1297 if (op[a->file][a->op_num].seqnum !=
1298 op[b->file][b->op_num].seqnum)
1299 return op[a->file][a->op_num].seqnum
1300 - op[b->file][b->op_num].seqnum;
1302 /* Cancelled transactions are assumed to happen first. */
1303 if (starts_transaction(&op[a->file][a->op_num])
1304 && !successful_transaction(&op[a->file][a->op_num]))
1306 if (starts_transaction(&op[b->file][b->op_num])
1307 && !successful_transaction(&op[b->file][b->op_num]))
1314 /* Now sort into seqnum order. */
1315 for (h = 0; h < total_keys * 2; h++) {
1316 struct op_desc *user = hash[h].user;
1318 qsort(user, hash[h].num_users, sizeof(user[0]), compare_seqnum);
1319 figure_deps(filename, op, &hash[h].key, user, hash[h].num_users,
1324 static int destroy_depend(struct depend *dep)
1326 list_del(&dep->pre_list);
1327 list_del(&dep->post_list);
1331 static void add_dependency(void *ctx,
1334 const struct op_desc *needs,
1335 const struct op_desc *prereq)
1339 /* We don't depend on ourselves. */
1340 if (needs->file == prereq->file) {
1341 assert(prereq->op_num < needs->op_num);
1346 printf("%s:%u: depends on %s:%u\n",
1347 filename[needs->file], needs->op_num+1,
1348 filename[prereq->file], prereq->op_num+1);
1351 dep = talloc(ctx, struct depend);
1352 dep->needs = *needs;
1353 dep->prereq = *prereq;
1355 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1356 /* If something in a traverse depends on something in another
1357 * traverse/transaction, it creates a dependency between the
1359 if ((in_traverse(op[prereq->file], prereq->op_num)
1360 && (starts_transaction(&op[needs->file][needs->op_num])
1361 || starts_traverse(&op[needs->file][needs->op_num])))
1362 || (in_traverse(op[needs->file], needs->op_num)
1363 && (starts_transaction(&op[prereq->file][prereq->op_num])
1364 || starts_traverse(&op[prereq->file][prereq->op_num])))) {
1367 /* We are satisfied by end of group. */
1368 start = op[prereq->file][prereq->op_num].group_start;
1369 dep->prereq.op_num = start + op[prereq->file][start].group_len;
1370 /* And we need that done by start of our group. */
1371 dep->needs.op_num = op[needs->file][needs->op_num].group_start;
1374 /* There is also this case:
1375 * <traverse> <read foo> ...
1376 * <transaction> ... </transaction> <create foo>
1377 * Where if we start the traverse then wait, we could block
1378 * the transaction and deadlock.
1380 * We try to address this by ensuring that where seqnum indicates it's
1381 * possible, we wait for <create foo> before *starting* traverse.
1383 else if (in_traverse(op[needs->file], needs->op_num)) {
1384 struct op *need = &op[needs->file][needs->op_num];
1385 if (op[needs->file][need->group_start].seqnum >
1386 op[prereq->file][prereq->op_num].seqnum) {
1387 dep->needs.op_num = need->group_start;
1392 /* If you depend on a transaction or chainlock, you actually
1393 * depend on it ending. */
1394 if (starts_transaction(&op[prereq->file][dep->prereq.op_num])
1395 || starts_chainlock(&op[prereq->file][dep->prereq.op_num])) {
1397 += op[dep->prereq.file][dep->prereq.op_num].group_len;
1399 printf("-> Actually end of transaction %s:%u\n",
1400 filename[dep->prereq->file], dep->prereq->op_num+1);
1403 /* We should never create a dependency from middle of
1405 assert(!in_transaction(op[prereq->file], dep->prereq.op_num)
1406 || op[prereq->file][dep->prereq.op_num].type
1407 == OP_TDB_TRANSACTION_COMMIT
1408 || op[prereq->file][dep->prereq.op_num].type
1409 == OP_TDB_TRANSACTION_CANCEL);
1411 list_add(&op[dep->prereq.file][dep->prereq.op_num].post,
1413 list_add(&op[dep->needs.file][dep->needs.op_num].pre,
1415 talloc_set_destructor(dep, destroy_depend);
1418 static bool changes_db(const TDB_DATA *key, const struct op *op)
1420 return gives(key, NULL, op) != NULL;
1423 static void depend_on_previous(struct op *op[],
1426 struct op_desc user[],
1436 if (prev == i - 1) {
1437 /* Just depend on previous. */
1438 add_dependency(NULL, op, filename, &user[i], &user[prev]);
1442 /* We have to wait for the readers. Find last one in *each* file. */
1443 memset(deps, 0, sizeof(deps));
1444 deps[user[i].file] = true;
1445 for (j = i - 1; j > prev; j--) {
1446 if (!deps[user[j].file]) {
1447 add_dependency(NULL, op, filename, &user[i], &user[j]);
1448 deps[user[j].file] = true;
1453 /* This is simple, but not complete. We don't take into account
1454 * indirect dependencies. */
1455 static void optimize_dependencies(struct op *op[], unsigned int num_ops[],
1460 /* There can only be one real dependency on each file */
1461 for (i = 0; i < num; i++) {
1462 for (j = 1; j < num_ops[i]; j++) {
1463 struct depend *dep, *next;
1464 struct depend *prev[num];
1466 memset(prev, 0, sizeof(prev));
1468 list_for_each_safe(&op[i][j].pre, dep, next, pre_list) {
1469 if (!prev[dep->prereq.file]) {
1470 prev[dep->prereq.file] = dep;
1473 if (prev[dep->prereq.file]->prereq.op_num
1474 < dep->prereq.op_num) {
1475 talloc_free(prev[dep->prereq.file]);
1476 prev[dep->prereq.file] = dep;
1483 for (i = 0; i < num; i++) {
1486 for (j = 0; j < num; j++)
1489 for (j = 1; j < num_ops[i]; j++) {
1490 struct depend *dep, *next;
1492 list_for_each_safe(&op[i][j].pre, dep, next, pre_list) {
1493 if (deps[dep->prereq.file]
1494 >= (int)dep->prereq.op_num)
1497 deps[dep->prereq.file]
1498 = dep->prereq.op_num;
1504 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1505 /* Force an order among the traversals, so they don't deadlock (as much) */
1506 static void make_traverse_depends(char *filename[],
1507 struct op *op[], unsigned int num_ops[],
1510 unsigned int i, num_traversals = 0;
1512 struct op_desc *desc;
1514 /* Sort by which one runs first. */
1515 int compare_traverse_desc(const void *_a, const void *_b)
1517 const struct op_desc *da = _a, *db = _b;
1518 const struct op *a = &op[da->file][da->op_num],
1519 *b = &op[db->file][db->op_num];
1521 if (a->seqnum != b->seqnum)
1522 return a->seqnum - b->seqnum;
1524 /* If they have same seqnum, it means one didn't make any
1525 * changes. Thus sort by end in that case. */
1526 return a[a->group_len].seqnum - b[b->group_len].seqnum;
1529 desc = talloc_array(NULL, struct op_desc, 1);
1532 for (i = 0; i < num; i++) {
1533 for (j = 1; j < num_ops[i]; j++) {
1534 /* Traverse start (ignore those in
1535 * transactions; they're already covered by
1536 * transaction dependencies). */
1537 if (starts_traverse(&op[i][j])
1538 && !in_transaction(op[i], j)) {
1539 desc = talloc_realloc(NULL, desc,
1542 desc[num_traversals].file = i;
1543 desc[num_traversals].op_num = j;
1548 qsort(desc, num_traversals, sizeof(desc[0]), compare_traverse_desc);
1550 for (i = 1; i < num_traversals; i++) {
1551 const struct op *prev = &op[desc[i-1].file][desc[i-1].op_num];
1552 const struct op *curr = &op[desc[i].file][desc[i].op_num];
1554 /* Read traverses don't depend on each other (read lock). */
1555 if (prev->type == OP_TDB_TRAVERSE_READ_START
1556 && curr->type == OP_TDB_TRAVERSE_READ_START)
1559 /* Only make dependency if it's clear. */
1560 if (compare_traverse_desc(&desc[i], &desc[i-1])) {
1561 /* i depends on end of traverse i-1. */
1562 struct op_desc end = desc[i-1];
1563 end.op_num += prev->group_len;
1564 add_dependency(NULL, op, filename, &desc[i], &end);
1570 static void set_nonblock(int fd)
1572 if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK) != 0)
1573 err(1, "Setting pipe nonblocking");
1576 static bool handle_backoff(struct op *op[], int fd)
1578 struct op_desc desc;
1579 bool handled = false;
1581 /* Sloppy coding: we assume PIPEBUF never fills. */
1582 while (read(fd, &desc, sizeof(desc)) != -1) {
1585 for (i = desc.op_num; i > 0; i--) {
1586 if (op[desc.file][i].type == OP_TDB_TRAVERSE) {
1587 /* We insert a fake end here. */
1588 op[desc.file][i].type
1589 = OP_TDB_TRAVERSE_END_EARLY;
1591 } else if (starts_traverse(&op[desc.file][i])) {
1592 unsigned int start = i;
1593 struct op tmp = op[desc.file][i];
1594 /* Move the ops outside traverse. */
1595 memmove(&op[desc.file][i],
1596 &op[desc.file][i+1],
1597 (desc.op_num-i-1) * sizeof(op[0][0]));
1598 op[desc.file][desc.op_num] = tmp;
1599 while (op[desc.file][i].group_start == start) {
1600 op[desc.file][i++].group_start
1610 #else /* !TRAVERSALS_TAKE_TRANSACTION_LOCK */
1611 static bool handle_backoff(struct op *op[], int fd)
1617 static void derive_dependencies(char *filename[],
1618 struct op *op[], unsigned int num_ops[],
1621 struct keyinfo *hash;
1624 /* Create hash table for faster key lookup. */
1625 hash = hash_ops(op, num_ops, num);
1627 /* Sort them by sequence number. */
1628 sort_ops(hash, filename, op, num);
1630 /* Create dependencies back to the last change, rather than
1631 * creating false dependencies by naively making each one
1632 * depend on the previous. This has two purposes: it makes
1633 * later optimization simpler, and it also avoids deadlock with
1634 * same sequence number ops inside traversals (if one
1635 * traversal doesn't write anything, two ops can have the same
1636 * sequence number yet we can create a traversal dependency
1637 * the other way). */
1638 for (h = 0; h < total_keys * 2; h++) {
1641 if (hash[h].num_users < 2)
1644 for (i = 0; i < hash[h].num_users; i++) {
1645 if (changes_db(&hash[h].key, &op[hash[h].user[i].file]
1646 [hash[h].user[i].op_num])) {
1647 depend_on_previous(op, filename, num,
1648 hash[h].user, i, prev);
1650 } else if (prev >= 0)
1651 add_dependency(hash, op, filename,
1653 &hash[h].user[prev]);
1657 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1658 make_traverse_depends(filename, op, num_ops, num);
1661 optimize_dependencies(op, num_ops, num);
1664 static struct timeval run_test(char *argv[],
1665 unsigned int num_ops[],
1666 unsigned int hashsize[],
1667 unsigned int tdb_flags[],
1668 unsigned int open_flags[],
1673 struct timeval start, end, diff;
1676 for (i = 0; argv[i+2]; i++) {
1677 struct tdb_context *tdb;
1682 err(1, "fork failed");
1685 tdb = tdb_open_ex(argv[1], hashsize[i],
1686 tdb_flags[i]|TDB_NOSYNC,
1687 open_flags[i], 0600, NULL, hash_key);
1689 err(1, "Opening tdb %s", argv[1]);
1691 /* This catches parent exiting. */
1692 if (read(fds[0], &c, 1) != 1)
1694 run_ops(tdb, pipes[i].fd[0], argv+2, op, i, 1,
1696 check_deps(argv[2+i], op[i], num_ops[i]);
1703 /* Let everything settle. */
1706 printf("Starting run...");
1708 gettimeofday(&start, NULL);
1709 /* Tell them all to go! Any write of sufficient length will do. */
1710 if (write(fds[1], hashsize, i) != i)
1711 err(1, "Writing to wakeup pipe");
1713 for (i = 0; argv[i + 2]; i++) {
1716 if (!WIFEXITED(status)) {
1717 warnx("Child died with signal %i", WTERMSIG(status));
1719 } else if (WEXITSTATUS(status) != 0)
1720 /* Assume child spat out error. */
1726 gettimeofday(&end, NULL);
1729 if (end.tv_usec < start.tv_usec) {
1730 end.tv_usec += 1000000;
1733 diff.tv_sec = end.tv_sec - start.tv_sec;
1734 diff.tv_usec = end.tv_usec - start.tv_usec;
1738 int main(int argc, char *argv[])
1740 struct timeval diff;
1741 unsigned int i, num_ops[argc], hashsize[argc], tdb_flags[argc], open_flags[argc];
1742 struct op *op[argc];
1746 errx(1, "Usage: %s <tdbfile> <tracefile>...", argv[0]);
1748 pipes = talloc_array(NULL, struct pipe, argc - 1);
1749 for (i = 0; i < argc - 2; i++) {
1750 printf("Loading tracefile %s...", argv[2+i]);
1752 op[i] = load_tracefile(argv[2+i], &num_ops[i], &hashsize[i],
1753 &tdb_flags[i], &open_flags[i]);
1754 if (pipe(pipes[i].fd) != 0)
1755 err(1, "creating pipe");
1759 printf("Calculating inter-dependencies...");
1761 derive_dependencies(argv+2, op, num_ops, i);
1764 /* Don't fork for single arg case: simple debugging. */
1766 struct tdb_context *tdb;
1767 tdb = tdb_open_ex(argv[1], hashsize[0], tdb_flags[0]|TDB_NOSYNC,
1768 open_flags[0], 0600, NULL, hash_key);
1769 printf("Single threaded run...");
1772 run_ops(tdb, pipes[0].fd[0], argv+2, op, 0, 1, num_ops[0],
1774 check_deps(argv[2], op[0], num_ops[0]);
1781 err(1, "creating pipe");
1783 #if TRAVERSALS_TAKE_TRANSACTION_LOCK
1784 if (pipe(pipes[argc-2].fd) != 0)
1785 err(1, "creating pipe");
1786 backoff_fd = pipes[argc-2].fd[1];
1787 set_nonblock(pipes[argc-2].fd[1]);
1788 set_nonblock(pipes[argc-2].fd[0]);
1792 diff = run_test(argv, num_ops, hashsize, tdb_flags, open_flags,
1794 } while (handle_backoff(op, pipes[argc-2].fd[0]));
1796 printf("Time replaying: %lu usec\n",
1797 diff.tv_sec * 1000000UL + diff.tv_usec);