[SCM] Samba Shared Repository - branch v3-6-test updated
Jeremy Allison
jra at samba.org
Mon Apr 25 14:22:11 MDT 2011
The branch, v3-6-test has been updated
via 2698b40 s3-selftest Rename s3 DC environment to s3dc
via 2df698f selftest: put the target on the environment
via 4aba6e4 s3: Run pthreadpooltest in make test
via 37d9636 s3: Add pthreadpooltest to main build (cherry picked from commit 39375de8354b676904e1fea097a68178acd987e4)
via 28394b9 s3: pthreadpool_sig_fd->pthreadpool_signal_fd (cherry picked from commit f4a0f856f31291dd316a937f8060d2f205e8d4d6)
via 39ab4b0 s3: Tiny doc for pthreadpool (cherry picked from commit 3c405f5e1d81d33a01ab822aeba93634338d5b25)
via 2caf8e0 s3: Many pthreadpool fixes
from 5f21737 s3: Fix Coverity ID 2478, UNINIT
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-6-test
- Log -----------------------------------------------------------------
commit 2698b40a3d920cfc5bb85333818d98f2fced9d9d
Author: Jeremy Allison <jra at samba.org>
Date: Mon Apr 25 13:12:23 2011 -0700
s3-selftest Rename s3 DC environment to s3dc
This should avoid a clash with the s4 DC environment in a future
combined 'make test'.
commit 2df698ffec823938566de0a3c7120d149b57bf0a
Author: Andrew Bartlett <abartlet at samba.org>
Date: Mon Apr 18 13:44:36 2011 +1000
selftest: put the target on the environment
This will allow us to have a 'switch' target type that creates
environments from Samba3 or Samba4 as required.
Andrew Bartlett
(cherry picked from commit d041ed233d1b10604ef1b9f7f1e68f6f5cd96132)
commit 4aba6e44cbd2d3cb3b20d864008971f424d99878
Author: Volker Lendecke <vl at samba.org>
Date: Sun Apr 24 10:36:56 2011 +0200
s3: Run pthreadpooltest in make test
Autobuild-User: Volker Lendecke <vlendec at samba.org>
Autobuild-Date: Mon Apr 25 10:39:12 CEST 2011 on sn-devel-104
(cherry picked from commit 422b2fa0d064f2afeeec400223bb8a47deecc4a5)
commit 37d963684aae4c80c4a3286bb22503592156b630
Author: Volker Lendecke <vl at samba.org>
Date: Sat Apr 23 16:49:04 2011 +0200
s3: Add pthreadpooltest to main build
(cherry picked from commit 39375de8354b676904e1fea097a68178acd987e4)
commit 28394b98affe38650c56cf37e110d08c71145f0f
Author: Volker Lendecke <vl at samba.org>
Date: Sun Apr 24 10:09:45 2011 +0200
s3: pthreadpool_sig_fd->pthreadpool_signal_fd
(cherry picked from commit f4a0f856f31291dd316a937f8060d2f205e8d4d6)
commit 39ab4b06f8fde50489d68a554102fdcea78c1fec
Author: Volker Lendecke <vl at samba.org>
Date: Sat Apr 23 22:25:36 2011 +0200
s3: Tiny doc for pthreadpool
(cherry picked from commit 3c405f5e1d81d33a01ab822aeba93634338d5b25)
commit 2caf8e097cd8f724c7cd93c3f8e1fc3cd095d8ff
Author: Volker Lendecke <vl at samba.org>
Date: Fri Apr 22 11:47:11 2011 +0200
s3: Many pthreadpool fixes
In particular, this makes it fork-safe
(cherry picked from commit 62689d8166b8e070f855e6910470796dd7e1b2c8)
-----------------------------------------------------------------------
Summary of changes:
selftest/selftest.pl | 16 +-
selftest/target/Samba3.pm | 58 +++---
source3/Makefile.in | 14 +-
source3/configure.in | 4 +-
source3/include/pthreadpool.h | 42 ---
source3/lib/fncall.c | 4 +-
source3/lib/pthreadpool/Makefile | 9 +
source3/lib/{ => pthreadpool}/pthreadpool.c | 259 +++++++++++++-------
source3/lib/pthreadpool/pthreadpool.h | 94 +++++++
source3/lib/pthreadpool/tests.c | 362 +++++++++++++++++++++++++++
source3/script/tests/test_pthreadpool.sh | 17 ++
source3/selftest/tests.py | 49 ++--
12 files changed, 738 insertions(+), 190 deletions(-)
delete mode 100644 source3/include/pthreadpool.h
create mode 100644 source3/lib/pthreadpool/Makefile
rename source3/lib/{ => pthreadpool}/pthreadpool.c (70%)
create mode 100644 source3/lib/pthreadpool/pthreadpool.h
create mode 100644 source3/lib/pthreadpool/tests.c
create mode 100755 source3/script/tests/test_pthreadpool.sh
Changeset truncated at 500 lines:
diff --git a/selftest/selftest.pl b/selftest/selftest.pl
index 9db3f21..158ff48 100755
--- a/selftest/selftest.pl
+++ b/selftest/selftest.pl
@@ -846,12 +846,15 @@ sub setup_env($$)
$testenv_vars = {};
} elsif (defined(get_running_env($envname))) {
$testenv_vars = get_running_env($envname);
- if (not $target->check_env($testenv_vars)) {
- print $target->getlog_env($testenv_vars);
+ if (not $testenv_vars->{target}->check_env($testenv_vars)) {
+ print $testenv_vars->{target}->getlog_env($testenv_vars);
$testenv_vars = undef;
}
} else {
$testenv_vars = $target->setup_env($envname, $prefix);
+ if (defined($testenv_vars) && not defined($testenv_vars->{target})) {
+ $testenv_vars->{target} = $target;
+ }
}
return undef unless defined($testenv_vars);
@@ -897,21 +900,24 @@ sub getlog_env($)
{
my ($envname) = @_;
return "" if ($envname eq "none");
- return $target->getlog_env(get_running_env($envname));
+ my $env = get_running_env($envname);
+ return $env->{target}->getlog_env($env);
}
sub check_env($)
{
my ($envname) = @_;
return 1 if ($envname eq "none");
- return $target->check_env(get_running_env($envname));
+ my $env = get_running_env($envname);
+ return $env->{target}->check_env($env);
}
sub teardown_env($)
{
my ($envname) = @_;
return if ($envname eq "none");
- $target->teardown_env(get_running_env($envname));
+ my $env = get_running_env($envname);
+ $env->{target}->teardown_env($env);
delete $running_envs{$envname};
}
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 38148eb..864f3dc 100644
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -98,20 +98,20 @@ sub setup_env($$$)
{
my ($self, $envname, $path) = @_;
- if ($envname eq "dc") {
- return $self->setup_dc("$path/dc");
+ if ($envname eq "s3dc") {
+ return $self->setup_dc("$path/s3dc");
} elsif ($envname eq "secshare") {
return $self->setup_secshare("$path/secshare");
} elsif ($envname eq "secserver") {
- if (not defined($self->{vars}->{dc})) {
- $self->setup_dc("$path/dc");
+ if (not defined($self->{vars}->{s3dc})) {
+ $self->setup_dc("$path/s3dc");
}
- return $self->setup_secserver("$path/secserver", $self->{vars}->{dc});
+ return $self->setup_secserver("$path/secserver", $self->{vars}->{s3dc});
} elsif ($envname eq "member") {
- if (not defined($self->{vars}->{dc})) {
- $self->setup_dc("$path/dc");
+ if (not defined($self->{vars}->{s3dc})) {
+ $self->setup_dc("$path/s3dc");
}
- return $self->setup_member("$path/member", $self->{vars}->{dc});
+ return $self->setup_member("$path/member", $self->{vars}->{s3dc});
} else {
return undef;
}
@@ -121,19 +121,19 @@ sub setup_dc($$)
{
my ($self, $path) = @_;
- print "PROVISIONING DC...";
+ print "PROVISIONING S3DC...";
- my $dc_options = "
+ my $s3dc_options = "
domain master = yes
domain logons = yes
lanman auth = yes
";
my $vars = $self->provision($path,
- "LOCALDC2",
+ "LOCALS3DC2",
2,
- "localdc2pass",
- $dc_options);
+ "locals3dc2pass",
+ $s3dc_options);
$self->check_or_start($vars,
($ENV{SMBD_MAXTIME} or 2700),
@@ -147,14 +147,14 @@ sub setup_dc($$)
$vars->{DC_USERNAME} = $vars->{USERNAME};
$vars->{DC_PASSWORD} = $vars->{PASSWORD};
- $self->{vars}->{dc} = $vars;
+ $self->{vars}->{s3dc} = $vars;
return $vars;
}
sub setup_member($$$)
{
- my ($self, $prefix, $dcvars) = @_;
+ my ($self, $prefix, $s3dcvars) = @_;
print "PROVISIONING MEMBER...";
@@ -173,8 +173,8 @@ sub setup_member($$$)
my $net = $self->binpath("net");
my $cmd = "";
$cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
- $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
- $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
+ $cmd .= "$net join $ret->{CONFIGURATION} $s3dcvars->{DOMAIN} member";
+ $cmd .= " -U$s3dcvars->{USERNAME}\%$s3dcvars->{PASSWORD}";
system($cmd) == 0 or die("Join failed\n$cmd");
@@ -184,11 +184,11 @@ sub setup_member($$$)
$self->wait_for_start($ret);
- $ret->{DC_SERVER} = $dcvars->{SERVER};
- $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
- $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
- $ret->{DC_USERNAME} = $dcvars->{USERNAME};
- $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
+ $ret->{DC_SERVER} = $s3dcvars->{SERVER};
+ $ret->{DC_SERVER_IP} = $s3dcvars->{SERVER_IP};
+ $ret->{DC_NETBIOSNAME} = $s3dcvars->{NETBIOSNAME};
+ $ret->{DC_USERNAME} = $s3dcvars->{USERNAME};
+ $ret->{DC_PASSWORD} = $s3dcvars->{PASSWORD};
return $ret;
}
@@ -223,13 +223,13 @@ sub setup_secshare($$)
sub setup_secserver($$$)
{
- my ($self, $prefix, $dcvars) = @_;
+ my ($self, $prefix, $s3dcvars) = @_;
print "PROVISIONING server with security=server...";
my $secserver_options = "
security = server
- password server = $dcvars->{SERVER_IP}
+ password server = $s3dcvars->{SERVER_IP}
";
my $ret = $self->provision($prefix,
@@ -246,11 +246,11 @@ sub setup_secserver($$$)
$self->wait_for_start($ret);
- $ret->{DC_SERVER} = $dcvars->{SERVER};
- $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
- $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
- $ret->{DC_USERNAME} = $dcvars->{USERNAME};
- $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
+ $ret->{DC_SERVER} = $s3dcvars->{SERVER};
+ $ret->{DC_SERVER_IP} = $s3dcvars->{SERVER_IP};
+ $ret->{DC_NETBIOSNAME} = $s3dcvars->{NETBIOSNAME};
+ $ret->{DC_USERNAME} = $s3dcvars->{USERNAME};
+ $ret->{DC_PASSWORD} = $s3dcvars->{PASSWORD};
return $ret;
}
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 42af44c..53886e1 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -97,6 +97,7 @@ TDBTOOL = @TDBTOOL@
TDBDUMP = @TDBDUMP@
TDBRESTORE = @TDBRESTORE@
TDBTORTURE = @TDBTORTURE@
+PTHREADPOOLTEST = @PTHREADPOOLTEST@
INSTALLCMD=@INSTALL@
INSTALLLIBCMD_SH=@INSTALLLIBCMD_SH@
@@ -230,7 +231,7 @@ TORTURE_PROGS = bin/smbtorture at EXEEXT@ bin/msgtest at EXEEXT@ \
bin/masktest at EXEEXT@ bin/locktest at EXEEXT@ \
bin/locktest2 at EXEEXT@ bin/nsstest at EXEEXT@ bin/vfstest at EXEEXT@ \
bin/pdbtest at EXEEXT@ $(TALLOCTORT) bin/replacetort at EXEEXT@ \
- $(TDBTORTURE) \
+ $(TDBTORTURE) $(PTHREADPOOLTEST) \
bin/smbconftort at EXEEXT@ bin/vlp at EXEEXT@
BIN_PROGS = @EXTRA_BIN_PROGS@ \
@@ -1128,6 +1129,9 @@ SMBCONFTORT_OBJ = $(SMBCONFTORT_OBJ0) \
$(LIBSMB_ERR_OBJ) \
$(POPT_LIB_OBJ)
+PTHREADPOOLTEST_OBJ = lib/pthreadpool/pthreadpool.o \
+ lib/pthreadpool/tests.o
+
LIBNET_OBJ = libnet/libnet_join.o \
libnet/libnet_keytab.o \
librpc/gen_ndr/ndr_libnet_join.o
@@ -1565,6 +1569,8 @@ replacetort : SHOWFLAGS bin/replacetort at EXEEXT@
smbconftort : SHOWFLAGS bin/smbconftort at EXEEXT@
+pthreadpooltest : SHOWFLAGS bin/pthreadpooltest at EXEEXT@
+
timelimit : SHOWFLAGS bin/timelimit at EXEEXT@
nsswitch : SHOWFLAGS bin/winbindd at EXEEXT@ bin/wbinfo at EXEEXT@ @WINBIND_NSS@ \
@@ -1897,6 +1903,10 @@ bin/smbconftort at EXEEXT@: $(SMBCONFTORT_OBJ) @BUILD_POPT@ $(LIBTALLOC) $(LIBTDB)
$(DYNEXP) $(LIBS) $(LDAP_LIBS) $(POPT_LIBS) \
$(LIBTALLOC_LIBS) $(LIBTDB_LIBS)
+bin/pthreadpooltest at EXEEXT@: $(PTHREADPOOLTEST_OBJ)
+ @echo Linking $@
+ @$(CC) -o $@ $(PTHREADPOOLTEST_OBJ) $(LDFLAGS) -lpthread
+
bin/masktest at EXEEXT@: $(BINARY_PREREQS) $(MASKTEST_OBJ) @BUILD_POPT@ $(LIBTALLOC) $(LIBTDB) $(LIBWBCLIENT)
@echo Linking $@
@$(CC) -o $@ $(MASKTEST_OBJ) $(LDFLAGS) $(DYNEXP) \
@@ -3446,7 +3456,7 @@ buildfarm-test:
subunit-test:
$(MAKE) test SUBUNIT_FORMATTER=cat
-SELFTEST_TESTENV = dc
+SELFTEST_TESTENV = s3dc
testenv:
$(MAKE) test SELFTEST_TESTENV=$(SELFTEST_TESTENV) TESTS="--testenv"
diff --git a/source3/configure.in b/source3/configure.in
index c951828..f4df36d 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -6646,7 +6646,9 @@ if test x"$enable_pthreadpool" = x"yes" -a x"$samba_cv_HAVE_PTHREAD" = x"yes"; t
LIBS="$LIBS $PTHREAD_LDFLAGS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
AC_DEFINE(WITH_PTHREADPOOL, 1, [Whether to include pthreadpool helpers])
- AC_SUBST(PTHREADPOOL_OBJ, "lib/pthreadpool.o")
+ AC_SUBST(PTHREADPOOL_OBJ, "lib/pthreadpool/pthreadpool.o")
+ PTHREADPOOLTEST="bin/pthreadpooltest\$(EXEEXT)"
+ AC_SUBST(PTHREADPOOLTEST)
fi
#################################################
diff --git a/source3/include/pthreadpool.h b/source3/include/pthreadpool.h
deleted file mode 100644
index 7ef7ddf..0000000
--- a/source3/include/pthreadpool.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * threadpool implementation based on pthreads
- * Copyright (C) Volker Lendecke 2009
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __PTHREADPOOL_H__
-#define __PTHREADPOOL_H__
-
-struct pthreadpool;
-
-int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult);
-int pthreadpool_destroy(struct pthreadpool *pool);
-
-/*
- * Add a job to a pthreadpool.
- */
-int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
- void (*fn)(void *private_data), void *private_data);
-
-/*
- * Get the signalling fd out of a thread pool. This fd will become readable
- * when a job is finished. The job that finished can be retrieved via
- * pthreadpool_finished_job().
- */
-int pthreadpool_sig_fd(struct pthreadpool *pool);
-int pthreadpool_finished_job(struct pthreadpool *pool);
-
-#endif
diff --git a/source3/lib/fncall.c b/source3/lib/fncall.c
index e810b68..91377e0 100644
--- a/source3/lib/fncall.c
+++ b/source3/lib/fncall.c
@@ -21,7 +21,7 @@
#if WITH_PTHREADPOOL
-#include "pthreadpool.h"
+#include "lib/pthreadpool/pthreadpool.h"
struct fncall_state {
struct fncall_context *ctx;
@@ -86,7 +86,7 @@ struct fncall_context *fncall_context_init(TALLOC_CTX *mem_ctx,
}
talloc_set_destructor(ctx, fncall_context_destructor);
- ctx->sig_fd = pthreadpool_sig_fd(ctx->pool);
+ ctx->sig_fd = pthreadpool_signal_fd(ctx->pool);
if (ctx->sig_fd == -1) {
TALLOC_FREE(ctx);
return NULL;
diff --git a/source3/lib/pthreadpool/Makefile b/source3/lib/pthreadpool/Makefile
new file mode 100644
index 0000000..48626bd
--- /dev/null
+++ b/source3/lib/pthreadpool/Makefile
@@ -0,0 +1,9 @@
+all: tests
+
+CFLAGS=-O3 -g -Wall
+
+pthreadpool.o: pthreadpool.c pthreadpool.h
+ gcc -c -O3 -o pthreadpool.o pthreadpool.c -I../../..
+
+tests: tests.o pthreadpool.o
+ gcc -o tests tests.o pthreadpool.o -lpthread
\ No newline at end of file
diff --git a/source3/lib/pthreadpool.c b/source3/lib/pthreadpool/pthreadpool.c
similarity index 70%
rename from source3/lib/pthreadpool.c
rename to source3/lib/pthreadpool/pthreadpool.c
index b62bab0..2a75a52 100644
--- a/source3/lib/pthreadpool.c
+++ b/source3/lib/pthreadpool/pthreadpool.c
@@ -26,8 +26,10 @@
#include <signal.h>
#include <assert.h>
#include <fcntl.h>
+#include <sys/time.h>
#include "pthreadpool.h"
+#include "lib/util/dlinklist.h"
struct pthreadpool_job {
struct pthreadpool_job *next;
@@ -38,6 +40,11 @@ struct pthreadpool_job {
struct pthreadpool {
/*
+ * List pthreadpools for fork safety
+ */
+ struct pthreadpool *prev, *next;
+
+ /*
* Control access to this struct
*/
pthread_mutex_t mutex;
@@ -85,6 +92,12 @@ struct pthreadpool {
pthread_t exited[1]; /* We alloc more */
};
+static pthread_mutex_t pthreadpools_mutex = PTHREAD_MUTEX_INITIALIZER;
+static struct pthreadpool *pthreadpools = NULL;
+static pthread_once_t pthreadpool_atfork_initialized = PTHREAD_ONCE_INIT;
+
+static void pthreadpool_prep_atfork(void);
+
/*
* Initialize a thread pool
*/
@@ -95,13 +108,21 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult)
size_t size;
int ret;
- size = sizeof(struct pthreadpool) + max_threads * sizeof(pthread_t);
+ size = sizeof(struct pthreadpool)
+ + (max_threads-1) * sizeof(pthread_t);
pool = (struct pthreadpool *)malloc(size);
if (pool == NULL) {
return ENOMEM;
}
+ ret = pipe(pool->sig_pipe);
+ if (ret == -1) {
+ int err = errno;
+ free(pool);
+ return err;
+ }
+
ret = pthread_mutex_init(&pool->mutex, NULL);
if (ret != 0) {
free(pool);
@@ -121,44 +142,117 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult)
pool->num_exited = 0;
pool->max_threads = max_threads;
pool->num_idle = 0;
- pool->sig_pipe[0] = -1;
- pool->sig_pipe[1] = -1;
+
+ ret = pthread_mutex_lock(&pthreadpools_mutex);
+ if (ret != 0) {
+ pthread_cond_destroy(&pool->condvar);
+ pthread_mutex_destroy(&pool->mutex);
+ free(pool);
+ return ret;
+ }
+ DLIST_ADD(pthreadpools, pool);
+
+ ret = pthread_mutex_unlock(&pthreadpools_mutex);
+ assert(ret == 0);
+
+ pthread_once(&pthreadpool_atfork_initialized, pthreadpool_prep_atfork);
*presult = pool;
+
return 0;
}
-/*
- * Create and return a file descriptor which becomes readable when a job has
- * finished
- */
-
-int pthreadpool_sig_fd(struct pthreadpool *pool)
+static void pthreadpool_prepare(void)
{
- int result, ret;
+ int ret;
+ struct pthreadpool *pool;
- ret = pthread_mutex_lock(&pool->mutex);
- if (ret != 0) {
- errno = ret;
- return -1;
+ ret = pthread_mutex_lock(&pthreadpools_mutex);
+ assert(ret == 0);
+
+ pool = pthreadpools;
+
+ while (pool != NULL) {
+ ret = pthread_mutex_lock(&pool->mutex);
+ assert(ret == 0);
+ pool = pool->next;
}
+}
+
+static void pthreadpool_parent(void)
+{
+ int ret;
+ struct pthreadpool *pool;
+
+ pool = DLIST_TAIL(pthreadpools);
+
+ while (1) {
+ ret = pthread_mutex_unlock(&pool->mutex);
+ assert(ret == 0);
- if (pool->sig_pipe[0] != -1) {
- result = pool->sig_pipe[0];
- goto done;
+ if (pool == pthreadpools) {
+ break;
+ }
+ pool = pool->prev;
}
- ret = pipe(pool->sig_pipe);
- if (ret == -1) {
- result = -1;
- goto done;
+ ret = pthread_mutex_unlock(&pthreadpools_mutex);
+ assert(ret == 0);
+}
+
+static void pthreadpool_child(void)
+{
+ int ret;
+ struct pthreadpool *pool;
+
--
Samba Shared Repository
More information about the samba-cvs
mailing list