[SCM] Samba Shared Repository - branch v3-2-test updated -
initial-v3-2-unstable-218-gab11c00
Jeremy Allison
jra at samba.org
Wed Nov 7 06:57:46 GMT 2007
The branch, v3-2-test has been updated
via ab11c0055761e97ba32a8c3ec4fa6f8763a262cd (commit)
via ef8da1698371c95495add53df81a978df709c88d (commit)
from 47640fb20e42f226e7ea104076fd52547bfe1abb (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit ab11c0055761e97ba32a8c3ec4fa6f8763a262cd
Author: Jeremy Allison <jra at samba.org>
Date: Tue Nov 6 22:57:35 2007 -0800
Keep the tdb code in sync with Samba4.
Mainly this is the svn changes :
------------------------------------------------------------------------
r23238 | tridge | 2007-05-30 01:15:49 -0700 (Wed, 30 May 2007) | 6 lines
merged transaction lock changes from ctdb
this ensures that having the global lock also implies the transaction
lock
------------------------------------------------------------------------
r22832 | tridge | 2007-05-13 18:00:06 -0700 (Sun, 13 May 2007) | 3 lines
merged the latest tdb changes from ctdb to Samba4
Jeremy.
commit ef8da1698371c95495add53df81a978df709c88d
Author: Jeremy Allison <jra at samba.org>
Date: Tue Nov 6 21:47:57 2007 -0800
Fix bug where tdb lock call interrupted with
an alarm sig would not terminate and could lead
to runaway smbd processes.
Thanks to Dave Daugherty @ Centrify for pointing
this out to us.
Jeremy.
-----------------------------------------------------------------------
Summary of changes:
source/lib/replace/replace.h | 4 +
source/lib/replace/system/wait.h | 4 +
source/lib/tdb/Makefile.in | 55 +++++++++----
source/lib/tdb/common/lock.c | 159 ++++++++++++++++++++++++++++++++---
source/lib/tdb/common/tdb.c | 33 ++++++--
source/lib/tdb/common/tdb_private.h | 5 +
source/lib/tdb/common/transaction.c | 9 +-
source/lib/tdb/common/traverse.c | 14 +--
source/lib/tdb/configure.ac | 4 +
source/lib/tdb/include/tdb.h | 11 +++
source/lib/tdb/libtdb.m4 | 12 ++-
source/lib/tdb/tdb.pc.in | 2 +-
source/lib/tdb/tools/tdbbackup.c | 1 +
source/lib/tdb/tools/tdbdump.c | 1 +
source/lib/tdb/tools/tdbtest.c | 2 +-
source/lib/tdb/tools/tdbtool.c | 1 +
source/lib/tdb/tools/tdbtorture.c | 2 +-
source/lib/util_tdb.c | 2 +
18 files changed, 267 insertions(+), 54 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/lib/replace/replace.h b/source/lib/replace/replace.h
index e42d5ff..55ed2e9 100644
--- a/source/lib/replace/replace.h
+++ b/source/lib/replace/replace.h
@@ -452,6 +452,10 @@ typedef int bool;
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
+#if !defined(HAVE_VOLATILE)
+#define volatile
+#endif
+
/**
this is a warning hack. The idea is to use this everywhere that we
get the "discarding const" warning from gcc. That doesn't actually
diff --git a/source/lib/replace/system/wait.h b/source/lib/replace/system/wait.h
index de94cf0..5784b1a 100644
--- a/source/lib/replace/system/wait.h
+++ b/source/lib/replace/system/wait.h
@@ -48,4 +48,8 @@
#define SA_RESETHAND SA_ONESHOT
#endif
+#if !defined(HAVE_SIG_ATOMIC_T_TYPE)
+typedef int sig_atomic_t;
+#endif
+
#endif
diff --git a/source/lib/tdb/Makefile.in b/source/lib/tdb/Makefile.in
index b2f42ea..e1ecbb3 100644
--- a/source/lib/tdb/Makefile.in
+++ b/source/lib/tdb/Makefile.in
@@ -12,10 +12,15 @@ libdir = @libdir@
VPATH = @srcdir@:@libreplacedir@
srcdir = @srcdir@
builddir = @builddir@
-CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/include -Iinclude -I at libreplacedir@
+CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/include -Iinclude
CFLAGS = $(CPPFLAGS) @CFLAGS@
LDFLAGS = @LDFLAGS@
EXEEXT = @EXEEXT@
+SHLD_FLAGS = @SHLD_FLAGS@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PICFLAG = @PICFLAG@
+SONAMEFLAG = @SONAMEFLAG@
+SHLIBEXT = @SHLIBEXT@
.PHONY: test
@@ -23,11 +28,14 @@ PROGS = bin/tdbtool$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT)
PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbtorture$(EXEEXT)
ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL)
-TDB_OBJ = @TDBOBJ@ @LIBREPLACEOBJ@
+TDB_OBJ = @TDB_OBJ@ @LIBREPLACEOBJ@
DIRS = bin common tools
-all: showflags dirs $(PROGS)
+SONAME = libtdb.$(SHLIBEXT).1
+SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION)
+
+all: showflags dirs $(PROGS) $(SOLIB) libtdb.a
showflags:
@echo 'tdb will be compiled with flags:'
@@ -36,39 +44,53 @@ showflags:
@echo ' LDFLAGS = $(LDFLAGS)'
@echo ' LIBS = $(LIBS)'
+.SUFFIXES: .c .o
+
.c.o:
@echo Compiling $*.c
@mkdir -p `dirname $@`
- @$(CC) $(CFLAGS) -c $< -o $@
+ @$(CC) $(PICFLAG) $(CFLAGS) -c $< -o $@
dirs:
@mkdir -p $(DIRS)
install: all
- mkdir -p $(bindir)
- mkdir -p $(includedir)
- mkdir -p $(libdir)
- mkdir -p $(libdir)/pkgconfig
- cp $(PROGS) $(bindir)
- cp $(srcdir)/include/tdb.h $(includedir)
- cp tdb.pc $(libdir)/pkgconfig
+ mkdir -p $(DESTDIR)$(bindir)
+ mkdir -p $(DESTDIR)$(includedir)
+ mkdir -p $(DESTDIR)$(libdir)
+ mkdir -p $(DESTDIR)$(libdir)/pkgconfig
+ cp $(PROGS) $(DESTDIR)$(bindir)
+ cp $(srcdir)/include/tdb.h $(DESTDIR)$(includedir)
+ cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig
+ cp libtdb.a $(SOLIB) $(DESTDIR)$(libdir)
libtdb.a: $(TDB_OBJ)
ar -rv libtdb.a $(TDB_OBJ)
-bin/tdbtest$(EXEEXT): tools/tdbtest.o libtdb.a
+libtdb.(SHLIBEXT): $(SOLIB)
+ ln -s $< $@
+
+$(SONAME): $(SOLIB)
+ ln -s $< $@
+
+$(SOLIB): $(TDB_OBJ)
+ $(CC) $(SHLD_FLAGS) $(SONAMEFLAG)$(SONAME) -o $@ $^
+
+TDB_LIB = libtdb.a
+
+bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm
-bin/tdbtool$(EXEEXT): tools/tdbtool.o libtdb.a
+bin/tdbtool$(EXEEXT): tools/tdbtool.o $(TDB_LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb
-bin/tdbtorture$(EXEEXT): tools/tdbtorture.o libtdb.a
+bin/tdbtorture$(EXEEXT): tools/tdbtorture.o $(TDB_LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb
-bin/tdbdump$(EXEEXT): tools/tdbdump.o libtdb.a
+bin/tdbdump$(EXEEXT): tools/tdbdump.o $(TDB_LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb
-bin/tdbbackup$(EXEEXT): tools/tdbbackup.o libtdb.a
+bin/tdbbackup$(EXEEXT): tools/tdbbackup.o $(TDB_LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb
test: bin/tdbtorture$(EXEEXT)
@@ -79,6 +101,7 @@ installcheck: test install
clean:
rm -f $(ALL_PROGS) *.o *.a common/*.o tools/*.o tdb.pc
rm -f test.db test.tdb torture.tdb test.gdbm
+ rm -f $(SONAME) $(SOLIB) libtdb.a
distclean: clean
rm -f *~ */*~
diff --git a/source/lib/tdb/common/lock.c b/source/lib/tdb/common/lock.c
index 22896f5..e3fe888 100644
--- a/source/lib/tdb/common/lock.c
+++ b/source/lib/tdb/common/lock.c
@@ -27,6 +27,13 @@
#include "tdb_private.h"
+#define TDB_MARK_LOCK 0x80000000
+
+void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *ptr)
+{
+ tdb->interrupt_sig_ptr = ptr;
+}
+
/* a byte range locking function - return 0 on success
this functions locks/unlocks 1 byte at the specified offset.
@@ -58,6 +65,13 @@ int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset,
do {
ret = fcntl(tdb->fd,lck_type,&fl);
+
+ /* Check for a sigalarm break. */
+ if (ret == -1 && errno == EINTR &&
+ tdb->interrupt_sig_ptr &&
+ *tdb->interrupt_sig_ptr) {
+ break;
+ }
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
@@ -104,10 +118,13 @@ int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len)
/* lock a list in the database. list -1 is the alloc list */
-int tdb_lock(struct tdb_context *tdb, int list, int ltype)
+static int _tdb_lock(struct tdb_context *tdb, int list, int ltype, int op)
{
struct tdb_lock_type *new_lck;
int i;
+ bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+ ltype &= ~TDB_MARK_LOCK;
/* a global lock allows us to avoid per chain locks */
if (tdb->global_lock.count &&
@@ -157,10 +174,9 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype)
/* Since fcntl locks don't nest, we do a lock for the first one,
and simply bump the count for future ones */
- if (tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list,ltype,F_SETLKW,
+ if (!mark_lock &&
+ tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list, ltype, op,
0, 1)) {
- TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d "
- "ltype=%d (%s)\n", list, ltype, strerror(errno)));
return -1;
}
@@ -174,6 +190,25 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype)
return 0;
}
+/* lock a list in the database. list -1 is the alloc list */
+int tdb_lock(struct tdb_context *tdb, int list, int ltype)
+{
+ int ret;
+ ret = _tdb_lock(tdb, list, ltype, F_SETLKW);
+ if (ret) {
+ TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d "
+ "ltype=%d (%s)\n", list, ltype, strerror(errno)));
+ }
+ return ret;
+}
+
+/* lock a list in the database. list -1 is the alloc list. non-blocking lock */
+int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype)
+{
+ return _tdb_lock(tdb, list, ltype, F_SETLK);
+}
+
+
/* unlock the database: returns void because it's too late for errors. */
/* changed to return int it may be interesting to know there
has been an error --simo */
@@ -182,6 +217,9 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
int ret = -1;
int i;
struct tdb_lock_type *lck = NULL;
+ bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+ ltype &= ~TDB_MARK_LOCK;
/* a global lock allows us to avoid per chain locks */
if (tdb->global_lock.count &&
@@ -226,8 +264,12 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
* anyway.
*/
- ret = tdb->methods->tdb_brlock(tdb, FREELIST_TOP+4*list, F_UNLCK,
- F_SETLKW, 0, 1);
+ if (mark_lock) {
+ ret = 0;
+ } else {
+ ret = tdb->methods->tdb_brlock(tdb, FREELIST_TOP+4*list, F_UNLCK,
+ F_SETLKW, 0, 1);
+ }
tdb->num_locks--;
/*
@@ -254,11 +296,50 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
return ret;
}
+/*
+ get the transaction lock
+ */
+int tdb_transaction_lock(struct tdb_context *tdb, int ltype)
+{
+ if (tdb->have_transaction_lock || tdb->global_lock.count) {
+ return 0;
+ }
+ if (tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, ltype,
+ F_SETLKW, 0, 1) == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_lock: failed to get transaction lock\n"));
+ tdb->ecode = TDB_ERR_LOCK;
+ return -1;
+ }
+ tdb->have_transaction_lock = 1;
+ return 0;
+}
+
+/*
+ release the transaction lock
+ */
+int tdb_transaction_unlock(struct tdb_context *tdb)
+{
+ int ret;
+ if (!tdb->have_transaction_lock) {
+ return 0;
+ }
+ ret = tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1);
+ if (ret == 0) {
+ tdb->have_transaction_lock = 0;
+ }
+ return ret;
+}
+
+
/* lock/unlock entire database */
-static int _tdb_lockall(struct tdb_context *tdb, int ltype)
+static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op)
{
+ bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+ ltype &= ~TDB_MARK_LOCK;
+
/* There are no locks on read-only dbs */
if (tdb->read_only || tdb->traverse_read)
return TDB_ERRCODE(TDB_ERR_LOCK, -1);
@@ -278,9 +359,12 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype)
return TDB_ERRCODE(TDB_ERR_LOCK, -1);
}
- if (tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, F_SETLKW,
+ if (!mark_lock &&
+ tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, op,
0, 4*tdb->header.hash_size)) {
- TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lockall failed (%s)\n", strerror(errno)));
+ if (op == F_SETLKW) {
+ TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lockall failed (%s)\n", strerror(errno)));
+ }
return -1;
}
@@ -290,9 +374,15 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype)
return 0;
}
+
+
/* unlock entire db */
static int _tdb_unlockall(struct tdb_context *tdb, int ltype)
{
+ bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+ ltype &= ~TDB_MARK_LOCK;
+
/* There are no locks on read-only dbs */
if (tdb->read_only || tdb->traverse_read) {
return TDB_ERRCODE(TDB_ERR_LOCK, -1);
@@ -307,7 +397,8 @@ static int _tdb_unlockall(struct tdb_context *tdb, int ltype)
return 0;
}
- if (tdb->methods->tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW,
+ if (!mark_lock &&
+ tdb->methods->tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW,
0, 4*tdb->header.hash_size)) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlockall failed (%s)\n", strerror(errno)));
return -1;
@@ -322,7 +413,25 @@ static int _tdb_unlockall(struct tdb_context *tdb, int ltype)
/* lock entire database with write lock */
int tdb_lockall(struct tdb_context *tdb)
{
- return _tdb_lockall(tdb, F_WRLCK);
+ return _tdb_lockall(tdb, F_WRLCK, F_SETLKW);
+}
+
+/* lock entire database with write lock - mark only */
+int tdb_lockall_mark(struct tdb_context *tdb)
+{
+ return _tdb_lockall(tdb, F_WRLCK | TDB_MARK_LOCK, F_SETLKW);
+}
+
+/* unlock entire database with write lock - unmark only */
+int tdb_lockall_unmark(struct tdb_context *tdb)
+{
+ return _tdb_unlockall(tdb, F_WRLCK | TDB_MARK_LOCK);
+}
+
+/* lock entire database with write lock - nonblocking varient */
+int tdb_lockall_nonblock(struct tdb_context *tdb)
+{
+ return _tdb_lockall(tdb, F_WRLCK, F_SETLK);
}
/* unlock entire database with write lock */
@@ -334,7 +443,13 @@ int tdb_unlockall(struct tdb_context *tdb)
/* lock entire database with read lock */
int tdb_lockall_read(struct tdb_context *tdb)
{
- return _tdb_lockall(tdb, F_RDLCK);
+ return _tdb_lockall(tdb, F_RDLCK, F_SETLKW);
+}
+
+/* lock entire database with read lock - nonblock varient */
+int tdb_lockall_read_nonblock(struct tdb_context *tdb)
+{
+ return _tdb_lockall(tdb, F_RDLCK, F_SETLK);
}
/* unlock entire database with read lock */
@@ -350,6 +465,26 @@ int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key)
return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
}
+/* lock/unlock one hash chain, non-blocking. This is meant to be used
+ to reduce contention - it cannot guarantee how many records will be
+ locked */
+int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
+{
+ return tdb_lock_nonblock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
+}
+
+/* mark a chain as locked without actually locking it. Warning! use with great caution! */
+int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key)
+{
+ return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK | TDB_MARK_LOCK);
+}
+
+/* unmark a chain as locked without actually locking it. Warning! use with great caution! */
+int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key)
+{
+ return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK | TDB_MARK_LOCK);
+}
+
int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
{
return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
diff --git a/source/lib/tdb/common/tdb.c b/source/lib/tdb/common/tdb.c
index 8f3c146..0e9d1db 100644
--- a/source/lib/tdb/common/tdb.c
+++ b/source/lib/tdb/common/tdb.c
@@ -30,10 +30,10 @@
TDB_DATA tdb_null;
/*
- increment the tdb sequence number if the tdb has been opened using
+ non-blocking increment of the tdb sequence number if the tdb has been opened using
the TDB_SEQNUM flag
*/
-static void tdb_increment_seqnum(struct tdb_context *tdb)
+void tdb_increment_seqnum_nonblock(struct tdb_context *tdb)
{
tdb_off_t seqnum=0;
@@ -41,16 +41,29 @@ static void tdb_increment_seqnum(struct tdb_context *tdb)
return;
}
- if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) {
- return;
- }
-
/* we ignore errors from this, as we have no sane way of
dealing with them.
*/
tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum);
seqnum++;
tdb_ofs_write(tdb, TDB_SEQNUM_OFS, &seqnum);
+}
+
+/*
+ increment the tdb sequence number if the tdb has been opened using
+ the TDB_SEQNUM flag
+*/
+static void tdb_increment_seqnum(struct tdb_context *tdb)
+{
+ if (!(tdb->flags & TDB_SEQNUM)) {
+ return;
+ }
+
+ if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) {
+ return;
+ }
+
+ tdb_increment_seqnum_nonblock(tdb);
tdb_brlock(tdb, TDB_SEQNUM_OFS, F_UNLCK, F_SETLKW, 1, 1);
}
@@ -653,3 +666,11 @@ int tdb_get_flags(struct tdb_context *tdb)
return tdb->flags;
}
+
+/*
+ enable sequence number handling on an open tdb
+*/
+void tdb_enable_seqnum(struct tdb_context *tdb)
+{
+ tdb->flags |= TDB_SEQNUM;
+}
diff --git a/source/lib/tdb/common/tdb_private.h b/source/lib/tdb/common/tdb_private.h
index d2f2c23..00bd0eb 100644
--- a/source/lib/tdb/common/tdb_private.h
+++ b/source/lib/tdb/common/tdb_private.h
@@ -28,6 +28,7 @@
#include "system/time.h"
#include "system/shmem.h"
#include "system/select.h"
+#include "system/wait.h"
#include "tdb.h"
#ifndef HAVE_GETPAGESIZE
@@ -161,6 +162,8 @@ struct tdb_context {
struct tdb_transaction *transaction;
int page_size;
int max_dead_records;
+ bool have_transaction_lock;
+ volatile sig_atomic_t *interrupt_sig_ptr;
};
@@ -172,6 +175,8 @@ void tdb_mmap(struct tdb_context *tdb);
int tdb_lock(struct tdb_context *tdb, int list, int ltype);
--
Samba Shared Repository
More information about the samba-cvs
mailing list