diff mbox

[2/2,v3] be2iscsi: Fix some error messages

Message ID 1471107782.3467.28.camel@perches.com (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Joe Perches Aug. 13, 2016, 5:03 p.m. UTC
On Sat, 2016-08-13 at 09:41 -0700, Joe Perches wrote:
> On Sat, 2016-08-13 at 14:31 +0200, Christophe JAILLET wrote:
> > Le 13/08/2016 à 13:35, Joe Perches a écrit :
> > > > @@ -268,7 +268,7 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc)
> > > >   				&nonemb_cmd.dma);
> > > >   	if (nonemb_cmd.va == NULL) {
> > > >   		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
> > > > -			    "BM_%d : Failed to allocate memory for"
> > > > +			    "BM_%d : Failed to allocate memory for "
> > > >   			    "mgmt_invalidate_icds\n");

This is the first time I've looked at the beiscsi_log macro.

It sure is odd and undesirable.

It's _very_ not nice to have a format string take an implied
__LINE__ argument.

It'd be much more intelligible to take the first bit as a
separate string, concatenate it in the macro with "_%d: "
and __LINE__ (if that's really useful, I think it's not)
and emit that as the format.

Something like:


So these beiscsi_log uses become something like:

	beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
		    "BM", "Failed to allocate memory for mgmt_invalidate_icds\n");

and the format and its arguments match.

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Joe Perches Aug. 13, 2016, 8:42 p.m. UTC | #1
Joe Perches (2):
  be2iscsi: Coalesce split strings and formats
  be2iscsi: Use a standard logging style

 drivers/scsi/be2iscsi/be_cmds.c  |  61 +++---
 drivers/scsi/be2iscsi/be_iscsi.c | 115 ++++++-----
 drivers/scsi/be2iscsi/be_main.c  | 398 +++++++++++++++++----------------------
 drivers/scsi/be2iscsi/be_main.h  |  19 +-
 drivers/scsi/be2iscsi/be_mgmt.c  |  99 +++++-----
 5 files changed, 314 insertions(+), 378 deletions(-)
Bart Van Assche Aug. 14, 2016, 2:34 p.m. UTC | #2
On 08/13/16 13:42, Joe Perches wrote:
> Joe Perches (2):
>   be2iscsi: Coalesce split strings and formats
>   be2iscsi: Use a standard logging style

Hello Joe,

As one can see in be_main.h the "level" argument of macro beiscsi_log() 
is ignored for log levels KERN_EMERG, KERN_ALERT, KERN_CRIT and
KERN_ERR. So for these log levels beiscsi_log() is a synonym of 
shost_printk(). Have you considered to replace beiscsi_log() with 
shost_printk() for these log levels and additionally to change 
beiscsi_log() for the other log levels into pr_debug()? pr_debug() 
statements namely already can be enabled and disabled at runtime. If the 
BEISCSI_LOG_* log category would be embedded in the log text that would 
allow to eliminate the phba->attr_log_enable structure member. 
Additionally, pr_debug() has a facility for displaying the source file 
name and the line number. That would allow to leave out __LINE__ from 
be2iscsi log statements. I don't think it is useful to have that line 
number in non-debug be2iscsi log statements.

Thanks,

Bart.

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches Aug. 14, 2016, 4:24 p.m. UTC | #3
On Sun, 2016-08-14 at 14:34 +0000, Bart Van Assche wrote:
> On 08/13/16 13:42, Joe Perches wrote:
> > Joe Perches (2):
> >   be2iscsi: Coalesce split strings and formats
> >   be2iscsi: Use a standard logging style
> Hello Joe,

Hello Bart.

> As one can see in be_main.h the "level" argument of macro beiscsi_log() 
> is ignored for log levels KERN_EMERG, KERN_ALERT, KERN_CRIT and
> KERN_ERR. So for these log levels beiscsi_log() is a synonym of 
> shost_printk(). Have you considered to replace beiscsi_log() with 
> shost_printk() for these log levels and additionally to change 
> beiscsi_log() for the other log levels into pr_debug()? pr_debug() 
> statements namely already can be enabled and disabled at runtime. If the 
> BEISCSI_LOG_* log category would be embedded in the log text that would 
> allow to eliminate the phba->attr_log_enable structure member. 
> Additionally, pr_debug() has a facility for displaying the source file 
> name and the line number. That would allow to leave out __LINE__ from 
> be2iscsi log statements. I don't think it is useful to have that line 
> number in non-debug be2iscsi log statements.

My main consideration for submitting a patch at all
was removing the apparent format/argument mismatches.

As far as I can grep, only KERN_ERR, KERN_WARNING and
KERN_INFO are actually used by be2iscsi today.

I agree with the removal of __LINE__ from the macros
as its utility is generally pretty low.

Besides, using stringify(__LINE__) is almost always
smaller object code than a format with "%d", __LINE__.

Prefixes like "BC" and "BS" are __FILE__ equivalents,
and could be removed as well with something like
"%s, kbasename(__FILE__)" used if _really_ desired.

I have no issue with defining and using beiscsi_<level>
equivalents to shost_printks.

I think the test inside beiscsi_log is better removed
with multiple specific beiscsi_<level> calls used.

I don't know why any KERN_ERR should ever be masked,
but perhaps something like:

#define beiscsi_printk(level, phba, mask, fmt, ...)		\
do {								\
	if ((mask) & (phba)->attr_log_enable)			\
		shost_printk(level, phba->shost, fmt, ##__VA_ARGS__); \
} while (0)

#define beiscsi_err(phba, mask, fmt, ...)			\
	beiscsi_printk(KERN_ERR, phba, mask, fmt, ##__VA_ARGS__)
#define beiscsi_warn(phba, mask, fmt, ...)			\
	beiscsi_printk(KERN_WARNING, phba, mask, fmt, ##__VA_ARGS__)
#define beiscsi_info(phba, mask, fmt, ...)			\
	beiscsi_printk(KERN_INFO, phba, mask, fmt, ##__VA_ARGS__)

with a sed of the .c files:

$ sed -i 's/beiscsi_log(phba, KERN_ERR/beiscsi_err(phba/g' drivers/scsi/be2iscsi/*.c
$ sed -i 's/beiscsi_log(phba, KERN_WARNING/beiscsi_warn(phba/g' drivers/scsi/be2iscsi/*.c
$ sed -i 's/beiscsi_log(phba, KERN_INFO/beiscsi_info(phba/g' drivers/scsi/be2iscsi/*.c

with argument realignment of those lines.

All of these are of course up to the actual maintainers of be2iscsi.

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bart Van Assche Aug. 14, 2016, 5:09 p.m. UTC | #4
On 08/14/16 09:24, Joe Perches wrote:
> On Sun, 2016-08-14 at 14:34 +0000, Bart Van Assche wrote:
>> As one can see in be_main.h the "level" argument of macro beiscsi_log()
>> is ignored for log levels KERN_EMERG, KERN_ALERT, KERN_CRIT and
>> KERN_ERR. So for these log levels beiscsi_log() is a synonym of
>> shost_printk(). Have you considered to replace beiscsi_log() with
>> shost_printk() for these log levels and additionally to change
>> beiscsi_log() for the other log levels into pr_debug()? pr_debug()
>> statements namely already can be enabled and disabled at runtime. If the
>> BEISCSI_LOG_* log category would be embedded in the log text that would
>> allow to eliminate the phba->attr_log_enable structure member.
>> Additionally, pr_debug() has a facility for displaying the source file
>> name and the line number. That would allow to leave out __LINE__ from
>> be2iscsi log statements. I don't think it is useful to have that line
>> number in non-debug be2iscsi log statements.
>
> My main consideration for submitting a patch at all
> was removing the apparent format/argument mismatches.
>
> As far as I can grep, only KERN_ERR, KERN_WARNING and
> KERN_INFO are actually used by be2iscsi today.
>
> I agree with the removal of __LINE__ from the macros
> as its utility is generally pretty low.
>
> Besides, using stringify(__LINE__) is almost always
> smaller object code than a format with "%d", __LINE__.
>
> Prefixes like "BC" and "BS" are __FILE__ equivalents,
> and could be removed as well with something like
> "%s, kbasename(__FILE__)" used if _really_ desired.
>
> I have no issue with defining and using beiscsi_<level>
> equivalents to shost_printks.
>
> I think the test inside beiscsi_log is better removed
> with multiple specific beiscsi_<level> calls used.
>
> I don't know why any KERN_ERR should ever be masked,
> but perhaps something like:
>
> #define beiscsi_printk(level, phba, mask, fmt, ...)		\
> do {								\
> 	if ((mask) & (phba)->attr_log_enable)			\
> 		shost_printk(level, phba->shost, fmt, ##__VA_ARGS__); \
> } while (0)
>
> #define beiscsi_err(phba, mask, fmt, ...)			\
> 	beiscsi_printk(KERN_ERR, phba, mask, fmt, ##__VA_ARGS__)
> #define beiscsi_warn(phba, mask, fmt, ...)			\
> 	beiscsi_printk(KERN_WARNING, phba, mask, fmt, ##__VA_ARGS__)
> #define beiscsi_info(phba, mask, fmt, ...)			\
> 	beiscsi_printk(KERN_INFO, phba, mask, fmt, ##__VA_ARGS__)
>
> with a sed of the .c files:
>
> $ sed -i 's/beiscsi_log(phba, KERN_ERR/beiscsi_err(phba/g' drivers/scsi/be2iscsi/*.c
> $ sed -i 's/beiscsi_log(phba, KERN_WARNING/beiscsi_warn(phba/g' drivers/scsi/be2iscsi/*.c
> $ sed -i 's/beiscsi_log(phba, KERN_INFO/beiscsi_info(phba/g' drivers/scsi/be2iscsi/*.c
>
> with argument realignment of those lines.
>
> All of these are of course up to the actual maintainers of be2iscsi.

Hello Joe,

My primary concern is how to enable and disable log messages from user 
space. Many drivers define their own logging macros and export a bitmask 
that allows to enable and disable logging messages per category. These 
bitmask control mechanisms are annoying because figuring out what bit 
controls which message category requires a search through the driver 
source code. I'd like to see all these custom logging macros disappear 
and being replaced by a single mechanism. The "dynamic debug" mechanism 
e.g. is in my opinion much easier to use than the different custom 
logging mechanisms.

Bart.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches Aug. 14, 2016, 5:29 p.m. UTC | #5
On Sun, 2016-08-14 at 17:09 +0000, Bart Van Assche wrote:

> My primary concern is how to enable and disable log messages from user 
> space. Many drivers define their own logging macros and export a bitmask 
> that allows to enable and disable logging messages per category. These 
> bitmask control mechanisms are annoying because figuring out what bit 
> controls which message category requires a search through the driver 
> source code. I'd like to see all these custom logging macros disappear 
> and being replaced by a single mechanism. The "dynamic debug" mechanism 
> e.g. is in my opinion much easier to use than the different custom 
> logging mechanisms.

Dynamic debug doesn't have a bitmask function and
still requires looking through the code for lines
and format strings.

I think you are looking for a system wide equivalent
for the ethtool/netif_<level> mechanism.

Nothing like that exists currently.

Some code uses a bitmask/and, other code uses a
level/comparison.

Care to propose something?

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bart Van Assche Aug. 17, 2016, 1:19 a.m. UTC | #6
On 08/14/16 10:29, Joe Perches wrote:
> On Sun, 2016-08-14 at 17:09 +0000, Bart Van Assche wrote:
>> My primary concern is how to enable and disable log messages from user
>> space. Many drivers define their own logging macros and export a bitmask
>> that allows to enable and disable logging messages per category. These
>> bitmask control mechanisms are annoying because figuring out what bit
>> controls which message category requires a search through the driver
>> source code. I'd like to see all these custom logging macros disappear
>> and being replaced by a single mechanism. The "dynamic debug" mechanism
>> e.g. is in my opinion much easier to use than the different custom
>> logging mechanisms.
>
> Dynamic debug doesn't have a bitmask function and
> still requires looking through the code for lines
> and format strings.
>
> I think you are looking for a system wide equivalent
> for the ethtool/netif_<level> mechanism.
>
> Nothing like that exists currently.
>
> Some code uses a bitmask/and, other code uses a
> level/comparison.
>
> Care to propose something?

Hello Joe,

As far as I can see all that the ethtool msglevel API implements is a 
mechanism to query and set the log level from user space. What various 
SCSI drivers implement is not a log level but a log mask mechanism. How 
about the following approach to associate a name with each bit in a log 
mask, to export these names to user space and to make it possible to 
enable/disable messages per log category:
* Introduce a variant of pr_debug() that allows to specify a textual
   representation of the log category (a short string without spaces).
* Make the log category names available in
   /sys/kernel/debug/dynamic_debug/...
* Today dynamic debug allows to enable/disable log messages by
   specifying the source file name, function name, line number, module
   name and/or format string. My proposal is to make it also possible to
   enable/disable log messages based on the log category name.

Anyway, this is just a proposal. Anyone is welcome to come up with an 
alternative proposal.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches Aug. 17, 2016, 3:39 a.m. UTC | #7
On Wed, 2016-08-17 at 01:19 +0000, Bart Van Assche wrote:
> On 08/14/16 10:29, Joe Perches wrote:
> > On Sun, 2016-08-14 at 17:09 +0000, Bart Van Assche wrote:
> > > My primary concern is how to enable and disable log messages from user
> > > space.
[]
> > I think you are looking for a system wide equivalent
> > for the ethtool/netif_ mechanism.
> > 
> > Nothing like that exists currently.
> > 
> > Some code uses a bitmask/and, other code uses a
> > level/comparison.
[]
> As far as I can see all that the ethtool msglevel API implements is a 
> mechanism to query and set the log level from user space. What various 
> SCSI drivers implement is not a log level but a log mask mechanism. How 
> about the following approach to associate a name with each bit in a log 
> mask, to export these names to user space and to make it possible to 
> enable/disable messages per log category:
> * Introduce a variant of pr_debug() that allows to specify a textual
>    representation of the log category (a short string without spaces).
> * Make the log category names available in
>    /sys/kernel/debug/dynamic_debug/...
> * Today dynamic debug allows to enable/disable log messages by
>    specifying the source file name, function name, line number, module
>    name and/or format string. My proposal is to make it also possible to
>    enable/disable log messages based on the log category name.

Many of these logging mechanisms are not just debug
facilities.

Perhaps a dynamic_debug control would be inappropriate.

There have also been various custom scsi log level
facilities like the blogic_msg for the very old
BusLogic blogic_msg.

These functions also sometimes write into some
device-specific buffer.

Perhaps the largest problem, if this is to be scsi only
rather than system wide, is finding out what and how
the various bits in a mask should be used.


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
index 30a4606..3f0fbbf 100644
--- a/drivers/scsi/be2iscsi/be_main.h
+++ b/drivers/scsi/be2iscsi/be_main.h
@@ -1084,11 +1084,12 @@  struct hwi_context_memory {
 #define __beiscsi_log(phba, level, fmt, arg...) \
 	shost_printk(level, phba->shost, fmt, __LINE__, ##arg)
 
-#define beiscsi_log(phba, level, mask, fmt, arg...) \
-do { \
-	uint32_t log_value = phba->attr_log_enable; \
-		if (((mask) & log_value) || (level[1] <= '3')) \
-			__beiscsi_log(phba, level, fmt, ##arg); \
-} while (0);
+#define beiscsi_log(phba, level, mask, prefix, fmt, ...)		\
+do {									\
+	uint32_t log_value = phba->attr_log_enable;			\
+	if (((mask) & log_value) || (level[1] <= '3'))			\
+		__beiscsi_log(phba, level, prefix "_%d: " fmt,		\
+			      ##__VA_ARGS__);				\
+} while (0)
 
 #endif