[PATCHES v2] Logging to multiple debug backends

Christof Schmitt cs at samba.org
Wed Mar 18 17:24:55 MDT 2015


Here is the updated patchset for the debug backends. The main change is
that an option field is reserved for the entries in the logging
parameter. It is unused at this point, but it will get used when logging
code from ctdb is also moved in a backend.

For completeness, the logging config with this patch applied looks like:
log level = 3 passdb:5 auth:10 winbind:2 (unchanged by this patchset)
logging = file at 5 syslog at 1 lttng at 10       (new parameter for the backends)

I also reworded the manpage entry for the new logging parameter.

Christof
-------------- next part --------------
From 71c760f79da2f60126ef38c025690e5c29838461 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 dd263d414ca8684a9d249e44edc2b66ad2be7231 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 705bcf89527aec46dd51240514164c3ebf1b9f0e 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 0746dae9cbc2ea8b88e862683cd20177c6ae7360 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 ea17b59c1460a0753322ccf1fa86cc7804c9106a 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 |  152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 152 insertions(+), 0 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 0405e00..73085ea 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -128,6 +128,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 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 +611,7 @@ Init debugging (one time stuff)
 
 static void debug_init(void)
 {
+	int i;
 	const char **p;
 
 	if (state.initialized)
@@ -477,6 +624,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 198faf0555bc667e20b6332ac5f236d6413a4ec6 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 73085ea..85392fc 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 7d264513fab35c9fea52d715ec44c54afb820124 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 85392fc..76280b3 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)
@@ -678,14 +721,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 b603c9937b45de7c381057d30b897fc692ed9e48 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 |   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 1883f9eda8b2de0bd2e5f71f8a50da63213be81a 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 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 76280b3..51c9548 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -685,12 +685,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);
 }
 
 /**
@@ -719,10 +747,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 a27be77dc8ace12aee90fab60e3aab76df056ee5 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 51c9548..9392f8b 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1038,23 +1038,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 4b1fa253482c87669693c22acdcaafad9b0c74d9 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 9392f8b..05b485a 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1037,30 +1037,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 32e9a8f6cf050f24eb09c57f55438a7fe715d8d7 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 05b485a..bdde34a 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1019,33 +1019,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 62fc635133357e90faff365070083c0dbd2abae9 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 bdde34a..afb6f05 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -698,9 +698,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 ccebf4c3c5407140a3cd533f4734b8c8fbeaf442 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     |    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 507e8101819ce148a997b5f8251b4564cc63d498 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 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 afb6f05..e8675fe 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 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/wscript b/wscript
index 4e06576..e3da66b 100644
--- a/wscript
+++ b/wscript
@@ -226,6 +226,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 cfa7b94706786186960a0e974f67e3f38b9a664a 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 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 e8675fe..f0fca24 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 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/wscript b/wscript
index e3da66b..9d3615b 100644
--- a/wscript
+++ b/wscript
@@ -77,6 +77,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
@@ -240,6 +248,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 272fda1b0eb3113b5c028a6064f6c498e6ea1dbe 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 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/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 e26ababaa56c9d8f58c990a87d062abeddde39ff 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 12f693e667dfc20d8a806323abc3a1f4dc07a930 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 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 f0fca24..90148e0 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