From patchwork Fri Jun 5 15:01:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Mladek X-Patchwork-Id: 481369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7B6A21401DA for ; Sat, 6 Jun 2015 01:06:53 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0t8h-00024c-7r; Fri, 05 Jun 2015 15:02:31 +0000 Received: from cantor2.suse.de ([195.135.220.15] helo=mx2.suse.de) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0t8O-0001t2-Dm for linux-mtd@lists.infradead.org; Fri, 05 Jun 2015 15:02:13 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DAB05ADA7; Fri, 5 Jun 2015 15:01:51 +0000 (UTC) From: Petr Mladek To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Subject: [RFC PATCH 03/18] kthread: Add kthread_stop_current() Date: Fri, 5 Jun 2015 17:01:02 +0200 Message-Id: <1433516477-5153-4-git-send-email-pmladek@suse.cz> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1433516477-5153-1-git-send-email-pmladek@suse.cz> References: <1433516477-5153-1-git-send-email-pmladek@suse.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150605_080212_681673_340B87F4 X-CRM114-Status: GOOD ( 12.51 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [195.135.220.15 listed in list.dnswl.org] Cc: linux-nfs@vger.kernel.org, Borislav Petkov , Jiri Kosina , Richard Weinberger , Trond Myklebust , linux-kernel@vger.kernel.org, Steven Rostedt , Michal Hocko , Chris Mason , Petr Mladek , linux-mtd@lists.infradead.org, linux-api@vger.kernel.org, Linus Torvalds , live-patching@vger.kernel.org, Thomas Gleixner , "Paul E. McKenney" , David Woodhouse , Anna Schumaker X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org For example, jffs2_gcd_mtd kthread can be stopped by SIGKILL. The signal is handled inside the main function. We would like to convert such kthreads to the iterant API and use proper signal handlers. The new functions will allow to pass the information between the signal handler and the main kthread functions. kthread_stop_current() allows to quit the kthread correctly. It means to leave the main cycle on a safe point and call clean up actions via post() function. Signed-off-by: Petr Mladek --- include/linux/kthread.h | 1 + kernel/kthread.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 06fe9ad192dd..100c1e006729 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -86,6 +86,7 @@ kthread_iterant_create_on_cpu(struct kthread_iterant *kti, }) void kthread_bind(struct task_struct *k, unsigned int cpu); +void kthread_stop_current(void); int kthread_stop(struct task_struct *k); bool kthread_should_stop(void); bool kthread_should_park(void); diff --git a/kernel/kthread.c b/kernel/kthread.c index 4b2698bcc622..688bb4cfd807 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -70,6 +70,19 @@ static struct kthread *to_live_kthread(struct task_struct *k) } /** + * kthread_stop_current - make the current kthread to terminate a safe way + * + * This function sets KTHREAD_SHOULD_STOP flags. It makes kthread to break + * the main loop and do some clean up actions before the main kthread + * function finishes. It is the standard behavior for SIGTERM signal. + */ +void kthread_stop_current(void) +{ + set_bit(KTHREAD_SHOULD_STOP, &to_kthread(current)->flags); +} +EXPORT_SYMBOL(kthread_stop_current); + +/** * kthread_should_stop - should this kthread return now? * * When someone calls kthread_stop() on your kthread, it will be woken