Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scst_targ: Check prepare_to_wait_exclusive_head() return value #177

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions scst/src/dev_handlers/scst_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
#endif
#include "scst_dev_handler.h"

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
#include <linux/sched/signal.h>
#endif

#ifndef INSIDE_KERNEL_TREE
#if defined(CONFIG_HIGHMEM4G) || defined(CONFIG_HIGHMEM64G)
#warning HIGHMEM kernel configurations are not supported by this module, \
Expand Down Expand Up @@ -2219,8 +2215,7 @@ static inline int test_cmd_threads(struct scst_user_dev *dev, bool can_block)
{
int res = !list_empty(&dev->udev_cmd_threads.active_cmd_list) ||
!list_empty(&dev->ready_cmd_list) ||
!can_block || !dev->blocking || dev->cleanup_done ||
signal_pending(current);
!can_block || !dev->blocking || dev->cleanup_done;
return res;
}

Expand All @@ -2233,9 +2228,11 @@ static int dev_user_get_next_cmd(struct scst_user_dev *dev,
TRACE_ENTRY();

while (1) {
scst_wait_event_interruptible_lock_irq(dev->udev_cmd_threads.cmd_list_waitQ,
test_cmd_threads(dev, can_block),
dev->udev_cmd_threads.cmd_list_lock);
res = scst_wait_event_interruptible_lock_irq(dev->udev_cmd_threads.cmd_list_waitQ,
test_cmd_threads(dev, can_block),
dev->udev_cmd_threads.cmd_list_lock);
if (res)
break;

dev_user_process_scst_commands(dev);

Expand All @@ -2248,12 +2245,6 @@ static int dev_user_get_next_cmd(struct scst_user_dev *dev,
TRACE_DBG("No ready commands, returning %d", res);
break;
}

if (signal_pending(current)) {
res = -EINTR;
TRACE_DBG("Signal pending, returning %d", res);
break;
}
}

TRACE_EXIT_RES(res);
Expand Down
51 changes: 34 additions & 17 deletions scst/src/scst_targ.c
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,39 @@ static inline int test_cmd_threads(struct scst_cmd_thread_t *thr)
return res;
}

static inline int
scst_wait_for_cmd(struct scst_cmd_threads *p_cmd_threads, struct scst_cmd_thread_t *thr)
{
DEFINE_WAIT(wq_entry);
int ret = 0;

if (test_cmd_threads(thr))
return 0;

for (;;) {
long __int = prepare_to_wait_exclusive_head(&p_cmd_threads->cmd_list_waitQ,
&wq_entry, TASK_INTERRUPTIBLE);

if (test_cmd_threads(thr))
break;

if (__int) {
ret = __int;
goto out;
}

spin_unlock(&thr->thr_cmd_list_lock);
spin_unlock_irq(&p_cmd_threads->cmd_list_lock);
schedule();
spin_lock_irq(&p_cmd_threads->cmd_list_lock);
spin_lock(&thr->thr_cmd_list_lock);
}
finish_wait(&p_cmd_threads->cmd_list_waitQ, &wq_entry);

out:
return ret;
}

int scst_cmd_thread(void *arg)
{
struct scst_cmd_thread_t *thr = arg;
Expand All @@ -4822,23 +4855,7 @@ int scst_cmd_thread(void *arg)
spin_lock_irq(&p_cmd_threads->cmd_list_lock);
spin_lock(&thr->thr_cmd_list_lock);
while (!kthread_should_stop()) {
if (!test_cmd_threads(thr)) {
DEFINE_WAIT(wait);

do {
prepare_to_wait_exclusive_head(
&p_cmd_threads->cmd_list_waitQ,
&wait, TASK_INTERRUPTIBLE);
if (test_cmd_threads(thr))
break;
spin_unlock(&thr->thr_cmd_list_lock);
spin_unlock_irq(&p_cmd_threads->cmd_list_lock);
schedule();
spin_lock_irq(&p_cmd_threads->cmd_list_lock);
spin_lock(&thr->thr_cmd_list_lock);
} while (!test_cmd_threads(thr));
finish_wait(&p_cmd_threads->cmd_list_waitQ, &wait);
}
scst_wait_for_cmd(p_cmd_threads, thr);

if (tm_dbg_is_release()) {
spin_unlock_irq(&p_cmd_threads->cmd_list_lock);
Expand Down