Commit cc4f5ba1 authored by Javier González's avatar Javier González Committed by Jens Axboe

lightnvm: pblk: ensure kthread alloc. before kicking it

When creating the write thread, ensure that the kthread has been created
before initializing the timer responsible from kicking it. Otherwise, if
the kthread creation fails or gets killed from used space, we risk
kicking an empty thread structure.

Also, since the kthread creation can be interrupted form user space,
adapt the error path to not report an error when this happens, since it
is intentional that the instance creation is aborted.
Signed-off-by: default avatarJavier González <javier@cnexlabs.com>
Updated source to reflect the new timer_setup API.
Signed-off-by: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8f554597
...@@ -883,15 +883,19 @@ static int pblk_lines_init(struct pblk *pblk) ...@@ -883,15 +883,19 @@ static int pblk_lines_init(struct pblk *pblk)
static int pblk_writer_init(struct pblk *pblk) static int pblk_writer_init(struct pblk *pblk)
{ {
timer_setup(&pblk->wtimer, pblk_write_timer_fn, 0);
mod_timer(&pblk->wtimer, jiffies + msecs_to_jiffies(100));
pblk->writer_ts = kthread_create(pblk_write_ts, pblk, "pblk-writer-t"); pblk->writer_ts = kthread_create(pblk_write_ts, pblk, "pblk-writer-t");
if (IS_ERR(pblk->writer_ts)) { if (IS_ERR(pblk->writer_ts)) {
pr_err("pblk: could not allocate writer kthread\n"); int err = PTR_ERR(pblk->writer_ts);
return PTR_ERR(pblk->writer_ts);
if (err != -EINTR)
pr_err("pblk: could not allocate writer kthread (%d)\n",
err);
return err;
} }
timer_setup(&pblk->wtimer, pblk_write_timer_fn, 0);
mod_timer(&pblk->wtimer, jiffies + msecs_to_jiffies(100));
return 0; return 0;
} }
...@@ -1042,7 +1046,8 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk, ...@@ -1042,7 +1046,8 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk,
ret = pblk_writer_init(pblk); ret = pblk_writer_init(pblk);
if (ret) { if (ret) {
pr_err("pblk: could not initialize write thread\n"); if (ret != -EINTR)
pr_err("pblk: could not initialize write thread\n");
goto fail_free_lines; goto fail_free_lines;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment