svn commit: samba r25892 - in branches/SAMBA_4_0/source/lib: replace replace/system tdb/common tdb/include tdb/tools

jra at samba.org jra at samba.org
Wed Nov 7 06:59:03 GMT 2007


Author: jra
Date: 2007-11-07 06:59:02 +0000 (Wed, 07 Nov 2007)
New Revision: 25892

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25892

Log:
Keep the tdb code in sync between 3.2.x and 4.0.
Add in the alarm fix to allow locks to exit on
alarm signal.
Sync up the changes in tools.
Jeremy.

Modified:
   branches/SAMBA_4_0/source/lib/replace/replace.h
   branches/SAMBA_4_0/source/lib/replace/system/wait.h
   branches/SAMBA_4_0/source/lib/tdb/common/io.c
   branches/SAMBA_4_0/source/lib/tdb/common/lock.c
   branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h
   branches/SAMBA_4_0/source/lib/tdb/include/tdb.h
   branches/SAMBA_4_0/source/lib/tdb/tools/tdbbackup.c
   branches/SAMBA_4_0/source/lib/tdb/tools/tdbdump.c
   branches/SAMBA_4_0/source/lib/tdb/tools/tdbtool.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/replace/replace.h
===================================================================
--- branches/SAMBA_4_0/source/lib/replace/replace.h	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/replace/replace.h	2007-11-07 06:59:02 UTC (rev 25892)
@@ -452,6 +452,10 @@
 #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

Modified: branches/SAMBA_4_0/source/lib/replace/system/wait.h
===================================================================
--- branches/SAMBA_4_0/source/lib/replace/system/wait.h	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/replace/system/wait.h	2007-11-07 06:59:02 UTC (rev 25892)
@@ -48,4 +48,8 @@
 #define SA_RESETHAND SA_ONESHOT
 #endif
 
+#if !defined(HAVE_SIG_ATOMIC_T_TYPE)
+typedef int sig_atomic_t;
 #endif
+
+#endif

Modified: branches/SAMBA_4_0/source/lib/tdb/common/io.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/io.c	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/tdb/common/io.c	2007-11-07 06:59:02 UTC (rev 25892)
@@ -94,7 +94,7 @@
 			/* try once more */
 			TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: wrote only "
 				 "%d of %d bytes at %d, trying once more\n",
-				 written, len, off));
+				 (int)written, len, off));
 			errno = ENOSPC;
 			written = pwrite(tdb->fd, (void *)((char *)buf+written),
 					 len-written,
@@ -274,11 +274,13 @@
 			return -1;
 		} else if (written == -1) {
 			TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write of "
-				"%d bytes failed (%s)\n", n, strerror(errno)));
+				 "%d bytes failed (%s)\n", (int)n,
+				 strerror(errno)));
 			return -1;
 		} else if (written != n) {
 			TDB_LOG((tdb, TDB_DEBUG_WARNING, "expand_file: wrote "
-				"only %d of %d bytes - retrying\n", written,n));
+				 "only %d of %d bytes - retrying\n", (int)written,
+				 (int)n));
 		}
 		addition -= written;
 		size += written;

Modified: branches/SAMBA_4_0/source/lib/tdb/common/lock.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/lock.c	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/tdb/common/lock.c	2007-11-07 06:59:02 UTC (rev 25892)
@@ -29,6 +29,11 @@
 
 #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.
 
@@ -60,6 +65,13 @@
 
 	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) {

Modified: branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h	2007-11-07 06:59:02 UTC (rev 25892)
@@ -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
@@ -162,6 +163,7 @@
 	int page_size;
 	int max_dead_records;
 	bool have_transaction_lock;
+	volatile sig_atomic_t *interrupt_sig_ptr;
 };
 
 

Modified: branches/SAMBA_4_0/source/lib/tdb/include/tdb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/include/tdb.h	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/tdb/include/tdb.h	2007-11-07 06:59:02 UTC (rev 25892)
@@ -147,6 +147,8 @@
 int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key);
 int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key);
 
+void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *sigptr);
+
 /* Debug functions. Not used in production. */
 void tdb_dump_all(struct tdb_context *tdb);
 int tdb_printfreelist(struct tdb_context *tdb);

Modified: branches/SAMBA_4_0/source/lib/tdb/tools/tdbbackup.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/tools/tdbbackup.c	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/tdb/tools/tdbbackup.c	2007-11-07 06:59:02 UTC (rev 25892)
@@ -44,6 +44,7 @@
 #include "system/locale.h"
 #include "system/time.h"
 #include "system/filesys.h"
+#include "system/wait.h"
 #include "tdb.h"
 
 #ifdef HAVE_GETOPT_H

Modified: branches/SAMBA_4_0/source/lib/tdb/tools/tdbdump.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/tools/tdbdump.c	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/tdb/tools/tdbdump.c	2007-11-07 06:59:02 UTC (rev 25892)
@@ -21,6 +21,7 @@
 #include "system/locale.h"
 #include "system/time.h"
 #include "system/filesys.h"
+#include "system/wait.h"
 #include "tdb.h"
 
 static void print_data(TDB_DATA d)

Modified: branches/SAMBA_4_0/source/lib/tdb/tools/tdbtool.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/tools/tdbtool.c	2007-11-07 05:35:16 UTC (rev 25891)
+++ branches/SAMBA_4_0/source/lib/tdb/tools/tdbtool.c	2007-11-07 06:59:02 UTC (rev 25892)
@@ -24,6 +24,7 @@
 #include "system/locale.h"
 #include "system/time.h"
 #include "system/filesys.h"
+#include "system/wait.h"
 #include "tdb.h"
 
 static int do_command(void);
@@ -34,6 +35,7 @@
 char *line;
 TDB_DATA iterate_kbuf;
 char cmdline[1024];
+static int disable_mmap;
 
 enum commands {
 	CMD_CREATE_TDB,
@@ -50,6 +52,8 @@
 	CMD_LIST_HASH_FREE,
 	CMD_LIST_FREE,
 	CMD_INFO,
+	CMD_MMAP,
+	CMD_SPEED,
 	CMD_FIRST,
 	CMD_NEXT,
 	CMD_SYSTEM,
@@ -77,6 +81,8 @@
 	{"list",	CMD_LIST_HASH_FREE},
 	{"free",	CMD_LIST_FREE},
 	{"info",	CMD_INFO},
+	{"speed",	CMD_SPEED},
+	{"mmap",	CMD_MMAP},
 	{"first",	CMD_FIRST},
 	{"1",		CMD_FIRST},
 	{"next",	CMD_NEXT},
@@ -87,6 +93,20 @@
 	{NULL,		CMD_HELP}
 };
 
+struct timeval tp1,tp2;
+
+static void _start_timer(void)
+{
+	gettimeofday(&tp1,NULL);
+}
+
+static double _end_timer(void)
+{
+	gettimeofday(&tp2,NULL);
+	return((tp2.tv_sec - tp1.tv_sec) + 
+	       (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
+}
+
 /* a tdb tool for manipulating a tdb database */
 
 static TDB_CONTEXT *tdb;
@@ -175,7 +195,7 @@
 static void create_tdb(const char *tdbname)
 {
 	if (tdb) tdb_close(tdb);
-	tdb = tdb_open(tdbname, 0, TDB_CLEAR_IF_FIRST,
+	tdb = tdb_open(tdbname, 0, TDB_CLEAR_IF_FIRST | (disable_mmap?TDB_NOMMAP:0),
 		       O_RDWR | O_CREAT | O_TRUNC, 0600);
 	if (!tdb) {
 		printf("Could not create %s: %s\n", tdbname, strerror(errno));
@@ -185,7 +205,7 @@
 static void open_tdb(const char *tdbname)
 {
 	if (tdb) tdb_close(tdb);
-	tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600);
+	tdb = tdb_open(tdbname, 0, disable_mmap?TDB_NOMMAP:0, O_RDWR, 0600);
 	if (!tdb) {
 		printf("Could not open %s: %s\n", tdbname, strerror(errno));
 	}
@@ -365,6 +385,31 @@
 		printf("%d records totalling %d bytes\n", count, total_bytes);
 }
 
+static void speed_tdb(const char *tlimit)
+{
+	unsigned timelimit = tlimit?atoi(tlimit):0;
+	double t;
+	int ops=0;
+	if (timelimit == 0) timelimit = 10;
+	printf("Testing traverse speed for %u seconds\n", timelimit);
+	_start_timer();
+	while ((t=_end_timer()) < timelimit) {
+		tdb_traverse(tdb, traverse_fn, NULL);
+		printf("%10.3f ops/sec\r", (++ops)/t);
+	}
+	printf("\n");
+}
+
+static void toggle_mmap(void)
+{
+	disable_mmap = !disable_mmap;
+	if (disable_mmap) {
+		printf("mmap is disabled\n");
+	} else {
+		printf("mmap is enabled\n");
+	}
+}
+
 static char *tdb_getline(const char *prompt)
 {
 	static char thisline[1024];
@@ -493,6 +538,12 @@
 	    case CMD_INFO:
 		info_tdb();
 		return 0;
+	    case CMD_SPEED:
+		speed_tdb(arg1);
+		return 0;
+	    case CMD_MMAP:
+		toggle_mmap();
+		return 0;
 	    case CMD_FIRST:
 		bIterate = 1;
 		first_record(tdb, &iterate_kbuf);



More information about the samba-cvs mailing list