1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-07 20:23:50 +03:00

r23195: Add void *private_data to brl_forall

This commit is contained in:
Volker Lendecke
2007-05-29 13:26:44 +00:00
committed by Gerald (Jerry) Carter
parent 3c9fb1c6f3
commit c91b2bdc16
5 changed files with 39 additions and 30 deletions

View File

@@ -62,18 +62,6 @@ struct byte_range_lock {
struct db_record *record; struct db_record *record;
}; };
#define BRLOCK_FN_CAST() \
void (*)(struct file_id id, struct server_id pid, \
enum brl_type lock_type, \
enum brl_flavour lock_flav, \
br_off start, br_off size)
#define BRLOCK_FN(fn) \
void (*fn)(struct file_id id, struct server_id pid, \
enum brl_type lock_type, \
enum brl_flavour lock_flav, \
br_off start, br_off size)
/* Internal structure in brlock.tdb. /* Internal structure in brlock.tdb.
The data in brlock records is an unsorted linear array of these The data in brlock records is an unsorted linear array of these
records. It is unnecessary to store the count as tdb provides the records. It is unnecessary to store the count as tdb provides the

View File

@@ -1447,6 +1447,15 @@ static BOOL validate_lock_entries(unsigned int *pnum_entries, struct lock_struct
return True; return True;
} }
struct brl_forall_cb {
void (*fn)(struct file_id id, struct server_id pid,
enum brl_type lock_type,
enum brl_flavour lock_flav,
br_off start, br_off size,
void *private_data);
void *private_data;
};
/**************************************************************************** /****************************************************************************
Traverse the whole database with this function, calling traverse_callback Traverse the whole database with this function, calling traverse_callback
on each lock. on each lock.
@@ -1454,14 +1463,13 @@ static BOOL validate_lock_entries(unsigned int *pnum_entries, struct lock_struct
static int traverse_fn(struct db_record *rec, void *state) static int traverse_fn(struct db_record *rec, void *state)
{ {
struct brl_forall_cb *cb = (struct brl_forall_cb *)state;
struct lock_struct *locks; struct lock_struct *locks;
struct file_id *key; struct file_id *key;
unsigned int i; unsigned int i;
unsigned int num_locks = 0; unsigned int num_locks = 0;
unsigned int orig_num_locks = 0; unsigned int orig_num_locks = 0;
BRLOCK_FN(traverse_callback) = (BRLOCK_FN_CAST())state;
/* In a traverse function we must make a copy of /* In a traverse function we must make a copy of
dbuf before modifying it. */ dbuf before modifying it. */
@@ -1493,12 +1501,13 @@ static int traverse_fn(struct db_record *rec, void *state)
} }
for ( i=0; i<num_locks; i++) { for ( i=0; i<num_locks; i++) {
traverse_callback(*key, cb->fn(*key,
locks[i].context.pid, locks[i].context.pid,
locks[i].lock_type, locks[i].lock_type,
locks[i].lock_flav, locks[i].lock_flav,
locks[i].start, locks[i].start,
locks[i].size); locks[i].size,
cb->private_data);
} }
SAFE_FREE(locks); SAFE_FREE(locks);
@@ -1509,12 +1518,21 @@ static int traverse_fn(struct db_record *rec, void *state)
Call the specified function on each lock in the database. Call the specified function on each lock in the database.
********************************************************************/ ********************************************************************/
int brl_forall(BRLOCK_FN(fn)) int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
enum brl_type lock_type,
enum brl_flavour lock_flav,
br_off start, br_off size,
void *private_data),
void *private_data)
{ {
struct brl_forall_cb cb;
if (!brlock_db) { if (!brlock_db) {
return 0; return 0;
} }
return brlock_db->traverse(brlock_db, traverse_fn, (void *)fn); cb.fn = fn;
cb.private_data = private_data;
return brlock_db->traverse(brlock_db, traverse_fn, &cb);
} }
/******************************************************************* /*******************************************************************

View File

@@ -121,7 +121,8 @@ static void print_brl(struct file_id id,
enum brl_type lock_type, enum brl_type lock_type,
enum brl_flavour lock_flav, enum brl_flavour lock_flav,
br_off start, br_off start,
br_off size) br_off size,
void *private_data)
{ {
#if NASTY_POSIX_LOCK_HACK #if NASTY_POSIX_LOCK_HACK
{ {
@@ -147,7 +148,7 @@ static void print_brl(struct file_id id,
static void show_locks(void) static void show_locks(void)
{ {
brl_forall(print_brl); brl_forall(print_brl, NULL);
/* system("cat /proc/locks"); */ /* system("cat /proc/locks"); */
} }

View File

@@ -139,7 +139,8 @@ static BOOL try_unlock(struct cli_state *c, int fstype,
static void print_brl(struct file_id id, struct server_id pid, static void print_brl(struct file_id id, struct server_id pid,
enum brl_type lock_type, enum brl_type lock_type,
enum brl_flavour lock_flav, enum brl_flavour lock_flav,
br_off start, br_off size) br_off start, br_off size,
void *private_data)
{ {
printf("%6d %s %s %.0f:%.0f(%.0f)\n", printf("%6d %s %s %.0f:%.0f(%.0f)\n",
(int)procid_to_pid(&pid), file_id_static_string(&id), (int)procid_to_pid(&pid), file_id_static_string(&id),
@@ -259,7 +260,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",
ret[0], ret[1]); ret[0], ret[1]);
} }
if (showall) brl_forall(print_brl); if (showall) brl_forall(print_brl, NULL);
if (ret[0] != ret[1]) return False; if (ret[0] != ret[1]) return False;
} else if (r2 < LOCK_PCT+UNLOCK_PCT) { } else if (r2 < LOCK_PCT+UNLOCK_PCT) {
/* unset a lock */ /* unset a lock */
@@ -274,7 +275,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
start, start+len-1, len, start, start+len-1, len,
ret[0], ret[1]); ret[0], ret[1]);
} }
if (showall) brl_forall(print_brl); if (showall) brl_forall(print_brl, NULL);
if (!hide_unlock_fails && ret[0] != ret[1]) return False; if (!hide_unlock_fails && ret[0] != ret[1]) return False;
} else { } else {
/* reopen the file */ /* reopen the file */
@@ -290,7 +291,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
if (showall) { if (showall) {
printf("reopen conn=%u fstype=%u f=%u\n", printf("reopen conn=%u fstype=%u f=%u\n",
conn, fstype, f); conn, fstype, f);
brl_forall(print_brl); brl_forall(print_brl, NULL);
} }
} }
return True; return True;

View File

@@ -171,7 +171,8 @@ static void print_brl(struct file_id id,
enum brl_type lock_type, enum brl_type lock_type,
enum brl_flavour lock_flav, enum brl_flavour lock_flav,
br_off start, br_off start,
br_off size) br_off size,
void *private_data)
{ {
static int count; static int count;
int i; int i;
@@ -389,7 +390,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo
d_printf("\n"); d_printf("\n");
if (show_brl) { if (show_brl) {
brl_forall(print_brl); brl_forall(print_brl, NULL);
} }
locking_end(); locking_end();