From: "Ewan D. Milne" <emilne@redhat.com>
To: linux-scsi@vger.kernel.org
Subject: [PATCH v2 4/8] [SCSI] Add support for scsi_target events
Date: Fri, 1 Feb 2013 12:53:11 -0500 [thread overview]
Message-ID: <1359741195-2641-5-git-send-email-emilne@redhat.com> (raw)
In-Reply-To: <1359741195-2641-1-git-send-email-emilne@redhat.com>
From: "Ewan D. Milne" <emilne@redhat.com>
Added capability to generate uevents on scsi_target objects.
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
drivers/scsi/scsi_lib.c | 135 +++++++++++++++++++++++++++++++++++++++++++++
drivers/scsi/scsi_priv.h | 3 +
drivers/scsi/scsi_scan.c | 17 ++++++
include/scsi/scsi_device.h | 34 ++++++++++++
4 files changed, 189 insertions(+)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 75b7cad..b815666 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2393,6 +2393,141 @@ scsi_target_resume(struct scsi_target *starget)
}
EXPORT_SYMBOL(scsi_target_resume);
+#ifdef CONFIG_SCSI_ENHANCED_UA
+/**
+ * starget_evt_emit - emit a single SCSI target uevent
+ * @starget: associated SCSI target
+ * @evt: event to emit
+ *
+ * Send a single uevent (starget_event) to the associated scsi_target.
+ */
+static void starget_evt_emit(struct scsi_target *starget,
+ struct starget_event *evt)
+{
+ int idx = 0;
+ char *envp[3];
+
+ switch (evt->evt_type) {
+ case STARGET_EVT_LUN_CHANGE_REPORTED:
+ envp[idx++] = "STARGET_LUN_CHANGE_REPORTED=1";
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+
+ envp[idx++] = NULL;
+
+ kobject_uevent_env(&starget->dev.kobj, KOBJ_CHANGE, envp);
+}
+
+/**
+ * starget_evt_work - send a uevent for each scsi event
+ * @work: work struct for scsi_target
+ *
+ * Dispatch queued events to their associated scsi_target kobjects
+ * as uevents.
+ */
+void starget_evt_work(struct work_struct *work)
+{
+ struct scsi_target *starget;
+ LIST_HEAD(event_list);
+
+ starget = container_of(work, struct scsi_target, event_work);
+
+ while (1) {
+ struct starget_event *evt;
+ struct list_head *this, *tmp;
+ unsigned long flags;
+
+ spin_lock_irqsave(&starget->list_lock, flags);
+ list_splice_init(&starget->event_list, &event_list);
+ spin_unlock_irqrestore(&starget->list_lock, flags);
+
+ if (list_empty(&event_list))
+ break;
+
+ list_for_each_safe(this, tmp, &event_list) {
+ evt = list_entry(this, struct starget_event, node);
+ list_del(&evt->node);
+ starget_evt_emit(starget, evt);
+ kfree(evt);
+ }
+ }
+}
+
+/**
+ * starget_evt_send - send asserted event to uevent thread
+ * @starget: scsi_target event occurred on
+ * @evt: event to send
+ *
+ * Assert scsi target event asynchronously.
+ */
+void starget_evt_send(struct scsi_target *starget, struct starget_event *evt)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&starget->list_lock, flags);
+ list_add_tail(&evt->node, &starget->event_list);
+ schedule_work(&starget->event_work);
+ spin_unlock_irqrestore(&starget->list_lock, flags);
+}
+EXPORT_SYMBOL_GPL(starget_evt_send);
+
+/**
+ * starget_evt_alloc - allocate a new scsi_target event
+ * @evt_type: type of event to allocate
+ * @gfpflags: GFP flags for allocation
+ *
+ * Allocates and returns a new starget_event.
+ */
+struct starget_event *starget_evt_alloc(enum scsi_target_event evt_type,
+ gfp_t gfpflags)
+{
+ struct starget_event *evt = kzalloc(sizeof(struct starget_event),
+ gfpflags);
+ if (!evt)
+ return NULL;
+
+ evt->evt_type = evt_type;
+ INIT_LIST_HEAD(&evt->node);
+
+ /* evt_type-specific initialization, if any */
+ switch (evt_type) {
+ case STARGET_EVT_LUN_CHANGE_REPORTED:
+ default:
+ /* do nothing */
+ break;
+ }
+
+ return evt;
+}
+EXPORT_SYMBOL_GPL(starget_evt_alloc);
+
+/**
+ * starget_evt_send_simple - send asserted event to uevent thread
+ * @starget: scsi_target event occurred on
+ * @evt_type: type of event to send
+ * @gfpflags: GFP flags for allocation
+ *
+ * Assert scsi target event asynchronously, given an event type.
+ */
+void starget_evt_send_simple(struct scsi_target *starget,
+ enum scsi_target_event evt_type, gfp_t gfpflags)
+{
+ struct starget_event *evt = starget_evt_alloc(evt_type, gfpflags);
+ if (!evt) {
+ starget_printk(KERN_ERR, starget, "event %d eaten due to OOM\n",
+ evt_type);
+ return;
+ }
+
+ starget_evt_send(starget, evt);
+}
+EXPORT_SYMBOL_GPL(starget_evt_send_simple);
+
+#endif
+
/**
* scsi_internal_device_block - internal function to put a device temporarily into the SDEV_BLOCK state
* @sdev: device to block
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 7f00813..5da5466 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -91,6 +91,9 @@ struct request_queue;
struct request;
extern struct kmem_cache *scsi_sdb_cache;
extern void sdev_evt_work(struct work_struct *work);
+#ifdef CONFIG_SCSI_ENHANCED_UA
+extern void starget_evt_work(struct work_struct *work);
+#endif
/* scsi_proc.c */
#ifdef CONFIG_SCSI_PROC_FS
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 47348ed..2d21597 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -425,6 +425,11 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
starget->can_queue = 0;
INIT_LIST_HEAD(&starget->siblings);
INIT_LIST_HEAD(&starget->devices);
+#ifdef CONFIG_SCSI_ENHANCED_UA
+ INIT_LIST_HEAD(&starget->event_list);
+ spin_lock_init(&starget->list_lock);
+ INIT_WORK(&starget->event_work, starget_evt_work);
+#endif
starget->state = STARGET_CREATED;
starget->scsi_level = SCSI_2;
starget->max_target_blocked = SCSI_DEFAULT_TARGET_BLOCKED;
@@ -472,7 +477,19 @@ static void scsi_target_reap_usercontext(struct work_struct *work)
{
struct scsi_target *starget =
container_of(work, struct scsi_target, ew.work);
+#ifdef CONFIG_SCSI_ENHANCED_UA
+ struct list_head *this, *tmp;
+
+ cancel_work_sync(&starget->event_work);
+
+ list_for_each_safe(this, tmp, &starget->event_list) {
+ struct starget_event *evt;
+ evt = list_entry(this, struct starget_event, node);
+ list_del(&evt->node);
+ kfree(evt);
+ }
+#endif
transport_remove_device(&starget->dev);
device_del(&starget->dev);
scsi_target_destroy(starget);
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index dad0a37..240aa6d 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -230,6 +230,24 @@ enum scsi_target_state {
STARGET_DEL,
};
+#ifdef CONFIG_SCSI_ENHANCED_UA
+enum scsi_target_event {
+ STARGET_EVT_LUN_CHANGE_REPORTED = 1, /* UA reported */
+
+ STARGET_EVT_LAST = STARGET_EVT_LUN_CHANGE_REPORTED,
+ STARGET_EVT_MAXBITS = STARGET_EVT_LAST + 1
+};
+
+struct starget_event {
+ enum scsi_target_event evt_type;
+ struct list_head node;
+
+ /* put union of data structures, for non-simple event types,
+ * here
+ */
+};
+#endif
+
/*
* scsi_target: representation of a scsi target, for now, this is only
* used for single_lun devices. If no one has active IO to the target,
@@ -252,6 +270,13 @@ struct scsi_target {
* means no lun present. */
unsigned int no_report_luns:1; /* Don't use
* REPORT LUNS for scanning. */
+#ifdef CONFIG_SCSI_ENHANCED_UA
+ DECLARE_BITMAP(supported_events, STARGET_EVT_MAXBITS);
+ struct list_head event_list; /* asserted events */
+ struct work_struct event_work;
+ spinlock_t list_lock;
+#endif
+
/* commands actually active on LLD. protected by host lock. */
unsigned int target_busy;
/*
@@ -369,6 +394,15 @@ extern int scsi_device_quiesce(struct scsi_device *sdev);
extern void scsi_device_resume(struct scsi_device *sdev);
extern void scsi_target_quiesce(struct scsi_target *);
extern void scsi_target_resume(struct scsi_target *);
+#ifdef CONFIG_SCSI_ENHANCED_UA
+extern struct starget_event *starget_evt_alloc(enum scsi_target_event evt_type,
+ gfp_t gfpflags);
+extern void starget_evt_send(struct scsi_target *starget,
+ struct starget_event *evt);
+extern void starget_evt_send_simple(struct scsi_target *starget,
+ enum scsi_target_event evt_type,
+ gfp_t gfpflags);
+#endif
extern void scsi_scan_target(struct device *parent, unsigned int channel,
unsigned int id, unsigned int lun, int rescan);
extern void scsi_target_reap(struct scsi_target *);
--
1.7.11.7
next prev parent reply other threads:[~2013-02-01 17:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-01 17:53 [PATCH v2 0/8] [SCSI] Enhanced sense and Unit Attention handling Ewan D. Milne
2013-02-01 17:53 ` [PATCH v2 1/8] [SCSI] Generate uevent on sd capacity change Ewan D. Milne
2013-02-01 17:53 ` [PATCH v2 2/8] [SCSI] Add a kernel config option for enhanced Unit Attention support Ewan D. Milne
2013-02-01 17:53 ` [PATCH v2 3/8] [SCSI] Rename scsi_evt_xxx to sdev_evt_xxx and scsi_event to sdev_event Ewan D. Milne
2013-02-01 17:53 ` Ewan D. Milne [this message]
2013-02-01 17:53 ` [PATCH v2 5/8] [SCSI] Generate uevents for certain Unit Attention codes Ewan D. Milne
2013-02-01 17:53 ` [PATCH v2 6/8] [SCSI] Add sysfs support for enhanced Unit Attention handling Ewan D. Milne
2013-02-01 17:53 ` [PATCH v2 7/8] [SCSI] Add sense and Unit Attention generation to scsi_debug Ewan D. Milne
2013-02-01 17:53 ` [PATCH v2 8/8] [SCSI] Streamline detection of FM/EOM/ILI status Ewan D. Milne
2013-04-11 21:52 ` [PATCH v2 0/8] [SCSI] Enhanced sense and Unit Attention handling Jeremy Linton
2013-04-15 14:13 ` Ewan Milne
2013-04-15 16:20 ` Jeremy Linton
2013-04-15 16:51 ` 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=1359741195-2641-5-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;
as well as URLs for NNTP newsgroup(s).