X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb%2Ftest%2Flock-tracking.c;h=8460c048dfcfb74d929153118293572162a78543;hb=426c8dc977d0fb46286042f7072d86bc053836a1;hp=bc4be14759211f6718bfda34d124652329d3544a;hpb=c4a9fd1b01822e75da853d3f3229de5d35409e31;p=ccan diff --git a/ccan/tdb/test/lock-tracking.c b/ccan/tdb/test/lock-tracking.c index bc4be147..8460c048 100644 --- a/ccan/tdb/test/lock-tracking.c +++ b/ccan/tdb/test/lock-tracking.c @@ -4,6 +4,7 @@ #include #include #include +#include struct lock { struct lock *next; @@ -13,6 +14,7 @@ struct lock { }; static struct lock *locks; int locking_errors = 0; +bool suppress_lockcheck = false; void (*unlock_callback)(int fd); int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) @@ -47,7 +49,7 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) break; } } - if (!old) { + if (!old && !suppress_lockcheck) { diag("Unknown unlock %u@%u", (int)fl->l_len, (int)fl->l_start); locking_errors++; @@ -68,13 +70,30 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) break; if (fl_end >= i->off && fl_end < i_end) break; + + /* tdb_allrecord_lock does this, handle adjacent: */ + if (fl->l_start == i_end && fl->l_type == i->type) { + i->len = fl->l_len ? i->len + fl->l_len : 0; + goto ok; + } } if (i) { - 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++; + /* Special case: upgrade of allrecord lock. */ + if (i->type == F_RDLCK && fl->l_type == F_WRLCK + && i->off == FREELIST_TOP + && fl->l_start == FREELIST_TOP + && 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->off = fl->l_start; @@ -83,7 +102,7 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ ) new->next = locks; locks = new; } - +ok: ret = fcntl(fd, cmd, fl); if (ret == 0 && fl->l_type == F_UNLCK && unlock_callback) unlock_callback(fd);