linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros
@ 2018-01-22  7:53 Johannes Thumshirn
  2018-01-22 16:33 ` Bart Van Assche
  2018-01-22 20:23 ` Joe Perches
  0 siblings, 2 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2018-01-22  7:53 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Linux Block Layer Mailinglist, Linux Kernel Mailinglist,
	Johannes Thumshirn

Use pr_debug instead of hand crafted macros. This way it is not needed to
re-compile the kernel to enable bsg debug outputs and it's possible to
selectively enable specific prints.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 block/bsg.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/block/bsg.c b/block/bsg.c
index 452f94f1c5d4..508e73c60add 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -55,14 +55,6 @@ enum {
 #define BSG_DEFAULT_CMDS	64
 #define BSG_MAX_DEVS		32768
 
-#undef BSG_DEBUG
-
-#ifdef BSG_DEBUG
-#define dprintk(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ##args)
-#else
-#define dprintk(fmt, args...)
-#endif
-
 static DEFINE_MUTEX(bsg_mutex);
 static DEFINE_IDR(bsg_minor_idr);
 
@@ -123,7 +115,7 @@ static struct bsg_command *bsg_alloc_command(struct bsg_device *bd)
 
 	bc->bd = bd;
 	INIT_LIST_HEAD(&bc->list);
-	dprintk("%s: returning free cmd %p\n", bd->name, bc);
+	pr_debug("%s: returning free cmd %p\n", bd->name, bc);
 	return bc;
 out:
 	spin_unlock_irq(&bd->lock);
@@ -222,7 +214,8 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t mode)
 	if (!bcd->class_dev)
 		return ERR_PTR(-ENXIO);
 
