Commit 3d48749d authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

block: ioc_task_link() can't fail

ioc_task_link() is used to share %current's ioc on clone.  If
%current->io_context is set, %current is guaranteed to have refcount
on the ioc and, thus, ioc_task_link() can't fail.

Replace error checking in ioc_task_link() with WARN_ON_ONCE() and make
it just increment refcount and nr_tasks.

-v2: Description typo fix (Vivek).
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 24acfc34
...@@ -120,18 +120,12 @@ struct io_context { ...@@ -120,18 +120,12 @@ struct io_context {
struct work_struct release_work; struct work_struct release_work;
}; };
static inline struct io_context *ioc_task_link(struct io_context *ioc) static inline void ioc_task_link(struct io_context *ioc)
{ {
/* WARN_ON_ONCE(atomic_long_read(&ioc->refcount) <= 0);
* if ref count is zero, don't allow sharing (ioc is going away, it's WARN_ON_ONCE(atomic_read(&ioc->nr_tasks) <= 0);
* a race). atomic_long_inc(&ioc->refcount);
*/
if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
atomic_inc(&ioc->nr_tasks); atomic_inc(&ioc->nr_tasks);
return ioc;
}
return NULL;
} }
struct task_struct; struct task_struct;
......
...@@ -901,9 +901,8 @@ static int copy_io(unsigned long clone_flags, struct task_struct *tsk) ...@@ -901,9 +901,8 @@ static int copy_io(unsigned long clone_flags, struct task_struct *tsk)
* Share io context with parent, if CLONE_IO is set * Share io context with parent, if CLONE_IO is set
*/ */
if (clone_flags & CLONE_IO) { if (clone_flags & CLONE_IO) {
tsk->io_context = ioc_task_link(ioc); ioc_task_link(ioc);
if (unlikely(!tsk->io_context)) tsk->io_context = ioc;
return -ENOMEM;
} else if (ioprio_valid(ioc->ioprio)) { } else if (ioprio_valid(ioc->ioprio)) {
new_ioc = get_task_io_context(tsk, GFP_KERNEL, NUMA_NO_NODE); new_ioc = get_task_io_context(tsk, GFP_KERNEL, NUMA_NO_NODE);
if (unlikely(!new_ioc)) if (unlikely(!new_ioc))
......
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