svn commit: samba r16916 - in branches/SAMBA_4_0/source/lib: . ldb/ldb_tdb tdb/common tdb/include tdb/tools

abartlet at samba.org abartlet at samba.org
Mon Jul 10 12:51:36 GMT 2006


Author: abartlet
Date: 2006-07-10 12:51:36 +0000 (Mon, 10 Jul 2006)
New Revision: 16916

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

Log:
Implement metze's proposed changes to the tdb logging API.  

This clearly links the log function with its private pointer, and
makes the argument list for tdb_open_ex a bit shorter.

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/lib/db_wrap.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
   branches/SAMBA_4_0/source/lib/tdb/common/open.c
   branches/SAMBA_4_0/source/lib/tdb/common/tdb.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/tdbtool.c
   branches/SAMBA_4_0/source/lib/tdb/tools/tdbtorture.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/db_wrap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/db_wrap.c	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/db_wrap.c	2006-07-10 12:51:36 UTC (rev 16916)
@@ -200,6 +200,8 @@
 			       int open_flags, mode_t mode)
 {
 	struct tdb_wrap *w;
+	struct tdb_logging_context log_ctx;
+	log_ctx.log_fn = tdb_wrap_log;
 
 	for (w=tdb_list;w;w=w->next) {
 		if (strcmp(name, w->name) == 0) {
@@ -215,7 +217,7 @@
 	w->name = talloc_strdup(w, name);
 
 	w->tdb = tdb_open_ex(name, hash_size, tdb_flags, 
-			     open_flags, mode, tdb_wrap_log, NULL, NULL);
+			     open_flags, mode, &log_ctx, NULL);
 	if (w->tdb == NULL) {
 		talloc_free(w);
 		return NULL;

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb_wrap.c	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb_wrap.c	2006-07-10 12:51:36 UTC (rev 16916)
@@ -63,7 +63,7 @@
 {
 	va_list ap;
 	const char *name = tdb_name(tdb);
-	struct ldb_context *ldb = talloc_get_type(tdb_logging_private(tdb), struct ldb_context);
+	struct ldb_context *ldb = talloc_get_type(tdb_get_logging_private(tdb), struct ldb_context);
 	enum ldb_debug_level ldb_level;
 	char *message; 
 	va_start(ap, fmt);
@@ -106,6 +106,9 @@
 {
 	struct ltdb_wrap *w;
 	struct stat st;
+	struct tdb_logging_context log_ctx;
+	log_ctx.log_fn = ltdb_log_fn;
+	log_ctx.log_private = ldb;
 
 	if (stat(path, &st) == 0) {
 		for (w=tdb_list;w;w=w->next) {
@@ -121,7 +124,7 @@
 		return NULL;
 	}
 
-	w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, ltdb_log_fn, ldb, NULL);
+	w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL);
 	if (w->tdb == NULL) {
 		talloc_free(w);
 		return NULL;

Modified: branches/SAMBA_4_0/source/lib/tdb/common/open.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/open.c	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/tdb/common/open.c	2006-07-10 12:51:36 UTC (rev 16916)
@@ -119,7 +119,7 @@
 struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
 		      int open_flags, mode_t mode)
 {
-	return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL, NULL);
+	return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL);
 }
 
 /* a default logging function */
@@ -131,7 +131,7 @@
 
 struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
 				int open_flags, mode_t mode,
-				tdb_log_func log_fn, void *log_private,
+				const struct tdb_logging_context *log_ctx,
 				tdb_hash_func hash_fn)
 {
 	struct tdb_context *tdb;
@@ -151,8 +151,12 @@
 	tdb->map_ptr = NULL;
 	tdb->flags = tdb_flags;
 	tdb->open_flags = open_flags;
-	tdb->log_fn = log_fn?log_fn:null_log_fn;
-	tdb->log_private = log_fn?log_private:NULL;
+	if (log_ctx) {
+		tdb->log = *log_ctx;
+	} else {
+		tdb->log.log_fn = null_log_fn;
+		tdb->log.log_private = NULL;
+	}
 	tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash;
 
 	/* cache the page size */
@@ -366,15 +370,15 @@
 }
 
 /* register a loging function */
-void tdb_logging_function(struct tdb_context *tdb, tdb_log_func log_fn, void *log_private)
+void tdb_set_logging_function(struct tdb_context *tdb,
+                              const struct tdb_logging_context *log)
 {
-	tdb->log_fn = log_fn?log_fn:null_log_fn;
-	tdb->log_private = log_fn?log_private:NULL;
+        tdb->log = *log;
 }
 
-void *tdb_logging_private(struct tdb_context *tdb)
+void *tdb_get_logging_private(struct tdb_context *tdb)
 {
-	return tdb->log_private;
+	return tdb->log.log_private;
 }
 
 /* reopen a tdb - this can be used after a fork to ensure that we have an independent

Modified: branches/SAMBA_4_0/source/lib/tdb/common/tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/tdb.c	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/tdb/common/tdb.c	2006-07-10 12:51:36 UTC (rev 16916)
@@ -402,7 +402,7 @@
 */
 tdb_log_func tdb_log_fn(struct tdb_context *tdb)
 {
-	return tdb->log_fn;
+	return tdb->log.log_fn;
 }
 
 

Modified: branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h	2006-07-10 12:51:36 UTC (rev 16916)
@@ -101,7 +101,7 @@
 /* NB assumes there is a local variable called "tdb" that is the
  * current context, also takes doubly-parenthesized print-style
  * argument. */
-#define TDB_LOG(x) tdb->log_fn x
+#define TDB_LOG(x) tdb->log.log_fn x
 
 /* lock offsets */
 #define GLOBAL_LOCK      0
@@ -197,8 +197,7 @@
 	struct tdb_context *next; /* all tdbs to avoid multiple opens */
 	dev_t device;	/* uniquely identifies this tdb */
 	ino_t inode;	/* uniquely identifies this tdb */
-	tdb_log_func log_fn;
-	void *log_private;
+	struct tdb_logging_context log;
 	unsigned int (*hash_fn)(TDB_DATA *key);
 	int open_flags; /* flags used in the open - needed by reopen */
 	unsigned int num_locks; /* number of chain locks held */

Modified: branches/SAMBA_4_0/source/lib/tdb/include/tdb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/include/tdb.h	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/tdb/include/tdb.h	2006-07-10 12:51:36 UTC (rev 16916)
@@ -83,17 +83,21 @@
 typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4);
 typedef unsigned int (*tdb_hash_func)(TDB_DATA *key);
 
+struct tdb_logging_context {
+        tdb_log_func log_fn;
+        void *log_private;
+};
+
 struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
 		      int open_flags, mode_t mode);
 struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
 			 int open_flags, mode_t mode,
-			 tdb_log_func log_fn, void *log_private,
+			 const struct tdb_logging_context *log_ctx,
 			 tdb_hash_func hash_fn);
-void *tdb_logging_private(struct tdb_context *tdb);
 
 int tdb_reopen(struct tdb_context *tdb);
 int tdb_reopen_all(int parent_longlived);
-void tdb_logging_function(struct tdb_context *tdb, tdb_log_func log_fn, void *log_private);
+void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log);
 enum TDB_ERROR tdb_error(struct tdb_context *tdb);
 const char *tdb_errorstr(struct tdb_context *tdb);
 TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key);

Modified: branches/SAMBA_4_0/source/lib/tdb/tools/tdbtool.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/tools/tdbtool.c	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/tdb/tools/tdbtool.c	2006-07-10 12:51:36 UTC (rev 16916)
@@ -183,6 +183,9 @@
 
 static void create_tdb(void)
 {
+	struct tdb_logging_context log_ctx;
+	log_ctx.log_fn = tdb_log;
+
 	char *tok = get_token(1);
 	if (!tok) {
 		help();
@@ -190,7 +193,7 @@
 	}
 	if (tdb) tdb_close(tdb);
 	tdb = tdb_open_ex(tok, 0, TDB_CLEAR_IF_FIRST,
-			  O_RDWR | O_CREAT | O_TRUNC, 0600, tdb_log, NULL, NULL);
+			  O_RDWR | O_CREAT | O_TRUNC, 0600, log_ctx, NULL);
 	if (!tdb) {
 		printf("Could not create %s: %s\n", tok, strerror(errno));
 	}

Modified: branches/SAMBA_4_0/source/lib/tdb/tools/tdbtorture.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/tools/tdbtorture.c	2006-07-10 12:35:27 UTC (rev 16915)
+++ branches/SAMBA_4_0/source/lib/tdb/tools/tdbtorture.c	2006-07-10 12:51:36 UTC (rev 16916)
@@ -237,6 +237,9 @@
 	extern char *optarg;
 	pid_t *pids;
 
+	struct tdb_logging_context log_ctx;
+	log_ctx.log_fn = tdb_log;
+
 	while ((c = getopt(argc, argv, "n:l:s:H:h")) != -1) {
 		switch (c) {
 		case 'n':
@@ -266,7 +269,7 @@
 	}
 
 	db = tdb_open_ex("torture.tdb", hash_size, TDB_CLEAR_IF_FIRST, 
-			 O_RDWR | O_CREAT, 0600, tdb_log, NULL, NULL);
+			 O_RDWR | O_CREAT, 0600, &log_ctx, NULL);
 	if (!db) {
 		fatal("db open failed");
 	}



More information about the samba-cvs mailing list