From patchwork Mon Jan 2 14:04:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 9493673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 565BC62AB2 for ; Mon, 2 Jan 2017 14:04:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4807A20008 for ; Mon, 2 Jan 2017 14:04:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C8932684F; Mon, 2 Jan 2017 14:04:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D719020008 for ; Mon, 2 Jan 2017 14:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755898AbdABOEW (ORCPT ); Mon, 2 Jan 2017 09:04:22 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36249 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755831AbdABOEV (ORCPT ); Mon, 2 Jan 2017 09:04:21 -0500 Received: by mail-pg0-f67.google.com with SMTP id n5so30556807pgh.3 for ; Mon, 02 Jan 2017 06:04:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=wzTOLPfzOE2wG6m4QJR7jSe5YraGS2QLoRUHNUtXtLc=; b=OfFI2/pEFkIZcvX14z8WVCkp7JhoK8BvtF2ig9c+4RaxKzpO9scelaZkMhm9woe8D/ BpLF0Uuwwln8Wc3nB+tJmBJxdzctNbEQ6YBAIp59hz5VdynbwwmdG1ItMUjVkhHH3qRH fJRc/1ziTIJnPTUXdVc2kDDfmki0Zky4cKR0/ocyRKX1Yym5/00kCRMH2XSo63VkQJ// pcHAkpvpMLa7Bz73xPm+vHSK1yRR9OdPt7wfvjHUaTW8ivVHht8dOmRtB+iWDoi0QYo/ elcB4Pa1G6ZZbYMD1ZGqpwq57HtoNX1/l9+G+bziOSXcsa5NWIG3bgdHW2SndOus1B0L 19fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=wzTOLPfzOE2wG6m4QJR7jSe5YraGS2QLoRUHNUtXtLc=; b=Zlc0/7BUXBxmlMBJpjorm1mevEjV4iKK5oL6ckGU5NBvCSMYu6bpeAY6I7c4Xda21X GAgCDc3xtefJfrsdljXRo/6CbHsmzzHQCFBY+JWmeYo4+cCfald6PxAQiZMUpxHDWR4a 9ywMGO9VJrhPn1i5j8DsOe2Ag3ancJkYInzWQTvm6Wgn+c57aPZOEMnNiklUfJpgUvO5 adUe1rHS+zM5pmNZivj6Vykx9lPfpSofOxDwQQskh7QDaeFIi0DDy0huCunLLkyMzJ+T sf3tKEoRzq5unnbjgbFHYnOLy47ms4nv2k1xqKda8LjSE8F+IlIAn+sP4TjVjvWUNLIt uS0A== X-Gm-Message-State: AIkVDXJHBgk123RmK4MU0XlHvlR0UbpwOX8KM9KrO/h6As2/dvLsEfeYJN8K0oVVgmBKcw== X-Received: by 10.84.204.8 with SMTP id a8mr128195020ple.172.1483365860596; Mon, 02 Jan 2017 06:04:20 -0800 (PST) Received: from [192.168.0.104] ([183.228.33.105]) by smtp.googlemail.com with ESMTPSA id p5sm120018408pgk.23.2017.01.02.06.04.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jan 2017 06:04:19 -0800 (PST) To: Trond Myklebust , linux-nfs@vger.kernel.org Cc: Anna Schumaker , kinglongmee@gmail.com From: Kinglong Mee Subject: [PATCH] NFSv4.x/callback: make sure callback thread is interruptible Message-ID: <2026e1dc-4a96-2359-dc62-f391a2d795a8@gmail.com> Date: Mon, 2 Jan 2017 22:04:11 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit bb6aeba736ba "NFSv4.x: Switch to using svc_set_num_threads() to manage the callback threads" change nfs start/stop threads through svc_set_num_threads(). It destroy old threads by SIGINT signal, but our nfs4_callback_svc() isn't interruptible. So that, the callback threads will never be killed. # mount -t nfs -overs=4.2 nfstestnic:/ /mnt/ # ps -ajx |grep NFS 2 5927 0 0 ? -1 S 0 0:00 [NFSv4 callback] # umount /mnt # ps -ajx |grep NFS 2 5927 0 0 ? -1 S 0 0:00 [NFSv4 callback] # mount -t nfs -overs=4.2 nfstestnic:/ /mnt/ # umount /mnt # ps -ajx |grep NFS 2 5927 0 0 ? -1 S 0 0:00 [NFSv4 callback] 2 5963 0 0 ? -1 S 0 0:00 [NFSv4 callback] After one mount, there will be one callback thread left that cannot killed, the same time, nfs.ko will never be unplugged. Signed-off-by: Kinglong Mee --- fs/nfs/callback.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c index 484bebc..0738470 100644 --- a/fs/nfs/callback.c +++ b/fs/nfs/callback.c @@ -73,6 +73,15 @@ nfs4_callback_svc(void *vrqstp) int err; struct svc_rqst *rqstp = vrqstp; + /* + * thread is spawned with all signals set to SIG_IGN, re-enable + * the ones that will bring down the thread + */ + allow_signal(SIGKILL); + allow_signal(SIGHUP); + allow_signal(SIGINT); + allow_signal(SIGQUIT); + set_freezable(); while (!kthread_should_stop()) { @@ -80,11 +89,19 @@ nfs4_callback_svc(void *vrqstp) * Listen for a request on the socket */ err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT); - if (err == -EAGAIN || err == -EINTR) + if (err == -EAGAIN) continue; + else if (err == -EINTR) + break; svc_process(rqstp); } - return 0; + + flush_signals(current); + rqstp->rq_server = NULL; + + /* Release the thread */ + svc_exit_thread(rqstp); + module_put_and_exit(0); } #if defined(CONFIG_NFS_V4_1) @@ -100,6 +117,15 @@ nfs41_callback_svc(void *vrqstp) int error; DEFINE_WAIT(wq); + /* + * thread is spawned with all signals set to SIG_IGN, re-enable + * the ones that will bring down the thread + */ + allow_signal(SIGKILL); + allow_signal(SIGHUP); + allow_signal(SIGINT); + allow_signal(SIGQUIT); + set_freezable(); while (!kthread_should_stop()) { @@ -121,11 +147,18 @@ nfs41_callback_svc(void *vrqstp) } else { spin_unlock_bh(&serv->sv_cb_lock); schedule(); + if (signalled()) + break; finish_wait(&serv->sv_cb_waitq, &wq); } - flush_signals(current); } - return 0; + + flush_signals(current); + rqstp->rq_server = NULL; + + /* Release the thread */ + svc_exit_thread(rqstp); + module_put_and_exit(0); } static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt,