All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@infradead.org>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH v3 04/13] lustre: libcfs: fix cfs_print_to_console()
Date: Fri, 6 Jul 2018 00:34:00 +0100 (BST)	[thread overview]
Message-ID: <alpine.LFD.2.21.1807052354100.12665@casper.infradead.org> (raw)
In-Reply-To: <87h8li2wz7.fsf@notabene.neil.brown.name>


> >> > The original code for cfs_print_to_console() used printk() and
> >> > used tricks to select which printk level to use. Later a cleanup
> >> > patch landed the just converted printk directly to pr_info which
> >> > is not exactly correct. Instead of converting back to printk lets
> >> > move everything to pr_* type functions which simplify the code.
> >> > This allows us to fold both dbghdr_to_err_string() and the
> >> > function dbghdr_to_info_string() into cfs_print_to_console().
> >> > 
> >> > Signed-off-by: James Simmons <jsimmons@infradead.org>
> >> > ---
> >> > .../staging/lustre/lnet/libcfs/linux-tracefile.c   | 55 ++++++----------------
> >> > 1 file changed, 14 insertions(+), 41 deletions(-)
> >> > 
> >> > diff --git a/drivers/staging/lustre/lnet/libcfs/linux-tracefile.c b/drivers/staging/lustre/lnet/libcfs/linux-tracefile.c
> >> > index 3af7722..c1747c4 100644
> >> > --- a/drivers/staging/lustre/lnet/libcfs/linux-tracefile.c
> >> > +++ b/drivers/staging/lustre/lnet/libcfs/linux-tracefile.c
> >> > @@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)
> >> > void cfs_print_to_console(struct ptldebug_header *hdr, int mask,
> >> > 			  const char *buf, int len, const char *file,
> >> > 			  const char *fn)
> >> > {
> >> > +	char *prefix = "Lustre";
> >> > +
> >> > +	if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET)
> >> > +		prefix = "LNet";
> >> > 
> >> > -	if (mask & D_EMERG) {
> >> > -		prefix = dbghdr_to_err_string(hdr);
> >> > -		ptype = KERN_EMERG;
> >> > +	if (mask & (D_CONSOLE | libcfs_printk)) {
> >> 
> >> This check is broken.  The default value of libcfs_printk (the mask
> >> that controls which messages should be printed to the console, and
> >> which ones should only be logged into the internal buffer) is:
> >> 
> >>     #define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)
> >> 
> >> so that means virtually every console message will be printed with
> >> pr_info() because this is matched first, instead of pr_emerg() or
> >> pr_err() below.
> >> 
> >> That is why the previous code was matching D_EMERG and D_ERROR first,
> >> then D_WARNING, and (D_CONSOLE | libcfs_printk) at the end.
> >
> > So to do this right we need:
> >
> > static void cfs_print_to_console(struct ptldebug_header *hdr, int mask,
> >                                  const char *buf, int len, const char 
> > *file,
> >                                  const char *fn)
> > {
> >         char *prefix = "Lustre";
> >
> >         if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET)
> >                 prefix = "LNet";
> >
> >         if (mask & D_CONSOLE) {
> >                 if (mask & D_EMERG) {
> >                         pr_emerg("%sError: %.*s", prefix, len, buf);
> >                 } else if (mask & D_ERROR) {
> >                         pr_err("%sError: %.*s", prefix, len, buf);
> >                 } else if (mask & D_WARNING) {
> >                         pr_warn("%s: %.*s", prefix, len, buf);
> >                 } else if (mask & libcfs_printk) {
> >                         pr_info("%s: %.*s", prefix, len, buf);
> >                 }
> >         } else {
> >                 if (mask & D_EMERG) {
> >                         pr_emerg("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix,
> >                                  hdr->ph_pid, hdr->ph_extern_pid, file,
> >                                  hdr->ph_line_num, fn, len, buf);
> >                 } else if (mask & D_ERROR) {
> >                         pr_err("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix,
> >                                hdr->ph_pid, hdr->ph_extern_pid, file,
> >                                hdr->ph_line_num, fn, len, buf);
> >                 } else if (mask & D_WARNING) {
> >                         pr_warn("%s: %d:%d:(%s:%d:%s()) %.*s", prefix,
> >                                 hdr->ph_pid, hdr->ph_extern_pid, file,
> >                                 hdr->ph_line_num, fn, len, buf);
> >                 } else if (mask & libcfs_printk) {
> >                         pr_info("%s: %.*s", prefix, len, buf);
> >                 }
> >         }
> > }
> 
> That doesn't look right either.
> The original code would *always* print something.
> This code looks like it might not (e.g. for mask == 0).

Is that correct behavior? A mask of zero means don't do anything.
Also if you look at the original in the OpenSFS branch you can see
if mask was to be 0 then ptype would be NULl :-( 

Note a D_CANT_MASK prevents some fields in the mask from being disabled.

> What is "D_CONSOLE" suppose to mean?  It seems to me "make the messages
> less verbose" and it isn't clear to me that what is called "D_CONSOLE".

It means two things. If by itself then it means use pr_info. If it is one
field in the mask then it means less detail. Confusing no :-( That is my
understanding of it. Maybe someone else can clarify if I'm wrong.

  reply	other threads:[~2018-07-05 23:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-27 19:38 [lustre-devel] [PATCH v3 00/13] lustre: libcfs: tracefile cleanups James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 01/13] lustre: libcfs: move tracefile locking from linux-tracefile.c to tracefile.c James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 02/13] lustre: libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb() James Simmons
2018-06-28 22:39   ` Andreas Dilger
2018-06-29  3:55     ` NeilBrown
2018-07-02  2:17       ` NeilBrown
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 03/13] lustre: libcfs: move tcd locking across to tracefile.c James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 04/13] lustre: libcfs: fix cfs_print_to_console() James Simmons
2018-06-27 21:27   ` NeilBrown
2018-06-28 22:30   ` Andreas Dilger
2018-06-29 16:17     ` James Simmons
2018-07-02  2:27       ` NeilBrown
2018-07-05 23:34         ` James Simmons [this message]
2018-07-05 23:35         ` James Simmons
2018-07-06  4:19           ` NeilBrown
2018-07-06 17:09           ` Andreas Dilger
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 05/13] lustre: libcfs: properly handle failure paths in cfs_tracefile_init_arch() James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 06/13] lustre: libcfs: merge linux-tracefile.c into tracefile.c James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 07/13] lustre: libcfs: remove cfs_trace_refill_stack() James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 08/13] lustre: libcfs: move cfs_trace_data data to tracefile.c James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 09/13] lustre: libcfs: cleanup tracefile.h James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 10/13] lustre: libcfs: fold cfs_tracefile_*_arch into their only callers James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 11/13] lustre: libcfs: renamed CFS_TCD_TYPE_MAX to CFS_TCD_TYPE_CNT James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 12/13] lustre: libcfs: discard TCD_MAX_TYPES James Simmons
2018-06-27 19:38 ` [lustre-devel] [PATCH v3 13/13] lustre: libcfs: format macros in tracefile.h James Simmons

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=alpine.LFD.2.21.1807052354100.12665@casper.infradead.org \
    --to=jsimmons@infradead.org \
    --cc=lustre-devel@lists.lustre.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.