From: "Ewan D. Milne" <emilne@redhat.com>
To: linux-scsi@vger.kernel.org
Subject: [PATCH] scsi: Add "missing" sysfs attribute to scsi_device structure
Date: Mon, 18 Nov 2013 12:10:56 -0500 [thread overview]
Message-ID: <1384794656-9449-1-git-send-email-emilne@redhat.com> (raw)
From: "Ewan D. Milne" <emilne@redhat.com>
This change adds a "missing" sysfs attribute to scsi_device
which is set when a previously scanned device no longer appears
in the REPORT LUNS inventory.
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
drivers/scsi/scsi_scan.c | 30 +++++++++++++++++++++++++++++-
drivers/scsi/scsi_sysfs.c | 2 ++
include/scsi/scsi_device.h | 1 +
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 2e5fe58..7908c06 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1317,9 +1317,11 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
struct scsi_lun *lunp, *lun_data;
u8 *data;
struct scsi_sense_hdr sshdr;
- struct scsi_device *sdev;
+ struct scsi_device *sdev, *sdev_i;
struct Scsi_Host *shost = dev_to_shost(&starget->dev);
int ret = 0;
+ unsigned long flags;
+ bool found;
/*
* Only support SCSI-3 and up devices if BLIST_NOREPORTLUN is not set.
@@ -1492,6 +1494,32 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
}
}
+ /*
+ * See if all of the LUNs that we know about on the target are
+ * still being reported in the REPORT LUNS data. If any are not,
+ * they have been removed from the target. Set the "missing" flag.
+ *
+ * We only do this for REPORT LUNS scanning, because we do not
+ * want to set the flag on LUNs that are inaccessible due to a
+ * transport error. Here, the target has responded to a command
+ * and told us that the LUN is not present.
+ */
+ spin_lock_irqsave(shost->host_lock, flags);
+ list_for_each_entry(sdev_i, &starget->devices, same_target_siblings) {
+ found = 0;
+ for (lunp = &lun_data[1]; lunp <= &lun_data[num_luns]; lunp++) {
+ lun = scsilun_to_int(lunp);
+ if (memcmp(&lunp->scsi_lun[sizeof(lun)], "\0\0\0\0", 4))
+ continue;
+ else if (lun == sdev_i->lun) {
+ found = 1;
+ break;
+ }
+ }
+ sdev_i->missing = !found;
+ }
+ spin_unlock_irqrestore(shost->host_lock, flags);
+
out_err:
kfree(lun_data);
out:
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 04c2a27..01635cc 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -536,6 +536,7 @@ sdev_rd_attr (scsi_level, "%d\n");
sdev_rd_attr (vendor, "%.8s\n");
sdev_rd_attr (model, "%.16s\n");
sdev_rd_attr (rev, "%.4s\n");
+sdev_rd_attr(missing, "%d\n");
/*
* TODO: can we make these symlinks to the block layer ones?
@@ -721,6 +722,7 @@ static struct attribute *scsi_sdev_attrs[] = {
&dev_attr_vendor.attr,
&dev_attr_model.attr,
&dev_attr_rev.attr,
+ &dev_attr_missing.attr,
&dev_attr_rescan.attr,
&dev_attr_delete.attr,
&dev_attr_state.attr,
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 6efb2e1..79775f1 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -152,6 +152,7 @@ struct scsi_device {
unsigned no_read_disc_info:1; /* Avoid READ_DISC_INFO cmds */
unsigned no_read_capacity_16:1; /* Avoid READ_CAPACITY_16 cmds */
unsigned is_visible:1; /* is the device visible in sysfs */
+ unsigned missing:1; /* No longer appears in REPORT LUNS data */
DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events */
struct list_head event_list; /* asserted events */
--
1.7.11.7
next reply other threads:[~2013-11-18 17:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-18 17:10 Ewan D. Milne [this message]
2013-11-18 17:45 ` [PATCH] scsi: Add "missing" sysfs attribute to scsi_device structure James Bottomley
2013-11-18 17:59 ` Ewan Milne
2013-11-18 18:15 ` James Bottomley
2013-11-18 18:28 ` Ewan Milne
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=1384794656-9449-1-git-send-email-emilne@redhat.com \
--to=emilne@redhat.com \
--cc=linux-scsi@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox