All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	Alan@suse.de, "Stern <stern"@rowland.harvard.edu,
	linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
	Hannes Reinecke <hare@suse.com>
Subject: [PATCHv4 2/5] scsi: Export blacklist flags to sysfs
Date: Tue, 29 Aug 2017 10:49:21 +0200	[thread overview]
Message-ID: <1503996564-110464-3-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1503996564-110464-1-git-send-email-hare@suse.de>

Each scsi device is scanned according to the found blacklist flags,
but this information is never presented to sysfs.
This makes it quite hard to figure out if blacklisting worked as
expected.
With this patch we're exporting an additional attribute 'blacklist'
containing the blacklist flags for this device.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/Makefile     |  8 +++++++
 drivers/scsi/mktbl.pl     | 26 ++++++++++++++++++++
 drivers/scsi/scsi_scan.c  |  1 +
 drivers/scsi/scsi_sysfs.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
 create mode 100644 drivers/scsi/mktbl.pl

diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 93dbe58..b25d094 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -191,6 +191,14 @@ clean-files :=	53c700_d.h 53c700_u.h
 
 $(obj)/53c700.o $(MODVERDIR)/$(obj)/53c700.ver: $(obj)/53c700_d.h
 
+$(obj)/scsi_sysfs.o: $(obj)/scsi_devinfo_tbl.c
+
+quiet_cmd_bflags = GEN     $@
+	cmd_bflags = $(PERL) -s $(src)/mktbl.pl BLIST $< > $@
+
+$(obj)/scsi_devinfo_tbl.c: include/scsi/scsi_devinfo.h
+	$(call if_changed,bflags)
+
 # If you want to play with the firmware, uncomment
 # GENERATE_FIRMWARE := 1
 
diff --git a/drivers/scsi/mktbl.pl b/drivers/scsi/mktbl.pl
new file mode 100644
index 0000000..0dc5cdb
--- /dev/null
+++ b/drivers/scsi/mktbl.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+#
+# Build a mapping table for C definitions.
+#
+# Copyright (c) 2017 Hannes Reinecke, SUSE Linux GmbH.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+
+my $prf;
+
+$prf = $ARGV[0];
+open IN_FILE, "<$ARGV[1]" || die;
+print "\t/*\n\t * Automatically generated by ", $0, ".\n";
+print "\t * Do not edit.\n\t */\n";
+while (<IN_FILE>) {
+    chomp;
+    if (/^#define ${prf}_([^[:blank:]]*).*/) {
+	print "\t{ ", $prf, "_", $1, ", \"", $1, "\" },\n";
+    }
+}
+close IN_FILE || die;
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index fd88dab..075918b 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -984,6 +984,7 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
 		scsi_attach_vpd(sdev);
 
 	sdev->max_queue_depth = sdev->queue_depth;
+	sdev->sdev_bflags = *bflags;
 
 	/*
 	 * Ok, the device is now all set up, we can
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index e9b78db..dbda738 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -20,6 +20,7 @@
 #include <scsi/scsi_dh.h>
 #include <scsi/scsi_transport.h>
 #include <scsi/scsi_driver.h>
+#include <scsi/scsi_devinfo.h>
 
 #include "scsi_priv.h"
 #include "scsi_logging.h"
@@ -110,6 +111,27 @@ static const char *scsi_access_state_name(unsigned char state)
 }
 #endif
 
+static const struct {
+	unsigned int	value;
+	char		*name;
+} 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;
+}
+
 static int check_set(unsigned long long *val, char *src)
 {
 	char *last;
@@ -955,6 +977,43 @@ static DEVICE_ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth,
 }
 static DEVICE_ATTR(wwid, S_IRUGO, sdev_show_wwid, NULL);
 
+static ssize_t
+sdev_show_blacklist(struct device *dev, struct device_attribute *attr,
+		    char *buf)
+{
+	struct scsi_device *sdev = to_scsi_device(dev);
+	int i;
+	char *ptr = buf;
+	ssize_t len = 0;
+
+	for (i = 0; i < sizeof(unsigned int) * 8; i++) {
+		unsigned int bflags = (unsigned int)1 << i;
+		ssize_t blen;
+		const char *name = NULL;
+
+		if (!(bflags & sdev->sdev_bflags))
+			continue;
+
+		if (ptr != buf) {
+			blen = snprintf(ptr, 2, " ");
+			ptr += blen;
+			len += blen;
+		}
+		name = sdev_bflags_name(bflags);
+		if (name)
+			blen = snprintf(ptr, strlen(name) + 1,
+					"%s", name);
+		else
+			blen = snprintf(ptr, 67, "INVALID_BIT(%d)", i);
+		ptr += blen;
+		len += blen;
+	}
+	if (len)
+		len += snprintf(ptr, 2, "\n");
+	return len;
+}
+static DEVICE_ATTR(blacklist, S_IRUGO, sdev_show_blacklist, NULL);
+
 #ifdef CONFIG_SCSI_DH
 static ssize_t
 sdev_show_dh_state(struct device *dev, struct device_attribute *attr,
@@ -1140,6 +1199,7 @@ static umode_t scsi_sdev_bin_attr_is_visible(struct kobject *kobj,
 	&dev_attr_queue_depth.attr,
 	&dev_attr_queue_type.attr,
 	&dev_attr_wwid.attr,
+	&dev_attr_blacklist.attr,
 #ifdef CONFIG_SCSI_DH
 	&dev_attr_dh_state.attr,
 	&dev_attr_access_state.attr,
-- 
1.8.5.6

  parent reply	other threads:[~2017-08-29  8:49 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 ` Hannes Reinecke [this message]
2017-08-29 16:02   ` [PATCHv4 2/5] scsi: Export blacklist flags to sysfs Bart Van Assche
2017-08-30 10:50     ` Hannes Reinecke
2017-08-30 15:39       ` Bart Van Assche
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=1503996564-110464-3-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc="Stern <stern"@rowland.harvard.edu \
    --cc=Alan@suse.de \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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 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.