mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nick Andrew <nick@nick-andrew.net>
To: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH v1 3/3] Sample refactor of socket.c to use recursive printk
Date: Sat, 06 Dec 2008 18:00:23 +1100	[thread overview]
Message-ID: <20081206070023.29149.92171.stgit@marcab.local.tull.net> (raw)
In-Reply-To: <20081206065922.29149.63380.stgit@marcab.local.tull.net>

Sample refactor of socket.c to use recursive printk

Add a new function net_printk which takes a level argument
(kernel message level), format string and varargs and
calls printk with this format string and arguments:

    printk("%sNET: %v\n", level, fmt, args);

This is a proof of concept to show that recursive printk
works and is useful.

Signed-off-by: Nick Andrew <nick@nick-andrew.net>
---

 net/socket.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)


diff --git a/net/socket.c b/net/socket.c
index 92764d8..d2e0d67 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -171,6 +171,19 @@ static DEFINE_PER_CPU(int, sockets_in_use) = 0;
 					   :unix_mkname()).
 					 */
 
+/* printk for net subsystem.
+ * Prefixes every message with NET:
+ *
+ */
+
+void net_printk(char *level, char *fmt, ...) {
+	va_list	ap;
+	va_start(ap, fmt);
+
+	printk("%sNET: %v\n", level, fmt, ap);
+	va_end(ap);
+}
+
 /**
  *	move_addr_to_kernel	-	copy a socket address into kernel space
  *	@uaddr: Address in user space
@@ -535,7 +548,7 @@ void sock_release(struct socket *sock)
 	}
 
 	if (sock->fasync_list)
-		printk(KERN_ERR "sock_release: fasync list not empty!\n");
+		net_printk(KERN_ERR, "sock_release: fasync list not empty!");
 
 	get_cpu_var(sockets_in_use)--;
 	put_cpu_var(sockets_in_use);
@@ -987,7 +1000,7 @@ static int sock_close(struct inode *inode, struct file *filp)
 	 */
 
 	if (!inode) {
-		printk(KERN_DEBUG "sock_close: NULL inode\n");
+		net_printk(KERN_DEBUG, "sock_close: NULL inode");
 		return 0;
 	}
 	sock_release(SOCKET_I(inode));
@@ -1116,7 +1129,7 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
 		static int warned;
 		if (!warned) {
 			warned = 1;
-			printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n",
+			net_printk(KERN_INFO, "%s uses obsolete (PF_INET,SOCK_PACKET)",
 			       current->comm);
 		}
 		family = PF_PACKET;
@@ -1134,7 +1147,7 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
 	sock = sock_alloc();
 	if (!sock) {
 		if (net_ratelimit())
-			printk(KERN_WARNING "socket: no more sockets\n");
+			net_printk(KERN_WARNING, "socket: no more sockets");
 		return -ENFILE;	/* Not exactly a match, but its the
 				   closest posix thing */
 	}
@@ -2162,7 +2175,7 @@ int sock_register(const struct net_proto_family *ops)
 	int err;
 
 	if (ops->family >= NPROTO) {
-		printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family,
+		net_printk(KERN_CRIT, "protocol %d >= NPROTO(%d)", ops->family,
 		       NPROTO);
 		return -ENOBUFS;
 	}
@@ -2176,7 +2189,7 @@ int sock_register(const struct net_proto_family *ops)
 	}
 	spin_unlock(&net_family_lock);
 
-	printk(KERN_INFO "NET: Registered protocol family %d\n", ops->family);
+	net_printk(KERN_INFO, "Registered protocol family %d", ops->family);
 	return err;
 }
 
@@ -2203,7 +2216,7 @@ void sock_unregister(int family)
 
 	synchronize_rcu();
 
-	printk(KERN_INFO "NET: Unregistered protocol family %d\n", family);
+	net_printk(KERN_INFO, "Unregistered protocol family %d", family);
 }
 
 static int __init sock_init(void)


  parent reply	other threads:[~2008-12-06  7:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-06  6:59 [RFC] Recursive printk Nick Andrew
2008-12-06  6:59 ` [RFC PATCH v1 1/3] Split the vsnprintf function into two parts Nick Andrew
2008-12-06  7:00 ` [RFC PATCH v1 2/3] Add %v support to vsnprintf() Nick Andrew
2008-12-06 17:27   ` Linus Torvalds
2008-12-06  7:00 ` Nick Andrew [this message]
2008-12-06  7:03   ` [RFC PATCH v1 3/3] Sample refactor of socket.c to use recursive printk David Miller
2008-12-06  7:18   ` Valdis.Kletnieks
2008-12-06  7:40     ` Nick Andrew
2008-12-06  7:20 ` [RFC] Recursive printk Andrew Morton
2008-12-06  7:33   ` Willy Tarreau
2008-12-06  7:41     ` Andrew Morton
2008-12-06  8:16       ` Willy Tarreau
2008-12-06  9:43       ` Takashi Iwai
2008-12-06  7:42   ` Joe Perches
2008-12-06  8:40     ` Nick Andrew
2008-12-06  9:11       ` Joe Perches
2008-12-06 23:16         ` Nick Andrew
2008-12-06 23:24           ` Linus Torvalds
2008-12-06 19:35       ` Al Viro
2008-12-06  8:30   ` Nick Andrew
2008-12-08  1:42     ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081206070023.29149.92171.stgit@marcab.local.tull.net \
    --to=nick@nick-andrew.net \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome