lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 26 Mar 2012 19:33:04 -0700
From:	Boaz Harrosh <bharrosh@...asas.com>
To:	Andrew Morton <akpm@...ux-foundation.org>,
	Oleg Nesterov <oleg@...hat.com>,
	Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>,
	<linux-security-module@...r.kernel.org>,
	Ingo Molnar <mingo@...e.hu>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Paul Turner <pjt@...gle.com>,
	Thomas Gleixner <tglx@...utronix.de>
CC:	linux-fsdevel <linux-fsdevel@...r.kernel.org>,
	linux-kernel <linux-kernel@...r.kernel.org>,
	NFS list <linux-nfs@...r.kernel.org>,
	Trond Myklebust <Trond.Myklebust@...app.com>,
	"Bhamare, Sachin" <sbhamare@...asas.com>,
	David Howells <dhowells@...hat.com>,
	Eric Paris <eparis@...hat.com>,
	"Srivatsa S. Bhat" <srivatsa.bhat@...ux.vnet.ibm.com>,
	Kay Sievers <kay.sievers@...y.org>,
	James Morris <jmorris@...ei.org>,
	"Eric W. Biederman" <ebiederm@...ssion.com>,
	Greg KH <gregkh@...uxfoundation.org>,
	"Rafael J. Wysocki" <rjw@...k.pl>,
	"keyrings@...ux-nfs.org" <keyrings@...ux-nfs.org>
Subject: Re: [PATCH 4/6 OPTION-A version 3] completion: Add new wait_for_completion_timeout_state

Sorry had a checkpatch problem near the switch statement (missing space)

Boaz
---
From: Boaz Harrosh <bharrosh@...asas.com>
Subject: [PATCH] completion: Add new wait_for_completion_timeout_state

There are sometime places where an API hides a completion
inside it's implementation, and needs to expose the kind of
wait it does to it's upper users. Instead of such cases that
now need an ugly switch case to call the different
wait_for_completion_xxx function define a generic one
which can do all.

A new user will be added to this API in linux/kmod.h.

The return value from this member is a more Linux Kernel natural.
It will return:
	0  - If the wait was actually completed by a complete() signal.
	-ERESTARTSYS - If interrupted
	-ETIMEDOUT - If timeout expired

CC: Oleg Nesterov <oleg@...hat.com>
Signed-off-by: Boaz Harrosh <bharrosh@...asas.com>
---
 include/linux/completion.h |    2 +
 kernel/sched/core.c        |   56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/include/linux/completion.h b/include/linux/completion.h
index 51494e6..c41b836 100644
--- a/include/linux/completion.h
+++ b/include/linux/completion.h
@@ -85,6 +85,8 @@ extern long wait_for_completion_interruptible_timeout(
 	struct completion *x, unsigned long timeout);
 extern long wait_for_completion_killable_timeout(
 	struct completion *x, unsigned long timeout);
+extern int wait_for_completion_timeout_state(
+	struct completion *x, unsigned long timeout, int state);
 extern bool try_wait_for_completion(struct completion *x);
 extern bool completion_done(struct completion *x);
 
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 503d642..7aef53e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3664,6 +3664,62 @@ int __sched wait_for_completion_killable(struct completion *x)
 EXPORT_SYMBOL(wait_for_completion_killable_timeout);
 
 /**
+ * wait_for_completion_timeout_state: - waits for completion of a task all modes
+ * @x:  holds the state of this particular completion
+ * @timeout:  timeout value in jiffies
+ * @state: Can be either 0 or TASK_KILLABLE or TASK_INTERRUPTIBLE
+ *
+ * This waits for either a completion of a specific task to be
+ * signaled or for a specified timeout to expire.
+ * If @state == TASK_KILLABLE It can be interrupted by a kill signal only.
+ * If @state == TASK_INTERRUPTIBLE It can be interrupted by any signal.
+ *
+ * This is a Swiss-army-knife of all the above, for API's that needs to hide
+ * a completion, and needs to expose it's control to users.
+ *
+ * The return value is:
+ *	0 means completion was signaled with a complete call.
+ *	-ERESTARTSYS if interrupted
+ *	-ETIMEDOUT if timeout expired
+ *  Be careful the return value is Boolean opposite to the above _timeout
+ *  members.
+ */
+int __sched
+wait_for_completion_timeout_state(struct completion *x,
+				  unsigned long timeout, int state)
+{
+	long t;
+	int ret;
+
+	if (!timeout)
+		timeout = MAX_SCHEDULE_TIMEOUT;
+
+	switch (state) {
+	default:
+		WARN_ON_ONCE(1);
+		/* fall through */
+	case 0:
+		state = TASK_UNINTERRUPTIBLE;
+		break;
+	case TASK_KILLABLE:
+	case TASK_INTERRUPTIBLE:
+		break;
+	}
+
+	t = wait_for_common(x, timeout, state);
+	if (likely(t > 0)) {
+		ret = 0;
+	} else  {
+		if (t < 0)
+			ret = t;
+		else
+			ret = -ETIMEDOUT;
+	}
+	return ret;
+}
+EXPORT_SYMBOL(wait_for_completion_timeout_state);
+
+/**
  *	try_wait_for_completion - try to decrement a completion without blocking
  *	@x:	completion structure
  *
-- 
1.7.6.5


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