summaryrefslogtreecommitdiff
path: root/source3/locking/brlock.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-01-16 11:14:44 +0000
committerAndrew Tridgell <tridge@samba.org>2000-01-16 11:14:44 +0000
commit54e1176ba17eaaba82254e4b629fa135802cec10 (patch)
tree7d341a5cf7f9e79967c7adddab7473992faac717 /source3/locking/brlock.c
parent33157e9bfc154f9151993e66bc26b3b282aac11a (diff)
downloadsamba-54e1176ba17eaaba82254e4b629fa135802cec10.tar.gz
samba-54e1176ba17eaaba82254e4b629fa135802cec10.tar.bz2
samba-54e1176ba17eaaba82254e4b629fa135802cec10.zip
added code to allow traversal of the byte range lock database
this is used with "smbstatus -B" to dump the lock list (This used to be commit 5f022629146701e6d543f77007dc944e4277ab0c)
Diffstat (limited to 'source3/locking/brlock.c')
-rw-r--r--source3/locking/brlock.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 11766433fc..7e8adf4f86 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);
+}