From: Boaz Harrosh <bharrosh@panasas.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
<linux-security-module@vger.kernel.org>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Turner <pjt@google.com>,
Thomas Gleixner <tglx@linutronix.de>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
NFS list <linux-nfs@vger.kernel.org>,
Trond Myklebust <Trond.Myklebust@netapp.com>,
"Bhamare, Sachin" <sbhamare@panasas.com>,
David Howells <dhowells@redhat.com>,
Eric Paris <eparis@redhat.com>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
Kay Sievers <kay.sievers@vrfy.org>,
James Morris <jmorris@namei.org>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Greg KH <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rjw@sisk.pl>,
"keyrings@linux-nfs.org" <keyrings@linux-nfs.org>
Subject: [PATCH 6/6] kmod: optional: Convert the use of xchg to a kref
Date: Mon, 26 Mar 2012 19:15:28 -0700 [thread overview]
Message-ID: <4F7122C0.2070800@panasas.com> (raw)
In-Reply-To: <4F711EA2.4030608@panasas.com>
if we use a kref instead of xchg to govern the lifetime
of struct subprocess_info, the code becomes simpler and
more generic. We can avoid some of the special cases.
Actually I like the xchg use here. But if it will break
some ARCHs that do not like xchg, then here is the work
needed.
No functional change
CC: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
include/linux/kmod.h | 4 +++-
kernel/kmod.c | 43 +++++++++++++++++--------------------------
2 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/include/linux/kmod.h b/include/linux/kmod.h
index 4d9f202..bd0c3c9 100644
--- a/include/linux/kmod.h
+++ b/include/linux/kmod.h
@@ -25,6 +25,7 @@
#include <linux/compiler.h>
#include <linux/workqueue.h>
#include <linux/sysctl.h>
+#include <linux/kref.h>
#define KMOD_PATH_LEN 256
@@ -54,8 +55,9 @@ extern __printf(2, 3)
#define UMH_KILLABLE 4 /* wait for EXEC/PROC killable */
struct subprocess_info {
+ struct kref kref;
struct work_struct work;
- struct completion *complete;
+ struct completion complete;
char *path;
char **argv;
char **envp;
diff --git a/kernel/kmod.c b/kernel/kmod.c
index 588cb6f..948a674 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -221,9 +221,11 @@ static int ____call_usermodehelper(void *data)
return 0;
}
-static
-void call_usermodehelper_freeinfo(struct subprocess_info *info)
+static void call_usermodehelper_freeinfo(struct kref *kref)
{
+ struct subprocess_info *info =
+ container_of(kref, struct subprocess_info, kref);
+
if (info->cleanup)
(*info->cleanup)(info);
kfree(info);
@@ -231,15 +233,8 @@ void call_usermodehelper_freeinfo(struct subprocess_info *info)
static void umh_complete(struct subprocess_info *sub_info)
{
- struct completion *comp = xchg(&sub_info->complete, NULL);
- /*
- * See call_usermodehelper_exec(). If xchg() returns NULL
- * we own sub_info, the UMH_KILLABLE caller has gone away.
- */
- if (comp)
- complete(comp);
- else
- call_usermodehelper_freeinfo(sub_info);
+ complete(&sub_info->complete);
+ kref_put(&sub_info->kref, call_usermodehelper_freeinfo);
}
/* Keventd can't block, but this (a child) can. */
@@ -302,7 +297,7 @@ static void __call_usermodehelper(struct work_struct *work)
switch (wait) {
case UMH_NO_WAIT:
- call_usermodehelper_freeinfo(sub_info);
+ kref_put(&sub_info->kref, call_usermodehelper_freeinfo);
break;
case UMH_WAIT_PROC:
@@ -431,6 +426,8 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
if (!sub_info)
goto out;
+ kref_init(&sub_info->kref);
+ init_completion(&sub_info->complete);
INIT_WORK(&sub_info->work, __call_usermodehelper);
sub_info->path = path;
sub_info->argv = argv;
@@ -521,7 +518,6 @@ void call_usermodehelper_setfns(struct subprocess_info *info,
static
int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
{
- DECLARE_COMPLETION_ONSTACK(done);
int wait_state;
int retval = 0;
@@ -534,26 +530,21 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
goto out;
}
- sub_info->complete = &done;
sub_info->wait = wait;
+ /* Balanced in __call_usermodehelper or wait_for_helper */
+ kref_get(&sub_info->kref);
queue_work(khelper_wq, &sub_info->work);
if (wait == UMH_NO_WAIT) /* task has freed sub_info */
- goto unlock;
+ goto out;
wait_state = (wait & UMH_KILLABLE) ? TASK_KILLABLE : 0;
- retval = wait_for_completion_timeout_state(&done, sub_info->timeout,
- wait_state);
- if (unlikely(retval)) {
- /* umh_complete() will see NULL and free sub_info */
- if (xchg(&sub_info->complete, NULL))
- goto unlock;
- }
-
- retval = sub_info->retval;
+ retval = wait_for_completion_timeout_state(&sub_info->complete,
+ sub_info->timeout, wait_state);
+ if (likely(!retval))
+ retval = sub_info->retval;
out:
- call_usermodehelper_freeinfo(sub_info);
-unlock:
+ kref_put(&sub_info->kref, call_usermodehelper_freeinfo);
helper_unlock();
return retval;
}
--
1.7.6.5
next prev parent reply other threads:[~2012-03-27 2:15 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-20 23:18 [PATCHSET 0/4] kmod: Optional timeout on the wait in call_usermodehelper_exec Boaz Harrosh
[not found] ` <4F691059.30405-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-20 23:23 ` [PATCH 1/4] kmod: Un-export call_usermodehelper_freeinfo() Boaz Harrosh
2012-03-20 23:26 ` [PATCH 2/4] kmod: Convert two call sites to call_usermodehelper_fns() Boaz Harrosh
[not found] ` <4F691217.5070108-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-22 3:00 ` James Morris
2012-03-20 23:28 ` [PATCH 3/4] kmod: Move call_usermodehelper_fns() to .c file and unexport it's helpers Boaz Harrosh
2012-03-20 23:32 ` [RFC 4/4] {RFC} kmod.c: Add new call_usermodehelper_timeout() API Boaz Harrosh
2012-03-22 2:44 ` Boaz Harrosh
2012-03-22 2:48 ` Boaz Harrosh
2012-03-22 2:52 ` Boaz Harrosh
2012-03-22 11:48 ` [RFC 4/4] {RFC} kmod.c: Add new call_usermodehelper_timeout()API Tetsuo Handa
[not found] ` <4F6A92FC.6060702-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-22 14:27 ` [RFC 4/4] {RFC} kmod.c: Add new call_usermodehelper_timeout() API Oleg Nesterov
[not found] ` <20120322142758.GA12370-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-03-22 14:42 ` Oleg Nesterov
2012-03-22 19:08 ` Boaz Harrosh
2012-03-22 22:16 ` [RFC 4/4] {RFC} kmod.c: Add new call_usermodehelper_timeout()API Tetsuo Handa
2012-03-23 4:48 ` Boaz Harrosh
[not found] ` <4F6C0092.1010901-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-23 5:23 ` Tetsuo Handa
2012-03-23 16:30 ` Oleg Nesterov
[not found] ` <4F6B789C.8020201-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-23 13:34 ` [RFC 4/4] {RFC} kmod.c: Add new call_usermodehelper_timeout() API Oleg Nesterov
2012-03-21 15:35 ` [PATCHSET 0/4] kmod: Optional timeout on the wait in call_usermodehelper_exec Greg KH
2012-03-22 0:18 ` Boaz Harrosh
2012-03-22 0:31 ` Myklebust, Trond
2012-03-22 1:18 ` Boaz Harrosh
2012-03-27 1:57 ` [PATCHSET 0/6 version 2] " Boaz Harrosh
2012-03-27 2:02 ` [PATCH 2/6] kmod: Convert two call sites to call_usermodehelper_fns() Boaz Harrosh
2012-03-27 2:04 ` [PATCH 3/6] kmod: Move call_usermodehelper_fns() to .c file and unexport all it's helpers Boaz Harrosh
[not found] ` <4F711EA2.4030608-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-27 2:00 ` [PATCH 1/6] kmod: Unexport call_usermodehelper_freeinfo() Boaz Harrosh
2012-03-27 2:06 ` [PATCH 4/6 OPTION-A] completion: Add new wait_for_completion_timeout_state Boaz Harrosh
2012-03-27 2:33 ` [PATCH 4/6 OPTION-A version 3] " Boaz Harrosh
[not found] ` <4F7126E0.5080700-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-27 8:11 ` Peter Zijlstra
2012-03-28 18:19 ` Boaz Harrosh
[not found] ` <4F735642.9030905-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-28 18:25 ` Peter Zijlstra
2012-03-28 17:38 ` Oleg Nesterov
2012-03-27 21:07 ` [PATCHSET 0/6 version 2] kmod: Optional timeout on the wait in call_usermodehelper_exec Andrew Morton
2012-03-28 20:19 ` Oleg Nesterov
2012-03-28 21:42 ` Boaz Harrosh
2012-03-27 2:09 ` [PATCH 4/6 option-B] kmod: add new wait_for_completion_timeout_state() helper Boaz Harrosh
2012-03-27 2:13 ` [PATCH 5/6] kmod: Add new call_usermodehelper_timeout() API Boaz Harrosh
[not found] ` <4F712246.6030201-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2012-03-27 15:43 ` Oleg Nesterov
2012-03-28 17:04 ` Oleg Nesterov
2012-03-27 2:15 ` Boaz Harrosh [this message]
2012-03-28 16:35 ` [PATCH 6/6] kmod: optional: Convert the use of xchg to a kref Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F7122C0.2070800@panasas.com \
--to=bharrosh@panasas.com \
--cc=Trond.Myklebust@netapp.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=ebiederm@xmission.com \
--cc=eparis@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=jmorris@namei.org \
--cc=kay.sievers@vrfy.org \
--cc=keyrings@linux-nfs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=pjt@google.com \
--cc=rjw@sisk.pl \
--cc=sbhamare@panasas.com \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).