[PATCHES v4] Logging to multiple debug backend (was Re: [PATCHES v3] Logging to multiple debug backend)

Christof Schmitt cs at samba.org
Mon Mar 23 11:23:40 MDT 2015


On Mon, Mar 23, 2015 at 02:13:55PM +1100, Amitay Isaacs wrote:
>      Ok, i learned something new about the waf framework. I initially added
>      the build checks to the top-level script, since that one has the systemd
>      checks. Since systemd is only used in lib/util, those checks can be
>      moved to lib/util, and then it also makes sense to add the new checks in
>      that directory.
> 
>    Much better, now that systemd/lttng checks are in lib/util.
> 
>      Here is the updated patch series for review again. I hope that we are
>      getting closer :-)
> 
>    Two minor fixes.  You can squash them with the appropriate patches.
> 
>    1. Move the #ifdef outside the conditional.  If the condition is false,
>    there is no code to execute. 

The patches "debug: Add syslog backend" and "debug: Set backends from
logging parameter in smb.conf" remove the code with the ifdefs from
setup logging. I squashed the patch with the code removal.

>    2. Since you moved the removal of FORMAT_BUFR_MAX as the first patch,
>    replace FORMAT_BUFR_MAX with FORMAT_BUFR_SIZE-1

That was an oversight, i squashed the change from FORMAT_BUFR_MAX to
FORMAT_BUFR_SIZE-1 with the wrong patch. That has been fixed now.

> 
>    Because of the 1st fix, some of the subsequent patches are slightly
>    different.
> 
>    Reviewed-by: me.

Thank you. Attached is the patch series again, with the above changes
and your reviewed-by tag. I will push this later today, unless someone
else does it first.

Christof
-------------- next part --------------
From 06ff26d40ad8d6486f7b7b7d075afa51f5ffb8f2 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 20 Mar 2015 12:13:14 -0700
Subject: [PATCH 01/22] build: Move systemd checks to lib/util

Only lib/util uses the systemd library, so it makes sense to have the
checks there. This also removes the need for the ctdb build script to
specify an empty tag for the systemd library.

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 ctdb/wscript               |    2 --
 lib/util/wscript           |    8 ++++++++
 lib/util/wscript_configure |   14 ++++++++++++++
 wscript                    |   22 ----------------------
 4 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/ctdb/wscript b/ctdb/wscript
index 5957f16..f0b68cd 100755
--- a/ctdb/wscript
+++ b/ctdb/wscript
@@ -212,8 +212,6 @@ def configure(conf):
             conf.ADD_EXTRA_INCLUDES('#ctdb')
         conf.ADD_EXTRA_INCLUDES('#lib #lib/replace')
 
-        conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
-
         del(conf.env.defines['PYTHONDIR'])
         del(conf.env.defines['PYTHONARCHDIR'])
 
diff --git a/lib/util/wscript b/lib/util/wscript
index d296e75..2371689 100644
--- a/lib/util/wscript
+++ b/lib/util/wscript
@@ -1,3 +1,11 @@
 def set_options(opt):
     ''' This is a bit strange, but disable is the flag, not enable. '''
     opt.add_option('--disable-fault-handling', action='store_true', dest='disable_fault_handling', help=('disable the fault handlers'), default=False)
+
+    opt.add_option('--with-systemd',
+                   help=("Enable systemd integration"),
+                   action='store_true', dest='enable_systemd')
+
+    opt.add_option('--without-systemd',
+                   help=("Disable systemd integration"),
+                   action='store_false', dest='enable_systemd')
diff --git a/lib/util/wscript_configure b/lib/util/wscript_configure
index bf017a5..8cf77b4 100644
--- a/lib/util/wscript_configure
+++ b/lib/util/wscript_configure
@@ -99,3 +99,17 @@ conf.CHECK_CODE('struct statvfs buf; buf.f_flags = 0',
                 headers='sys/statvfs.h',
                 local_include=False,
                 execute=False)
+
+if Options.options.enable_systemd != False:
+    conf.CHECK_CFG(package='libsystemd-daemon', args='--cflags --libs',
+                   msg='Checking for libsystemd-daemon', uselib_store="SYSTEMD-DAEMON")
+    conf.CHECK_HEADERS('systemd/sd-daemon.h', lib='systemd-daemon')
+    conf.CHECK_LIB('systemd-daemon', shlib=True)
+
+if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H') and
+    conf.CONFIG_SET('HAVE_LIBSYSTEMD_DAEMON')):
+    conf.DEFINE('HAVE_SYSTEMD', '1')
+    conf.env['ENABLE_SYSTEMD'] = True
+else:
+    conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
+    conf.undefine('HAVE_SYSTEMD')
diff --git a/wscript b/wscript
index 4e06576..146556b 100644
--- a/wscript
+++ b/wscript
@@ -69,14 +69,6 @@ def set_options(opt):
                   help=("Disable RELRO builds"),
                   action="store_false", dest='enable_relro')
 
-    opt.add_option('--with-systemd',
-                   help=("Enable systemd integration"),
-                   action='store_true', dest='enable_systemd')
-
-    opt.add_option('--without-systemd',
-                   help=("Disable systemd integration"),
-                   action='store_false', dest='enable_systemd')
-
     gr = opt.option_group('developer options')
 
     opt.tool_options('python') # options for disabling pyc or pyo compilation
@@ -212,20 +204,6 @@ def configure(conf):
                          msg="Checking compiler for full RELRO support"):
             conf.env['ENABLE_RELRO'] = True
 
-    if Options.options.enable_systemd != False:
-        conf.CHECK_CFG(package='libsystemd-daemon', args='--cflags --libs',
-                       msg='Checking for libsystemd-daemon', uselib_store="SYSTEMD-DAEMON")
-        conf.CHECK_HEADERS('systemd/sd-daemon.h', lib='systemd-daemon')
-        conf.CHECK_LIB('systemd-daemon', shlib=True)
-
-    if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H') and
-        conf.CONFIG_SET('HAVE_LIBSYSTEMD_DAEMON')):
-        conf.DEFINE('HAVE_SYSTEMD', '1')
-        conf.env['ENABLE_SYSTEMD'] = True
-    else:
-        conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
-        conf.undefine('HAVE_SYSTEMD')
-
     conf.SAMBA_CONFIG_H('include/config.h')
 
 def etags(ctx):
-- 
1.7.1


From a3a81a886c6e3aba3da3d90db73257f1ddf98ee1 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 20 Mar 2015 14:19:09 -0700
Subject: [PATCH 02/22] debug: Remove FORMAT_BUFR_MAX, use FORMAT_BUFR_SIZE - 1 instead

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 80a1c25..ba8bee1 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -37,14 +37,13 @@
 
 /* -------------------------------------------------------------------------- **
  * Defines...
- *
- *  FORMAT_BUFR_MAX - Index of the last byte of the format buffer;
- *                    format_bufr[FORMAT_BUFR_MAX] should always be reserved
- *                    for a terminating null byte.
  */
 
+/*
+ * format_bufr[FORMAT_BUFR_SIZE - 1] should always be reserved
+ * for a terminating null byte.
+ */
 #define FORMAT_BUFR_SIZE 1024
-#define FORMAT_BUFR_MAX (FORMAT_BUFR_SIZE - 1)
 
 /* -------------------------------------------------------------------------- **
  * This module implements Samba's debugging utility.
@@ -889,7 +888,7 @@ static void format_debug_text( const char *msg )
 		}
 
 		/* If there's room, copy the character to the format buffer. */
-		if( format_pos < FORMAT_BUFR_MAX )
+		if (format_pos < FORMAT_BUFR_SIZE - 1)
 			format_bufr[format_pos++] = msg[i];
 
 		/* If a newline is encountered, print & restart. */
@@ -899,7 +898,7 @@ static void format_debug_text( const char *msg )
 		/* If the buffer is full dump it out, reset it, and put out a line
 		 * continuation indicator.
 		 */
-		if( format_pos >= FORMAT_BUFR_MAX ) {
+		if (format_pos >= FORMAT_BUFR_SIZE - 1) {
 			bufr_print();
 			(void)Debug1( " +>\n" );
 		}
-- 
1.7.1


From dd8fde314783ecdfa9f15f7a54f8b9b3198c4271 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Wed, 17 Dec 2014 09:59:52 -0700
Subject: [PATCH 03/22] debug: Remove some unneeded function declarations

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |    2 +-
 lib/util/debug.h |    3 ---
 2 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index ba8bee1..c502d27 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -305,7 +305,7 @@ int debug_add_class(const char *classname)
  Utility to translate names to debug class index's (public version).
 ****************************************************************************/
 
-int debug_lookup_classname(const char *classname)
+static int debug_lookup_classname(const char *classname)
 {
 	int ndx;
 
diff --git a/lib/util/debug.h b/lib/util/debug.h
index a8a0d69..8063ace 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -236,10 +236,8 @@ struct debug_settings {
 
 void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
 
-void debug_close_dbf(void);
 void gfree_debugsyms(void);
 int debug_add_class(const char *classname);
-int debug_lookup_classname(const char *classname);
 bool debug_parse_levels(const char *params_str);
 void debug_setup_talloc_log(void);
 void debug_set_logfile(const char *name);
@@ -250,7 +248,6 @@ bool need_to_check_log_size( void );
 void check_log_size( void );
 void dbgflush( void );
 bool dbghdrclass(int level, int cls, const char *location, const char *func);
-bool dbghdr(int level, const char *location, const char *func);
 bool debug_get_output_is_stderr(void);
 bool debug_get_output_is_stdout(void);
 void debug_schedule_reopen_logs(void);
-- 
1.7.1


From e4de8a1f35beaa59e1064f3736c90544834637c0 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Tue, 24 Feb 2015 14:09:18 -0700
Subject: [PATCH 04/22] debug: Always store short version of prog_name in debug state

Storing the prog_name in the debug state is not necessary at this point,
but it will be used later.

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index c502d27..9a4e571 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -479,20 +479,23 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
 		state.logtype = new_logtype;
 	}
 	if (prog_name) {
+		const char *p = strrchr(prog_name, '/');
+
+		if (p) {
+			prog_name = p + 1;
+		}
+
 		state.prog_name = prog_name;
 	}
 	reopen_logs_internal();
 
 	if (state.logtype == DEBUG_FILE) {
 #ifdef WITH_SYSLOG
-		const char *p = strrchr(prog_name, '/');
-		if (p)
-			prog_name = p + 1;
 #ifdef LOG_DAEMON
-		openlog( prog_name, LOG_PID, SYSLOG_FACILITY );
+		openlog(state.prog_name, LOG_PID, SYSLOG_FACILITY );
 #else
 		/* for old systems that have no facility codes. */
-		openlog( prog_name, LOG_PID );
+		openlog(state.prog_name, LOG_PID );
 #endif
 #endif
 	}
-- 
1.7.1


From 1771482f4c1669397bd0997413502a7b3f398b2c Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 13:17:49 -0700
Subject: [PATCH 05/22] debug: Move logging to callback to separate function

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 9a4e571..e3725a9 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -546,6 +546,20 @@ void debug_set_callback(void *private_ptr, debug_callback_fn fn)
 	}
 }
 
+static void debug_callback_log(const char *msg, int msg_level)
+{
+	size_t msg_len = strlen(msg);
+	char msg_copy[msg_len];
+
+	if ((msg_len > 0) && (msg[msg_len-1] == '\n')) {
+		memcpy(msg_copy, msg, msg_len-1);
+		msg_copy[msg_len-1] = '\0';
+		msg = msg_copy;
+	}
+
+	state.callback(state.callback_private, msg_level, msg);
+}
+
 /**************************************************************************
  reopen the log files
  note that we now do this unconditionally
@@ -764,16 +778,7 @@ static int Debug1(const char *msg)
 	debug_count++;
 
 	if (state.logtype == DEBUG_CALLBACK) {
-		size_t msg_len = strlen(msg);
-		char msg_copy[msg_len];
-
-		if ((msg_len > 0) && (msg[msg_len-1] == '\n')) {
-			memcpy(msg_copy, msg, msg_len-1);
-			msg_copy[msg_len-1] = '\0';
-			msg = msg_copy;
-		}
-
-		state.callback(state.callback_private, current_msg_level, msg);
+		debug_callback_log(msg, current_msg_level);
 		goto done;
 	}
 
-- 
1.7.1


From 591b4cd81fe6a6f094dd696e90ac08882d8b86cf Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 13:29:48 -0700
Subject: [PATCH 06/22] debug: Move mapping from level to syslog priority to helper function

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   40 +++++++++++++++++++++++++---------------
 1 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index e3725a9..351a88c 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -102,6 +102,30 @@ static struct {
 	.fd = 2 /* stderr by default */
 };
 
+#ifdef WITH_SYSLOG
+static int debug_level_to_priority(int level)
+{
+	/*
+	 * map debug levels to syslog() priorities note that not all
+	 * DEBUG(0, ...) calls are necessarily errors
+	 */
+	static const int priority_map[4] = {
+		LOG_ERR,     /* 0 */
+		LOG_WARNING, /* 1 */
+		LOG_NOTICE,  /* 2 */
+		LOG_INFO,    /* 3 */
+	};
+	int priority;
+
+	if( level >= ARRAY_SIZE(priority_map) || level < 0)
+		priority = LOG_DEBUG;
+	else
+		priority = priority_map[level];
+
+	return priority;
+}
+#endif
+
 /* -------------------------------------------------------------------------- **
  * External variables.
  */
@@ -808,21 +832,7 @@ static int Debug1(const char *msg)
 
 #ifdef WITH_SYSLOG
 	if( current_msg_level < state.settings.syslog ) {
-		/* map debug levels to syslog() priorities
-		 * note that not all DEBUG(0, ...) calls are
-		 * necessarily errors */
-		static const int priority_map[4] = {
-			LOG_ERR,     /* 0 */
-			LOG_WARNING, /* 1 */
-			LOG_NOTICE,  /* 2 */
-			LOG_INFO,    /* 3 */
-		};
-		int     priority;
-
-		if( current_msg_level >= ARRAY_SIZE(priority_map) || current_msg_level < 0)
-			priority = LOG_DEBUG;
-		else
-			priority = priority_map[current_msg_level];
+		int priority = debug_level_to_priority(current_msg_level);
 
 		/*
 		 * Specify the facility to interoperate with other syslog
-- 
1.7.1


From d773a68f602a8fc3b0a83a2e381c50bb49d391b8 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 13:49:13 -0700
Subject: [PATCH 07/22] debug: Add infrastructure for supporting multiple backends

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |  152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 152 insertions(+), 0 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 351a88c..9eba5b8 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -127,6 +127,152 @@ static int debug_level_to_priority(int level)
 #endif
 
 /* -------------------------------------------------------------------------- **
+ * Debug backends. When logging to DEBUG_FILE, send the log entries to
+ * all active backends.
+ */
+
+static struct debug_backend {
+	const char *name;
+	int log_level;
+	int new_log_level;
+	void (*reload)(bool enabled, bool prev_enabled, const char *prog_name);
+	void (*log)(int msg_level, const char *msg, const char *msg_no_nl);
+} debug_backends[] = {
+};
+
+static struct debug_backend *debug_find_backend(const char *name)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		if (strcmp(name, debug_backends[i].name) == 0) {
+			return &debug_backends[i];
+		}
+	}
+
+	return NULL;
+}
+
+/*
+ * parse "backend[:option][@loglevel]
+ */
+static void debug_backend_parse_token(char *tok)
+{
+	char *backend_name_option, *backend_name,*backend_level, *saveptr;
+	struct debug_backend *b;
+
+	/*
+	 * First parse into backend[:option] and loglevel
+	 */
+	backend_name_option = strtok_r(tok, "@\0", &saveptr);
+	if (backend_name_option == NULL) {
+		return;
+	}
+
+	backend_level = strtok_r(NULL, "\0", &saveptr);
+
+	/*
+	 * Now parse backend[:option]
+	 */
+	backend_name = strtok_r(backend_name_option, ":\0", &saveptr);
+	if (backend_name == NULL) {
+		return;
+	}
+
+	/*
+	 * No backend is using the option yet.
+	 */
+#if 0
+	backend_option = strtok_r(NULL, "\0", &saveptr);
+#endif
+
+	/*
+	 * Find and update backend
+	 */
+	b = debug_find_backend(backend_name);
+	if (b == NULL) {
+		return;
+	}
+
+	if (backend_level == NULL) {
+		b->new_log_level = MAX_DEBUG_LEVEL;
+	} else {
+		b->new_log_level = atoi(backend_level);
+	}
+}
+
+/*
+ * parse "backend1[:option1][@loglevel1] backend2[option2][@loglevel2] ... "
+ * and enable/disable backends accordingly
+ */
+static void debug_set_backends(const char *param)
+{
+	size_t str_len = strlen(param);
+	char str[str_len+1];
+	char *tok, *saveptr;
+	int i;
+
+	/*
+	 * initialize new_log_level to detect backends that have been
+	 * disabled
+	 */
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		debug_backends[i].new_log_level = -1;
+	}
+
+	memcpy(str, param, str_len + 1);
+
+	tok = strtok_r(str, LIST_SEP, &saveptr);
+	if (tok == NULL) {
+		return;
+	}
+
+	while (tok != NULL) {
+		debug_backend_parse_token(tok);
+		tok = strtok_r(NULL, LIST_SEP, &saveptr);
+	}
+
+	/*
+	 * Let backends react to config changes
+	 */
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		struct debug_backend *b = &debug_backends[i];
+
+		if (b->reload) {
+			bool enabled = b->new_log_level > -1;
+			bool previously_enabled = b->log_level > -1;
+
+			b->reload(enabled, previously_enabled, state.prog_name);
+		}
+		b->log_level = b->new_log_level;
+	}
+}
+
+static void debug_backends_log(const char *msg, int msg_level)
+{
+	char msg_no_nl[FORMAT_BUFR_SIZE];
+	int i, len;
+
+	/*
+	 * Some backends already add an extra newline, so also provide
+	 * a buffer without the newline character.
+	 */
+	len = MIN(strlen(msg), FORMAT_BUFR_SIZE - 1);
+	if (msg[len - 1] == '\n') {
+		len--;
+	}
+
+	memcpy(msg_no_nl, msg, len);
+	msg_no_nl[len] = '\0';
+
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		if (msg_level <= debug_backends[i].log_level) {
+			debug_backends[i].log(msg_level, msg, msg_no_nl);
+		}
+	}
+}
+
+/* -------------------------------------------------------------------------- **
  * External variables.
  */
 
@@ -464,6 +610,7 @@ Init debugging (one time stuff)
 
 static void debug_init(void)
 {
+	int i;
 	const char **p;
 
 	if (state.initialized)
@@ -476,6 +623,11 @@ static void debug_init(void)
 	for(p = default_classname_table; *p; p++) {
 		debug_add_class(*p);
 	}
+
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		debug_backends[i].log_level = -1;
+		debug_backends[i].new_log_level = -1;
+	}
 }
 
 /* This forces in some smb.conf derived values into the debug system.
-- 
1.7.1


From 492d0b48ce30b1a306d2129582328803dca182a4 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 14:00:02 -0700
Subject: [PATCH 08/22] debug: Add file backend

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 9eba5b8..e085aea 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -131,6 +131,13 @@ static int debug_level_to_priority(int level)
  * all active backends.
  */
 
+static void debug_file_log(int msg_level,
+			   const char *msg, const char *msg_no_nl)
+{
+	check_log_size();
+	write(state.fd, msg, strlen(msg));
+}
+
 static struct debug_backend {
 	const char *name;
 	int log_level;
@@ -138,6 +145,10 @@ static struct debug_backend {
 	void (*reload)(bool enabled, bool prev_enabled, const char *prog_name);
 	void (*log)(int msg_level, const char *msg, const char *msg_no_nl);
 } debug_backends[] = {
+	{
+		.name = "file",
+		.log = debug_file_log,
+	},
 };
 
 static struct debug_backend *debug_find_backend(const char *name)
-- 
1.7.1


From bb1148286877a52898a287c3b73fd35b687918a9 Mon Sep 17 00:00:00 2001
From: Amitay Isaacs <amitay at gmail.com>
Date: Mon, 23 Mar 2015 13:30:31 +1100
Subject: [PATCH 09/22] debug: Add syslog backend

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index e085aea..35deb79 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -138,6 +138,42 @@ static void debug_file_log(int msg_level,
 	write(state.fd, msg, strlen(msg));
 }
 
+#ifdef WITH_SYSLOG
+static void debug_syslog_reload(bool enabled, bool previously_enabled,
+				const char *prog_name)
+{
+	if (enabled && !previously_enabled) {
+#ifdef LOG_DAEMON
+		openlog(prog_name, LOG_PID, SYSLOG_FACILITY);
+#else
+		/* for old systems that have no facility codes. */
+		openlog(prog_name, LOG_PID );
+#endif
+		return;
+	}
+
+	if (!enabled && previously_enabled) {
+		closelog();
+	}
+}
+
+static void debug_syslog_log(int msg_level,
+			     const char *msg, const char *msg_no_nl)
+{
+	int priority;
+
+	priority = debug_level_to_priority(msg_level);
+
+	/*
+	 * Specify the facility to interoperate with other syslog
+	 * callers (vfs_full_audit for example).
+	 */
+	priority |= SYSLOG_FACILITY;
+
+	syslog(priority, "%s", msg);
+}
+#endif /* WITH_SYSLOG */
+
 static struct debug_backend {
 	const char *name;
 	int log_level;
@@ -149,6 +185,13 @@ static struct debug_backend {
 		.name = "file",
 		.log = debug_file_log,
 	},
+#ifdef WITH_SYSLOG
+	{
+		.name = "syslog",
+		.reload = debug_syslog_reload,
+		.log = debug_syslog_log,
+	},
+#endif
 };
 
 static struct debug_backend *debug_find_backend(const char *name)
@@ -676,16 +719,11 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
 	}
 	reopen_logs_internal();
 
-	if (state.logtype == DEBUG_FILE) {
 #ifdef WITH_SYSLOG
-#ifdef LOG_DAEMON
-		openlog(state.prog_name, LOG_PID, SYSLOG_FACILITY );
-#else
-		/* for old systems that have no facility codes. */
-		openlog(state.prog_name, LOG_PID );
-#endif
-#endif
+	if (state.logtype == DEBUG_FILE) {
+		debug_syslog_reload(true, false, state.prog_name);
 	}
+#endif
 }
 
 /***************************************************************************
-- 
1.7.1


From 119882e3bec4f53aaf9594ffb808dde47e059401 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 14:21:32 -0700
Subject: [PATCH 10/22] param: Add new 'logging' parameter

This parameter allows to configure multiple backends at the same time.

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 docs-xml/smbdotconf/logging/logging.xml |   37 +++++++++++++++++++++++++++++++
 lib/param/param_table.c                 |    9 +++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100644 docs-xml/smbdotconf/logging/logging.xml

diff --git a/docs-xml/smbdotconf/logging/logging.xml b/docs-xml/smbdotconf/logging/logging.xml
new file mode 100644
index 0000000..f888c46
--- /dev/null
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -0,0 +1,37 @@
+<samba:parameter name="logging"
+		 type="string"
+		 context="G"
+		 developer="1" advanced="1"
+		 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+<description>
+
+  <para>This parameter configures logging backends backends. Multiple
+    backends can be specified at the same time, with different log
+    levels for each backend. The parameter is a list of backends,
+    where each backend is specified as backend[:option][@loglevel].</para>
+
+  <para>The 'option' parameter can be used to pass backend-specific
+    options.</para>
+
+  <para>The log level for a backend is optional, if it is not set for
+    a backend, all messages are sent to this backend. The parameter
+    <smbconfoption name="log level"/> determines overall log levels,
+    while the log levels specified here define what is sent to the
+    individual backends.</para>
+
+  <para>When <smbconfoption name="logging"/> is set, it overrides the
+    <smbconfoption  name="syslog"/>  and  <smbconfoption  name="syslog
+    only"/> parameters.</para>
+
+  <para>Some backends are only available when Samba has been compiled
+  with the additional libraries. The overall list of logging backends:</para>
+
+  <itemizedlist>
+    <listitem><para><parameter moreinfo="none">syslog</parameter></para></listitem>
+    <listitem><para><parameter moreinfo="none">file</parameter></para></listitem>
+  </itemizedlist>
+
+</description>
+<value type="default"></value>
+<value type="example">syslog at 1 file</value>
+</samba:parameter>
diff --git a/lib/param/param_table.c b/lib/param/param_table.c
index 447c99b..464a7c9 100644
--- a/lib/param/param_table.c
+++ b/lib/param/param_table.c
@@ -1206,6 +1206,15 @@ struct parm_struct parm_table[] = {
 		.flags		= FLAG_ADVANCED,
 	},
 	{
+		.label		= "logging",
+		.type		= P_STRING,
+		.p_class	= P_GLOBAL,
+		.offset		= GLOBAL_VAR(logging),
+		.special	= NULL,
+		.enum_list	= NULL,
+		.flags		= FLAG_ADVANCED,
+	},
+	{
 		.label		= "max log size",
 		.type		= P_BYTES,
 		.p_class	= P_GLOBAL,
-- 
1.7.1


From ff54b903b943966793a3bd17de744f66930a7540 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 14:46:32 -0700
Subject: [PATCH 11/22] debug: Set backends from logging parameter in smb.conf

Fallback to the settings of 'syslog' and 'syslog only' if logging has not
been set.

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/param/loadparm.c |    6 +++---
 lib/util/debug.c     |   42 ++++++++++++++++++++++++++++++++----------
 lib/util/debug.h     |    4 +++-
 lib/util/debug_s3.c  |    5 ++---
 4 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index c619ad2..e2b0ca2 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -2875,15 +2875,15 @@ static bool lpcfg_update(struct loadparm_context *lp_ctx)
 	ZERO_STRUCT(settings);
 	/* Add any more debug-related smb.conf parameters created in
 	 * future here */
-	settings.syslog = lp_ctx->globals->syslog;
-	settings.syslog_only = lp_ctx->globals->syslog_only;
 	settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
 	settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
 	settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
 	settings.debug_pid = lp_ctx->globals->debug_pid;
 	settings.debug_uid = lp_ctx->globals->debug_uid;
 	settings.debug_class = lp_ctx->globals->debug_class;
-	debug_set_settings(&settings);
+	debug_set_settings(&settings, lp_ctx->globals->logging,
+			   lp_ctx->globals->syslog,
+			   lp_ctx->globals->syslog_only);
 
 	/* FIXME: This is a bit of a hack, but we can't use a global, since 
 	 * not everything that uses lp also uses the socket library */
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 35deb79..412333b 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -684,12 +684,40 @@ static void debug_init(void)
 	}
 }
 
-/* This forces in some smb.conf derived values into the debug system.
- * There are no pointers in this structure, so we can just
- * structure-assign it in */
-void debug_set_settings(struct debug_settings *settings)
+void debug_set_settings(struct debug_settings *settings,
+			const char *logging_param,
+			int syslog_level, bool syslog_only)
 {
+	char fake_param[20];
+
+	/*
+	 * This forces in some smb.conf derived values into the debug
+	 * system. There are no pointers in this structure, so we can
+	 * just structure-assign it in
+	 */
 	state.settings = *settings;
+
+	state.settings.syslog = syslog_level;
+	state.settings.syslog_only = syslog_only;
+
+	/*
+	 * If 'logging' is not set, create backend settings from
+	 * deprecated 'syslog' and 'syslog only' paramters
+	 */
+	if (!logging_param) {
+		if (syslog_only) {
+			snprintf(fake_param, sizeof(fake_param),
+				 "syslog:%d", syslog_level - 1);
+		} else {
+			snprintf(fake_param, sizeof(fake_param),
+				 "syslog:%d file:%d", syslog_level -1,
+				 MAX_DEBUG_LEVEL);
+		}
+
+		logging_param = fake_param;
+	}
+
+	debug_set_backends(logging_param);
 }
 
 /**
@@ -718,12 +746,6 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
 		state.prog_name = prog_name;
 	}
 	reopen_logs_internal();
-
-#ifdef WITH_SYSLOG
-	if (state.logtype == DEBUG_FILE) {
-		debug_syslog_reload(true, false, state.prog_name);
-	}
-#endif
 }
 
 /***************************************************************************
diff --git a/lib/util/debug.h b/lib/util/debug.h
index 8063ace..9a3accc 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -241,7 +241,9 @@ int debug_add_class(const char *classname);
 bool debug_parse_levels(const char *params_str);
 void debug_setup_talloc_log(void);
 void debug_set_logfile(const char *name);
-void debug_set_settings(struct debug_settings *settings);
+void debug_set_settings(struct debug_settings *settings,
+			const char *logging_param,
+			int syslog_level, bool syslog_only);
 bool reopen_logs_internal( void );
 void force_check_log_size( void );
 bool need_to_check_log_size( void );
diff --git a/lib/util/debug_s3.c b/lib/util/debug_s3.c
index ccf577f..160e2ef 100644
--- a/lib/util/debug_s3.c
+++ b/lib/util/debug_s3.c
@@ -34,15 +34,14 @@ bool reopen_logs(void)
 
 		ZERO_STRUCT(settings);
 		settings.max_log_size = lp_max_log_size();
-		settings.syslog = lp_syslog();
-		settings.syslog_only = lp_syslog_only();
 		settings.timestamp_logs = lp_timestamp_logs();
 		settings.debug_prefix_timestamp = lp_debug_prefix_timestamp();
 		settings.debug_hires_timestamp = lp_debug_hires_timestamp();
 		settings.debug_pid = lp_debug_pid();
 		settings.debug_uid = lp_debug_uid();
 		settings.debug_class = lp_debug_class();
-		debug_set_settings(&settings);
+		debug_set_settings(&settings, lp_logging(talloc_tos()),
+				   lp_syslog(), lp_syslog_only());
 	}
 	return reopen_logs_internal();
 }
-- 
1.7.1


From 6a80c668474f619184625e87d1b616443aef99fd Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 14:51:00 -0700
Subject: [PATCH 12/22] debug: Remove codepath to open file in Debug1

This is not used, the log file is already open from the call to
reopen_logs_internal.

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   17 -----------------
 1 files changed, 0 insertions(+), 17 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 412333b..1d8bf81 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1037,23 +1037,6 @@ static int Debug1(const char *msg)
 	}
 
 #ifdef WITH_SYSLOG
-	if( !state.settings.syslog_only)
-#endif
-	{
-		if( state.fd <= 0 ) {
-			mode_t oldumask = umask( 022 );
-			int fd = open( state.debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 );
-			(void)umask( oldumask );
-			if(fd == -1) {
-				goto done;
-			}
-			smb_set_close_on_exec(fd);
-			state.fd = fd;
-		}
-	}
-
-
-#ifdef WITH_SYSLOG
 	if( current_msg_level < state.settings.syslog ) {
 		int priority = debug_level_to_priority(current_msg_level);
 
-- 
1.7.1


From ad576edabf06bcc62b46cf607aa08ce8f6df8240 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 14:56:38 -0700
Subject: [PATCH 13/22] debug: Use backends instead of explicitly logging to syslog or file

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   25 +------------------------
 1 files changed, 1 insertions(+), 24 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 1d8bf81..806138a 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1036,30 +1036,7 @@ static int Debug1(const char *msg)
 		goto done;
 	}
 
-#ifdef WITH_SYSLOG
-	if( current_msg_level < state.settings.syslog ) {
-		int priority = debug_level_to_priority(current_msg_level);
-
-		/*
-		 * Specify the facility to interoperate with other syslog
-		 * callers (vfs_full_audit for example).
-		 */
-		priority |= SYSLOG_FACILITY;
-
-		syslog(priority, "%s", msg);
-	}
-#endif
-
-	check_log_size();
-
-#ifdef WITH_SYSLOG
-	if( !state.settings.syslog_only)
-#endif
-	{
-		if (state.fd > 0) {
-			write(state.fd, msg, strlen(msg));
-		}
-	}
+	debug_backends_log(msg, current_msg_level);
 
  done:
 	errno = old_errno;
-- 
1.7.1


From 632d69ac78ba01d7f01176f47ea7013e0ada50a9 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 15:00:04 -0700
Subject: [PATCH 14/22] debug: Simplify Debug1

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 806138a..8e08fcd 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1018,33 +1018,32 @@ void check_log_size( void )
  This is called by dbghdr() and format_debug_text().
 ************************************************************************/
 
-static int Debug1(const char *msg)
+static void Debug1(const char *msg)
 {
 	int old_errno = errno;
 
 	debug_count++;
 
-	if (state.logtype == DEBUG_CALLBACK) {
+	switch(state.logtype) {
+	case DEBUG_CALLBACK:
 		debug_callback_log(msg, current_msg_level);
-		goto done;
-	}
-
-	if ( state.logtype != DEBUG_FILE ) {
+		break;
+	case DEBUG_STDOUT:
+	case DEBUG_STDERR:
+	case DEBUG_DEFAULT_STDOUT:
+	case DEBUG_DEFAULT_STDERR:
 		if (state.fd > 0) {
 			write(state.fd, msg, strlen(msg));
 		}
-		goto done;
-	}
-
-	debug_backends_log(msg, current_msg_level);
+		break;
+	case DEBUG_FILE:
+		debug_backends_log(msg, current_msg_level);
+		break;
+	};
 
- done:
 	errno = old_errno;
-
-	return( 0 );
 }
 
-
 /**************************************************************************
  Print the buffer content via Debug1(), then reset the buffer.
  Input:  none
-- 
1.7.1


From 19ac99263b3a51e7e9710c3af99a1dff5a1e238b Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 15:07:36 -0700
Subject: [PATCH 15/22] debug: Remove now unused syslog variables from debug_settings

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/debug.c |    3 ---
 lib/util/debug.h |    2 --
 2 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 8e08fcd..7602a51 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -697,9 +697,6 @@ void debug_set_settings(struct debug_settings *settings,
 	 */
 	state.settings = *settings;
 
-	state.settings.syslog = syslog_level;
-	state.settings.syslog_only = syslog_only;
-
 	/*
 	 * If 'logging' is not set, create backend settings from
 	 * deprecated 'syslog' and 'syslog only' paramters
diff --git a/lib/util/debug.h b/lib/util/debug.h
index 9a3accc..379572f 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -224,8 +224,6 @@ enum debug_logtype {
 
 struct debug_settings {
 	size_t max_log_size;
-	int syslog;
-	bool syslog_only;
 	bool timestamp_logs;
 	bool debug_prefix_timestamp;
 	bool debug_hires_timestamp;
-- 
1.7.1


From 408a68225b56e1ca7d9e788d7089a78733871aac Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 15:13:37 -0700
Subject: [PATCH 16/22] param: Mark syslog and syslog_only as deprecated

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 docs-xml/smbdotconf/logging/syslog.xml     |    4 ++++
 docs-xml/smbdotconf/logging/syslogonly.xml |    5 +++++
 lib/param/param_table.c                    |    4 ++--
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/docs-xml/smbdotconf/logging/syslog.xml b/docs-xml/smbdotconf/logging/syslog.xml
index e4722d8..f58a9a5 100644
--- a/docs-xml/smbdotconf/logging/syslog.xml
+++ b/docs-xml/smbdotconf/logging/syslog.xml
@@ -16,6 +16,10 @@
     level less than this value will be sent to syslog. There still will be some
     logging to log.[sn]mbd even if <emphasis>syslog only</emphasis> is enabled.
     </para>
+
+    <para>The <smbconfoption name="logging"/> parameter should be used
+      instead. When <smbconfoption name="logging"/> is set, it
+      overrides the <smbconfoption name="syslog"/> parameter.</para>
 </description>
 <value type="default">1</value>
 </samba:parameter>
diff --git a/docs-xml/smbdotconf/logging/syslogonly.xml b/docs-xml/smbdotconf/logging/syslogonly.xml
index 0fe7471..aec40c2 100644
--- a/docs-xml/smbdotconf/logging/syslogonly.xml
+++ b/docs-xml/smbdotconf/logging/syslogonly.xml
@@ -9,6 +9,11 @@
     syslog only, and not to the debug log files. There still will be some
 	logging to log.[sn]mbd even if <emphasis>syslog only</emphasis> is enabled.
     </para>
+
+
+    <para>The <smbconfoption name="logging"/> parameter should be used
+      instead. When <smbconfoption name="logging"/> is set, it
+      overrides the <smbconfoption name="syslog only"/> parameter.</para>
 </description>
 <value type="default">no</value>
 </samba:parameter>
diff --git a/lib/param/param_table.c b/lib/param/param_table.c
index 464a7c9..d78b4d1 100644
--- a/lib/param/param_table.c
+++ b/lib/param/param_table.c
@@ -1185,7 +1185,7 @@ struct parm_struct parm_table[] = {
 		.offset		= GLOBAL_VAR(syslog),
 		.special	= NULL,
 		.enum_list	= NULL,
-		.flags		= FLAG_ADVANCED,
+		.flags		= FLAG_ADVANCED | FLAG_DEPRECATED,
 	},
 	{
 		.label		= "syslog only",
@@ -1194,7 +1194,7 @@ struct parm_struct parm_table[] = {
 		.offset		= GLOBAL_VAR(syslog_only),
 		.special	= NULL,
 		.enum_list	= NULL,
-		.flags		= FLAG_ADVANCED,
+		.flags		= FLAG_ADVANCED | FLAG_DEPRECATED,
 	},
 	{
 		.label		= "log file",
-- 
1.7.1


From 10f09b621248632199437113d40440c4d2cb6a15 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 20 Mar 2015 14:36:58 -0700
Subject: [PATCH 17/22] debug: Add systemd backend

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 docs-xml/smbdotconf/logging/logging.xml |    1 +
 lib/util/debug.c                        |   21 ++++++++++++++++++++-
 lib/util/wscript_build                  |    1 +
 lib/util/wscript_configure              |   14 ++++++++++++++
 4 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/docs-xml/smbdotconf/logging/logging.xml b/docs-xml/smbdotconf/logging/logging.xml
index f888c46..039a965 100644
--- a/docs-xml/smbdotconf/logging/logging.xml
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -29,6 +29,7 @@
   <itemizedlist>
     <listitem><para><parameter moreinfo="none">syslog</parameter></para></listitem>
     <listitem><para><parameter moreinfo="none">file</parameter></para></listitem>
+    <listitem><para><parameter moreinfo="none">systemd</parameter></para></listitem>
   </itemizedlist>
 
 </description>
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 7602a51..81acbb1 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -102,7 +102,7 @@ static struct {
 	.fd = 2 /* stderr by default */
 };
 
