[PATCHES] Logging to multiple debug backends

Christof Schmitt cs at samba.org
Fri Mar 13 12:57:13 MDT 2015


The attached patches add support for multiple debug backends. Today's
code only has the notion of logging to a file, and optionally logging to
syslog through the 'syslog' and 'syslog only' parameters.  With the
patches applied, this becomes more flexible. Multiple logging backends
can be configured through the new 'logging' parameter, e.g.:

logging = lttng:10 file:5 syslog:0 

Additional backends are the new interface to the systemd journal that
can log more attributes for each message, and for gpfs. The existing
config parameters 'syslog' and 'syslog only' are marked as 'deprecated'
for now. Once the 'logging' parameter has been  around for a while, the
previous parameters could be removed.

Any review and comments would be appreciated.

Christof
-------------- next part --------------
From 9d2676e21dff137b3a41f5a1b0939d266abb35d1 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 01/19] debug: Remove some unneeded function declarations

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 80a1c25..9d411a6 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -306,7 +306,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 1ecc129b287666c21462514d103d08eb5e70c64a 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 02/19] 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>
---
 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 9d411a6..78b4599 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -480,20 +480,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 c5be9630da6cb193b433dd32cf6906337a6bd293 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 03/19] debug: Move logging to callback to separate function

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 78b4599..ea9e58f 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -547,6 +547,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
@@ -765,16 +779,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 13361599694b4aa0eaa67cc22fc275e8f4aa740c 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 04/19] debug: Move mapping from level to syslog priority to helper function

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 ea9e58f..0405e00 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -103,6 +103,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.
  */
@@ -809,21 +833,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 ef60b2b4afa5ba4629d204e7de40de5fe1b0259e 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 05/19] debug: Add infrastructure for supporting multiple backends

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 lib/util/debug.c |  127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 127 insertions(+), 0 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 0405e00..275c22f 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -128,6 +128,127 @@ 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;
+}
+
+static void debug_backend_parse_token(char *tok)
+{
+	char *backend_name, *backend_level, *saveptr;
+	struct debug_backend *b;
+
+	backend_name = strtok_r(tok, ":\0", &saveptr);
+	if (backend_name == NULL) {
+		return;
+	}
+
+	b = debug_find_backend(backend_name);
+	if (b == NULL) {
+		return;
+	}
+
+	backend_level = strtok_r(NULL, "\0", &saveptr);
+	if (backend_level == NULL) {
+		b->new_log_level = MAX_DEBUG_LEVEL;
+	} else {
+		b->new_log_level = atoi(backend_level);
+	}
+}
+
+/*
+ * parse string "backend1[:loglevel1] backend2[: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 len = strlen(msg);
+	int i;
+
+	/*
+	 * Some backends already add an extra newline, so also provide
+	 * a buffer without the newline character.
+	 */
+	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.
  */
 
@@ -465,6 +586,7 @@ Init debugging (one time stuff)
 
 static void debug_init(void)
 {
+	int i;
 	const char **p;
 
 	if (state.initialized)
@@ -477,6 +599,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 3a9ad46e2ef95a81b317408e68e0e115e7e9fdf1 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 06/19] debug: Add file backend

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 275c22f..3dad696 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -132,6 +132,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;
@@ -139,6 +146,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 667b8a6a84f43c6d7dee57e6139fb04a29b67acf Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 14:14:53 -0700
Subject: [PATCH 07/19] debug: Add syslog backend

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 lib/util/debug.c |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 3dad696..376eae7 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -139,6 +139,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;
@@ -150,6 +186,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)
@@ -653,14 +696,7 @@ 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
+		debug_syslog_reload(true, false, state.prog_name);
 	}
 }
 
-- 
1.7.1


From d6d47813f618e931d42974c82ed6927cc37a8e38 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 08/19] 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>
---
 docs-xml/smbdotconf/logging/logging.xml |   29 +++++++++++++++++++++++++++++
 lib/param/param_table.c                 |    9 +++++++++
 2 files changed, 38 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..83b5183
--- /dev/null
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -0,0 +1,29 @@
+<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 log level for a backend is optional,
+    if it is not set for a backend, all messages are sent to this
+    backend. The parameter 'log level' determines overall log levels,
+    while the log levels specified here apply to the individual
+    backends.</para>
+
+  <para>When 'logging' is set, it overrides the 'syslog' and 'syslog
+  only' parameters.</para>
+
+  <para>The following backends are available:</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:1 file</value>
+</samba:parameter>
diff --git a/lib/param/param_table.c b/lib/param/param_table.c
index 00274ca..bb3204a 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 2251482f75aae14bee0cc705950f3669953704e4 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 09/19] 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>
---
 lib/param/loadparm.c |    6 +++---
 lib/util/debug.c     |   40 ++++++++++++++++++++++++++++++++--------
 lib/util/debug.h     |    4 +++-
 lib/util/debug_s3.c  |    5 ++---
 4 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 115575c..f9d7bd1 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -2843,15 +2843,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 376eae7..213193a 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -660,12 +660,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);
 }
 
 /**
@@ -694,10 +722,6 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
 		state.prog_name = prog_name;
 	}
 	reopen_logs_internal();
-
-	if (state.logtype == DEBUG_FILE) {
-		debug_syslog_reload(true, false, state.prog_name);
-	}
 }
 
 /***************************************************************************
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 31222f6a792041d5d3e1199f4c332fae24acd696 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 10/19] 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>
---
 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 213193a..de2d808 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1013,23 +1013,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 ae10f95b0913e4b82fb17684ea11b0bc612fb0f2 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 11/19] debug: Use backends instead of explicitly logging to syslog or file

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 de2d808..ad1c375 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1012,30 +1012,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 2d2e420bd07a6689c371371eac32ed63112c1785 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 12/19] debug: Simplify Debug1

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 ad1c375..adb1cb1 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -994,33 +994,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 98dc751169365dacc486f913f8ca86c54647610f 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 13/19] debug: Remove now unused syslog variables from debug_settings

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 adb1cb1..52a62d7 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -673,9 +673,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 b2e3e9752a559190ff21d5740354d25b90bd25bd 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 14/19] param: Mark syslog and syslog_only as deprecated

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

diff --git a/docs-xml/smbdotconf/logging/syslog.xml b/docs-xml/smbdotconf/logging/syslog.xml
index e4722d8..6a5bd8c 100644
--- a/docs-xml/smbdotconf/logging/syslog.xml
+++ b/docs-xml/smbdotconf/logging/syslog.xml
@@ -16,6 +16,9 @@
     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 'logging' parameter should be used instead. When
+    'logging' is set, it overrides the '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..b4aee7e 100644
--- a/docs-xml/smbdotconf/logging/syslogonly.xml
+++ b/docs-xml/smbdotconf/logging/syslogonly.xml
@@ -9,6 +9,10 @@
     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 'logging' parameter should be used instead. When
+      'logging' is set, it overrides the '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 bb3204a..94f1417 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 763a54f4f167b2caa61fa50b64e2aa2e91489528 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 9 Jan 2015 15:34:05 -0700
Subject: [PATCH 15/19] debug: Add systemd backend

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 docs-xml/smbdotconf/logging/logging.xml |    1 +
 lib/util/debug.c                        |   21 ++++++++++++++++++++-
 lib/util/wscript_build                  |    1 +
 wscript                                 |   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 83b5183..4bc5668 100644
--- a/docs-xml/smbdotconf/logging/logging.xml
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -21,6 +21,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 52a62d7..d06965f 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -103,7 +103,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)
 {
 	/*
@@ -175,6 +175,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;
@@ -193,6 +205,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 b1cdfd5..1da4f24 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/wscript b/wscript
index f1d2e97..5b302e2 100644
--- a/wscript
+++ b/wscript
@@ -229,6 +229,20 @@ def configure(conf):
         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')
+
     conf.SAMBA_CONFIG_H('include/config.h')
 
 def etags(ctx):
-- 
1.7.1


From f0793681ffacb98cb7e54cc8c88c2b31ed587be3 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 16/19] debug: Add lttng backend

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 docs-xml/smbdotconf/logging/logging.xml |    1 +
 lib/util/debug.c                        |   17 +++++++++++++++++
 lib/util/wscript_build                  |    2 +-
 wscript                                 |   19 +++++++++++++++++++
 4 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/docs-xml/smbdotconf/logging/logging.xml b/docs-xml/smbdotconf/logging/logging.xml
index 4bc5668..77957b7 100644
--- a/docs-xml/smbdotconf/logging/logging.xml
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -22,6 +22,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 d06965f..553c74c 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -187,6 +187,16 @@ 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;
@@ -212,6 +222,13 @@ 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_build b/lib/util/wscript_build
index 1da4f24..9aa2df9 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/wscript b/wscript
index 5b302e2..37da8c8 100644
--- a/wscript
+++ b/wscript
@@ -78,6 +78,14 @@ def set_options(opt):
                    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')
+
     gr = opt.option_group('developer options')
 
     opt.tool_options('python') # options for disabling pyc or pyo compilation
@@ -243,6 +251,17 @@ def configure(conf):
         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
+
     conf.SAMBA_CONFIG_H('include/config.h')
 
 def etags(ctx):
-- 
1.7.1


From c942dc9d52a9ef212b43d854fb73f9286902a603 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 17/19] gpfswrap: Move gpfswrap to lib/util

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 lib/util/gpfswrap.c           |  226 +++++++++++++++++++++++++++++++++++++++++
 lib/util/gpfswrap.h           |   48 +++++++++
 lib/util/wscript_build        |   12 ++-
 source3/modules/gpfswrap.c    |  226 -----------------------------------------
 source3/modules/gpfswrap.h    |   48 ---------
 source3/modules/vfs_gpfs.c    |    2 +-
 source3/modules/wscript_build |    4 +-
 7 files changed, 288 insertions(+), 278 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 9aa2df9..95a76d3 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/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'),
-- 
1.7.1


From 1b4f479b592609abe57c812c4cfb7cc1203633a7 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 18/19] gpfswrap: Add wrappers for tracing API

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 e5cd2e0efdfd4801999b56a48a35005decf7c060 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 19/19] debug: Add GPFS tracing backend

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 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 77957b7..96d0e29 100644
--- a/docs-xml/smbdotconf/logging/logging.xml
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -23,6 +23,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 553c74c..e246945 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -196,6 +196,37 @@ 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
 
 static struct debug_backend {
 	const char *name;
@@ -229,6 +260,14 @@ static struct debug_backend {
 		.log = debug_lttng_log,
 	},
 #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



More information about the samba-technical mailing list