summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@steeleye.com>2006-02-23 12:43:43 -0600
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-02-27 23:34:40 -0600
commit1fa44ecad2b86475e038aed81b0bf333fa484f8b (patch)
tree62e9e9aac0aaf64e6f8e69809d8ab513e22346a1
parentba3af0aff042caa1f41b5f7164cab37c717b8811 (diff)
downloadop-kernel-dev-1fa44ecad2b86475e038aed81b0bf333fa484f8b.zip
op-kernel-dev-1fa44ecad2b86475e038aed81b0bf333fa484f8b.tar.gz
[SCSI] add execute_in_process_context() API
We have several points in the SCSI stack (primarily for our device functions) where we need to guarantee process context, but (given the place where the last reference was released) we cannot guarantee this. This API gets around the issue by executing the function directly if the caller has process context, but scheduling a workqueue to execute in process context if the caller doesn't have it. Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
-rw-r--r--include/linux/workqueue.h6
-rw-r--r--kernel/workqueue.c29
2 files changed, 35 insertions, 0 deletions
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 86b1113..957c21c 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -20,6 +20,10 @@ struct work_struct {
struct timer_list timer;
};
+struct execute_work {
+ struct work_struct work;
+};
+
#define __WORK_INITIALIZER(n, f, d) { \
.entry = { &(n).entry, &(n).entry }, \
.func = (f), \
@@ -74,6 +78,8 @@ extern void init_workqueues(void);
void cancel_rearming_delayed_work(struct work_struct *work);
void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
struct work_struct *);
+int execute_in_process_context(void (*fn)(void *), void *,
+ struct execute_work *);
/*
* Kill off a pending schedule_delayed_work(). Note that the work callback
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index b052e2c..e9e464a 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -27,6 +27,7 @@
#include <linux/cpu.h>
#include <linux/notifier.h>
#include <linux/kthread.h>
+#include <linux/hardirq.h>
/*
* The per-CPU workqueue (if single thread, we always use the first
@@ -476,6 +477,34 @@ void cancel_rearming_delayed_work(struct work_struct *work)
}
EXPORT_SYMBOL(cancel_rearming_delayed_work);
+/**
+ * execute_in_process_context - reliably execute the routine with user context
+ * @fn: the function to execute
+ * @data: data to pass to the function
+ * @ew: guaranteed storage for the execute work structure (must
+ * be available when the work executes)
+ *
+ * Executes the function immediately if process context is available,
+ * otherwise schedules the function for delayed execution.
+ *
+ * Returns: 0 - function was executed
+ * 1 - function was scheduled for execution
+ */
+int execute_in_process_context(void (*fn)(void *data), void *data,
+ struct execute_work *ew)
+{
+ if (!in_interrupt()) {
+ fn(data);
+ return 0;
+ }
+
+ INIT_WORK(&ew->work, fn, data);
+ schedule_work(&ew->work);
+
+ return 1;
+}
+EXPORT_SYMBOL_GPL(execute_in_process_context);
+
int keventd_up(void)
{
return keventd_wq != NULL;
OpenPOWER on IntegriCloud