From patchwork Sat Mar 5 12:46:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 12770344 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC3B2C433FE for ; Sat, 5 Mar 2022 12:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231699AbiCEMc3 (ORCPT ); Sat, 5 Mar 2022 07:32:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231687AbiCEMcZ (ORCPT ); Sat, 5 Mar 2022 07:32:25 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADDFD240049; Sat, 5 Mar 2022 04:31:35 -0800 (PST) Received: from kwepemi100012.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K9kZY5S57zdgJQ; Sat, 5 Mar 2022 20:30:13 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by kwepemi100012.china.huawei.com (7.221.188.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 5 Mar 2022 20:31:33 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 5 Mar 2022 20:31:32 +0800 From: ChenXiaoSong To: , , CC: , , , , , Subject: [PATCH -next 1/2] nfs: nfs{,4}_file_flush should consume writeback error Date: Sat, 5 Mar 2022 20:46:35 +0800 Message-ID: <20220305124636.2002383-2-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220305124636.2002383-1-chenxiaosong2@huawei.com> References: <20220305124636.2002383-1-chenxiaosong2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org filemap_sample_wb_err() will return 0 if nobody has seen the error yet, then filemap_check_wb_err() will return the unchanged writeback error. Reproducer: nfs server | nfs client --------------------------------|----------------------------------------------- # No space left on server | fallocate -l 100G /server/file1 | | mount -t nfs $nfs_server_ip:/ /mnt | # Expected error: No space left on device | dd if=/dev/zero of=/mnt/file2 count=1 ibs=100K # Release space on server | rm /server/file1 | | # Unexpected error: No space left on device | dd if=/dev/zero of=/mnt/file2 count=1 ibs=100K Fix this by using file_check_and_advance_wb_err(). If there is an error during the writeback process, it should be returned when user space calls close() or fsync(), flush() is called when user space calls close(). Note that fsync() will not be called after close(). Fixes: 67dd23f9e6fb ("nfs: ensure correct writeback errors are returned on close()") Signed-off-by: ChenXiaoSong --- fs/nfs/file.c | 4 +--- fs/nfs/nfs4file.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 76d76acbc594..83d63bce9596 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -141,7 +141,6 @@ static int nfs_file_flush(struct file *file, fl_owner_t id) { struct inode *inode = file_inode(file); - errseq_t since; dprintk("NFS: flush(%pD2)\n", file); @@ -150,9 +149,8 @@ nfs_file_flush(struct file *file, fl_owner_t id) return 0; /* Flush writes to the server and return any errors */ - since = filemap_sample_wb_err(file->f_mapping); nfs_wb_all(inode); - return filemap_check_wb_err(file->f_mapping, since); + return file_check_and_advance_wb_err(file); } ssize_t diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index e79ae4cbc395..63a57e5b6db7 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -111,7 +111,6 @@ static int nfs4_file_flush(struct file *file, fl_owner_t id) { struct inode *inode = file_inode(file); - errseq_t since; dprintk("NFS: flush(%pD2)\n", file); @@ -127,9 +126,8 @@ nfs4_file_flush(struct file *file, fl_owner_t id) return filemap_fdatawrite(file->f_mapping); /* Flush writes to the server and return any errors */ - since = filemap_sample_wb_err(file->f_mapping); nfs_wb_all(inode); - return filemap_check_wb_err(file->f_mapping, since); + return file_check_and_advance_wb_err(file); } #ifdef CONFIG_NFS_V4_2 From patchwork Sat Mar 5 12:46:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 12770343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A62ADC433EF for ; Sat, 5 Mar 2022 12:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231696AbiCEMc3 (ORCPT ); Sat, 5 Mar 2022 07:32:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbiCEMcZ (ORCPT ); Sat, 5 Mar 2022 07:32:25 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC3EB24004A; Sat, 5 Mar 2022 04:31:35 -0800 (PST) Received: from kwepemi100011.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K9kYy17jSzBryw; Sat, 5 Mar 2022 20:29:42 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by kwepemi100011.china.huawei.com (7.221.188.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 5 Mar 2022 20:31:34 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 5 Mar 2022 20:31:33 +0800 From: ChenXiaoSong To: , , CC: , , , , , Subject: [PATCH -next 2/2] nfs: nfs_file_write() check writeback errors correctly Date: Sat, 5 Mar 2022 20:46:36 +0800 Message-ID: <20220305124636.2002383-3-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220305124636.2002383-1-chenxiaosong2@huawei.com> References: <20220305124636.2002383-1-chenxiaosong2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If nobody has seen the writeback error yet, then filemap_sample_wb_err() always return 0. Even if there is no new writeback error between filemap_sample_wb_err() and filemap_check_wb_err(), filemap_check_wb_err() will return the old error. Fix this by using file->f_mapping->wb_err as the old error. Fixes: ce368536dd61 ("nfs: nfs_file_write() should check for writeback errors") Signed-off-by: ChenXiaoSong --- fs/nfs/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 83d63bce9596..8763f89c176a 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -635,7 +635,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) nfs_clear_invalid_mapping(file->f_mapping); - since = filemap_sample_wb_err(file->f_mapping); + since = file->f_mapping->wb_err; nfs_start_io_write(inode); result = generic_write_checks(iocb, from); if (result > 0) { @@ -669,7 +669,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) goto out; /* Return error values */ - error = filemap_check_wb_err(file->f_mapping, since); + error = errseq_check(&file->f_mapping->wb_err, since); if (nfs_need_check_write(file, inode, error)) { int err = nfs_wb_all(inode); if (err < 0)