Commit d0b36a7c authored by Rusty Russell's avatar Rusty Russell

tdb: more testcase fixup.

parent f4ed2127
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <ccan/tdb/tdb_private.h>
struct lock { struct lock {
struct lock *next; struct lock *next;
...@@ -13,6 +14,7 @@ struct lock { ...@@ -13,6 +14,7 @@ struct lock {
}; };
static struct lock *locks; static struct lock *locks;
int locking_errors = 0; int locking_errors = 0;
bool suppress_lockcheck = false;
void (*unlock_callback)(int fd); void (*unlock_callback)(int fd);
int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ )
...@@ -47,7 +49,7 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) ...@@ -47,7 +49,7 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ )
break; break;
} }
} }
if (!old) { if (!old && !suppress_lockcheck) {
diag("Unknown unlock %u@%u", diag("Unknown unlock %u@%u",
(int)fl->l_len, (int)fl->l_start); (int)fl->l_len, (int)fl->l_start);
locking_errors++; locking_errors++;
...@@ -70,11 +72,22 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) ...@@ -70,11 +72,22 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ )
break; break;
} }
if (i) { if (i) {
diag("%s lock %u@%u overlaps %u@%u", /* Special case: upgrade of allrecord lock. */
fl->l_type == F_WRLCK ? "write" : "read", if (i->type == F_RDLCK && fl->l_type == F_WRLCK
(int)fl->l_len, (int)fl->l_start, && i->off == FREELIST_TOP
i->len, (int)i->off); && fl->l_start == FREELIST_TOP
locking_errors++; && i->len == 0
&& fl->l_len == 0) {
i->type = F_WRLCK;
goto ok;
}
if (!suppress_lockcheck) {
diag("%s lock %u@%u overlaps %u@%u",
fl->l_type == F_WRLCK ? "write" : "read",
(int)fl->l_len, (int)fl->l_start,
i->len, (int)i->off);
locking_errors++;
}
} }
new = malloc(sizeof *new); new = malloc(sizeof *new);
new->off = fl->l_start; new->off = fl->l_start;
...@@ -83,7 +96,7 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) ...@@ -83,7 +96,7 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ )
new->next = locks; new->next = locks;
locks = new; locks = new;
} }
ok:
ret = fcntl(fd, cmd, fl); ret = fcntl(fd, cmd, fl);
if (ret == 0 && fl->l_type == F_UNLCK && unlock_callback) if (ret == 0 && fl->l_type == F_UNLCK && unlock_callback)
unlock_callback(fd); unlock_callback(fd);
......
#ifndef LOCK_TRACKING_H #ifndef LOCK_TRACKING_H
#define LOCK_TRACKING_H #define LOCK_TRACKING_H
#include <stdbool.h>
/* Set this if you want a callback after fnctl unlock. */ /* Set this if you want a callback after fnctl unlock. */
extern void (*unlock_callback)(int fd); extern void (*unlock_callback)(int fd);
...@@ -11,4 +13,7 @@ unsigned int forget_locking(void); ...@@ -11,4 +13,7 @@ unsigned int forget_locking(void);
/* Number of errors in locking. */ /* Number of errors in locking. */
extern int locking_errors; extern int locking_errors;
/* Suppress lock checking. */
extern bool suppress_lockcheck;
#endif /* LOCK_TRACKING_H */ #endif /* LOCK_TRACKING_H */
...@@ -116,6 +116,7 @@ reset: ...@@ -116,6 +116,7 @@ reset:
if (setjmp(jmpbuf) != 0) { if (setjmp(jmpbuf) != 0) {
/* We're partway through. Simulate our death. */ /* We're partway through. Simulate our death. */
close(tdb->fd); close(tdb->fd);
forget_locking();
in_transaction = false; in_transaction = false;
if (external_agent_operation(agent, NEEDS_RECOVERY_KEEP_OPENED, if (external_agent_operation(agent, NEEDS_RECOVERY_KEEP_OPENED,
...@@ -144,11 +145,12 @@ reset: ...@@ -144,11 +145,12 @@ reset:
external_agent_operation(agent, CLOSE, ""); external_agent_operation(agent, CLOSE, "");
/* Suppress logging as this tries to use closed fd. */ /* Suppress logging as this tries to use closed fd. */
suppress_logging = true; suppress_logging = true;
suppress_lockcheck = true;
tdb_close(tdb); tdb_close(tdb);
suppress_logging = false; suppress_logging = false;
suppress_lockcheck = false;
target++; target++;
current = 0; current = 0;
forget_locking();
goto reset; goto reset;
} }
...@@ -195,7 +197,7 @@ int main(int argc, char *argv[]) ...@@ -195,7 +197,7 @@ int main(int argc, char *argv[])
struct agent *agent; struct agent *agent;
int i; int i;
plan_tests(6); plan_tests(12);
unlock_callback = maybe_die; unlock_callback = maybe_die;
agent = prepare_external_agent(); agent = prepare_external_agent();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment