[Ocfs2-commits] zab commits r2155 - trunk/fs/ocfs2/cluster

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Apr 20 13:31:35 CDT 2005


Author: zab
Signed-off-by: mfasheh
Date: 2005-04-20 13:31:33 -0500 (Wed, 20 Apr 2005)
New Revision: 2155

Added:
   trunk/fs/ocfs2/cluster/masklog.c
   trunk/fs/ocfs2/cluster/masklog.h
Modified:
   trunk/fs/ocfs2/cluster/Makefile
   trunk/fs/ocfs2/cluster/nodemanager.c
   trunk/fs/ocfs2/cluster/tcp.c
Log:
Introduce the mask logging so that we can turn on and off debugging at run
time.  Only tcp.c uses it as an example.  Once everything uses it we can get
rid of QUIET build options, etc.

Signed-off-by: mfasheh


Modified: trunk/fs/ocfs2/cluster/Makefile
===================================================================
--- trunk/fs/ocfs2/cluster/Makefile	2005-04-20 18:24:23 UTC (rev 2154)
+++ trunk/fs/ocfs2/cluster/Makefile	2005-04-20 18:31:33 UTC (rev 2155)
@@ -39,6 +39,7 @@
 
 SOURCES =			\
 	heartbeat.c		\
+	masklog.c		\
 	nodemanager.c		\
 	tcp.c			\
 	ver.c
@@ -46,6 +47,7 @@
 HEADERS = 			\
 	cl_compat.h		\
 	heartbeat.h		\
+	masklog.h		\
 	nodemanager.h		\
 	ocfs2_heartbeat.h	\
 	ocfs2_nodemanager.h	\

Added: trunk/fs/ocfs2/cluster/masklog.c
===================================================================
--- trunk/fs/ocfs2/cluster/masklog.c	2005-04-20 18:24:23 UTC (rev 2154)
+++ trunk/fs/ocfs2/cluster/masklog.c	2005-04-20 18:31:33 UTC (rev 2155)
@@ -0,0 +1,182 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2004, 2005 Oracle.  All rights reserved.
+ *
+ * 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 2 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/string.h>
+#include <asm/uaccess.h>
+
+#include "masklog.h"
+
+struct mlog_bits mlog_active_bits = MLOG_BITS_RHS(MLOG_INITIAL_MASK);
+EXPORT_SYMBOL(mlog_active_bits);
+
+static char *mlog_bit_names[MLOG_MAX_BITS];
+
+static void *mlog_name_from_pos(loff_t *caller_pos)
+{
+	loff_t pos = *caller_pos;
+	while (pos < ARRAY_SIZE(mlog_bit_names) && mlog_bit_names[pos] == NULL)
+		pos++;
+
+	if (pos >= ARRAY_SIZE(mlog_bit_names))
+		return NULL;
+
+	*caller_pos = pos;
+	return &mlog_bit_names[pos];
+}
+
+static void *mlog_seq_start(struct seq_file *seq, loff_t *pos)
+{
+	return mlog_name_from_pos(pos);
+}
+
+static void *mlog_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+	(*pos)++;
+	return mlog_name_from_pos(pos);
+}
+
+static int mlog_seq_show(struct seq_file *seq, void *v)
+{
+	char **name = v;
+	int bit = name - mlog_bit_names;
+
+	seq_printf(seq, "%s %s\n", *name,
+		   __mlog_test_u64((u64)1 << bit, mlog_active_bits) ?
+			"on" : "off");
+	return 0;
+}
+
+static void mlog_seq_stop(struct seq_file *p, void *v)
+{
+}
+
+static struct seq_operations mlog_seq_ops = {
+	.start = mlog_seq_start,
+	.next = mlog_seq_next,
+	.stop = mlog_seq_stop,
+	.show = mlog_seq_show,
+};
+
+static int mlog_fop_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &mlog_seq_ops);
+}
+
+static ssize_t mlog_fop_write(struct file *filp, const char __user *buf,
+			      size_t count, loff_t *pos)
+{
+	char *name;
+	char str[16], *mask, *val;
+	unsigned i;
+
+	if (count == 0)
+		return 0;
+
+	/* count at least mask + space + 1 */
+	if (*pos != 0 || count < 3 || count >= sizeof(str))
+		return -EINVAL;
+
+	if (copy_from_user(str, buf, count))
+		return -EFAULT;
+
+	str[count] = '\0';
+
+	mask = str;
+	val = strpbrk(str, " ");
+	if (val == NULL)
+		return -EINVAL;
+	*val = '\0';
+	val++;
+
+	if (strlen(val) == 0)
+		return -EINVAL;
+
+	for (i = 0; i < ARRAY_SIZE(mlog_bit_names); i++) {
+		name = mlog_bit_names[i];
+		if (name == NULL || strnicmp(mask, name, strlen(name)))
+			continue;
+		break;
+	}
+	if (i == ARRAY_SIZE(mlog_bit_names))
+		return -EINVAL;
+
+	if (!strnicmp(val, "on", 2) || !strnicmp(val, "1", 1)) {
+		__mlog_set_u64((u64)1 << i, mlog_active_bits);
+	} else if (!strnicmp(val, "off", 3) || !strnicmp(val, "0", 1)) {
+		__mlog_clear_u64((u64)1 << i, mlog_active_bits);
+	} else
+		return -EINVAL;
+
+	*pos += count;
+	return count;
+}
+
+static struct file_operations mlog_seq_fops = {
+	.owner = THIS_MODULE,
+	.open = mlog_fop_open,
+	.read = seq_read,
+	.write = mlog_fop_write,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
+
+#define set_a_string(which) do {					\
+	struct mlog_bits _bits = {{0,}, };				\
+	int _bit;							\
+	__mlog_set_u64(ML_##which, _bits);				\
+	_bit = find_first_bit(_bits.words, MLOG_MAX_BITS);		\
+	mlog_bit_names[_bit] = #which;					\
+} while (0)
+
+#define LOGMASK_PROC_NAME "log_mask"
+
+void mlog_remove_proc(struct proc_dir_entry *parent)
+{
+	remove_proc_entry(LOGMASK_PROC_NAME, parent);
+}
+
+int mlog_init_proc(struct proc_dir_entry *parent)
+{
+	struct proc_dir_entry *p;
+
+	set_a_string(ENTRY);
+	set_a_string(EXIT);
+	set_a_string(TCP);
+	set_a_string(MSG);
+	set_a_string(SOCKET);
+	set_a_string(ERROR);
+	set_a_string(NOTICE);
+	set_a_string(KTHREAD);
+
+	p = create_proc_entry(LOGMASK_PROC_NAME, S_IRUGO, parent);
+	if (p == NULL)
+		return -ENOMEM;
+
+	p->proc_fops = &mlog_seq_fops;
+
+	return 0;
+}
+EXPORT_SYMBOL(mlog_init_proc);

Added: trunk/fs/ocfs2/cluster/masklog.h
===================================================================
--- trunk/fs/ocfs2/cluster/masklog.h	2005-04-20 18:24:23 UTC (rev 2154)
+++ trunk/fs/ocfs2/cluster/masklog.h	2005-04-20 18:31:33 UTC (rev 2155)
@@ -0,0 +1,152 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2005 Oracle.  All rights reserved.
+ *
+ * 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 2 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#ifndef CLUSTER_MASKLOG_H
+#define CLUSTER_MASKLOG_H
+
+/*
+ * For now this is a trivial wrapper around printk() that gives the critical
+ * ability to enable sets of debugging output at run-time.  In the future this
+ * will almost certainly be redirected to relayfs so that it can pay a
+ * substantially lower heisenberg tax.
+ *
+ * Callers associate the message with a bitmask and a global bitmask is
+ * maintained with help from /proc.  If any of the bits match the message is
+ * output.
+ *
+ * We must have efficient bit tests on i386 and it seems gcc still emits crazy
+ * code for the 64bit compare.  It emits very good code for the dual unsigned
+ * long tests, though, completely avoiding tests that can never pass if the
+ * caller gives a constant bitmask that fills one of the longs with all 0s.  So
+ * the desire is to have almost all of the calls decided on by comparing just
+ * one of the longs.  This leads to having infrequently given bits that are
+ * frequently matched in the high bits.
+ *
+ * _ERROR and _NOTICE are used for messages that always go to the console and
+ * have appropriate KERN_ prefixes.  We wrap these in our function instead of
+ * just calling printk() so that this can eventually make its way through
+ * relayfs along with the debugging messages.  Everything else gets KERN_DEBUG.
+ * The inline tests and macro dance give GCC the opportunity to quite cleverly
+ * only emit the appropriage printk() when the caller passes in a constant
+ * mask, as is almost always the case.
+ *
+ * All this bitmask nonsense is hidden from the /proc interface so that Joel
+ * doesn't have an aneurism.  Reading the file gives a straight forward
+ * indication of which bits are on or off:
+ * 	ENTRY off
+ * 	EXIT off
+ * 	TCP off
+ * 	MSG off
+ * 	SOCKET off
+ * 	ERROR off
+ * 	NOTICE on
+ *
+ * Writing changes the state of a given bit and requires a strictly formatted
+ * single write() call:
+ *
+ * 	write(fd, "ENTRY on", 8);
+ *
+ * would turn the entry bit on.  "1" is also accepted in the place of "on", and
+ * "off" and "0" behave as expected.
+ *
+ * Some trivial shell can flip all the bits on or off:
+ *
+ * log_mask="/proc/fs/ocfs2_nodemanager/log_mask"
+ * cat $log_mask | (
+ * 	while read bit status; do
+ * 		# $1 is "on" or "off", say
+ * 		echo "$bit $1" > $log_mask
+ * 	done
+ * )
+ */
+
+/* bits that are frequently given and infrequently matched in the low word */
+#define ML_ENTRY	0x0000000000000001ULL /* func call entry */
+#define ML_EXIT		0x0000000000000002ULL /* func call exit */
+#define ML_TCP		0x0000000000000004ULL /* cluster/tcp.c */
+#define ML_MSG		0x0000000000000008ULL /* network messages */
+#define ML_SOCKET	0x0000000000000010ULL /* socket lifetime */
+/* bits that are infrequently given and frequently matched in the high word */
+#define ML_ERROR	0x0000000100000000ULL /* sent to KERN_ERR */
+#define ML_NOTICE	0x0000000200000000ULL /* setn to KERN_NOTICE */
+#define ML_KTHREAD	0x0000000400000000ULL /* kernel thread activity */
+
+#define MLOG_INITIAL_MASK (ML_ERROR|ML_NOTICE)
+
+#define MLOG_MAX_BITS 64
+
+struct mlog_bits {
+	unsigned long words[MLOG_MAX_BITS / BITS_PER_LONG];
+};
+
+extern struct mlog_bits mlog_active_bits;
+
+#if BITS_PER_LONG == 32
+
+#define __mlog_test_u64(mask, bits)	\
+	( (u32)(mask) & bits.words[0] || ((u64)(mask) >> 32) & bits.words[1] )
+#define __mlog_set_u64(mask, bits) do {		\
+	bits.words[0] |= (u32)(mask);		\
+       	bits.words[1] |= (u64)(mask) >> 32;	\
+} while (0)
+#define __mlog_clear_u64(mask, bits) do {	\
+	bits.words[0] &= ~((u32)(mask));		\
+       	bits.words[1] &= ~((u64)(mask) >> 32);	\
+} while (0)
+#define MLOG_BITS_RHS(mask) {		\
+	{				\
+		[0] = (u32)(mask),	\
+		[1] = (u64)(mask) >> 32,\
+	}				\
+}
+
+#else /* 32bit long above, 64bit long below */
+
+#define __mlog_test_u64(mask, bits)	((mask) & bits.words[0])
+#define __mlog_set_u64(mask, bits) do {	\
+	bits.words[0] |= (mask);
+} while (0)
+#define __mlog_clear_u64(mask, bits) do {	\
+	bits.words[0] &= ~(mask);
+} while (0)
+#define MLOG_BITS_RHS(mask) mask
+
+#endif
+
+#define __mlog_printk(level, fmt, args...)				\
+	printk(level "(%u,%u)"__FILE__":%s:%d " fmt, current->pid,	\
+	       smp_processor_id(), __PRETTY_FUNCTION__, __LINE__, ##args)
+
+#define mlog(mask, fmt, args...) do {					\
+	u64 __m = MLOG_MASK_PREFIX (mask);				\
+	if (__mlog_test_u64(__m, mlog_active_bits)) {			\
+		if (__m & ML_ERROR)					\
+			__mlog_printk(KERN_ERR, "ERROR: "fmt, ##args);	\
+		else if (__m & ML_NOTICE)				\
+			__mlog_printk(KERN_NOTICE, fmt, ##args);	\
+		else __mlog_printk(KERN_DEBUG, fmt, ##args);		\
+	}								\
+} while (0)
+
+int mlog_init_proc(struct proc_dir_entry *parent);
+void mlog_remove_proc(struct proc_dir_entry *parent);
+
+#endif /* CLUSTER_MASKLOG_H */

Modified: trunk/fs/ocfs2/cluster/nodemanager.c
===================================================================
--- trunk/fs/ocfs2/cluster/nodemanager.c	2005-04-20 18:24:23 UTC (rev 2154)
+++ trunk/fs/ocfs2/cluster/nodemanager.c	2005-04-20 18:31:33 UTC (rev 2155)
@@ -62,6 +62,7 @@
 #include "tcp.h"
 #include "nodemanager.h"
 #include "heartbeat.h"
+#include "masklog.h"
 #include "ver.h"
 
 #include "configfs.h"
@@ -765,6 +766,9 @@
 	},
 };
 
+#define NM_PROC_PATH "fs/ocfs2_nodemanager"
+static struct proc_dir_entry *nm_proc;
+
 static void __exit exit_nm(void)
 {
 	nmprintk("unloading nm module\n");
@@ -775,6 +779,8 @@
 	/* XXX sync with hb callbacks and shut down hb? */
 	net_unregister_hb_callbacks();
 	configfs_unregister_subsystem(&nm_cluster_group.cs_subsys);
+	mlog_remove_proc(nm_proc);
+	remove_proc_entry(NM_PROC_PATH, NULL);
 }
 
 static int __init init_nm(void)
@@ -783,28 +789,45 @@
 
 	cluster_print_version();
 
+	hb_init();
+
 	ocfs2_table_header = register_sysctl_table(ocfs2_root_table, 0);
 	if (!ocfs2_table_header) {
 		printk(KERN_ERR "nodemanager: unable to register sysctl\n");
-		goto bail;
+		ret = -ENOMEM; /* or something. */
+		goto out;
 	}
 
-	hb_init();
 	ret = net_register_hb_callbacks();
-	if (!ret) {
-		config_group_init(&nm_cluster_group.cs_subsys.su_group);
-		init_MUTEX(&nm_cluster_group.cs_subsys.su_sem);
-		ret = configfs_register_subsystem(&nm_cluster_group.cs_subsys);
-		if (ret) {
-			printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
-			net_unregister_hb_callbacks();
-		}
+	if (ret)
+		goto out_sysctl;
+
+	config_group_init(&nm_cluster_group.cs_subsys.su_group);
+	init_MUTEX(&nm_cluster_group.cs_subsys.su_sem);
+	ret = configfs_register_subsystem(&nm_cluster_group.cs_subsys);
+	if (ret) {
+		printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
+		goto out_callbacks;
 	}
 
-bail:
-	if (ret && ocfs2_table_header)
-		unregister_sysctl_table(ocfs2_table_header);
+	nm_proc = proc_mkdir(NM_PROC_PATH, 0);
+	if (nm_proc == NULL) {
+		ret = -ENOMEM; /* shrug */
+		goto out_subsys;
+	}
 
+	ret = mlog_init_proc(nm_proc);
+	if (ret == 0)
+		goto out;
+
+	remove_proc_entry(NM_PROC_PATH, NULL);
+out_subsys:
+	configfs_unregister_subsystem(&nm_cluster_group.cs_subsys);
+out_callbacks:
+	net_unregister_hb_callbacks();
+out_sysctl:
+	unregister_sysctl_table(ocfs2_table_header);
+out:
 	return ret;
 }
 

Modified: trunk/fs/ocfs2/cluster/tcp.c
===================================================================
--- trunk/fs/ocfs2/cluster/tcp.c	2005-04-20 18:24:23 UTC (rev 2154)
+++ trunk/fs/ocfs2/cluster/tcp.c	2005-04-20 18:31:33 UTC (rev 2155)
@@ -105,29 +105,17 @@
 #include "heartbeat.h"
 #include "tcp.h"
 #include "nodemanager.h"
+#include "masklog.h"
 
-#ifndef ENABLE_NETPRINTK
-#define netprintk(x, arg...)    
-#define netprintk0(x)           
-#define msgprintk(hdr, fmt, args...)
-#define msgprintk0(hdr, fmt)
-#define scprintk(sc, fmt, args...)
-#define scprintk0(sc, fmt)
-#else
-#define netprintk(x, arg...)    printk("(tcp:%d)(%s:%d) " x, current->pid, __FUNCTION__, __LINE__, ##arg)
-#define netprintk0(x)           printk("(tcp:%d)(%s:%d) " x, current->pid, __FUNCTION__, __LINE__)
+#define MLOG_MASK_PREFIX ML_TCP|
 
 #define __msg_fmt "[mag %u len %u typ %u status %d key %u num %u] "
 #define __msg_args __hdr->magic, __hdr->data_len, __hdr->msg_type, 	\
  	__hdr->status,	__hdr->key, __hdr->msg_num
-#define msgprintk(hdr, fmt, args...) do {				\
+#define msglog(hdr, fmt, args...) do {					\
 	typeof(hdr) __hdr = (hdr);					\
-	printk(__msg_fmt fmt, __msg_args, args);			\
+	mlog(ML_MSG, __msg_fmt fmt, __msg_args, ##args);		\
 } while (0)
-#define msgprintk0(hdr, fmt) do {					\
-	typeof(hdr) __hdr = (hdr);					\
-	printk(__msg_fmt fmt, __msg_args);				\
-} while (0)
 
 #define __sc_fmt 							\
 	"[sc %p refs %d sock %p node %p from_con %u item_on %d "	\
@@ -135,16 +123,11 @@
 #define __sc_args __sc, atomic_read(&__sc->sc_kref.refcount), 		\
 	__sc->sc_sock,	__sc->sc_node, __sc->sc_from_connect, 		\
 	!list_empty(&__sc->sc_item), __sc->sc_page, __sc->sc_page_off
-#define scprintk(sc, fmt, args...) do {					\
+#define sclog(sc, fmt, args...) do {					\
 	typeof(sc) __sc = (sc);						\
-	printk(__sc_fmt fmt, __sc_args, args);				\
+	mlog(ML_SOCKET, __sc_fmt fmt, __sc_args, ##args);		\
 } while (0)
-#define scprintk0(sc, fmt) do {						\
-	typeof(sc) __sc = (sc);						\
-	printk(__sc_fmt fmt, __sc_args);				\
-} while (0)
 
-#endif
 
 /* let's only pollute this unit with these ridiculous definitions */
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
@@ -252,15 +235,15 @@
 		goto out;
 	}
 
-	netprintk0("starting net receive thread...\n");
+	mlog(ML_KTHREAD, "starting net receive thread...\n");
 
 	node->nd_rx_thread = kthread_run(net_receive_thread, sock,
 				     "netrecv-%s", node->nd_name);
 	if (IS_ERR(node->nd_rx_thread)) {
 		ret = PTR_ERR(node->nd_rx_thread);
 		node->nd_rx_thread = NULL;
-		netprintk("unable to launch net receive thread, error=%ld\n",
-			  (long)ret);
+		mlog(ML_ERROR, "unable to launch net receive thread, "
+		     "error=%ld\n", (long)ret);
 		goto out;
 	}
 
