r14954: Fix #3569 based on William Jojo's work. AIX also
authorJeremy Allison <jra@samba.org>
Thu, 6 Apr 2006 22:31:45 +0000 (22:31 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:15:55 +0000 (11:15 -0500)
has the linear posix locking issue which causes
CLEAR_IF_FIRST to cause performance problems.
As we know we're in a daemon architecture with
long-lived parent we can avoid this in the Samba
case. Add a comment explaining this.
Jeremy.

source/nsswitch/winbindd_dual.c
source/smbd/server.c
source/tdb/tdb.c
source/tdb/tdb.h
source/tdb/tdbtorture.c

index a049bf7b7a32c718b85be4af86ff7cd8727c89e5..cdfa1e049320f9c7b9faf1a09e86266b531fded9 100644 (file)
@@ -629,7 +629,7 @@ static BOOL fork_domain_child(struct winbindd_child *child)
        close(fdpair[1]);
 
        /* tdb needs special fork handling */
-       if (tdb_reopen_all() == -1) {
+       if (tdb_reopen_all(1) == -1) {
                DEBUG(0,("tdb_reopen_all failed.\n"));
                _exit(0);
        }
index dfead851e8e01853b29f2f29ee999ed165432e57..ba31827eb3fd2da411a3120cf33895fe8cbadfe3 100644 (file)
@@ -474,7 +474,7 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_
 
                                set_need_random_reseed();
                                /* tdb needs special fork handling - remove CLEAR_IF_FIRST flags */
-                               if (tdb_reopen_all() == -1) {
+                               if (tdb_reopen_all(1) == -1) {
                                        DEBUG(0,("tdb_reopen_all failed.\n"));
                                        smb_panic("tdb_reopen_all failed.");
                                }
index 4303976087d1dd9e59ac7f2ef7338d1dbfd78e05..ad73a1d9aa03acaaf5f005011749460807c2073e 100644 (file)
@@ -2098,11 +2098,27 @@ fail:
 }
 
 /* reopen all tdb's */
-int tdb_reopen_all(void)
+int tdb_reopen_all(int parent_longlived)
 {
        TDB_CONTEXT *tdb;
 
        for (tdb=tdbs; tdb; tdb = tdb->next) {
+               /*
+                * If the parent is longlived (ie. a
+                * parent daemon architecture), we know
+                * it will keep it's active lock on a
+                * tdb opened with CLEAR_IF_FIRST. Thus
+                * for child processes we don't have to
+                * add an active lock. This is essential
+                * to improve performance on systems that
+                * keep POSIX locks as a non-scalable data
+                * structure in the kernel.
+                */
+               if (parent_longlived) {
+                       /* Ensure no clear-if-first. */
+                       tdb->flags &= ~TDB_CLEAR_IF_FIRST;
+               }
+
                if (tdb_reopen(tdb) != 0)
                        return -1;
        }
index d1c976cd56b3deeb7cb1ec80f06d57fc4f7b0ff0..b5b87ee5a542e64bb3744de12418bae0bbe1df3d 100644 (file)
@@ -128,7 +128,7 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
                         tdb_hash_func hash_fn);
 
 int tdb_reopen(TDB_CONTEXT *tdb);
-int tdb_reopen_all(void);
+int tdb_reopen_all(int);
 void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
 enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
 const char *tdb_errorstr(TDB_CONTEXT *tdb);
index d03cc2a6103051579c2cb8db2cbe3a74c672c245..2d367b91e1f3012af64ce009376915dde2a3e42a 100644 (file)
@@ -103,7 +103,7 @@ static void addrec_db(void)
 
 #if REOPEN_PROB
        if (random() % REOPEN_PROB == 0) {
-               tdb_reopen_all();
+               tdb_reopen_all(1);
                goto next;
        } 
 #endif
@@ -192,7 +192,7 @@ int main(int argc, char *argv[])
        for (i=0;i<NPROC;i++) {
                pids[i] = fork();
                if (pids[i] == 0) {
-                       tdb_reopen_all();
+                       tdb_reopen_all(1);
 
                        tdb_logging_function(db, tdb_log);