Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp240847pxj; Fri, 14 May 2021 02:12:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJNyxr8EmOYQGVHtApO1d2IgLc5NR+XrejKY8z6FkL8/LtOwpMztg9w33cn6ty/Gy5BOTs X-Received: by 2002:a17:907:7243:: with SMTP id ds3mr46789478ejc.100.1620983567870; Fri, 14 May 2021 02:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620983567; cv=none; d=google.com; s=arc-20160816; b=ZlI9FJxtaj1C81l/vI2rwGAZcsEOx58Vya8hrmGMk0XklvhlrOpKiuhj+QZByR4hEO dxJBZZ9oykO8VF8cHf8FIZCmBVlv8VJclLJXHNPP2VlLBDULl19dxexX4lOII4qwS02M ILPrZSPkWjcWKR89W8R6SZzfrrq9gBJcwKRgHd3r0MRmT4iTKM81PmsNPAKSmlaN2cnp 2ZYysqu0+UgXCjfznDc7QCeIb92HCoTNTCydcQyy5RG/LXbQwKQSadAcTVaUuT9R981T qKFLP1CfNWKzbhuhmht5bAKogTMjRYDZ2Mkl8J1te7yDrKN7m+ZXy9RTgeGqI0ZYZikD i4jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KIL/G2dOWeyzHltqweD2JWGXMczf1Zcfegwd3TAfBew=; b=w1WmlTgGLybQW8FVM4yGU5zrZYOH2KkPwAAjxmIrOcJaFYaqIrBn6bb9zdRDdcpueN glRnnfIvLPhy2tGOStNv4xHorksbY+EYAwkym+yj/IGQu0T38VIMcEsLQL3ZCr537zY2 +C15g1CD+qkBmlIwCNGXe9Q8PbsCX89P+q+NcIJg3s84jEOhgVqkoeLTpKAhzDIM6Z6S p6nwrPLAfAiUux31OEpP1T5/RvAR7WdtJrHFTKTwHw+OtWF6OKoKp/91SJtv/HX+wJFn mqgUgqGz1XvzIx/I4cfo6naTEwJ9g4Jk1dLEhqsVP79Ui0VCiM6H4wWOVH0rksvpkqQ4 iLtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=EWbfy97J; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si6685080ejz.659.2021.05.14.02.12.15; Fri, 14 May 2021 02:12:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=EWbfy97J; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229506AbhENEAd (ORCPT + 99 others); Fri, 14 May 2021 00:00:33 -0400 Received: from mail.synology.com ([211.23.38.101]:35408 "EHLO synology.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229469AbhENEAc (ORCPT ); Fri, 14 May 2021 00:00:32 -0400 Received: from localhost.localdomain (unknown [10.17.200.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by synology.com (Postfix) with ESMTPSA id E3540249C33; Fri, 14 May 2021 11:59:20 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1620964760; bh=K7cdwnj/D7xJljx/DSyjsWJJz6s6FJtjEV6RF1pE/zo=; h=From:To:Cc:Subject:Date; b=EWbfy97JD84LsxKnUTyVbLHTN5MyjCC0NRTSmtBerI1pr7Di+JIbZaRKUyytSIVie jsGISseFr9jINty+NId+J421mxwYaLt6hOx8y5moN0otAptgUvFmzJRTOqj45nVJjt SXeb22B1Mj6qXSMGMacBF45JVhmRZvSeJ23JAB4I= From: Nick Huang To: bfields@fieldses.org, chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org, Yu Hsiang Huang , Bing Jing Chang , Robbie Ko Subject: [PATCH] nfsd: Prevent truncation of an unlinked inode from blocking access to its directory Date: Fri, 14 May 2021 11:58:29 +0800 Message-Id: <20210514035829.5230-1-nickhuang@synology.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Yu Hsiang Huang Truncation of an unlinked inode may take a long time for I/O waiting, and it doesn't have to prevent access to the directory. Thus, let truncation occur outside the directory's mutex, just like do_unlinkat() does. Signed-off-by: Yu Hsiang Huang Signed-off-by: Bing Jing Chang Signed-off-by: Robbie Ko --- fs/nfsd/vfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 15adf1f6ab21..39948f130712 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1859,6 +1859,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, { struct dentry *dentry, *rdentry; struct inode *dirp; + struct inode *rinode; __be32 err; int host_err; @@ -1887,6 +1888,8 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, host_err = -ENOENT; goto out_drop_write; } + rinode = d_inode(rdentry); + ihold(rinode); if (!type) type = d_inode(rdentry)->i_mode & S_IFMT; @@ -1902,6 +1905,8 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, if (!host_err) host_err = commit_metadata(fhp); dput(rdentry); + fh_unlock(fhp); + iput(rinode); /* truncate the inode here */ out_drop_write: fh_drop_write(fhp); -- 2.25.1