diff options
Diffstat (limited to 'source3/locking')
-rw-r--r-- | source3/locking/brlock.c | 44 | ||||
-rw-r--r-- | source3/locking/locking.c | 2 |
2 files changed, 43 insertions, 3 deletions
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index 11766433fc1..7e8adf4f860 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -90,11 +90,11 @@ static BOOL brl_conflict(struct lock_struct *lck1, /**************************************************************************** open up the brlock.tdb database ****************************************************************************/ -void brl_init(void) +void brl_init(int read_only) { if (tdb) return; tdb = tdb_open(lock_path("brlock.tdb"), 0, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT, 0644); + read_only?O_RDONLY:O_RDWR|O_CREAT, 0644); if (!tdb) { DEBUG(0,("Failed to open byte range locking database\n")); } @@ -329,3 +329,43 @@ void brl_close(SMB_DEV_T dev, SMB_INO_T ino, pid_t pid, int tid, int fnum) if (dbuf.dptr) free(dbuf.dptr); tdb_unlockchain(tdb, kbuf); } + + +static void (*traverse_callback)(SMB_DEV_T dev, SMB_INO_T ino, int pid, + enum brl_type lock_type, + br_off start, br_off size); + +/**************************************************************************** +traverse the whole database with this function, calling traverse_callback +on each lock +****************************************************************************/ +static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) +{ + struct lock_struct *locks; + struct lock_key *key; + int i; + + locks = (struct lock_struct *)dbuf.dptr; + key = (struct lock_key *)kbuf.dptr; + + for (i=0;i<dbuf.dsize/sizeof(*locks);i++) { + traverse_callback(key->device, key->inode, + locks[i].context.pid, + locks[i].lock_type, + locks[i].start, + locks[i].size); + } + return 0; +} + +/******************************************************************* + Call the specified function on each lock in the database +********************************************************************/ +int brl_forall(void (*fn)(SMB_DEV_T dev, SMB_INO_T ino, int pid, + enum brl_type lock_type, + br_off start, br_off size)) +{ + if (!tdb) return 0; + traverse_callback = fn; + return tdb_traverse(tdb, traverse_fn); +} diff --git a/source3/locking/locking.c b/source3/locking/locking.c index 5348659917c..9753b5ea615 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -145,7 +145,7 @@ BOOL do_unlock(files_struct *fsp,connection_struct *conn, ****************************************************************************/ BOOL locking_init(int read_only) { - brl_init(); + brl_init(read_only); if (tdb) return True; |