Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp475128pxp; Sat, 5 Mar 2022 08:46:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjgmka2Q74Alj9ffaesLeg1miORoX61M5un8FIcCbQTnS7qca/2mjl0A4bdHvq3FL2Nz9E X-Received: by 2002:a17:906:c048:b0:6ce:a6f5:b23a with SMTP id bm8-20020a170906c04800b006cea6f5b23amr3301614ejb.350.1646498797655; Sat, 05 Mar 2022 08:46:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646498797; cv=none; d=google.com; s=arc-20160816; b=i6IWw5lYMfQjGOniNefNv53/XWvopBF0JJPvKGA/lHHZc9Mk7yPoUNGjwVQEGo116J nEH54gbDZhXnKr9s0dAXgAPNNHDcuwNpz2L7XyB6YNdFXjNtCJCXFqJ59PdNmNgwTm9I g7FQes/XPsJTck/lQIUybdzVAl8QraZ2qerHuWZzgJhkj4i+fEh4lBZQIvmtmm9SSm5g ErU4qv0/2FiG7C0vIy0kzJ/RuqsPIwWCE+QGtIAUDDbqEsjwLEKrsceXaHcDZmoi5dhb MDICJ42LDSPPG/bflyUjR9n3iyo7J95hqk62zVMbAEu7RlwP9CYnPEFuSpyg48zF7BzA l1Mg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BfQ0wqxJKrjnbR1XXUuKuMwk4MEfs3Nk7QE60n9WJqk=; b=jcOZmPC7v8xF/rxGN5lXMOsIp1J7OGLMAp17S2CgambStZNemi5wLoXInmIkQ0snFh X/eaeouEmTMmMogVsFsQa7Rvt6eI8xnq3ja/i5rJgbIpKy9SIBQKxy2hJ06TKI9+ZncY iBmYwIlAtlBCmwnghJIx1CEvSukm9jOJ6mT4Y6jQVn7609HGfu8n27IMXm2nueRaX2j2 Z+QAbaWSggwosIhiOTqOn7pKCA7YQq/OORIVJfwuBl3/QCLBfVGlMWljYkMW5OVm8jH5 cdsgWi+U5BD2gZtFe9DYGALW/cQXq8n2RVR6bDjrp5hY46c3X4dQJATJ0kDZwHaacmw/ 4iFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne10-20020a1709077b8a00b006ced85cc073si5002962ejc.10.2022.03.05.08.45.55; Sat, 05 Mar 2022 08:46:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231699AbiCEMc3 (ORCPT + 99 others); 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 -- 2.31.1