Skip to contentSkip to conversation

autofs4: Use no_printk() for no-op DPRINTK() and use __VA_ARGS__ too

PATCH In review David Howells 3 participants 4 messages Aug 8, 2011 – Aug 9, 2011 Kernel automounter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 autofs4: Use no_printk() for no-op DPRINTK() and use __VA_ARGS__ too

Use no_printk() for autofs's no-op DPRINTK() to prevent unused statements from becoming accidentally obsolete, and use __VA_ARGS__ too as that's the standard way.

---

 fs/autofs4/autofs_i.h |   10 +++++++---
 fs/autofs4/waitq.c    |    3 ++-
 2 files changed, 9 insertions(+), 4 deletions(-)
fs/autofs4/autofs_i.h +7 -3
index 475f9c5..c3a419f 100644
@@ -40,13 +40,17 @@
 /* #define DEBUG */
 
 #ifdef DEBUG
-#define DPRINTK(fmt, args...)				\
+#define DPRINTK(fmt, ...)				\
 do {							\
 	printk(KERN_DEBUG "pid %d: %s: " fmt "\n",	\
-		current->pid, __func__, ##args);	\
+		current->pid, __func__, ##__VA_ARGS__);	\
 } while (0)
 #else
-#define DPRINTK(fmt, args...) do {} while (0)
+#define DPRINTK(fmt, ...)					\
+do {								\
+	no_printk(KERN_DEBUG "pid %d: %s: " fmt "\n",		\
+		  current->pid, __func__, ##__VA_ARGS__);	\
+} while (0)
 #endif
 
 #define AUTOFS_WARN(fmt, args...)			\
fs/autofs4/waitq.c +2 -1
index 2543598..6313a0d 100644
@@ -104,7 +104,8 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
 	size_t pktsz;
 
 	DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
-		wq->wait_queue_token, wq->name.len, wq->name.name, type);
+		(unsigned long)wq->wait_queue_token,
+		wq->name.len, wq->name.name, type);
 
 	memset(&pkt,0,sizeof pkt); /* For security reasons */
 
#1 lore raw
Quoted 3 lines · David Howells

Use no_printk() for autofs's no-op DPRINTK() to prevent unused statements from becoming accidentally obsolete, and use __VA_ARGS__ too as that's the standard way.

Gaah. May I suggest just avoiding the duplication by doing

   #ifdef DEBUG
   # define autofs_debug_printk printk
   #else
   # define autofs_debug_printk no_printk
   #endif

   #define DPRINTK(fmt, ...)                                      \
       autofs_debug_printk(KERN_DEBUG "pid %d: %s: " fmt "\n",           \
                 current->pid, __func__, ##__VA_ARGS__)

which also drops the pointless do { } while (0) protection since it's already a well-formed statement?

Linus

#2 lore raw

PATCH 1/1 autofs4: Use pr_fmt and pr_<level>

Use the standard logging forms. All logging entries are not prefixed with "autofs4:" via pr_fmt.

Convert printks without KERN_<LEVEL> to pr_info and pr_err.

Convert AUTOFS_WARN and AUTOFS_ERROR to pr_warn and pr_err. Use a specific pr_fmt to add __func__ and pid to the single source file where AUTOFS_<LEVEL> were used. Add newlines to these converted printks as well.

Convert DPRINTK uses to pr_debug.
Add newlines to pr_debug uses. Remove __func__ and pid as these can be added by using dynamic_debug controls '+f' and '+t' and respectivly.

Coalesce long formats.

---
 fs/autofs4/autofs_i.h  |   12 ------------
 fs/autofs4/dev-ioctl.c |   27 +++++++++++++--------------
 fs/autofs4/expire.c    |   41 ++++++++++++++++++++++-------------------
 fs/autofs4/inode.c     |   19 ++++++++++---------
 fs/autofs4/root.c      |   48 +++++++++++++++++++++++++-----------------------
 fs/autofs4/waitq.c     |   23 +++++++++++++----------
 6 files changed, 83 insertions(+), 87 deletions(-)
fs/autofs4/autofs_i.h +0 -12
index 326dc08..8082505 100644
@@ -39,18 +39,6 @@
 
 /* #define DEBUG */
 
-#define DPRINTK(fmt, ...)				\
-	pr_debug("pid %d: %s: " fmt "\n",		\
-		current->pid, __func__, ##__VA_ARGS__)
-
-#define AUTOFS_WARN(fmt, ...)				\
-	printk(KERN_WARNING "pid %d: %s: " fmt "\n",	\
-		current->pid, __func__, ##__VA_ARGS__)
-
-#define AUTOFS_ERROR(fmt, ...)				\
-	printk(KERN_ERR "pid %d: %s: " fmt "\n",	\
-		current->pid, __func__, ##__VA_ARGS__)
-
 /* Unified info structure.  This is pointed to by both the dentry and
    inode structures.  Each file in the filesystem has an instance of this
    structure.  It holds a reference to the dentry, so dentries are never
fs/autofs4/dev-ioctl.c +13 -14
index 509fe1e..456ddeb 100644
@@ -7,6 +7,8 @@
  * option, any later version, incorporated herein by reference.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ":%s:pid %d: " fmt, __func__, current->pid
+
 #include <linux/module.h>
 #include <linux/vmalloc.h>
 #include <linux/miscdevice.h>
@@ -74,11 +76,10 @@ static int check_dev_ioctl_version(int cmd, struct autofs_dev_ioctl *param)
 
 	if ((AUTOFS_DEV_IOCTL_VERSION_MAJOR != param->ver_major) ||
 	    (AUTOFS_DEV_IOCTL_VERSION_MINOR < param->ver_minor)) {
-		AUTOFS_WARN("ioctl control interface version mismatch: "
-		     "kernel(%u.%u), user(%u.%u), cmd(%d)",
-		     AUTOFS_DEV_IOCTL_VERSION_MAJOR,
-		     AUTOFS_DEV_IOCTL_VERSION_MINOR,
-		     param->ver_major, param->ver_minor, cmd);
+		pr_warn("ioctl control interface version mismatch: kernel(%u.%u), user(%u.%u), cmd(%d)\n",
+			AUTOFS_DEV_IOCTL_VERSION_MAJOR,
+			AUTOFS_DEV_IOCTL_VERSION_MINOR,
+			param->ver_major, param->ver_minor, cmd);
 		err = -EINVAL;
 	}
 
@@ -122,24 +123,22 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
 
 	err = check_dev_ioctl_version(cmd, param);
 	if (err) {
-		AUTOFS_WARN("invalid device control module version "
-		     "supplied for cmd(0x%08x)", cmd);
+		pr_warn("invalid device control module version supplied for cmd(0x%08x)\n",
+			cmd);
 		goto out;
 	}
 
 	if (param->size > sizeof(*param)) {
 		err = invalid_str(param->path, param->size - sizeof(*param));
 		if (err) {
-			AUTOFS_WARN(
-			  "path string terminator missing for cmd(0x%08x)",
-			  cmd);
+			pr_warn("path string terminator missing for cmd(0x%08x)\n",
+				cmd);
 			goto out;
 		}
 
 		err = check_name(param->path);
 		if (err) {
-			AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
-				    cmd);
+			pr_warn("invalid path supplied for cmd(0x%08x)\n", cmd);
 			goto out;
 		}
 	}
@@ -649,7 +648,7 @@ static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __use
 
 	fn = lookup_dev_ioctl(cmd);
 	if (!fn) {
-		AUTOFS_WARN("unknown command 0x%08x", command);
+		pr_warn("unknown command 0x%08x\n", command);
 		return -ENOTTY;
 	}
 
@@ -747,7 +746,7 @@ int autofs_dev_ioctl_init(void)
 
 	r = misc_register(&_autofs_dev_ioctl_misc);
 	if (r) {
-		AUTOFS_ERROR("misc_register failed for control device");
+		pr_err("misc_register failed for control device\n");
 		return r;
 	}
 
fs/autofs4/expire.c +22 -19

109 lines not on this page · raw message

fs/autofs4/inode.c +10 -9
index 180fa24..fdba022 100644
@@ -11,6 +11,8 @@
  *
  * ------------------------------------------------------------------------- */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/file.h>
@@ -66,7 +68,7 @@ void autofs4_kill_sb(struct super_block *sb)
 	kfree(sbi);
 
 out_kill_sb:
-	DPRINTK("shutting down");
+	pr_debug("shutting down\n");
 	kill_litter_super(sb);
 }
 
@@ -209,7 +211,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
 	if (!sbi)
 		goto fail_unlock;
-	DPRINTK("starting up, sbi = %p",sbi);
+	pr_debug("starting up, sbi = %p\n", sbi);
 
 	s->s_fs_info = sbi;
 	sbi->magic = AUTOFS_SBI_MAGIC;
@@ -258,7 +260,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 	if (parse_options(data, &pipefd, &root_inode->i_uid, &root_inode->i_gid,
 				&sbi->oz_pgrp, &sbi->type, &sbi->min_proto,
 				&sbi->max_proto)) {
-		printk("autofs: called with bogus options\n");
+		pr_info("called with bogus options\n");
 		goto fail_dput;
 	}
 
@@ -271,8 +273,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 	/* Couldn't this be tested earlier? */
 	if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
 	    sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
-		printk("autofs: kernel does not match daemon version "
-		       "daemon (%d, %d) kernel (%d, %d)\n",
+		pr_info("kernel does not match daemon version daemon (%d, %d) kernel (%d, %d)\n",
 			sbi->min_proto, sbi->max_proto,
 			AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
 		goto fail_dput;
@@ -285,11 +286,11 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 		sbi->version = sbi->max_proto;
 	sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
 
-	DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
+	pr_debug("pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp);
 	pipe = fget(pipefd);
 	
 	if (!pipe) {
-		printk("autofs: could not open pipe file descriptor\n");
+		pr_info("could not open pipe file descriptor\n");
 		goto fail_dput;
 	}
 	if (!pipe->f_op || !pipe->f_op->write)
@@ -308,14 +309,14 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 	 * Failure ... clean up.
 	 */
 fail_fput:
-	printk("autofs: pipe file descriptor does not contain proper ops\n");
+	pr_info("pipe file descriptor does not contain proper ops\n");
 	fput(pipe);
 	/* fall through */
 fail_dput:
 	dput(root);
 	goto fail_free;
 fail_iput:
-	printk("autofs: get root dentry failed\n");
+	pr_info("get root dentry failed\n");
 	iput(root_inode);
 fail_ino:
 	kfree(ino);
fs/autofs4/root.c +25 -23

127 lines not on this page · raw message

fs/autofs4/waitq.c +13 -10
index e1fbdee..37cb49b 100644
@@ -11,6 +11,8 @@
  *
  * ------------------------------------------------------------------------- */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/signal.h>
@@ -34,7 +36,7 @@ void autofs4_catatonic_mode(struct autofs_sb_info *sbi)
 		return;
 	}
 
-	DPRINTK("entering catatonic mode");
+	pr_debug("entering catatonic mode\n");
 
 	sbi->catatonic = 1;
 	wq = sbi->queues;
@@ -103,8 +105,9 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
 	struct file *pipe = NULL;
 	size_t pktsz;
 
-	DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
-		(unsigned long) wq->wait_queue_token, wq->name.len, wq->name.name, type);
+	pr_debug("wait id = 0x%08lx, name = %.*s, type=%d\n",
+		(unsigned long)wq->wait_queue_token,
+		 wq->name.len, wq->name.name, type);
 
 	memset(&pkt,0,sizeof pkt); /* For security reasons */
 
@@ -162,7 +165,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
 		break;
 	}
 	default:
-		printk("autofs4_notify_daemon: bad type %d!\n", type);
+		pr_err("%s: bad type %d!\n", __func__, type);
 		return;
 	}
 
@@ -437,9 +440,9 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
 					autofs_ptype_expire_indirect;
 		}
 
-		DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
-			(unsigned long) wq->wait_queue_token, wq->name.len,
-			wq->name.name, notify);
+		pr_debug("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
+			 (unsigned long)wq->wait_queue_token, wq->name.len,
+			 wq->name.name, notify);
 
 		/* autofs4_notify_daemon() may block */
 		autofs4_notify_daemon(sbi, wq, type);
@@ -447,8 +450,8 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
 		wq->wait_ctr++;
 		mutex_unlock(&sbi->wq_mutex);
 		kfree(qstr.name);
-		DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
-			(unsigned long) wq->wait_queue_token, wq->name.len,
+		pr_debug("existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
+			 (unsigned long)wq->wait_queue_token, wq->name.len,
 			wq->name.name, notify);
 	}
 
@@ -474,7 +477,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
 		recalc_sigpending();
 		spin_unlock_irqrestore(&current->sighand->siglock, irqflags);
 	} else {
-		DPRINTK("skipped sleeping");
+		pr_debug("skipped sleeping\n");
 	}
 
 	status = wq->status;
Signature · 1 line
1.7.6.405.gc1be0
#3 lore raw
In reply to David Howells
Quoted 3 lines · David Howells

Use no_printk() for autofs's no-op DPRINTK() to prevent unused statements from becoming accidentally obsolete, and use __VA_ARGS__ too as that's the standard way.

[]

Quoted 12 lines
fs/autofs4/autofs_i.h +1 -1
index 475f9c5..c3a419f 100644
@@ -40,13 +40,17 @@
 /* #define DEBUG */
 
 #ifdef DEBUG
-#define DPRINTK(fmt, args...)				\
+#define DPRINTK(fmt, ...)				\
 do {							\
 	printk(KERN_DEBUG "pid %d: %s: " fmt "\n",	\

fs/autofs4/autofs_i.h line 53

Quoted 10 lines
fs/autofs4/autofs_i.h +6 -2
-		current->pid, __func__, ##args);	\
+		current->pid, __func__, ##__VA_ARGS__);	\
 } while (0)
 #else
-#define DPRINTK(fmt, args...) do {} while (0)
+#define DPRINTK(fmt, ...)					\
+do {								\
+	no_printk(KERN_DEBUG "pid %d: %s: " fmt "\n",		\
+		  current->pid, __func__, ##__VA_ARGS__);	\
+} while (0)

single statement macros don't need do {} while (0), and this could be

#define DPRINTK(fmt, args...)					\
	pr_debug("pid %d: %s: " fmt "\n",			\
		 current->pid, __func__, ##__VA_ARGS__)

When using dynamic debug __func__ and pid are unnecessary as these can be added to any pr_debug output with '+f' and '+t' so I think those should not be added either.

I think the DPRINTK macro should be removed altogether and pr_debug should be used instead.