-	dprintk("map hdr %llx/%u %llx/%u\n", (unsigned long long) hdr->dout_xferp,
+	pr_debug("map hdr %llx/%u %llx/%u\n",
+		 (unsigned long long) hdr->dout_xferp,
 		hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp,
 		hdr->din_xfer_len);
 
@@ -299,7 +292,7 @@ static void bsg_rq_end_io(struct request *rq, blk_status_t status)
 	struct bsg_device *bd = bc->bd;
 	unsigned long flags;
 
-	dprintk("%s: finished rq %p bc %p, bio %p\n",
+	pr_debug("%s: finished rq %p bc %p, bio %p\n",
 		bd->name, rq, bc, bc->bio);
 
 	bc->hdr.duration = jiffies_to_msecs(jiffies - bc->hdr.duration);
@@ -333,7 +326,7 @@ static void bsg_add_command(struct bsg_device *bd, struct request_queue *q,
 	list_add_tail(&bc->list, &bd->busy_list);
 	spin_unlock_irq(&bd->lock);
 
-	dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
+	pr_debug("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
 
 	rq->end_io_data = bc;
 	blk_execute_rq_nowait(q, NULL, rq, at_head, bsg_rq_end_io);
@@ -379,7 +372,7 @@ static struct bsg_command *bsg_get_done_cmd(struct bsg_device *bd)
 		}
 	} while (1);
 
-	dprintk("%s: returning done %p\n", bd->name, bc);
+	pr_debug("%s: returning done %p\n", bd->name, bc);
 
 	return bc;
 }
@@ -390,7 +383,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
 	struct scsi_request *req = scsi_req(rq);
 	int ret = 0;
 
-	dprintk("rq %p bio %p 0x%x\n", rq, bio, req->result);
+	pr_debug("rq %p bio %p 0x%x\n", rq, bio, req->result);
 	/*
 	 * fill in all the output members
 	 */
@@ -469,7 +462,7 @@ static int bsg_complete_all_commands(struct bsg_device *bd)
 	struct bsg_command *bc;
 	int ret, tret;
 
-	dprintk("%s: entered\n", bd->name);
+	pr_debug("%s: entered\n", bd->name);
 
 	/*
 	 * wait for all commands to complete
@@ -572,7 +565,7 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 	int ret;
 	ssize_t bytes_read;
 
-	dprintk("%s: read %zd bytes\n", bd->name, count);
+	pr_debug("%s: read %zd bytes\n", bd->name, count);
 
 	bsg_set_block(bd, file);
 
@@ -646,7 +639,7 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
 	ssize_t bytes_written;
 	int ret;
 
-	dprintk("%s: write %zd bytes\n", bd->name, count);
+	pr_debug("%s: write %zd bytes\n", bd->name, count);
 
 	if (unlikely(uaccess_kernel()))
 		return -EINVAL;
@@ -664,7 +657,7 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
 	if (!bytes_written || err_block_err(ret))
 		bytes_written = ret;
 
-	dprintk("%s: returning %zd\n", bd->name, bytes_written);
+	pr_debug("%s: returning %zd\n", bd->name, bytes_written);
 	return bytes_written;
 }
 
@@ -717,7 +710,7 @@ static int bsg_put_device(struct bsg_device *bd)
 	hlist_del(&bd->dev_list);
 	mutex_unlock(&bsg_mutex);
 
-	dprintk("%s: tearing down\n", bd->name);
+	pr_debug("%s: tearing down\n", bd->name);
 
 	/*
 	 * close can always block
@@ -744,9 +737,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
 					 struct file *file)
 {
 	struct bsg_device *bd;
-#ifdef BSG_DEBUG
 	unsigned char buf[32];
-#endif
 
 	if (!blk_queue_scsi_passthrough(rq)) {
 		WARN_ONCE(true, "Attempt to register a non-SCSI queue\n");
@@ -771,7 +762,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
 	hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
 
 	strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
-	dprintk("bound to <%s>, max queue %d\n",
+	pr_debug("bound to <%s>, max queue %d\n",
 		format_dev_t(buf, inode->i_rdev), bd->max_queue);
 
 	mutex_unlock(&bsg_mutex);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros
  2018-01-22  7:53 [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros Johannes Thumshirn
@ 2018-01-22 16:33 ` Bart Van Assche
  2018-01-22 20:23 ` Joe Perches
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2018-01-22 16:33 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: Linux Block Layer Mailinglist, Linux Kernel Mailinglist

On 01/21/18 23:53, Johannes Thumshirn wrote:
> -	dprintk("map hdr %llx/%u %llx/%u\n", (unsigned long long) hdr->dout_xferp,
> +	pr_debug("map hdr %llx/%u %llx/%u\n",
> +		 (unsigned long long) hdr->dout_xferp,
>   		hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp,
>   		hdr->din_xfer_len);

Should the indentation of the arguments have been adjusted?

> @@ -299,7 +292,7 @@ static void bsg_rq_end_io(struct request *rq, blk_status_t status)
>   	struct bsg_device *bd = bc->bd;
>   	unsigned long flags;
>   
> -	dprintk("%s: finished rq %p bc %p, bio %p\n",
> +	pr_debug("%s: finished rq %p bc %p, bio %p\n",
>   		bd->name, rq, bc, bc->bio);

Same question here ...

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros
  2018-01-22  7:53 [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros Johannes Thumshirn
  2018-01-22 16:33 ` Bart Van Assche
@ 2018-01-22 20:23 ` Joe Perches
  2018-01-22 20:42   ` Bart Van Assche
  1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2018-01-22 20:23 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe
  Cc: Linux Block Layer Mailinglist, Linux Kernel Mailinglist

On Mon, 2018-01-22 at 08:53 +0100, Johannes Thumshirn wrote:
> Use pr_debug instead of hand crafted macros. This way it is not needed to
> re-compile the kernel to enable bsg debug outputs and it's possible to
> selectively enable specific prints.

Perhaps better to use

#define bsg_dbg(bd, fmt, ...) \
	pr_debug(bd->name, fmt, ##__VA_ARGS__)

> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> ---
>  block/bsg.c | 35 +++++++++++++----------------------
>  1 file changed, 13 insertions(+), 22 deletions(-)
> 
> diff --git a/block/bsg.c b/block/bsg.c
> index 452f94f1c5d4..508e73c60add 100644
> --- a/block/bsg.c
> +++ b/block/bsg.c
> @@ -55,14 +55,6 @@ enum {
>  #define BSG_DEFAULT_CMDS	64
>  #define BSG_MAX_DEVS		32768
>  
> -#undef BSG_DEBUG
> -
> -#ifdef BSG_DEBUG
> -#define dprintk(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ##args)
> -#else
> -#define dprintk(fmt, args...)
> -#endif
> -
>  static DEFINE_MUTEX(bsg_mutex);
>  static DEFINE_IDR(bsg_minor_idr);
>  
> @@ -123,7 +115,7 @@ static struct bsg_command *bsg_alloc_command(struct bsg_device *bd)
>  
>  	bc->bd = bd;
>  	INIT_LIST_HEAD(&bc->list);
> -	dprintk("%s: returning free cmd %p\n", bd->name, bc);
> +	pr_debug("%s: returning free cmd %p\n", bd->name, bc);
>  	return bc;
>  out:
>  	spin_unlock_irq(&bd->lock);
> @@ -222,7 +214,8 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t mode)
>  	if (!bcd->class_dev)
>  		return ERR_PTR(-ENXIO);
>  
> -	dprintk("map hdr %llx/%u %llx/%u\n", (unsigned long long) hdr->dout_xferp,
> +	pr_debug("map hdr %llx/%u %llx/%u\n",
> +		 (unsigned long long) hdr->dout_xferp,
>  		hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp,
>  		hdr->din_xfer_len);
>  
> @@ -299,7 +292,7 @@ static void bsg_rq_end_io(struct request *rq, blk_status_t status)
>  	struct bsg_device *bd = bc->bd;
>  	unsigned long flags;
>  
> -	dprintk("%s: finished rq %p bc %p, bio %p\n",
> +	pr_debug("%s: finished rq %p bc %p, bio %p\n",
>  		bd->name, rq, bc, bc->bio);
>  
>  	bc->hdr.duration = jiffies_to_msecs(jiffies - bc->hdr.duration);
> @@ -333,7 +326,7 @@ static void bsg_add_command(struct bsg_device *bd, struct request_queue *q,
>  	list_add_tail(&bc->list, &bd->busy_list);
>  	spin_unlock_irq(&bd->lock);
>  
> -	dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
> +	pr_debug("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
>  
>  	rq->end_io_data = bc;
>  	blk_execute_rq_nowait(q, NULL, rq, at_head, bsg_rq_end_io);
> @@ -379,7 +372,7 @@ static struct bsg_command *bsg_get_done_cmd(struct bsg_device *bd)
>  		}
>  	} while (1);
>  
> -	dprintk("%s: returning done %p\n", bd->name, bc);
> +	pr_debug("%s: returning done %p\n", bd->name, bc);
>  
>  	return bc;
>  }
> @@ -390,7 +383,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
>  	struct scsi_request *req = scsi_req(rq);
>  	int ret = 0;
>  
> -	dprintk("rq %p bio %p 0x%x\n", rq, bio, req->result);
> +	pr_debug("rq %p bio %p 0x%x\n", rq, bio, req->result);
>  	/*
>  	 * fill in all the output members
>  	 */
> @@ -469,7 +462,7 @@ static int bsg_complete_all_commands(struct bsg_device *bd)
>  	struct bsg_command *bc;
>  	int ret, tret;
>  
> -	dprintk("%s: entered\n", bd->name);
> +	pr_debug("%s: entered\n", bd->name);

function tracing and this should be removed.

>  
>  	/*
>  	 * wait for all commands to complete
> @@ -572,7 +565,7 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
>  	int ret;
>  	ssize_t bytes_read;
>  
> -	dprintk("%s: read %zd bytes\n", bd->name, count);
> +	pr_debug("%s: read %zd bytes\n", bd->name, count);
>  
>  	bsg_set_block(bd, file);
>  
> @@ -646,7 +639,7 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
>  	ssize_t bytes_written;
>  	int ret;
>  
> -	dprintk("%s: write %zd bytes\n", bd->name, count);
> +	pr_debug("%s: write %zd bytes\n", bd->name, count);
>  
>  	if (unlikely(uaccess_kernel()))
>  		return -EINVAL;
> @@ -664,7 +657,7 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
>  	if (!bytes_written || err_block_err(ret))
>  		bytes_written = ret;
>  
> -	dprintk("%s: returning %zd\n", bd->name, bytes_written);
> +	pr_debug("%s: returning %zd\n", bd->name, bytes_written);
>  	return bytes_written;
>  }
>  
> @@ -717,7 +710,7 @@ static int bsg_put_device(struct bsg_device *bd)
>  	hlist_del(&bd->dev_list);
>  	mutex_unlock(&bsg_mutex);
>  
> -	dprintk("%s: tearing down\n", bd->name);
> +	pr_debug("%s: tearing down\n", bd->name);
>  
>  	/*
>  	 * close can always block
> @@ -744,9 +737,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
>  					 struct file *file)
>  {
>  	struct bsg_device *bd;
> -#ifdef BSG_DEBUG
>  	unsigned char buf[32];
> -#endif
>  
>  	if (!blk_queue_scsi_passthrough(rq)) {
>  		WARN_ONCE(true, "Attempt to register a non-SCSI queue\n");
> @@ -771,7 +762,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
>  	hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
>  
>  	strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
> -	dprintk("bound to <%s>, max queue %d\n",
> +	pr_debug("bound to <%s>, max queue %d\n",
>  		format_dev_t(buf, inode->i_rdev), bd->max_queue);
>  
>  	mutex_unlock(&bsg_mutex);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros
  2018-01-22 20:23 ` Joe Perches
@ 2018-01-22 20:42   ` Bart Van Assche
  2018-01-22 21:04     ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2018-01-22 20:42 UTC (permalink / raw)
  To: joe, jthumshirn, axboe; +Cc: linux-kernel, linux-block

On Mon, 2018-01-22 at 12:23 -0800, Joe Perches wrote:
> On Mon, 2018-01-22 at 08:53 +0100, Johannes Thumshirn wrote:
> > Use pr_debug instead of hand crafted macros. This way it is not needed to
> > re-compile the kernel to enable bsg debug outputs and it's possible to
> > selectively enable specific prints.
> 
> Perhaps better to use
> 
> #define bsg_dbg(bd, fmt, ...) \
> 	pr_debug(bd->name, fmt, ##__VA_ARGS__)

Hello Joe,

Why do you think that would be better?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros
  2018-01-22 20:42   ` Bart Van Assche
@ 2018-01-22 21:04     ` Joe Perches
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2018-01-22 21:04 UTC (permalink / raw)
  To: Bart Van Assche, jthumshirn, axboe; +Cc: linux-kernel, linux-block

On Mon, 2018-01-22 at 20:42 +0000, Bart Van Assche wrote:
> On Mon, 2018-01-22 at 12:23 -0800, Joe Perches wrote:
> > On Mon, 2018-01-22 at 08:53 +0100, Johannes Thumshirn wrote:
> > > Use pr_debug instead of hand crafted macros. This way it is not needed to
> > > re-compile the kernel to enable bsg debug outputs and it's possible to
> > > selectively enable specific prints.
> > 
> > Perhaps better to use
> > 
> > #define bsg_dbg(bd, fmt, ...) \
> > 	pr_debug(bd->name, fmt, ##__VA_ARGS__)

That was written with my brain switched off
and was obviously incorrect.

> Hello Joe,

Hi Bart.

> Why do you think that would be better?

All of the messages save one already emit bd->name
(and that one that doesn't use bd->name could likely
use it too)

So maybe this is better:

#define bsg_dbg(bd, fmt, ...) \
	pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)

cheers, Joe

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-22 21:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-22  7:53 [PATCH TRIVIAL] bsg: use pr_debug instead of hand crafted macros Johannes Thumshirn
2018-01-22 16:33 ` Bart Van Assche
2018-01-22 20:23 ` Joe Perches
2018-01-22 20:42   ` Bart Van Assche
2018-01-22 21:04     ` Joe Perches

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).