public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <Bart.VanAssche@wdc.com>
To: "hare@suse.de" <hare@suse.de>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>
Cc: "hch@lst.de" <hch@lst.de>,
	"james.bottomley@hansenpartnership.com"
	<james.bottomley@hansenpartnership.com>,
	"Alan@suse.de" <Alan@suse.de>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"hare@suse.com" <hare@suse.com>,
	"stern@rowland.harvard.edu" <stern@rowland.harvard.edu>
Subject: Re: [PATCHv4 2/5] scsi: Export blacklist flags to sysfs
Date: Wed, 30 Aug 2017 15:39:03 +0000	[thread overview]
Message-ID: <1504107541.2526.11.camel@wdc.com> (raw)
In-Reply-To: <9e7eb07d-7796-ace6-ee04-d88e22e730b0@suse.de>

On Wed, 2017-08-30 at 12:50 +0200, Hannes Reinecke wrote:
> On 08/29/2017 06:02 PM, Bart Van Assche wrote:
> > On Tue, 2017-08-29 at 10:49 +0200, Hannes Reinecke wrote:
> > > +} sdev_bflags[] = {
> > > +#include "scsi_devinfo_tbl.c"
> > > +};
> > > +
> > > +static const char *sdev_bflags_name(unsigned int bflags)
> > > +{
> > > +	int i;
> > > +	const char *name = NULL;
> > > +
> > > +	for (i = 0; i < ARRAY_SIZE(sdev_bflags); i++) {
> > > +		if (sdev_bflags[i].value == bflags) {
> > > +			name = sdev_bflags[i].name;
> > > +			break;
> > > +		}
> > > +	}
> > > +	return name;
> > > +}
> > 
> > How about using ilog2() of the BLIST_* values as index of the table such that
> > an array lookup can be used instead of a for-loop over the entire array?
> 
> Not sure if that'll work. The BLIST_* values in fact form a sparse
> array, so the lookup array 'sdev_bflags' actually an associative array.
> And I dare not convert it to a normal array as then I couldn't to the
> automatice table creation anymore.
> 
> So I'm not sure if ilog2 will save me anything here.

Hello Hannes,

Are you aware that there is already code upstream for converting a bitmask
into a list of names of flags that supports sparse bit definitions? From
block/blk-mq-debugfs.c:

#define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
static const char *const hctx_flag_name[] = {
	HCTX_FLAG_NAME(SHOULD_MERGE),
	HCTX_FLAG_NAME(TAG_SHARED),
	HCTX_FLAG_NAME(SG_MERGE),
	HCTX_FLAG_NAME(BLOCKING),
	HCTX_FLAG_NAME(NO_SCHED),
};
#undef HCTX_FLAG_NAME

static int blk_flags_show(struct seq_file *m, const unsigned long flags,
			  const char *const *flag_name, int flag_name_count)
{
	bool sep = false;
	int i;

	for (i = 0; i < sizeof(flags) * BITS_PER_BYTE; i++) {
		if (!(flags & BIT(i)))
			continue;
		if (sep)
			seq_puts(m, "|");
		sep = true;
		if (i < flag_name_count && flag_name[i])
			seq_puts(m, flag_name[i]);
		else
			seq_printf(m, "%d", i);
	}
	return 0;
}

[ ... ]
	blk_flags_show(m, hctx->flags ^ BLK_ALLOC_POLICY_TO_MQ_FLAG(alloc_policy),
		       hctx_flag_name, ARRAY_SIZE(hctx_flag_name));
[ ... ]

Bart.

  reply	other threads:[~2017-08-30 15:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29  8:49 [PATCHv4 0/5] Fixup blacklist handling Hannes Reinecke
2017-08-29  8:49 ` [PATCHv4 1/5] scsi_debug: allow to specify inquiry vendor and model Hannes Reinecke
2017-08-29  8:49 ` [PATCHv4 2/5] scsi: Export blacklist flags to sysfs Hannes Reinecke
2017-08-29 16:02   ` Bart Van Assche
2017-08-30 10:50     ` Hannes Reinecke
2017-08-30 15:39       ` Bart Van Assche [this message]
2017-08-30  0:10   ` kbuild test robot
2017-08-29  8:49 ` [PATCHv4 3/5] scsi_devinfo: Reformat blacklist flags Hannes Reinecke
2017-08-29 16:06   ` Bart Van Assche
2017-08-29  8:49 ` [PATCHv4 4/5] scsi_devinfo: Whitespace fixes Hannes Reinecke
2017-08-29  8:49 ` [PATCHv4 5/5] scsi_devinfo: fixup string compare Hannes Reinecke
2017-08-29 16:30   ` Bart Van Assche

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=1504107541.2526.11.camel@wdc.com \
    --to=bart.vanassche@wdc.com \
    --cc=Alan@suse.de \
    --cc=hare@suse.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stern@rowland.harvard.edu \
    /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