Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2257342iof; Wed, 8 Jun 2022 00:38:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXWqYVX1uuv5BAnQoR9x+XXiE1tVe5LhOjLjlQc4H/iNMc/eVPTmxkIS2aKSsVMezFiQqg X-Received: by 2002:a17:90b:1e47:b0:1e6:7d04:2f4 with SMTP id pi7-20020a17090b1e4700b001e67d0402f4mr35733628pjb.93.1654673905526; Wed, 08 Jun 2022 00:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654673905; cv=none; d=google.com; s=arc-20160816; b=I9RmsBTHyr8Dllg0FQaaczc63V63gXQRIHGsod/zC9nuNIOHsabIfWmm80UTW+E46H XjzCof4DeVJZa2Ooqos7UUCnXBrOXc2LYgDBucyRrUg3rVPViIAIRdGhU6uSM5/mMBRb euJeyYF5tJAkxnCxU0H6Ut9Hs3EBSOQzeB94katznegH0GNwDYK5yiffOo3LsOF2Obd0 Kzn6ZLg4XQ8wbJP5ZCgFj5d7tMqhlU3aumw0unvZRdr4tg6M/r/HEDwSNaFJd763OatO lmFr06sJFfD0mBbNSdgvRcQuCRpZffr/uBu52BekaEzQFs0H0XfHRCknZ1aiGPZHUsCF 6P4g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1nvTSfhQey6+JOtdDb/jDeGn86VXL8ydT3uREbMtX4g=; b=daC1U2WHyq4OL9jYvtTzFI3e81Fw+HwqZib7gMJ6BJDNedpXJWl4MPzYC9KtooBqjt ctunHrjHFau4eDDCKIayhaZDtkUgacbpWWUsWCjgyHxZ7H6st7dFk6In34O89Q55tsic uSTdLFnGlljj+Dqd1p6W9U077BJqSfiYrQhkDXkk8kqhbSrEgVmW4ZR/vnFveZxtew21 /dysUrIn2B31VIW/1yMnXih+eeYMXCXQlNM9he7j53H+zxccVwnrpupjmVI4iNewiUcR LyAQuk9W6Eu+B7DXwiBRm+dTxqWtvcyr5RfRssj1gA+MJB9Y6TMeUPoeq9b8UWo3VVji iRwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="y2/hzhXX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id cm18-20020a056a00339200b0051b98c3d62asi18395558pfb.233.2022.06.08.00.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 00:38:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="y2/hzhXX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9AED726D243; Wed, 8 Jun 2022 00:09:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352414AbiFHBtJ (ORCPT + 99 others); Tue, 7 Jun 2022 21:49:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383900AbiFGWIU (ORCPT ); Tue, 7 Jun 2022 18:08:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6524256959; Tue, 7 Jun 2022 12:18:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 542E0B823D5; Tue, 7 Jun 2022 19:18:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A543EC385A5; Tue, 7 Jun 2022 19:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629516; bh=9R5ZdtnFBk0LJ87brCjYh7QbNZwGS+6WpNNS9NjwiEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y2/hzhXXLaQ8HdZvctMivsyfFhOuXE8UUxKuyFxgXBLOC9aM1wiF1DHfxmODhE78w rTuDyBMfrlCCvkUCumnmcn2ftQaXNv0QIZBgEfqUPJWI+vTuZ+6U586uImmulVj+Hu 6r3et7PmYnR3dIXCBvsIYJsBE8gSlin96hDZXvEA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, ChenXiaoSong , Trond Myklebust , Anna Schumaker , Sasha Levin Subject: [PATCH 5.18 678/879] NFS: Dont report ENOSPC write errors twice Date: Tue, 7 Jun 2022 19:03:16 +0200 Message-Id: <20220607165022.528205277@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-kernel@vger.kernel.org From: Trond Myklebust [ Upstream commit e6005436f6cc9ed13288f936903f0151e5543485 ] Any errors reported by the write() system call need to be cleared from the file descriptor's error tracking. The current call to nfs_wb_all() causes the error to be reported, but since it doesn't call file_check_and_advance_wb_err(), we can end up reporting the same error a second time when the application calls fsync(). Note that since Linux 4.13, the rule is that EIO may be reported for write(), but it must be reported by a subsequent fsync(), so let's just drop reporting it in write. The check for nfs_ctx_key_to_expire() is just a duplicate to the one already in nfs_write_end(), so let's drop that too. Reported-by: ChenXiaoSong Fixes: ce368536dd61 ("nfs: nfs_file_write() should check for writeback errors") Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/file.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 7c380e555224..87e4cd5e8fe2 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -598,18 +598,6 @@ static const struct vm_operations_struct nfs_file_vm_ops = { .page_mkwrite = nfs_vm_page_mkwrite, }; -static int nfs_need_check_write(struct file *filp, struct inode *inode, - int error) -{ - struct nfs_open_context *ctx; - - ctx = nfs_file_open_context(filp); - if (nfs_error_is_fatal_on_server(error) || - nfs_ctx_key_to_expire(ctx, inode)) - return 1; - return 0; -} - ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; @@ -637,7 +625,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) if (iocb->ki_flags & IOCB_APPEND || iocb->ki_pos > i_size_read(inode)) { result = nfs_revalidate_file_size(inode, file); if (result) - goto out; + return result; } nfs_clear_invalid_mapping(file->f_mapping); @@ -656,6 +644,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) written = result; iocb->ki_pos += written; + nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); if (mntflags & NFS_MOUNT_WRITE_EAGER) { result = filemap_fdatawrite_range(file->f_mapping, @@ -673,17 +662,22 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) } result = generic_write_sync(iocb, written); if (result < 0) - goto out; + return result; +out: /* Return error values */ error = filemap_check_wb_err(file->f_mapping, since); - if (nfs_need_check_write(file, inode, error)) { - int err = nfs_wb_all(inode); - if (err < 0) - result = err; + switch (error) { + default: + break; + case -EDQUOT: + case -EFBIG: + case -ENOSPC: + nfs_wb_all(inode); + error = file_check_and_advance_wb_err(file); + if (error < 0) + result = error; } - nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); -out: return result; out_swapfile: -- 2.35.1