From: Christof Schmitt <christof.schmitt@de.ibm.com>
To: James Bottomley <James.Bottomley@suse.de>
Cc: linux-scsi@vger.kernel.org, linux-s390@vger.kernel.org,
schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com,
Christof Schmitt <christof.schmitt@de.ibm.com>
Subject: [patch 20/27] zfcp: Use kthread API for zfcp erp thread
Date: Tue, 18 Aug 2009 15:43:25 +0200 [thread overview]
Message-ID: <20090818135031.423756000@de.ibm.com> (raw)
In-Reply-To: 20090818134305.841868000@de.ibm.com
[-- Attachment #1: 722-zfcp-kthread-api.diff --]
[-- Type: text/plain, Size: 7455 bytes --]
From: Christof Schmitt <christof.schmitt@de.ibm.com>
Switch the creation of the zfcp erp thread from the deprecated
kernel_thread API to the kthread API. This allows also the removal of
some flags in zfcp since the kthread API handles thread creation and
shutdown internally. To allow the usage of the kthread_stop function,
replace the erp ready semaphore with a waitqueue for waiting until erp
actions arrive on the ready queue.
Reviewed-by: Swen Schillig <swen@vnet.ibm.com>
Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com>
---
drivers/s390/scsi/zfcp_aux.c | 4 --
drivers/s390/scsi/zfcp_def.h | 6 +---
drivers/s390/scsi/zfcp_erp.c | 62 ++++++++++++++++---------------------------
3 files changed, 27 insertions(+), 45 deletions(-)
--- a/drivers/s390/scsi/zfcp_aux.c 2009-08-17 11:29:50.000000000 +0200
+++ b/drivers/s390/scsi/zfcp_aux.c 2009-08-17 11:29:53.000000000 +0200
@@ -529,7 +529,7 @@ int zfcp_adapter_enqueue(struct ccw_devi
goto generic_services_failed;
init_waitqueue_head(&adapter->remove_wq);
- init_waitqueue_head(&adapter->erp_thread_wqh);
+ init_waitqueue_head(&adapter->erp_ready_wq);
init_waitqueue_head(&adapter->erp_done_wqh);
INIT_LIST_HEAD(&adapter->port_list_head);
@@ -541,8 +541,6 @@ int zfcp_adapter_enqueue(struct ccw_devi
rwlock_init(&adapter->erp_lock);
rwlock_init(&adapter->abort_lock);
- sema_init(&adapter->erp_ready_sem, 0);
-
INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
INIT_WORK(&adapter->scan_work, _zfcp_fc_scan_ports_later);
--- a/drivers/s390/scsi/zfcp_def.h 2009-08-17 11:29:34.000000000 +0200
+++ b/drivers/s390/scsi/zfcp_def.h 2009-08-17 11:29:53.000000000 +0200
@@ -222,8 +222,6 @@ struct zfcp_ls_adisc {
#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
-#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
-#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
@@ -481,10 +479,9 @@ struct zfcp_adapter {
atomic_t status; /* status of this adapter */
struct list_head erp_ready_head; /* error recovery for this
adapter/devices */
+ wait_queue_head_t erp_ready_wq;
struct list_head erp_running_head;
rwlock_t erp_lock;
- struct semaphore erp_ready_sem;
- wait_queue_head_t erp_thread_wqh;
wait_queue_head_t erp_done_wqh;
struct zfcp_erp_action erp_action; /* pending error recovery */
atomic_t erp_counter;
@@ -492,6 +489,7 @@ struct zfcp_adapter {
actions */
u32 erp_low_mem_count; /* nr of erp actions waiting
for memory */
+ struct task_struct *erp_thread;
struct zfcp_wka_ports *gs; /* generic services */
struct zfcp_dbf *dbf; /* debug traces */
struct zfcp_adapter_mempool pool; /* Adapter memory pools */
--- a/drivers/s390/scsi/zfcp_erp.c 2009-08-17 11:29:38.000000000 +0200
+++ b/drivers/s390/scsi/zfcp_erp.c 2009-08-17 11:29:53.000000000 +0200
@@ -9,6 +9,7 @@
#define KMSG_COMPONENT "zfcp"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+#include <linux/kthread.h>
#include "zfcp_ext.h"
#define ZFCP_MAX_ERPS 3
@@ -75,7 +76,7 @@ static void zfcp_erp_action_ready(struct
list_move(&act->list, &act->adapter->erp_ready_head);
zfcp_dbf_rec_action("erardy1", act);
- up(&adapter->erp_ready_sem);
+ wake_up(&adapter->erp_ready_wq);
zfcp_dbf_rec_thread("erardy2", adapter->dbf);
}
@@ -212,8 +213,7 @@ static int zfcp_erp_action_enqueue(int w
int retval = 1, need;
struct zfcp_erp_action *act = NULL;
- if (!(atomic_read(&adapter->status) &
- ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
+ if (!adapter->erp_thread)
return -EIO;
need = zfcp_erp_required_act(want, adapter, port, unit);
@@ -226,7 +226,7 @@ static int zfcp_erp_action_enqueue(int w
goto out;
++adapter->erp_total_count;
list_add_tail(&act->list, &adapter->erp_ready_head);
- up(&adapter->erp_ready_sem);
+ wake_up(&adapter->erp_ready_wq);
zfcp_dbf_rec_thread("eracte1", adapter->dbf);
retval = 0;
out:
@@ -641,7 +641,8 @@ static int zfcp_erp_adapter_strat_fsf_xc
}
zfcp_dbf_rec_thread_lock("erasfx1", adapter->dbf);
- down(&adapter->erp_ready_sem);
+ wait_event(adapter->erp_ready_wq,
+ !list_empty(&adapter->erp_ready_head));
zfcp_dbf_rec_thread_lock("erasfx2", adapter->dbf);
if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
break;
@@ -682,7 +683,8 @@ static int zfcp_erp_adapter_strategy_ope
return ZFCP_ERP_FAILED;
zfcp_dbf_rec_thread_lock("erasox1", adapter->dbf);
- down(&adapter->erp_ready_sem);
+ wait_event(adapter->erp_ready_wq,
+ !list_empty(&adapter->erp_ready_head));
zfcp_dbf_rec_thread_lock("erasox2", adapter->dbf);
if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
return ZFCP_ERP_FAILED;
@@ -1285,21 +1287,17 @@ static int zfcp_erp_thread(void *data)
struct list_head *next;
struct zfcp_erp_action *act;
unsigned long flags;
- int ignore;
-
- daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
- /* Block all signals */
- siginitsetinv(¤t->blocked, 0);
- atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
- wake_up(&adapter->erp_thread_wqh);
-
- while (!(atomic_read(&adapter->status) &
- ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
+ for (;;) {
zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf);
- ignore = down_interruptible(&adapter->erp_ready_sem);
+ wait_event_interruptible(adapter->erp_ready_wq,
+ !list_empty(&adapter->erp_ready_head) ||
+ kthread_should_stop());
zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf);
+ if (kthread_should_stop())
+ break;
+
write_lock_irqsave(&adapter->erp_lock, flags);
next = adapter->erp_ready_head.next;
write_unlock_irqrestore(&adapter->erp_lock, flags);
@@ -1313,9 +1311,6 @@ static int zfcp_erp_thread(void *data)
}
}
- atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
- wake_up(&adapter->erp_thread_wqh);
-
return 0;
}
@@ -1327,18 +1322,17 @@ static int zfcp_erp_thread(void *data)
*/
int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
{
- int retval;
+ struct task_struct *thread;
- atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
- retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
- if (retval < 0) {
+ thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
+ dev_name(&adapter->ccw_device->dev));
+ if (IS_ERR(thread)) {
dev_err(&adapter->ccw_device->dev,
"Creating an ERP thread for the FCP device failed.\n");
- return retval;
+ return PTR_ERR(thread);
}
- wait_event(adapter->erp_thread_wqh,
- atomic_read(&adapter->status) &
- ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
+
+ adapter->erp_thread = thread;
return 0;
}
@@ -1353,16 +1347,8 @@ int zfcp_erp_thread_setup(struct zfcp_ad
*/
void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
{
- atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
- up(&adapter->erp_ready_sem);
- zfcp_dbf_rec_thread_lock("erthrk1", adapter->dbf);
-
- wait_event(adapter->erp_thread_wqh,
- !(atomic_read(&adapter->status) &
- ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
-
- atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
- &adapter->status);
+ kthread_stop(adapter->erp_thread);
+ adapter->erp_thread = NULL;
}
/**
next prev parent reply other threads:[~2009-08-18 13:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-18 13:43 [patch 00/27] zfcp updates for 2.6.32 Christof Schmitt
2009-08-18 13:43 ` [patch 01/27] zfcp: invalid usage after free of port resources Christof Schmitt
2009-08-18 13:43 ` [patch 02/27] zfcp: Move debug data from zfcp_data to own data structure Christof Schmitt
2009-08-18 13:43 ` [patch 03/27] zfcp: Only collect SCSI debug data for matching trace levels Christof Schmitt
2009-08-18 13:43 ` [patch 04/27] zfcp: Only collect FSF/HBA " Christof Schmitt
2009-08-18 13:43 ` [patch 05/27] zfcp: Remove useless assignment Christof Schmitt
2009-08-18 13:43 ` [patch 06/27] zfcp: Only issue one test link command per port Christof Schmitt
2009-08-18 13:43 ` [patch 07/27] zfcp: Implicitly close all wka ports Christof Schmitt
2009-08-18 13:43 ` [patch 08/27] zfcp: fix layering oddities between zfcp_fsf and zfcp_qdio Christof Schmitt
2009-08-18 13:43 ` [patch 09/27] zfcp: Replace fsf_req wait_queue with completion Christof Schmitt
2009-08-18 13:43 ` [patch 10/27] zfcp: Improve request allocation through mempools Christof Schmitt
2009-08-18 13:43 ` [patch 11/27] zfcp: Remove the useless ZFCP_REQ_AUTO_CLEANUP flag Christof Schmitt
2009-08-18 13:43 ` [patch 12/27] zfcp: Move workqueue to adapter struct Christof Schmitt
2009-08-18 13:43 ` [patch 13/27] zfcp: Separate qdio attributes from zfcp_fsf_req Christof Schmitt
2009-08-18 13:43 ` [patch 14/27] zfcp: Move qdio related data out of zfcp_adapter Christof Schmitt
2009-08-18 13:43 ` [patch 15/27] zfcp: Decouple gid_pn requests from erp Christof Schmitt
2009-08-18 13:43 ` [patch 16/27] zfcp: Update dbf calls Christof Schmitt
2009-08-18 13:43 ` [patch 17/27] zfcp: introduce _setup, _destroy for qdio and FC Christof Schmitt
2009-08-18 13:43 ` [patch 18/27] zfcp: Apply common naming conventions to zfcp_fc Christof Schmitt
2009-08-18 13:43 ` [patch 19/27] zfcp: resolve false usage of dd_data in fc_rport Christof Schmitt
2009-08-18 13:43 ` Christof Schmitt [this message]
2009-08-18 13:43 ` [patch 21/27] zfcp: Simplify and update ct/gs and els timeout handling Christof Schmitt
2009-08-18 13:43 ` [patch 22/27] zfcp: Defer resource allocation to first ccw_set_online call Christof Schmitt
2009-08-18 13:43 ` [patch 23/27] zfcp: Replace config semaphore with mutex Christof Schmitt
2009-08-18 13:43 ` [patch 24/27] zfcp: proper use of device register Christof Schmitt
2009-08-18 13:43 ` [patch 25/27] zfcp: Handle failures during device allocation correctly Christof Schmitt
2009-08-18 13:43 ` [patch 26/27] zfcp: Remove duplicated code for debug timestamps Christof Schmitt
2009-08-18 13:43 ` [patch 27/27] zfcp: optimize zfcp_qdio_account Christof Schmitt
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=20090818135031.423756000@de.ibm.com \
--to=christof.schmitt@de.ibm.com \
--cc=James.Bottomley@suse.de \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=schwidefsky@de.ibm.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.