diff options
author | Oleg Nesterov <oleg@redhat.com> | 2012-03-23 18:02:47 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-23 19:58:41 -0400 |
commit | d0bd587a80960d7ba7e0c8396e154028c9045c54 (patch) | |
tree | 3765f8eccdc5f982ba173a7a05d8981d573b9486 /kernel | |
parent | b3449922502f5a161ee2b5022a33aec8472fbf18 (diff) |
usermodehelper: implement UMH_KILLABLE
Implement UMH_KILLABLE, should be used along with UMH_WAIT_EXEC/PROC.
The caller must ensure that subprocess_info->path/etc can not go away
until call_usermodehelper_freeinfo().
call_usermodehelper_exec(UMH_KILLABLE) does
wait_for_completion_killable. If it fails, it uses
xchg(&sub_info->complete, NULL) to serialize with umh_complete() which
does the same xhcg() to access sub_info->complete.
If call_usermodehelper_exec wins, it can safely return. umh_complete()
should get NULL and call call_usermodehelper_freeinfo().
Otherwise we know that umh_complete() was already called, in this case
call_usermodehelper_exec() falls back to wait_for_completion() which
should succeed "very soon".
Note: UMH_NO_WAIT == -1 but it obviously should not be used with
UMH_KILLABLE. We delay the neccessary cleanup to simplify the back
porting.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Tejun Heo <tj@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/kmod.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/kernel/kmod.c b/kernel/kmod.c index 8ea25944ce33..f92f917c450c 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c | |||
@@ -201,7 +201,15 @@ EXPORT_SYMBOL(call_usermodehelper_freeinfo); | |||
201 | 201 | ||
202 | static void umh_complete(struct subprocess_info *sub_info) | 202 | static void umh_complete(struct subprocess_info *sub_info) |
203 | { | 203 | { |
204 | complete(sub_info->complete); | 204 | struct completion *comp = xchg(&sub_info->complete, NULL); |
205 | /* | ||
206 | * See call_usermodehelper_exec(). If xchg() returns NULL | ||
207 | * we own sub_info, the UMH_KILLABLE caller has gone away. | ||
208 | */ | ||
209 | if (comp) | ||
210 | complete(comp); | ||
211 | else | ||
212 | call_usermodehelper_freeinfo(sub_info); | ||
205 | } | 213 | } |
206 | 214 | ||
207 | /* Keventd can't block, but this (a child) can. */ | 215 | /* Keventd can't block, but this (a child) can. */ |
@@ -252,6 +260,9 @@ static void __call_usermodehelper(struct work_struct *work) | |||
252 | enum umh_wait wait = sub_info->wait; | 260 | enum umh_wait wait = sub_info->wait; |
253 | pid_t pid; | 261 | pid_t pid; |
254 | 262 | ||
263 | if (wait != UMH_NO_WAIT) | ||
264 | wait &= ~UMH_KILLABLE; | ||
265 | |||
255 | /* CLONE_VFORK: wait until the usermode helper has execve'd | 266 | /* CLONE_VFORK: wait until the usermode helper has execve'd |
256 | * successfully We need the data structures to stay around | 267 | * successfully We need the data structures to stay around |
257 | * until that is done. */ | 268 | * until that is done. */ |
@@ -461,9 +472,21 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, | |||
461 | queue_work(khelper_wq, &sub_info->work); | 472 | queue_work(khelper_wq, &sub_info->work); |
462 | if (wait == UMH_NO_WAIT) /* task has freed sub_info */ | 473 | if (wait == UMH_NO_WAIT) /* task has freed sub_info */ |
463 | goto unlock; | 474 | goto unlock; |
475 | |||
476 | if (wait & UMH_KILLABLE) { | ||
477 | retval = wait_for_completion_killable(&done); | ||
478 | if (!retval) | ||
479 | goto wait_done; | ||
480 | |||
481 | /* umh_complete() will see NULL and free sub_info */ | ||
482 | if (xchg(&sub_info->complete, NULL)) | ||
483 | goto unlock; | ||
484 | /* fallthrough, umh_complete() was already called */ | ||
485 | } | ||
486 | |||
464 | wait_for_completion(&done); | 487 | wait_for_completion(&done); |
488 | wait_done: | ||
465 | retval = sub_info->retval; | 489 | retval = sub_info->retval; |
466 | |||
467 | out: | 490 | out: |
468 | call_usermodehelper_freeinfo(sub_info); | 491 | call_usermodehelper_freeinfo(sub_info); |
469 | unlock: | 492 | unlock: |