-#ifdef WITH_SYSLOG
+#if defined(WITH_SYSLOG) || defined(HAVE_SYSTEMD_JOURNAL)
 static int debug_level_to_priority(int level)
 {
 	/*
@@ -174,6 +174,18 @@ static void debug_syslog_log(int msg_level,
 }
 #endif /* WITH_SYSLOG */
 
+#ifdef HAVE_SYSTEMD_JOURNAL
+#include <systemd/sd-journal.h>
+static void debug_systemd_log(int msg_level,
+			      const char *msg, const char *msg_no_nl)
+{
+	sd_journal_send("MESSAGE=%s", msg_no_nl,
+			"PRIORITY=%d", debug_level_to_priority(msg_level),
+			"LEVEL=%d", msg_level,
+			NULL);
+}
+#endif
+
 static struct debug_backend {
 	const char *name;
 	int log_level;
@@ -192,6 +204,13 @@ static struct debug_backend {
 		.log = debug_syslog_log,
 	},
 #endif
+
+#ifdef HAVE_SYSTEMD_JOURNAL
+	{
+		.name = "systemd",
+		.log = debug_systemd_log,
+	},
+#endif
 };
 
 static struct debug_backend *debug_find_backend(const char *name)
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index b2e406e..5f89c83 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -31,6 +31,7 @@ bld.SAMBA_SUBSYSTEM('close-low-fd',
 bld.SAMBA_LIBRARY('samba-debug',
                   source='debug.c',
                   deps='replace time-basic close-low-fd talloc socket-blocking',
+                  public_deps='systemd-journal',
                   local_include=False,
                   private_library=True)
 
diff --git a/lib/util/wscript_configure b/lib/util/wscript_configure
index 8cf77b4..0153fb8 100644
--- a/lib/util/wscript_configure
+++ b/lib/util/wscript_configure
@@ -113,3 +113,17 @@ if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H') and
 else:
     conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
     conf.undefine('HAVE_SYSTEMD')
+
+if Options.options.enable_systemd != False:
+    conf.check_cfg(package='libsystemd-journal', args='--cflags --libs',
+                   msg='Checking for libsystemd-journal',
+                   uselib_store="SYSTEMD-JOURNAL")
+    conf.CHECK_HEADERS('systemd/sd-journal.h', lib='systemd-journal')
+    conf.CHECK_LIB('systemd-journal', shlib=True)
+
+if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_JOURNAL_H') and
+    conf.CONFIG_SET('HAVE_LIBSYSTEMD_JOURNAL')):
+    conf.DEFINE('HAVE_SYSTEMD_JOURNAL', '1')
+else:
+    conf.SET_TARGET_TYPE('systemd-journal', 'EMPTY')
+    conf.undefine('HAVE_SYSTEMD_JOURNAL')
-- 
1.7.1


From 272045c04cd833b1ad5df32c2dcf1e28b675b0b3 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 16:17:08 -0700
Subject: [PATCH 18/22] debug: Add lttng backend

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 docs-xml/smbdotconf/logging/logging.xml |    1 +
 lib/util/debug.c                        |   17 +++++++++++++++++
 lib/util/wscript                        |    8 ++++++++
 lib/util/wscript_build                  |    2 +-
 lib/util/wscript_configure              |   14 ++++++++++++++
 5 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/docs-xml/smbdotconf/logging/logging.xml b/docs-xml/smbdotconf/logging/logging.xml
index 039a965..20842bd 100644
--- a/docs-xml/smbdotconf/logging/logging.xml
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -30,6 +30,7 @@
     <listitem><para><parameter moreinfo="none">syslog</parameter></para></listitem>
     <listitem><para><parameter moreinfo="none">file</parameter></para></listitem>
     <listitem><para><parameter moreinfo="none">systemd</parameter></para></listitem>
+    <listitem><para><parameter moreinfo="none">lttng</parameter></para></listitem>
   </itemizedlist>
 
 </description>
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 81acbb1..c2781af 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -186,6 +186,15 @@ static void debug_systemd_log(int msg_level,
 }
 #endif
 
+#ifdef HAVE_LTTNG_TRACEF
+#include <lttng/tracef.h>
+static void debug_lttng_log(int msg_level,
+			    const char *msg, const char *msg_no_nl)
+{
+	tracef(msg_no_nl);
+}
+#endif /* WITH_LTTNG_TRACEF */
+
 static struct debug_backend {
 	const char *name;
 	int log_level;
@@ -211,6 +220,14 @@ static struct debug_backend {
 		.log = debug_systemd_log,
 	},
 #endif
+
+#ifdef HAVE_LTTNG_TRACEF
+	{
+		.name = "lttng",
+		.log = debug_lttng_log,
+	},
+#endif
+
 };
 
 static struct debug_backend *debug_find_backend(const char *name)
diff --git a/lib/util/wscript b/lib/util/wscript
index 2371689..26b5564 100644
--- a/lib/util/wscript
+++ b/lib/util/wscript
@@ -9,3 +9,11 @@ def set_options(opt):
     opt.add_option('--without-systemd',
                    help=("Disable systemd integration"),
                    action='store_false', dest='enable_systemd')
+
+    opt.add_option('--with-lttng',
+                   help=("Enable lttng integration"),
+                   action='store_true', dest='enable_lttng')
+
+    opt.add_option('--without-lttng',
+                   help=("Disable lttng integration"),
+                   action='store_false', dest='enable_lttng')
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 5f89c83..182f80a 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -31,7 +31,7 @@ bld.SAMBA_SUBSYSTEM('close-low-fd',
 bld.SAMBA_LIBRARY('samba-debug',
                   source='debug.c',
                   deps='replace time-basic close-low-fd talloc socket-blocking',
-                  public_deps='systemd-journal',
+                  public_deps='systemd-journal lttng-ust',
                   local_include=False,
                   private_library=True)
 
diff --git a/lib/util/wscript_configure b/lib/util/wscript_configure
index 0153fb8..84c3414 100644
--- a/lib/util/wscript_configure
+++ b/lib/util/wscript_configure
@@ -127,3 +127,17 @@ if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_JOURNAL_H') and
 else:
     conf.SET_TARGET_TYPE('systemd-journal', 'EMPTY')
     conf.undefine('HAVE_SYSTEMD_JOURNAL')
+
+if Options.options.enable_lttng != False:
+    conf.check_cfg(package='lttng-ust', args='--cflags --libs',
+                   msg='Checking for lttng-ust', uselib_store="LTTNG-UST")
+    conf.CHECK_HEADERS('lttng/tracef.h', lib='lttng-st')
+    conf.CHECK_LIB('lttng-ust', shlib=True)
+
+if (conf.CONFIG_SET('HAVE_LTTNG_TRACEF_H') and
+    conf.CONFIG_SET('HAVE_LTTNG_UST')):
+    conf.DEFINE('HAVE_LTTNG_TRACEF', '1')
+    conf.env['HAVE_LTTNG_TRACEF'] = True
+else:
+    conf.SET_TARGET_TYPE('lttng-ust', 'EMPTY')
+    conf.undefine('HAVE_LTTNG_TRACEF')
-- 
1.7.1


From cb8cbcce8ea92ca7fd5c1c40148dc2fc0dfa1256 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Thu, 19 Feb 2015 16:02:11 -0700
Subject: [PATCH 19/22] gpfswrap: Move gpfswrap to lib/util

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/gpfswrap.c           |  226 +++++++++++++++++++++++++++++++++++++++++
 lib/util/gpfswrap.h           |   48 +++++++++
 lib/util/wscript_build        |   12 ++-
 lib/util/wscript_configure    |    4 +
 source3/modules/gpfswrap.c    |  226 -----------------------------------------
 source3/modules/gpfswrap.h    |   48 ---------
 source3/modules/vfs_gpfs.c    |    2 +-
 source3/modules/wscript_build |    4 +-
 source3/wscript               |    4 -
 9 files changed, 292 insertions(+), 282 deletions(-)
 create mode 100644 lib/util/gpfswrap.c
 create mode 100644 lib/util/gpfswrap.h
 delete mode 100644 source3/modules/gpfswrap.c
 delete mode 100644 source3/modules/gpfswrap.h

diff --git a/lib/util/gpfswrap.c b/lib/util/gpfswrap.c
new file mode 100644
index 0000000..aac2f44
--- /dev/null
+++ b/lib/util/gpfswrap.c
@@ -0,0 +1,226 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  Wrapper for GPFS library
+ *  Copyright (C) Volker Lendecke 2005
+ *  Copyright (C) Christof Schmitt 2015
+ *
+ *  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/>.
+ */
+
+#include "replace.h"
+#include "gpfswrap.h"
+
+static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
+static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
+static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
+static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
+static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
+					    int *len);
+static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags,
+					struct gpfs_winattr *attrs);
+static int (*gpfs_get_winattrs_path_fn)(char *pathname,
+					struct gpfs_winattr *attrs);
+static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
+static int (*gpfs_prealloc_fn)(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
+static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
+static int (*gpfs_lib_init_fn)(int flags);
+static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
+				     gpfs_timestruc_t times[4]);
+static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufp);
+static int (*gpfs_fcntl_fn)(int fd, void *argp);
+static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idp);
+
+int gpfswrap_init(void)
+{
+	static void *l;
+
+	if (l != NULL) {
+		return 0;
+	}
+
+	l = dlopen("libgpfs.so", RTLD_LAZY);
+	if (l == NULL) {
+		return -1;
+	}
+
+	gpfs_set_share_fn	      = dlsym(l, "gpfs_set_share");
+	gpfs_set_lease_fn	      = dlsym(l, "gpfs_set_lease");
+	gpfs_getacl_fn		      = dlsym(l, "gpfs_getacl");
+	gpfs_putacl_fn		      = dlsym(l, "gpfs_putacl");
+	gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
+	gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
+	gpfs_get_winattrs_path_fn     = dlsym(l, "gpfs_get_winattrs_path");
+	gpfs_get_winattrs_fn	      = dlsym(l, "gpfs_get_winattrs");
+	gpfs_prealloc_fn	      = dlsym(l, "gpfs_prealloc");
+	gpfs_ftruncate_fn	      = dlsym(l, "gpfs_ftruncate");
+	gpfs_lib_init_fn	      = dlsym(l, "gpfs_lib_init");
+	gpfs_set_times_path_fn	      = dlsym(l, "gpfs_set_times_path");
+	gpfs_quotactl_fn	      = dlsym(l, "gpfs_quotactl");
+	gpfs_fcntl_fn		      = dlsym(l, "gpfs_fcntl");
+	gpfs_getfilesetid_fn	      = dlsym(l, "gpfs_getfilesetid");
+
+	return 0;
+}
+
+int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
+{
+	if (gpfs_set_share_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_set_share_fn(fd, allow, deny);
+}
+
+int gpfswrap_set_lease(int fd, unsigned int type)
+{
+	if (gpfs_set_lease_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_set_lease_fn(fd, type);
+}
+
+int gpfswrap_getacl(char *pathname, int flags, void *acl)
+{
+	if (gpfs_getacl_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_getacl_fn(pathname, flags, acl);
+}
+
+int gpfswrap_putacl(char *pathname, int flags, void *acl)
+{
+	if (gpfs_putacl_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_putacl_fn(pathname, flags, acl);
+}
+
+int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len)
+{
+	if (gpfs_get_realfilename_path_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
+}
+
+int gpfswrap_set_winattrs_path(char *pathname, int flags,
+			       struct gpfs_winattr *attrs)
+{
+	if (gpfs_set_winattrs_path_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
+}
+
+int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs)
+{
+	if (gpfs_get_winattrs_path_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_get_winattrs_path_fn(pathname, attrs);
+}
+
+int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
+{
+	if (gpfs_get_winattrs_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_get_winattrs_fn(fd, attrs);
+}
+
+int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes)
+{
+	if (gpfs_prealloc_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_prealloc_fn(fd, start, bytes);
+}
+
+int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
+{
+	if (gpfs_ftruncate_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_ftruncate_fn(fd, length);
+}
+
+int gpfswrap_lib_init(int flags)
+{
+	if (gpfs_lib_init_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_lib_init_fn(flags);
+}
+
+int gpfswrap_set_times_path(char *pathname, int flags,
+			    gpfs_timestruc_t times[4])
+{
+	if (gpfs_set_times_path_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_set_times_path_fn(pathname, flags, times);
+}
+
+int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp)
+{
+	if (gpfs_quotactl_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_quotactl_fn(pathname, cmd, id, bufp);
+}
+
+int gpfswrap_fcntl(int fd, void *argp)
+{
+	if (gpfs_fcntl_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_fcntl_fn(fd, argp);
+}
+
+int gpfswrap_getfilesetid(char *pathname, char *name, int *idp)
+{
+	if (gpfs_getfilesetid_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_getfilesetid_fn(pathname, name, idp);
+}
diff --git a/lib/util/gpfswrap.h b/lib/util/gpfswrap.h
new file mode 100644
index 0000000..d30b05f
--- /dev/null
+++ b/lib/util/gpfswrap.h
@@ -0,0 +1,48 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  Wrapper for GPFS library
+ *  Copyright (C) Christian Ambach <cambach1 at de.ibm.com> 2006
+ *  Copyright (C) Christof Schmitt 2015
+ *
+ *  Major code contributions by Chetan Shringarpure <chetan.sh at in.ibm.com>
+ *                           and Gomati Mohanan <gomati.mohanan at in.ibm.com>
+ *
+ *  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 __GPFSWRAP_H__
+#define __GPFSWRAP_H__
+
+#include <gpfs_fcntl.h>
+
+int gpfswrap_init(void);
+int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny);
+int gpfswrap_set_lease(int fd, unsigned int type);
+int gpfswrap_getacl(char *pathname, int flags, void *acl);
+int gpfswrap_putacl(char *pathname, int flags, void *acl);
+int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len);
+int gpfswrap_set_winattrs_path(char *pathname, int flags,
+			       struct gpfs_winattr *attrs);
+int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs);
+int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs);
+int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
+int gpfswrap_ftruncate(int fd, gpfs_off64_t length);
+int gpfswrap_lib_init(int flags);
+int gpfswrap_set_times_path(char *pathname, int flags,
+			    gpfs_timestruc_t times[4]);
+int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp);
+int gpfswrap_fcntl(int fd, void *argp);
+int gpfswrap_getfilesetid(char *pathname, char *name, int *idp);
+
+#endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 182f80a..50d53ed 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -28,9 +28,19 @@ bld.SAMBA_SUBSYSTEM('close-low-fd',
                     deps='replace',
                     local_include=False)
 
+samba_debug_add_deps = ''
+
+if bld.CONFIG_SET('HAVE_GPFS'):
+    bld.SAMBA_SUBSYSTEM('gpfswrap',
+                        source='gpfswrap.c',
+                        deps='replace',
+                        local_include=False,
+                        includes=bld.CONFIG_GET('CPPPATH_GPFS'))
+    samba_debug_add_deps += ' gpfswrap'
+
 bld.SAMBA_LIBRARY('samba-debug',
                   source='debug.c',
-                  deps='replace time-basic close-low-fd talloc socket-blocking',
+                  deps='replace time-basic close-low-fd talloc socket-blocking' + samba_debug_add_deps,
                   public_deps='systemd-journal lttng-ust',
                   local_include=False,
                   private_library=True)
diff --git a/lib/util/wscript_configure b/lib/util/wscript_configure
index 84c3414..ddd4882 100644
--- a/lib/util/wscript_configure
+++ b/lib/util/wscript_configure
@@ -141,3 +141,7 @@ if (conf.CONFIG_SET('HAVE_LTTNG_TRACEF_H') and
 else:
     conf.SET_TARGET_TYPE('lttng-ust', 'EMPTY')
     conf.undefine('HAVE_LTTNG_TRACEF')
+
+conf.env['CPPPATH_GPFS'] = '/usr/lpp/mmfs/include/'
+if conf.CHECK_HEADERS('gpfs_fcntl.h', False, False, "gpfs"):
+    conf.DEFINE('HAVE_GPFS', '1')
diff --git a/source3/modules/gpfswrap.c b/source3/modules/gpfswrap.c
deleted file mode 100644
index aac2f44..0000000
--- a/source3/modules/gpfswrap.c
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- *  Unix SMB/CIFS implementation.
- *  Wrapper for GPFS library
- *  Copyright (C) Volker Lendecke 2005
- *  Copyright (C) Christof Schmitt 2015
- *
- *  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/>.
- */
-
-#include "replace.h"
-#include "gpfswrap.h"
-
-static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
-static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
-static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
-static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
-static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
-					    int *len);
-static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags,
-					struct gpfs_winattr *attrs);
-static int (*gpfs_get_winattrs_path_fn)(char *pathname,
-					struct gpfs_winattr *attrs);
-static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
-static int (*gpfs_prealloc_fn)(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
-static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
-static int (*gpfs_lib_init_fn)(int flags);
-static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
-				     gpfs_timestruc_t times[4]);
-static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufp);
-static int (*gpfs_fcntl_fn)(int fd, void *argp);
-static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idp);
-
-int gpfswrap_init(void)
-{
-	static void *l;
-
-	if (l != NULL) {
-		return 0;
-	}
-
-	l = dlopen("libgpfs.so", RTLD_LAZY);
-	if (l == NULL) {
-		return -1;
-	}
-
-	gpfs_set_share_fn	      = dlsym(l, "gpfs_set_share");
-	gpfs_set_lease_fn	      = dlsym(l, "gpfs_set_lease");
-	gpfs_getacl_fn		      = dlsym(l, "gpfs_getacl");
-	gpfs_putacl_fn		      = dlsym(l, "gpfs_putacl");
-	gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
-	gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
-	gpfs_get_winattrs_path_fn     = dlsym(l, "gpfs_get_winattrs_path");
-	gpfs_get_winattrs_fn	      = dlsym(l, "gpfs_get_winattrs");
-	gpfs_prealloc_fn	      = dlsym(l, "gpfs_prealloc");
-	gpfs_ftruncate_fn	      = dlsym(l, "gpfs_ftruncate");
-	gpfs_lib_init_fn	      = dlsym(l, "gpfs_lib_init");
-	gpfs_set_times_path_fn	      = dlsym(l, "gpfs_set_times_path");
-	gpfs_quotactl_fn	      = dlsym(l, "gpfs_quotactl");
-	gpfs_fcntl_fn		      = dlsym(l, "gpfs_fcntl");
-	gpfs_getfilesetid_fn	      = dlsym(l, "gpfs_getfilesetid");
-
-	return 0;
-}
-
-int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
-{
-	if (gpfs_set_share_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_set_share_fn(fd, allow, deny);
-}
-
-int gpfswrap_set_lease(int fd, unsigned int type)
-{
-	if (gpfs_set_lease_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_set_lease_fn(fd, type);
-}
-
-int gpfswrap_getacl(char *pathname, int flags, void *acl)
-{
-	if (gpfs_getacl_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_getacl_fn(pathname, flags, acl);
-}
-
-int gpfswrap_putacl(char *pathname, int flags, void *acl)
-{
-	if (gpfs_putacl_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_putacl_fn(pathname, flags, acl);
-}
-
-int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len)
-{
-	if (gpfs_get_realfilename_path_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
-}
-
-int gpfswrap_set_winattrs_path(char *pathname, int flags,
-			       struct gpfs_winattr *attrs)
-{
-	if (gpfs_set_winattrs_path_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
-}
-
-int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs)
-{
-	if (gpfs_get_winattrs_path_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_get_winattrs_path_fn(pathname, attrs);
-}
-
-int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
-{
-	if (gpfs_get_winattrs_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_get_winattrs_fn(fd, attrs);
-}
-
-int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes)
-{
-	if (gpfs_prealloc_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_prealloc_fn(fd, start, bytes);
-}
-
-int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
-{
-	if (gpfs_ftruncate_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_ftruncate_fn(fd, length);
-}
-
-int gpfswrap_lib_init(int flags)
-{
-	if (gpfs_lib_init_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_lib_init_fn(flags);
-}
-
-int gpfswrap_set_times_path(char *pathname, int flags,
-			    gpfs_timestruc_t times[4])
-{
-	if (gpfs_set_times_path_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_set_times_path_fn(pathname, flags, times);
-}
-
-int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp)
-{
-	if (gpfs_quotactl_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_quotactl_fn(pathname, cmd, id, bufp);
-}
-
-int gpfswrap_fcntl(int fd, void *argp)
-{
-	if (gpfs_fcntl_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_fcntl_fn(fd, argp);
-}
-
-int gpfswrap_getfilesetid(char *pathname, char *name, int *idp)
-{
-	if (gpfs_getfilesetid_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_getfilesetid_fn(pathname, name, idp);
-}
diff --git a/source3/modules/gpfswrap.h b/source3/modules/gpfswrap.h
deleted file mode 100644
index d30b05f..0000000
--- a/source3/modules/gpfswrap.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  Unix SMB/CIFS implementation.
- *  Wrapper for GPFS library
- *  Copyright (C) Christian Ambach <cambach1 at de.ibm.com> 2006
- *  Copyright (C) Christof Schmitt 2015
- *
- *  Major code contributions by Chetan Shringarpure <chetan.sh at in.ibm.com>
- *                           and Gomati Mohanan <gomati.mohanan at in.ibm.com>
- *
- *  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 __GPFSWRAP_H__
-#define __GPFSWRAP_H__
-
-#include <gpfs_fcntl.h>
-
-int gpfswrap_init(void);
-int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny);
-int gpfswrap_set_lease(int fd, unsigned int type);
-int gpfswrap_getacl(char *pathname, int flags, void *acl);
-int gpfswrap_putacl(char *pathname, int flags, void *acl);
-int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len);
-int gpfswrap_set_winattrs_path(char *pathname, int flags,
-			       struct gpfs_winattr *attrs);
-int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs);
-int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs);
-int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
-int gpfswrap_ftruncate(int fd, gpfs_off64_t length);
-int gpfswrap_lib_init(int flags);
-int gpfswrap_set_times_path(char *pathname, int flags,
-			    gpfs_timestruc_t times[4]);
-int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp);
-int gpfswrap_fcntl(int fd, void *argp);
-int gpfswrap_getfilesetid(char *pathname, char *name, int *idp);
-
-#endif
diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index 999e83b..8d9d897 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -30,7 +30,7 @@
 #include "system/filesys.h"
 #include "auth.h"
 #include "lib/util/tevent_unix.h"
-#include "gpfswrap.h"
+#include "lib/util/gpfswrap.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
diff --git a/source3/modules/wscript_build b/source3/modules/wscript_build
index a4afcd7..018cbe9 100644
--- a/source3/modules/wscript_build
+++ b/source3/modules/wscript_build
@@ -275,8 +275,8 @@ bld.SAMBA3_MODULE('vfs_commit',
 
 bld.SAMBA3_MODULE('vfs_gpfs',
                  subsystem='vfs',
-                 source='vfs_gpfs.c gpfswrap.c',
-                 deps='NFS4_ACLS non_posix_acls',
+                 source='vfs_gpfs.c',
+                 deps='NFS4_ACLS non_posix_acls gpfswrap',
                  init_function='',
                  internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_gpfs'),
                  enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_gpfs'),
diff --git a/source3/wscript b/source3/wscript
index ffff44d..818cdad 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -1506,10 +1506,6 @@ main() {
             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
             conf.undefine('WITH_PTHREADPOOL')
 
-    conf.env['CPPPATH_GPFS'] = '/usr/lpp/mmfs/include/'
-    if conf.CHECK_HEADERS('gpfs_fcntl.h', False, False, "gpfs"):
-        conf.DEFINE('HAVE_GPFS', '1')
-
     if (conf.CHECK_HEADERS('linux/ioctl.h sys/ioctl.h linux/fs.h') and
 	conf.CHECK_DECLS('FS_IOC_GETFLAGS FS_COMPR_FL', headers='linux/fs.h')):
 	    conf.DEFINE('HAVE_LINUX_IOCTL', '1')
-- 
1.7.1


From 707ea4fa6c8dfe7b14d9ab14aa54fca43a4d37b9 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Tue, 24 Feb 2015 16:18:59 -0700
Subject: [PATCH 20/22] gpfswrap: Add wrappers for tracing API

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 lib/util/gpfswrap.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/util/gpfswrap.h |    4 ++++
 2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/lib/util/gpfswrap.c b/lib/util/gpfswrap.c
index aac2f44..732fcb6 100644
--- a/lib/util/gpfswrap.c
+++ b/lib/util/gpfswrap.c
@@ -40,6 +40,10 @@ static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
 static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufp);
 static int (*gpfs_fcntl_fn)(int fd, void *argp);
 static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idp);
+static int (*gpfs_init_trace_fn)(void);
+static int (*gpfs_query_trace_fn)(void);
+static void (*gpfs_add_trace_fn)(int level, const char *msg);
+static void (*gpfs_fini_trace_fn)(void);
 
 int gpfswrap_init(void)
 {
@@ -69,6 +73,10 @@ int gpfswrap_init(void)
 	gpfs_quotactl_fn	      = dlsym(l, "gpfs_quotactl");
 	gpfs_fcntl_fn		      = dlsym(l, "gpfs_fcntl");
 	gpfs_getfilesetid_fn	      = dlsym(l, "gpfs_getfilesetid");
+	gpfs_init_trace_fn	      = dlsym(l, "gpfs_init_trace");
+	gpfs_query_trace_fn	      = dlsym(l, "gpfs_query_trace");
+	gpfs_add_trace_fn	      = dlsym(l, "gpfs_add_trace");
+	gpfs_fini_trace_fn	      = dlsym(l, "gpfs_fini_trace");
 
 	return 0;
 }
@@ -224,3 +232,41 @@ int gpfswrap_getfilesetid(char *pathname, char *name, int *idp)
 
 	return gpfs_getfilesetid_fn(pathname, name, idp);
 }
+
+int gpfswrap_init_trace(void)
+{
+	if (gpfs_init_trace_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_init_trace_fn();
+}
+
+int gpfswrap_query_trace(void)
+{
+	if (gpfs_query_trace_fn == NULL) {
+		errno = ENOSYS;
+		return -1;
+	}
+
+	return gpfs_query_trace_fn();
+}
+
+void gpfswrap_add_trace(int level, const char *msg)
+{
+	if (gpfs_add_trace_fn == NULL) {
+		return;
+	}
+
+	gpfs_add_trace_fn(level, msg);
+}
+
+void gpfswrap_fini_trace(void)
+{
+	if (gpfs_fini_trace_fn == NULL) {
+		return;
+	}
+
+	gpfs_fini_trace_fn();
+}
diff --git a/lib/util/gpfswrap.h b/lib/util/gpfswrap.h
index d30b05f..fc8ac4a 100644
--- a/lib/util/gpfswrap.h
+++ b/lib/util/gpfswrap.h
@@ -44,5 +44,9 @@ int gpfswrap_set_times_path(char *pathname, int flags,
 int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp);
 int gpfswrap_fcntl(int fd, void *argp);
 int gpfswrap_getfilesetid(char *pathname, char *name, int *idp);
+int gpfswrap_init_trace(void);
+int gpfswrap_query_trace(void);
+void gpfswrap_add_trace(int level, const char *msg);
+void gpfswrap_fini_trace(void);
 
 #endif
-- 
1.7.1


From c25420e2d38faa12aacd6e3a1945e0f1755f91e3 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Thu, 19 Feb 2015 16:32:44 -0700
Subject: [PATCH 21/22] debug: Add GPFS tracing backend

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 docs-xml/smbdotconf/logging/logging.xml |    1 +
 lib/util/debug.c                        |   39 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/docs-xml/smbdotconf/logging/logging.xml b/docs-xml/smbdotconf/logging/logging.xml
index 20842bd..41b6c08 100644
--- a/docs-xml/smbdotconf/logging/logging.xml
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -31,6 +31,7 @@
     <listitem><para><parameter moreinfo="none">file</parameter></para></listitem>
     <listitem><para><parameter moreinfo="none">systemd</parameter></para></listitem>
     <listitem><para><parameter moreinfo="none">lttng</parameter></para></listitem>
+    <listitem><para><parameter moreinfo="none">gpfs</parameter></para></listitem>
   </itemizedlist>
 
 </description>
diff --git a/lib/util/debug.c b/lib/util/debug.c
index c2781af..6b16cd7 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -195,6 +195,38 @@ static void debug_lttng_log(int msg_level,
 }
 #endif /* WITH_LTTNG_TRACEF */
 
+#ifdef HAVE_GPFS
+#include "gpfswrap.h"
+static void debug_gpfs_reload(bool enabled, bool previously_enabled,
+			      const char *prog_name)
+{
+	gpfswrap_init();
+
+	if (enabled && !previously_enabled) {
+		gpfswrap_init_trace();
+		return;
+	}
+
+	if (!enabled && previously_enabled) {
+		gpfswrap_fini_trace();
+		return;
+	}
+
+	if (enabled) {
+		/*
+		 * Trigger GPFS library to adjust state if necessary.
+		 */
+		gpfswrap_query_trace();
+	}
+}
+
+static void debug_gpfs_log(int msg_level,
+			   const char *msg, const char *msg_no_nl)
+{
+	gpfswrap_add_trace(msg_level, msg_no_nl);
+}
+#endif /* HAVE_GPFS */
+
 static struct debug_backend {
 	const char *name;
 	int log_level;
@@ -228,6 +260,13 @@ static struct debug_backend {
 	},
 #endif
 
+#ifdef HAVE_GPFS
+	{
+		.name = "gpfs",
+		.reload = debug_gpfs_reload,
+		.log = debug_gpfs_log,
+	},
+#endif
 };
 
 static struct debug_backend *debug_find_backend(const char *name)
-- 
1.7.1


From fe1cde414687453f6c157418992f7476532d48eb Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Thu, 19 Mar 2015 13:15:24 -0700
Subject: [PATCH 22/22] WHATSNEW: Add logging backends

Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
---
 WHATSNEW.txt |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index b389b5c..ac2e40d 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -16,6 +16,11 @@ UPGRADING
 NEW FEATURES
 ============
 
+The logging code now supports logging to multiple backends.  In
+addition to the previously available syslog and file backends, the
+backends for logging to the systemd-journal, lttng and gpfs have been
+added. Please consult the section for the 'logging' parameter in the
+smb.conf manpage for details.
 
 
 ######################################################################
@@ -27,6 +32,7 @@ smb.conf changes
 
    Parameter Name			Description	Default
    --------------			-----------	-------
+   logging				New		(empty)
 
 
 KNOWN ISSUES
-- 
1.7.1



More information about the samba-technical mailing list