public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Nao Nishijima <nao.nishijima.xt@hitachi.com>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	James.Bottomley@HansenPartnership.com, kay.sievers@vrfy.org,
	jcm@redhat.com, greg@kroah.com,
	dle-develop@lists.sourceforge.net,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	yrl.pp-manager.tt@hitachi.com, dgilbert@interlog.com,
	stefanr@s5r6.in-berlin.de, hare@suse.de
Subject: [PATCH] scsi: Make functions out of logging macros.
Date: Fri, 08 Jul 2011 22:42:55 -0700	[thread overview]
Message-ID: <1310190175.3848.5.camel@Joe-Laptop> (raw)
In-Reply-To: <20110708084610.2091.8405.stgit@ltc197.sdl.hitachi.co.jp>

Reduce size of code and text of scmd_printk and sd_printk
macros by converting to the macros to functions and using
vsprintf extension %pV.  This moves the code out-of-line
and centralizes the code used to emit additional arguments.

Save ~32KB of space in an x86 allyesconfig.

$ size drivers/scsi/built-in.o*
   text	   data	    bss	    dec	    hex	filename
5860439	 135396	1393024	7388859	 70bebb	drivers/scsi/built-in.o.new
5882368	 135396	1395848	7413612	 711f6c	drivers/scsi/built-in.o.old
5887100	 135396	1397264	7419760	 713770	drivers/scsi/built-in.o.with_patch_1_and_2

Signed-off-by: Joe Perches <joe@perches.com>

---

Re: [RFC PATCH 2/4] sd: modify printk for alias_name

On Fri, 2011-07-08 at 17:46 +0900, Nao Nishijima wrote: 
> This patch modify sd_printk() and scmd_printk() to use alias_name. If user set
> an alias_name, those print an alias_name instead of a disk_name.
 
Instead of larding more function/macros into these
relatively heavily used logging macros, how about
converting the logging macros into functions?

 drivers/scsi/scsi_lib.c    |   26 ++++++++++++++++++++++++++
 drivers/scsi/sd.c          |   23 +++++++++++++++++++++++
 drivers/scsi/sd.h          |    8 +++-----
 include/scsi/scsi_device.h |    8 +++-----
 4 files changed, 55 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ec1803a..249c54c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2571,3 +2571,29 @@ void scsi_kunmap_atomic_sg(void *virt)
 	kunmap_atomic(virt, KM_BIO_SRC_IRQ);
 }
 EXPORT_SYMBOL(scsi_kunmap_atomic_sg);
+
+/* Logging utilities */
+
+int scmd_printk(const char *prefix, const struct scsi_cmnd *scmd,
+		const char *format, ...)
+{
+	struct va_format vaf;
+	va_list args;
+	int r;
+
+	va_start(args, format);
+
+	vaf.fmt = format;
+	vaf.va = &args;
+
+	if (scmd->request->rq_disk)
+		r = sdev_printk(prefix, scmd->device, "[%s] %pV",
+				alias_name(scmd->request->rq_disk), &vaf);
+	else
+		r = sdev_printk(prefix, scmd->device, "%pV", &vaf);
+
+	va_end(args);
+
+	return r;
+}
+EXPORT_SYMBOL(scmd_printk);
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 953773c..2251e01 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2888,3 +2888,26 @@ static void sd_print_result(struct scsi_disk *sdkp, int result)
 	scsi_show_result(result);
 }
 
+int sd_printk(const char *prefix, const struct scsi_disk *sdsk,
+	      const char *format, ...)
+{
+	struct va_format vaf;
+	va_list args;
+	int r;
+
+	va_start(args, format);
+
+	vaf.fmt = format;
+	vaf.va = &args;
+
+	if (sdsk->disk)
+		r = sdev_printk(prefix, sdsk->device, "[%s] %pV",
+				alias_name(sdsk->disk), &vaf);
+	else
+		r = sdev_printk(prefix, sdsk->device, "%pV", &vaf);
+
+	va_end(args);
+
+	return r;
+}
+EXPORT_SYMBOL(sd_printk);
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 6ad798b..46aa748 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -88,11 +88,9 @@ static inline struct scsi_disk *scsi_disk(struct gendisk *disk)
 	return container_of(disk->private_data, struct scsi_disk, driver);
 }
 
