[openib-general] [PATCH] ucm: Only print messages when debug level set

Hal Rosenstock halr at voltaire.com
Wed Jul 13 06:24:00 PDT 2005


ucm: Only print messages when debug level set

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

This patch is dependent on the previous kfree ucm patch.

--- ucm.c.kfree	2005-07-13 08:10:00.000000000 -0400
+++ ucm.c	2005-07-13 09:12:03.000000000 -0400
@@ -49,6 +49,11 @@ MODULE_AUTHOR("Libor Michalek");
 MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access");
 MODULE_LICENSE("Dual BSD/GPL");
 
+int ucm_debug_level;
+
+module_param_named(debug_level, ucm_debug_level, int, 0644);
+MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
+
 enum {
 	IB_UCM_MAJOR = 231,
 	IB_UCM_MINOR = 255
@@ -56,6 +61,10 @@ enum {
 
 #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR)
 
+#define ucm_dbg(format, arg...)                 \
+	if (ucm_debug_level > 0)        \
+		printk(KERN_DEBUG format, ## arg)
+
 static struct semaphore ctx_id_mutex;
 static struct idr       ctx_id_table;
 static int              ctx_id_rover = 0;
@@ -107,7 +116,7 @@ static void ib_ucm_ctx_put(struct ib_ucm
 
 	up(&ctx->file->mutex);
 
-	printk(KERN_ERR "UCM: Destroyed CM ID <%d>\n", ctx->id);
+	ucm_dbg("UCM: Destroyed CM ID <%d>\n", ctx->id);
 
 	ib_destroy_cm_id(ctx->cm_id);
 	kfree(ctx);
@@ -145,7 +154,7 @@ retry:
 	if (result)
 		goto error;
 
-	printk(KERN_ERR "UCM: Allocated CM ID <%d>\n", ctx->id);
+	ucm_dbg("UCM: Allocated CM ID <%d>\n", ctx->id);
 
 	return ctx;
 error:
@@ -405,8 +414,8 @@ static int ib_ucm_event_handler(struct i
 		break;
 	}
 
-	printk(KERN_ERR "UCM: Event. CM ID <%d> event <%d>\n",
-	       id, event->event);
+	ucm_dbg("UCM: Event. CM ID <%d> event <%d>\n",
+		id, event->event);
 
 	ctx = ib_ucm_ctx_get(id);
 	if (!ctx)
@@ -1234,8 +1243,8 @@ static ssize_t ib_ucm_write(struct file 
 	if (copy_from_user(&hdr, buf, sizeof(hdr)))
 		return -EFAULT;
 
-	printk(KERN_ERR "UCM: Write. cmd <%d> in <%d> out <%d> len <%Zu>\n",
-	       hdr.cmd, hdr.in, hdr.out, len);
+	ucm_dbg("UCM: Write. cmd <%d> in <%d> out <%d> len <%Zu>\n",
+		hdr.cmd, hdr.in, hdr.out, len);
 
 	if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table))
 		return -EINVAL;
@@ -1282,7 +1291,7 @@ static int ib_ucm_open(struct inode *ino
 	filp->private_data = file;
 	file->filp = filp;
 
-	printk(KERN_ERR "UCM: Created struct\n");
+	ucm_dbg("UCM: Created struct\n");
 
 	return 0;
 }
@@ -1308,7 +1317,7 @@ static int ib_ucm_close(struct inode *in
 
 	kfree(file);
 
-	printk(KERN_ERR "UCM: Deleted struct\n");
+	ucm_dbg("UCM: Deleted struct\n");
 	return 0;
 }
 
@@ -1330,7 +1339,7 @@ static int __init ib_ucm_init(void)
 
 	result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm");
 	if (result) {
-		printk(KERN_ERR "UCM: Error <%d> registering dev\n", result);
+		ucm_dbg("UCM: Error <%d> registering dev\n", result);
 		goto err_chr;
 	}
 
@@ -1338,14 +1347,14 @@ static int __init ib_ucm_init(void)
 
 	result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1);
 	if (result) {
-		printk(KERN_ERR "UCM: Error <%d> adding cdev\n", result);
+		ucm_dbg("UCM: Error <%d> adding cdev\n", result);
 		goto err_cdev;
 	}
 
 	ib_ucm_class = class_simple_create(THIS_MODULE, "infiniband_cm");
 	if (IS_ERR(ib_ucm_class)) {
 		result = PTR_ERR(ib_ucm_class);
-		printk(KERN_ERR "UCM: Error <%d> creating class\n", result);
+		ucm_dbg("UCM: Error <%d> creating class\n", result);
 		goto err_class;
 	}
 






More information about the general mailing list