LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: nbd-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, Markus Pargmann <mpa@pengutronix.de>
Subject: [PATCH 6/9] nbd: Restructure debugging prints
Date: Thu, 12 Feb 2015 21:57:34 +0100	[thread overview]
Message-ID: <1423774657-12748-7-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1423774657-12748-1-git-send-email-mpa@pengutronix.de>

dprintk has some name collisions with other frameworks and drivers. It
is also not necessary to have these custom debug print filters. Dynamic
debug offers the same amount of filtered debugging.

This patch replaces all dprintks with dev_dbg(). It also removes the
ioctl dprintk which prints the ingoing ioctls which should be
replaceable by strace or similar stuff.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/block/nbd.c | 86 ++++++++++++-----------------------------------------
 1 file changed, 19 insertions(+), 67 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 13c8371cbf4c..60a38b06a79b 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -63,21 +63,6 @@ struct nbd_device {
 
 #define NBD_MAGIC 0x68797548
 
-#ifdef NDEBUG
-#define dprintk(flags, fmt...)
-#else /* NDEBUG */
-#define dprintk(flags, fmt...) do { \
-	if (debugflags & (flags)) printk(KERN_DEBUG fmt); \
-} while (0)
-#define DBG_IOCTL       0x0004
-#define DBG_INIT        0x0010
-#define DBG_EXIT        0x0020
-#define DBG_BLKDEV      0x0100
-#define DBG_RX          0x0200
-#define DBG_TX          0x0400
-static unsigned int debugflags;
-#endif /* NDEBUG */
-
 static unsigned int nbds_max = 16;
 static struct nbd_device *nbd_dev;
 static int max_part;
@@ -94,27 +79,6 @@ static int max_part;
  */
 static DEFINE_SPINLOCK(nbd_lock);
 
-#ifndef NDEBUG
-static const char *ioctl_cmd_to_ascii(int cmd)
-{
-	switch (cmd) {
-	case NBD_SET_SOCK: return "set-sock";
-	case NBD_SET_BLKSIZE: return "set-blksize";
-	case NBD_SET_SIZE: return "set-size";
-	case NBD_SET_TIMEOUT: return "set-timeout";
-	case NBD_SET_FLAGS: return "set-flags";
-	case NBD_DO_IT: return "do-it";
-	case NBD_CLEAR_SOCK: return "clear-sock";
-	case NBD_CLEAR_QUE: return "clear-que";
-	case NBD_PRINT_DEBUG: return "print-debug";
-	case NBD_SET_SIZE_BLOCKS: return "set-size-blocks";
-	case NBD_DISCONNECT: return "disconnect";
-	case BLKROSET: return "set-read-only";
-	case BLKFLSBUF: return "flush-buffer-cache";
-	}
-	return "unknown";
-}
-
 static const char *nbdcmd_to_ascii(int cmd)
 {
 	switch (cmd) {
@@ -126,16 +90,15 @@ static const char *nbdcmd_to_ascii(int cmd)
 	}
 	return "invalid";
 }
-#endif /* NDEBUG */
 
-static void nbd_end_request(struct request *req)
+static void nbd_end_request(struct nbd_device *nbd, struct request *req)
 {
 	int error = req->errors ? -EIO : 0;
 	struct request_queue *q = req->q;
 	unsigned long flags;
 
-	dprintk(DBG_BLKDEV, "%s: request %p: %s\n", req->rq_disk->disk_name,
-			req, error ? "failed" : "done");
+	dev_dbg(disk_to_dev(nbd->disk), "%s: request %p: %s\n",
+		req->rq_disk->disk_name, req, error ? "failed" : "done");
 
 	spin_lock_irqsave(q->queue_lock, flags);
 	__blk_end_request_all(req, error);
@@ -276,11 +239,9 @@ static int nbd_send_req(struct nbd_device *nbd, struct request *req)
 	}
 	memcpy(request.handle, &req, sizeof(req));
 
-	dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%uB)\n",
-			nbd->disk->disk_name, req,
-			nbdcmd_to_ascii(nbd_cmd(req)),
-			(unsigned long long)blk_rq_pos(req) << 9,
-			blk_rq_bytes(req));
+	dev_dbg(disk_to_dev(nbd->disk), "%s: request %p: sending control (%s@%llu,%uB)\n",
+		nbd->disk->disk_name, req, nbdcmd_to_ascii(nbd_cmd(req)),
+		(unsigned long long)blk_rq_pos(req) << 9, blk_rq_bytes(req));
 	result = sock_xmit(nbd, 1, &request, sizeof(request),
 			(nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
 	if (result <= 0) {
@@ -300,8 +261,8 @@ static int nbd_send_req(struct nbd_device *nbd, struct request *req)
 			flags = 0;
 			if (!rq_iter_last(bvec, iter))
 				flags = MSG_MORE;
-			dprintk(DBG_TX, "%s: request %p: sending %d bytes data\n",
-					nbd->disk->disk_name, req, bvec.bv_len);
+			dev_dbg(disk_to_dev(nbd->disk), "%s: request %p: sending %d bytes data\n",
+				nbd->disk->disk_name, req, bvec.bv_len);
 			result = sock_send_bvec(nbd, &bvec, flags);
 			if (result <= 0) {
 				dev_err(disk_to_dev(nbd->disk),
@@ -394,8 +355,8 @@ static struct request *nbd_read_stat(struct nbd_device *nbd)
 		return req;
 	}
 
-	dprintk(DBG_RX, "%s: request %p: got reply\n",
-			nbd->disk->disk_name, req);
+	dev_dbg(disk_to_dev(nbd->disk), "%s: request %p: got reply\n",
+		nbd->disk->disk_name, req);
 	if (nbd_cmd(req) == NBD_CMD_READ) {
 		struct req_iterator iter;
 		struct bio_vec bvec;
@@ -408,7 +369,7 @@ static struct request *nbd_read_stat(struct nbd_device *nbd)
 				req->errors++;
 				return req;
 			}
-			dprintk(DBG_RX, "%s: request %p: got %d bytes data\n",
+			dev_dbg(disk_to_dev(nbd->disk), "%s: request %p: got %d bytes data\n",
 				nbd->disk->disk_name, req, bvec.bv_len);
 		}
 	}
@@ -449,7 +410,7 @@ static int nbd_do_it(struct nbd_device *nbd)
 	}
 
 	while ((req = nbd_read_stat(nbd)) != NULL)
-		nbd_end_request(req);
+		nbd_end_request(nbd, req);
 
 	device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
 	nbd->pid = 0;
@@ -478,7 +439,7 @@ static void nbd_clear_que(struct nbd_device *nbd)
 				 queuelist);
 		list_del_init(&req->queuelist);
 		req->errors++;
-		nbd_end_request(req);
+		nbd_end_request(nbd, req);
 	}
 
 	while (!list_empty(&nbd->waiting_queue)) {
@@ -486,7 +447,7 @@ static void nbd_clear_que(struct nbd_device *nbd)
 				 queuelist);
 		list_del_init(&req->queuelist);
 		req->errors++;
-		nbd_end_request(req);
+		nbd_end_request(nbd, req);
 	}
 }
 
@@ -530,7 +491,7 @@ static void nbd_handle_req(struct nbd_device *nbd, struct request *req)
 	if (nbd_send_req(nbd, req) != 0) {
 		dev_err(disk_to_dev(nbd->disk), "Request send failed\n");
 		req->errors++;
-		nbd_end_request(req);
+		nbd_end_request(nbd, req);
 	} else {
 		spin_lock(&nbd->queue_lock);
 		list_add_tail(&req->queuelist, &nbd->queue_head);
@@ -545,7 +506,7 @@ static void nbd_handle_req(struct nbd_device *nbd, struct request *req)
 
 error_out:
 	req->errors++;
-	nbd_end_request(req);
+	nbd_end_request(nbd, req);
 }
 
 static int nbd_thread(void *data)
@@ -593,8 +554,8 @@ static void do_nbd_request(struct request_queue *q)
 
 		spin_unlock_irq(q->queue_lock);
 
-		dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n",
-				req->rq_disk->disk_name, req, req->cmd_type);
+		dev_dbg(disk_to_dev(nbd->disk), "%s: request %p: dequeued (flags=%x)\n",
+			req->rq_disk->disk_name, req, req->cmd_type);
 
 		nbd = req->rq_disk->private_data;
 
@@ -604,7 +565,7 @@ static void do_nbd_request(struct request_queue *q)
 			dev_err(disk_to_dev(nbd->disk),
 				"Attempted send on closed socket\n");
 			req->errors++;
-			nbd_end_request(req);
+			nbd_end_request(nbd, req);
 			spin_lock_irq(q->queue_lock);
 			continue;
 		}
@@ -791,10 +752,6 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
 
 	BUG_ON(nbd->magic != NBD_MAGIC);
 
-	/* Anyone capable of this syscall can do *real bad* things */
-	dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n",
-		nbd->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg);
-
 	mutex_lock(&nbd->tx_lock);
 	error = __nbd_ioctl(bdev, nbd, cmd, arg);
 	mutex_unlock(&nbd->tx_lock);
@@ -884,7 +841,6 @@ static int __init nbd_init(void)
 	}
 
 	printk(KERN_INFO "nbd: registered device at major %d\n", NBD_MAJOR);
-	dprintk(DBG_INIT, "nbd: debugflags=0x%x\n", debugflags);
 
 	for (i = 0; i < nbds_max; i++) {
 		struct gendisk *disk = nbd_dev[i].disk;
@@ -943,7 +899,3 @@ module_param(nbds_max, int, 0444);
 MODULE_PARM_DESC(nbds_max, "number of network block devices to initialize (default: 16)");
 module_param(max_part, int, 0444);
 MODULE_PARM_DESC(max_part, "number of partitions per device (default: 0)");
-#ifndef NDEBUG
-module_param(debugflags, int, 0644);
-MODULE_PARM_DESC(debugflags, "flags for controlling debug output");
-#endif
-- 
2.1.4


  parent reply	other threads:[~2015-02-12 20:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12 20:57 [PATCH 0/9] nbd: cleanups Markus Pargmann
2015-02-12 20:57 ` [PATCH 1/9] Documentation: nbd: Reformat to allow more documentation Markus Pargmann
2015-02-12 20:57 ` [PATCH 2/9] Documentation: nbd: Add list of module parameters Markus Pargmann
2015-02-14 10:29   ` [Nbd] " Wouter Verhelst
2015-02-15 21:53     ` Markus Pargmann
2015-02-12 20:57 ` [PATCH 3/9] nbd: Remove kernel internal header Markus Pargmann
2015-02-14 10:30   ` [Nbd] " Wouter Verhelst
2015-02-15 21:56     ` Markus Pargmann
2015-02-12 20:57 ` [PATCH 4/9] nbd: Replace kthread_create with kthread_run Markus Pargmann
2015-02-12 20:57 ` [PATCH 5/9] nbd: Fix device bytesize type Markus Pargmann
2015-02-12 20:57 ` Markus Pargmann [this message]
2015-02-12 21:08   ` [PATCH 6/9] nbd: Restructure debugging prints Joe Perches
2015-02-13  9:58     ` Markus Pargmann
2015-02-13 10:05       ` Joe Perches
2015-02-13 11:24         ` Markus Pargmann
2015-02-13 11:48           ` Joe Perches
2015-02-15 22:20             ` Markus Pargmann
2015-02-16  0:06               ` Joe Perches
2015-02-12 20:57 ` [PATCH 7/9] nbd: Remove fixme that was already fixed Markus Pargmann
2015-02-12 20:57 ` [PATCH 8/9] nbd: Return error code directly Markus Pargmann
2015-02-12 20:57 ` [PATCH 9/9] nbd: Return error pointer directly Markus Pargmann
2015-04-02  8:11 [PULL] NBD patches for 4.1 Markus Pargmann
2015-04-02  8:11 ` [PATCH 6/9] nbd: Restructure debugging prints Markus Pargmann

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=1423774657-12748-7-git-send-email-mpa@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nbd-general@lists.sourceforge.net \
    --subject='Re: [PATCH 6/9] nbd: Restructure debugging prints' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).