From 5f598500960dab2bdc9ef34bc81ec2602249367d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 1 May 2016 22:41:20 +0000 Subject: [PATCH 1/2] scst_sysfs, LUN replacement: Initialize 'read_only' before using it See also r6834. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6882 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 43b769591..4bd8e302f 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -1436,14 +1436,14 @@ static int __scst_process_luns_mgmt_store(char *buffer, } case SCST_LUN_ACTION_REPLACE: { - unsigned int flags = (read_only ? SCST_ADD_LUN_READ_ONLY : 0) | - (replace_gen_ua ? SCST_REPL_LUN_GEN_UA : 0); + unsigned int flags = replace_gen_ua ? SCST_REPL_LUN_GEN_UA : 0; res = scst_parse_add_repl_param(acg, dev, pp, &virt_lun, &read_only); if (res != 0) goto out_unlock; + flags |= read_only ? SCST_ADD_LUN_READ_ONLY : 0; res = scst_acg_repl_lun(acg, tgt_kobj ? tgt->tgt_luns_kobj : acg->luns_kobj, dev, virt_lun, flags); From 33627cc8d8db0ee651b3b7320af46a5e34424282 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Wed, 4 May 2016 02:43:06 +0000 Subject: [PATCH 2/2] When trying to remove a megaraid_sas device, the scst will hang inside scst_free_device: [ 380.448608] [4]: scst: Detached from scsi0, channel 2, id 1, lun 0, type 0 [ 601.138688] INFO: task kworker/0:0:4 blocked for more than 120 seconds. [ 601.138756] Tainted: P OE 3.19.0-58-quantastor #64~14.04.1 [ 601.138810] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 601.138869] kworker/0:0 D ffff88085c6fba58 0 4 2 0x00000000 [ 601.138926] Workqueue: events megasas_aen_polling [megaraid_sas] [ 601.138930] ffff88085c6fba58 ffff88085c6f09d0 0000000000013e80 ffff88085c6fbfd8 [ 601.138934] 0000000000013e80 ffffffff81c1d4e0 ffff88085c6f09d0 ffff88085c6fba38 [ 601.138938] ffff88085c6fbbd8 7fffffffffffffff ffff88085c6fbbd0 ffff88085c6f09d0 [ 601.138942] Call Trace: [ 601.138955] [] schedule+0x29/0x70 [ 601.138960] [] schedule_timeout+0x244/0x2c0 [ 601.138968] [] ? irq_work_queue+0x6b/0x90 [ 601.138975] [] ? wake_up_klogd+0x32/0x40 [ 601.138979] [] ? console_unlock+0x208/0x480 [ 601.138983] [] wait_for_completion+0xa4/0x170 [ 601.138989] [] ? wake_up_state+0x20/0x20 [ 601.138995] [] flush_workqueue+0x10c/0x5b0 [ 601.139002] [] flush_scheduled_work+0x15/0x20 [ 601.139044] [] scst_free_device+0x16/0x50 [scst] [ 601.139051] [] scst_remove+0x2df/0x3a0 [scst] [ 601.139056] [] ? enclosure_find+0x93/0xa0 [enclosure] [ 601.139061] [] device_del+0xe1/0x270 [ 601.139062] [] device_unregister+0x22/0x70 [ 601.139066] [] __scsi_remove_device+0xbb/0xd0 [ 601.139068] [] scsi_remove_device+0x26/0x40 [ 601.139074] [] megasas_aen_polling+0x362/0x610 [megaraid_sas] [ 601.139076] [] process_one_work+0x14f/0x440 [ 601.139077] [] worker_thread+0x118/0x510 [ 601.139079] [] ? rescuer_thread+0x3d0/0x3d0 [ 601.139082] [] kthread+0xc9/0xe0 [ 601.139084] [] ? kthread_create_on_node+0x1c0/0x1c0 [ 601.139087] [] ret_from_fork+0x58/0x90 [ 601.139089] [] ? kthread_create_on_node+0x1c0/0x1c0 The problem is that scst_free_device will call flush_scheduled_work to wait for ext_blockers_work, but scst_free_device itself is called from schedule_work, thus creating deadlock. Instead of using heavy-handed flush_scheduled_work, we use flush_work to wait for ext_blockers_work to finish. Signed-off-by: Chunwei Chen git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6883 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index f40661b6a..67ae0de29 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4206,7 +4206,7 @@ void scst_free_device(struct scst_device *dev) #endif /* Ensure that ext_blockers_work is done */ - flush_scheduled_work(); + flush_work(&dev->ext_blockers_work); scst_deinit_threads(&dev->dev_cmd_threads);