r23195: Add void *private_data to brl_forall
authorVolker Lendecke <vlendec@samba.org>
Tue, 29 May 2007 13:26:44 +0000 (13:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:22:53 +0000 (12:22 -0500)
source/include/locking.h
source/locking/brlock.c
source/torture/locktest.c
source/torture/locktest2.c
source/utils/status.c

index f02d8171337809543fddb34679be2d168a564659..d61b5fe1e436108617ea4c9984c76689b8258bfc 100644 (file)
@@ -62,18 +62,6 @@ struct byte_range_lock {
        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. 
    The data in brlock records is an unsorted linear array of these
    records.  It is unnecessary to store the count as tdb provides the
index a37afbddd53e560e829ffb1fef048c588daadd97..b51076bf433e4689e444d55b3f46ea04502c6bf0 100644 (file)
@@ -1447,6 +1447,15 @@ static BOOL validate_lock_entries(unsigned int *pnum_entries, struct lock_struct
        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
  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)
 {
+       struct brl_forall_cb *cb = (struct brl_forall_cb *)state;
        struct lock_struct *locks;
        struct file_id *key;
        unsigned int i;
        unsigned int 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
           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++) {
-               traverse_callback(*key,
-                                 locks[i].context.pid,
-                                 locks[i].lock_type,
-                                 locks[i].lock_flav,
-                                 locks[i].start,
-                                 locks[i].size);
+               cb->fn(*key,
+                      locks[i].context.pid,
+                      locks[i].lock_type,
+                      locks[i].lock_flav,
+                      locks[i].start,
+                      locks[i].size,
+                      cb->private_data);
        }
 
        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.
 ********************************************************************/
 
-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) {
                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);
 }
 
 /*******************************************************************
index 92838f0ff20de8130d15fe7ea5cae5500887770c..7a970488b37fbaaebec931f4ecd63f8be27a7064 100644 (file)
@@ -121,7 +121,8 @@ static void print_brl(struct file_id id,
                        enum brl_type lock_type,
                        enum brl_flavour lock_flav,
                        br_off start,
-                       br_off size)
+                       br_off size,
+                       void *private_data)
 {
 #if NASTY_POSIX_LOCK_HACK
        {
@@ -147,7 +148,7 @@ static void print_brl(struct file_id id,
 
 static void show_locks(void)
 {
-       brl_forall(print_brl);
+       brl_forall(print_brl, NULL);
        /* system("cat /proc/locks"); */
 }
 
index 184c84be439a4ab98246534ffe719fe490db8385..0da7e9cf00ca90a4543689de957c60b089fc7e2c 100644 (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, 
                      enum brl_type lock_type,
                      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", 
               (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",
                               ret[0], ret[1]);
                }
-               if (showall) brl_forall(print_brl);
+               if (showall) brl_forall(print_brl, NULL);
                if (ret[0] != ret[1]) return False;
        } else if (r2 < LOCK_PCT+UNLOCK_PCT) {
                /* unset a lock */
@@ -274,7 +275,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                               start, start+len-1, len,
                               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;
        } else {
                /* reopen the file */
@@ -290,7 +291,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                if (showall) {
                        printf("reopen conn=%u fstype=%u f=%u\n",
                               conn, fstype, f);
-                       brl_forall(print_brl);
+                       brl_forall(print_brl, NULL);
                }
        }
        return True;
index 207be3091215d1e049991e1c178cb966dfe8e2a0..5b769a036b74a2a58757acc464c9d8f9c5a0f72a 100644 (file)
@@ -171,7 +171,8 @@ static void print_brl(struct file_id id,
                        enum brl_type lock_type,
                        enum brl_flavour lock_flav,
                        br_off start,
-                       br_off size)
+                       br_off size,
+                       void *private_data)
 {
        static int count;
        int i;
@@ -389,7 +390,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo
                d_printf("\n");
 
                if (show_brl) {
-                       brl_forall(print_brl);
+                       brl_forall(print_brl, NULL);
                }
                
                locking_end();