Skip to content

Commit 345e296

Browse files
hreineckemartinkpetersen
authored andcommitted
scsi: scsi: Export blacklist flags to sysfs
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 <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent e5203cf commit 345e296

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

drivers/scsi/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ clean-files := 53c700_d.h 53c700_u.h
191191

192192
$(obj)/53c700.o $(MODVERDIR)/$(obj)/53c700.ver: $(obj)/53c700_d.h
193193

194+
$(obj)/scsi_sysfs.o: $(obj)/scsi_devinfo_tbl.c
195+
196+
quiet_cmd_bflags = GEN $@
197+
cmd_bflags = sed -n 's/.*BLIST_\([A-Z0-9_]*\) *.*/BLIST_FLAG_NAME(\1),/p' $< > $@
198+
199+
$(obj)/scsi_devinfo_tbl.c: include/scsi/scsi_devinfo.h
200+
$(call if_changed,bflags)
201+
194202
# If you want to play with the firmware, uncomment
195203
# GENERATE_FIRMWARE := 1
196204

drivers/scsi/scsi_scan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
984984
scsi_attach_vpd(sdev);
985985

986986
sdev->max_queue_depth = sdev->queue_depth;
987+
sdev->sdev_bflags = *bflags;
987988

988989
/*
989990
* Ok, the device is now all set up, we can

drivers/scsi/scsi_sysfs.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <scsi/scsi_dh.h>
2121
#include <scsi/scsi_transport.h>
2222
#include <scsi/scsi_driver.h>
23+
#include <scsi/scsi_devinfo.h>
2324

2425
#include "scsi_priv.h"
2526
#include "scsi_logging.h"
@@ -966,6 +967,41 @@ sdev_show_wwid(struct device *dev, struct device_attribute *attr,
966967
}
967968
static DEVICE_ATTR(wwid, S_IRUGO, sdev_show_wwid, NULL);
968969

970+
#define BLIST_FLAG_NAME(name) [ilog2(BLIST_##name)] = #name
971+
static const char *const sdev_bflags_name[] = {
972+
#include "scsi_devinfo_tbl.c"
973+
};
974+
#undef BLIST_FLAG_NAME
975+
976+
static ssize_t
977+
sdev_show_blacklist(struct device *dev, struct device_attribute *attr,
978+
char *buf)
979+
{
980+
struct scsi_device *sdev = to_scsi_device(dev);
981+
int i;
982+
ssize_t len = 0;
983+
984+
for (i = 0; i < sizeof(sdev->sdev_bflags) * BITS_PER_BYTE; i++) {
985+
const char *name = NULL;
986+
987+
if (!(sdev->sdev_bflags & BIT(i)))
988+
continue;
989+
if (i < ARRAY_SIZE(sdev_bflags_name) && sdev_bflags_name[i])
990+
name = sdev_bflags_name[i];
991+
992+
if (name)
993+
len += snprintf(buf + len, PAGE_SIZE - len,
994+
"%s%s", len ? " " : "", name);
995+
else
996+
len += snprintf(buf + len, PAGE_SIZE - len,
997+
"%sINVALID_BIT(%d)", len ? " " : "", i);
998+
}
999+
if (len)
1000+
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1001+
return len;
1002+
}
1003+
static DEVICE_ATTR(blacklist, S_IRUGO, sdev_show_blacklist, NULL);
1004+
9691005
#ifdef CONFIG_SCSI_DH
9701006
static ssize_t
9711007
sdev_show_dh_state(struct device *dev, struct device_attribute *attr,
@@ -1151,6 +1187,7 @@ static struct attribute *scsi_sdev_attrs[] = {
11511187
&dev_attr_queue_depth.attr,
11521188
&dev_attr_queue_type.attr,
11531189
&dev_attr_wwid.attr,
1190+
&dev_attr_blacklist.attr,
11541191
#ifdef CONFIG_SCSI_DH
11551192
&dev_attr_dh_state.attr,
11561193
&dev_attr_access_state.attr,

0 commit comments

Comments
 (0)