-#define sd_printk(prefix, sdsk, fmt, a...)				\
-        (sdsk)->disk ?							\
-	sdev_printk(prefix, (sdsk)->device, "[%s] " fmt,		\
-		    (sdsk)->disk->disk_name, ##a) :			\
-	sdev_printk(prefix, (sdsk)->device, fmt, ##a)
+extern __attribute__((format (printf, 3, 4)))
+int sd_printk(const char *prefix, const struct scsi_disk *sdsk,
+	      const char *format, ...);
 
 /*
  * A DIF-capable target device can be formatted with different
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index dd82e02..c79631b 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -216,11 +216,9 @@ struct scsi_dh_data {
 #define sdev_printk(prefix, sdev, fmt, a...)	\
 	dev_printk(prefix, &(sdev)->sdev_gendev, fmt, ##a)
 
-#define scmd_printk(prefix, scmd, fmt, a...)				\
-        (scmd)->request->rq_disk ?					\
-	sdev_printk(prefix, (scmd)->device, "[%s] " fmt,		\
-		    (scmd)->request->rq_disk->disk_name, ##a) :		\
-	sdev_printk(prefix, (scmd)->device, fmt, ##a)
+extern __attribute__((format (printf, 3, 4)))
+int scmd_printk(const char *prefix, const struct scsi_cmnd *scmd,
+		const char *format, ...);
 
 enum scsi_target_state {
 	STARGET_CREATED = 1,
-- 
1.7.6.131.g99019



  reply	other threads:[~2011-07-09  5:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-08  8:45 [RFC PATCH 0/4] Persistent device name using alias name Nao Nishijima
2011-07-08  8:46 ` [RFC PATCH 1/4] block: add a new attribute "alias name" in gendisk structure Nao Nishijima
2011-07-08  8:46 ` [RFC PATCH 2/4] sd: modify printk for alias_name Nao Nishijima
2011-07-09  5:42   ` Joe Perches [this message]
2011-07-09 13:32     ` [PATCH] scsi: Make functions out of logging macros Nao Nishijima
2011-07-08  8:46 ` [RFC PATCH 3/4] fs: modify disk_name() for alias name Nao Nishijima
2011-07-08  8:46 ` [RFC PATCH 4/4] sd: cleanup " Nao Nishijima
2011-07-08 14:54 ` [RFC PATCH 0/4] Persistent device name using " Greg KH
2011-07-08 15:41   ` Kay Sievers
2011-07-08 15:47     ` Greg KH
2011-07-08 15:54       ` James Bottomley
2011-07-08 16:04         ` Greg KH
2011-07-08 16:17           ` James Bottomley
2011-07-08 16:32             ` Greg KH
2011-07-08 16:15         ` Kay Sievers
2011-07-08 16:38           ` Kay Sievers
2011-07-11 11:47             ` Hannes Reinecke
2011-07-09  6:11           ` Masami Hiramatsu
2011-08-03 17:16             ` Borislav Petkov
2011-08-10  2:01               ` Masami Hiramatsu
2011-07-08 19:45 ` Karel Zak
2011-07-08 19:58   ` Greg KH
2011-07-15  6:55   ` Nao Nishijima
2011-07-15 12:48     ` Karel Zak
2011-07-16 11:40       ` Nao Nishijima

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=1310190175.3848.5.camel@Joe-Laptop \
    --to=joe@perches.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=dgilbert@interlog.com \
    --cc=dle-develop@lists.sourceforge.net \
    --cc=greg@kroah.com \
    --cc=hare@suse.de \
    --cc=jcm@redhat.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=nao.nishijima.xt@hitachi.com \
    --cc=stefanr@s5r6.in-berlin.de \
    --cc=yrl.pp-manager.tt@hitachi.com \
    /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