@@ -277,7 +260,7 @@
 void net_stop_rx_thread(struct nm_node *node)
 {
 	if (node->nd_rx_thread) {
-		netprintk("waiting for net thread to exit....\n");
+		mlog(ML_KTHREAD, "waiting for net thread to exit....\n");
 		kthread_stop(node->nd_rx_thread);
 		node->nd_rx_thread = NULL;
 		net_recv_task = NULL;
@@ -298,7 +281,7 @@
 {
 	struct net_sock_container *sc = container_of(kref,
 					struct net_sock_container, sc_kref);
-	scprintk0(sc, "releasing\n");
+	sclog(sc, "releasing\n");
 	if (sc->sc_sock) {
 		sock_release(sc->sc_sock);
 		sc->sc_sock = NULL;
@@ -307,7 +290,7 @@
 
 static void sc_put(struct net_sock_container *sc)
 {
-	scprintk0(sc, "put\n");
+	sclog(sc, "put\n");
 	kref_put(&sc->sc_kref, sc_kref_release);
 }
 
@@ -381,7 +364,7 @@
 	if (sc == NULL)
 		goto out;
 
-	scprintk(sc, "detaching with node %p\n", node);
+	sclog(sc, "detaching with node %p\n", node);
 
 	spin_lock_bh(&sc->sc_lock);
 	if (sc->sc_node) {
@@ -406,7 +389,7 @@
 		spin_lock_bh(&node->nd_lock);
 		/* if the node is still pointing to us, drop that */
 		if (node->nd_sc == sc) {
-			printk(KERN_NOTICE "ocfs2:tcp: no longer connected to "
+			mlog(ML_NOTICE, "ocfs2:tcp: no longer connected to "
 			       "node %s at %u.%u.%u.%u:%d\n", node->nd_name,
 			       NIPQUAD(node->nd_ipv4_address), 
 			       ntohs(node->nd_ipv4_port));
@@ -428,7 +411,7 @@
 
 out:
 	if (sc) {
-		scprintk(sc, "detach droping %d refs\n", nr_puts);
+		sclog(sc, "detach droping %d refs\n", nr_puts);
 		while(nr_puts--)
 			sc_put(sc);
 	}
@@ -448,7 +431,7 @@
 		list_del_init(&sc->sc_item);
 		spin_unlock_bh(&net_active_lock);
 
-		scprintk0(sc, "found on connect list\n");
+		sclog(sc, "found on connect list\n");
 
 		net_attach_sc(sc);
 		sc_put(sc);
@@ -463,7 +446,7 @@
 		list_del_init(&sc->sc_item);
 		spin_unlock_bh(&net_active_lock);
 
-		scprintk0(sc, "found on detach list\n");
+		sclog(sc, "found on detach list\n");
 
 		net_detach_sc(sc, NULL);
 		sc_put(sc);
@@ -489,7 +472,7 @@
 {
 	struct socket *sock = data;
 
-	netprintk0("net thread running...\n");
+	mlog(ML_KTHREAD, "net thread running...\n");
 
        	while(!kthread_should_stop()) {
 		net_try_accept(sock);
@@ -501,7 +484,7 @@
 					 kthread_should_stop());
 	}
 
-	netprintk("net thread exiting\n");
+	mlog(ML_KTHREAD, "net thread exiting\n");
 	sock_release(sock);
 	return 0;
 }
@@ -566,20 +549,20 @@
 	int ret = 0;
 
 	if (max_len > NET_MAX_PAYLOAD_BYTES) {
-		netprintk("max_len for message handler out of range: %u\n", 
+		mlog(0, "max_len for message handler out of range: %u\n", 
 			max_len);
 		ret = -EINVAL;
 		goto out;
 	}
 
 	if (!msg_type) {
-		netprintk("no message type provided: %u, %p\n", msg_type, func);
+		mlog(0, "no message type provided: %u, %p\n", msg_type, func);
 		ret = -EINVAL;
 		goto out;
 
 	}
 	if (!func) {
-		netprintk("no message handler provided: %u, %p\n",
+		mlog(0, "no message handler provided: %u, %p\n",
 		       msg_type, func);
 		ret = -EINVAL;
 		goto out;
@@ -698,7 +681,8 @@
 	ret = sock_sendmsg(sock, &msg, total);
 	set_fs(oldfs);
 	if (ret != total) {
-		netprintk("sendmsg returned %d instead of %zu\n", ret, total);
+		mlog(ML_ERROR, "sendmsg returned %d instead of %zu\n", ret,
+		     total);
 		if (ret >= 0)
 			ret = -EPIPE; /* should be smarter, I bet */
 		goto out;
@@ -707,7 +691,7 @@
 	ret = 0;
 out:
 	if (ret < 0)
-		netprintk("returning error: %d\n", ret);
+		mlog(0, "returning error: %d\n", ret);
 	return ret;
 }
 
@@ -797,8 +781,8 @@
 		num_kills++;
 	}
 	
-	netprintk("node %s (%u) died, killed %d messages\n", node->nd_name,
-		  node->nd_num, num_kills);
+	mlog(0, "node %s (%u) died, killed %d messages\n", node->nd_name,
+	     node->nd_num, num_kills);
 }
 
 static int net_nsw_completed(struct nm_node * node,
@@ -828,13 +812,13 @@
 	BUG_ON(net_recv_task && (current == net_recv_task));
 
 	if (net_recv_task == NULL) {
-		netprintk0("attempt to tx without a setup rx thread\n");
+		mlog(0, "attempt to tx without a setup rx thread\n");
 		ret = -ESRCH;
 		goto out;
 	}
 
 	if (caller_iovlen == 0) {
-		netprintk0("bad iovec array length\n");
+		mlog(0, "bad iovec array length\n");
 		ret = -EINVAL;
 		goto out;
 	}
@@ -843,7 +827,7 @@
 		caller_bytes += caller_iov[i].iov_len;
 
 	if (caller_bytes > NET_MAX_PAYLOAD_BYTES) {
-		netprintk("total payload len %zu too large\n", caller_bytes);
+		mlog(0, "total payload len %zu too large\n", caller_bytes);
 		ret = -EINVAL;
 		goto out;
 	}
@@ -855,7 +839,7 @@
 
 	node = nm_get_node_by_num(target_node);
 	if (node == NULL) {
-		netprintk("node %u unknown\n", target_node);
+		mlog(0, "node %u unknown\n", target_node);
 		ret = -EINVAL;
 		goto out;
 	}
@@ -868,14 +852,14 @@
 	iovlen = caller_iovlen + 1;
 	iov = kmalloc(sizeof(struct iovec) * iovlen, GFP_KERNEL);
 	if (iov == NULL) {
-		netprintk("failed to %zu element iovec!\n", iovlen);
+		mlog(0, "failed to %zu element iovec!\n", iovlen);
 		ret = -ENOMEM;
 		goto out;
 	}
 
 	msg = kmalloc(sizeof(net_msg), GFP_KERNEL);
 	if (!msg) {
-		netprintk("failed to allocate a net_msg!\n");
+		mlog(0, "failed to allocate a net_msg!\n");
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -903,9 +887,9 @@
 	ret = net_send_tcp_msg(sc->sc_sock, iov, iovlen,
 			       sizeof(net_msg) + caller_bytes);
 	net_msg_to_host(msg);  /* just swapping for printk, its unused now */
-	msgprintk(msg, "sending returned %d\n", ret);
+	msglog(msg, "sending returned %d\n", ret);
 	if (ret < 0) {
-		netprintk("error returned from net_send_tcp_msg=%d\n", ret);
+		mlog(0, "error returned from net_send_tcp_msg=%d\n", ret);
 		goto out;
 	}
 
@@ -919,8 +903,8 @@
 	if (status && !ret)
 		*status = nsw.ns_status;
 
-	netprintk("woken, returning system status %d, user status %d",
-		  ret, nsw.ns_status);
+	mlog(0, "woken, returning system status %d, user status %d",
+	     ret, nsw.ns_status);
 out:
 	if (sc)
 		sc_put(sc);
@@ -981,7 +965,7 @@
 	hdr->magic = NET_MSG_STATUS_MAGIC;  // twiddle the magic
 	hdr->data_len = 0;
 
-	msgprintk(hdr, "about to send status magic %d\n", err);
+	msglog(hdr, "about to send status magic %d\n", err);
 	/* hdr has been in host byteorder this whole time */
 	net_msg_to_net(hdr);
 	return net_send_tcp_msg(sock, &iov, 1, sizeof(net_msg));
@@ -997,7 +981,7 @@
 	assert_spin_locked(&net_active_lock);
 
 	if (list_empty(&sc->sc_item)) {
-		scprintk(sc, "adding to list %p\n", list);
+		sclog(sc, "adding to list %p\n", list);
 		kref_get(&sc->sc_kref);
 		list_add_tail(&sc->sc_item, list);
 	}
@@ -1021,7 +1005,7 @@
 		goto out;
 	}
 
-	scprintk0(sc, "data_ready hit\n");
+	sclog(sc, "data_ready hit\n");
 
 	spin_lock(&net_active_lock);
 	net_sc_list_add(sc, &net_active_list);
@@ -1057,7 +1041,7 @@
 		list_del_init(&sc->sc_item);
 		spin_unlock_bh(&net_active_lock);
 
-		scprintk0(sc, "found on active list\n");
+		sclog(sc, "found on active list\n");
 
 		err = 0;
 		read_eagain = 0;
@@ -1109,7 +1093,7 @@
 		/* this was swabbed above when we first read it */
 		hdr = page_address(sc->sc_page);
 
-		msgprintk(hdr, "at page_off %zu\n", sc->sc_page_off);
+		msglog(hdr, "at page_off %zu\n", sc->sc_page_off);
 
 		/* do we need more payload? */
 		if (sc->sc_page_off - sizeof(net_msg) < hdr->data_len) {
@@ -1143,7 +1127,7 @@
 			node = NULL;
 		}
 
-		scprintk(sc, "finished reading with %d\n", err);
+		sclog(sc, "finished reading with %d\n", err);
 		if (err == -EAGAIN)
 			err = 0;
 
@@ -1160,7 +1144,7 @@
 		/* this exists to catch the framing errors, all other
 		 * errors should come through state_change, really. */
 		if (err) {
-			scprintk(sc, "saw err %d, closing\n", err);
+			sclog(sc, "saw err %d, closing\n", err);
 			net_detach_sc(sc, NULL);
 		}
 
@@ -1203,8 +1187,8 @@
 	if (net_hb_down) {
 		status = hb_unregister_callback(net_hb_down);
 		if (status < 0)
-			printk("ocfs2_tcp: Status return %d unregistering "
-			       "heartbeat callback!\n", status);
+			mlog(ML_ERROR, "Status return %d unregistering "
+			     "heartbeat callback!\n", status);
 		kfree(net_hb_down);
 		net_hb_down = NULL;
 	}
@@ -1219,8 +1203,7 @@
 	enum net_system_error syserr;
 	struct net_msg_handler *nmh = NULL;
 
-	netprintk("received message header... magic=%u type=%u key=%u\n", 
-		  hdr->magic, hdr->msg_type, hdr->key);
+	msglog(hdr, "processing message\n");
 
 	if (hdr->magic == NET_MSG_STATUS_MAGIC) {
 		/* special type for returning message status */
@@ -1229,7 +1212,7 @@
 		ret = 0;
 		goto out;
 	} else if (hdr->magic != NET_MSG_MAGIC) {
-		msgprintk0(hdr, "bad magic\n");
+		msglog(hdr, "bad magic\n");
 		ret = -EINVAL;
 		goto out;
 	}
@@ -1258,8 +1241,8 @@
 	/* this destroys the hdr, so don't use it after this */
 	ret = net_send_status_magic(sock, hdr, syserr, handler_status);
 	hdr = NULL;
-	netprintk("sending handler status %d, syserr %d returned %d\n",
-		  handler_status, syserr, ret);
+	mlog(0, "sending handler status %d, syserr %d returned %d\n",
+	     handler_status, syserr, ret);
 
 out:
 	if (nmh)
@@ -1280,7 +1263,7 @@
 	struct net_sock_container *detach = NULL;
 	struct nm_node *node = sc->sc_node;
 
-	scprintk(sc, "attaching with node %p\n", node);
+	sclog(sc, "attaching with node %p\n", node);
 
 	BUG_ON(node == NULL);
 
@@ -1319,11 +1302,10 @@
 			atomic_inc(&node->nd_sc_generation);
 			wake_up_all(&node->nd_sc_wq);
 		}
-		printk(KERN_NOTICE "ocfs2:tcp: %s connection to node %s at "
-		       "%u.%u.%u.%u:%d\n", 
-		       sc->sc_from_connect ? "initiated" : "accepted",
-		       node->nd_name, NIPQUAD(node->nd_ipv4_address), 
-		       ntohs(node->nd_ipv4_port));
+		mlog(ML_NOTICE, "%s connection to node %s at %u.%u.%u.%u:%d\n", 
+		     sc->sc_from_connect ? "initiated" : "accepted",
+		     node->nd_name, NIPQUAD(node->nd_ipv4_address), 
+		     ntohs(node->nd_ipv4_port));
 	}
 	spin_unlock_bh(&node->nd_lock); 
 	if (ret)
@@ -1344,7 +1326,7 @@
 	net_sc_list_add(sc, &net_active_list);
 	spin_unlock_bh(&net_active_lock);
 out:
-	scprintk(sc, "attaching now node %p returned %d\n", node, ret);
+	sclog(sc, "attaching now node %p returned %d\n", node, ret);
 	return ret;
 }
 
@@ -1364,7 +1346,7 @@
 		goto out;
 	}
 
-	scprintk(sc, "state_change to %d\n", sk->sk_state);
+	sclog(sc, "state_change to %d\n", sk->sk_state);
 
 	state_change = sc->sc_state_change;
 
@@ -1412,7 +1394,7 @@
 	INIT_LIST_HEAD(&sc->sc_item);
 	INIT_LIST_HEAD(&sc->sc_handlers);
 
-	scprintk0(sc, "alloced\n");
+	sclog(sc, "alloced\n");
 
 	ret = sc;
 	sc->sc_page = page;
@@ -1450,7 +1432,7 @@
 
 	ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
 	if (ret < 0) {
-		netprintk("can't create socket: %d\n", ret);
+		mlog(0, "can't create socket: %d\n", ret);
 		goto out;
 	}
 
@@ -1460,7 +1442,7 @@
 	ret = sock->ops->bind(sock, (struct sockaddr *)&myaddr,
 			      sizeof(myaddr));
 	if (ret) {
-		netprintk("bind failed: %d\n", ret);
+		mlog(0, "bind failed: %d\n", ret);
 		goto out;
 	}
 	
@@ -1483,7 +1465,7 @@
 	if (ret == -EINPROGRESS)
 		ret = 0;
 
-	scprintk(sc, "->connect gave %d\n", ret);
+	sclog(sc, "->connect gave %d\n", ret);
 out:
 	/* if ret == 0 then the callback has the responsibility of calling
 	 * net_finish_connect */
@@ -1585,15 +1567,15 @@
 
 out:
 	if (sc) {
-		scprintk(sc, "returning for node %s (%u)\n", node->nd_name,
+		sclog(sc, "returning for node %s (%u)\n", node->nd_name,
 			 node->nd_num);
 		*sc_ret = sc;
 	}
 
 	BUG_ON(ret == 0 && sc == NULL);
 	BUG_ON(ret && sc);
-	netprintk("sc_get for node %s (%u) gave %d, %p\n", node->nd_name,
-		  node->nd_num, ret, sc);
+	mlog(0, "sc_get for node %s (%u) gave %d, %p\n", node->nd_name,
+	     node->nd_num, ret, sc);
 	return ret;
 }
 
@@ -1625,17 +1607,12 @@
 	
 	node = nm_get_node_by_ip(sin.sin_addr.s_addr);
 	if (node == NULL) {
-		printk(KERN_WARNING "attempt to connect from unknown node at "
-			  "%u.%u.%u.%u:%d\n", NIPQUAD(sin.sin_addr.s_addr),
-			  ntohs(sin.sin_port));
+		mlog(ML_NOTICE, "attempt to connect from unknown node at "
+		     "%u.%u.%u.%u:%d\n", NIPQUAD(sin.sin_addr.s_addr),
+		     ntohs(sin.sin_port));
 		goto out;
 	}
 
-	if (ntohs(sin.sin_port) >= 1024)
-		netprintk("warning: connect from unprivileged port: "
-			  "%u.%u.%u.%u:%d\n", NIPQUAD(sin.sin_addr.s_addr),
-			  ntohs(sin.sin_port));
-
 	sc = sc_alloc(node, 0);
 	if (sc == NULL) {
 		ret = -ENOMEM;
@@ -1669,7 +1646,7 @@
 
 	error = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
 	if (error < 0) {
-		netprintk("unable to create socket, error=%d\n", error);
+		mlog(ML_ERROR, "unable to create socket, error=%d\n", error);
 		goto bail;
 	}
 
@@ -1680,8 +1657,8 @@
 
 	error = sock->ops->bind(sock, (struct sockaddr *)&sin, sizeof(sin));
 	if (error < 0) {
-		netprintk ("unable to bind socket to port %d, error=%d\n", 
-			ntohs(port), error);
+		mlog(ML_ERROR, "unable to bind socket to port %d, error=%d\n", 
+		     ntohs(port), error);
 		goto bail;
 	}
 



More information about the Ocfs2-commits mailing list