Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1420632iob; Sat, 14 May 2022 08:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAPe+20Rmwbifqk2Oms5X+eo53os3BYPZdcdQRbiH7TBQwvVrPu0prUtQPUAjqG+/mFRfR X-Received: by 2002:a05:6402:3226:b0:427:cef3:9fb3 with SMTP id g38-20020a056402322600b00427cef39fb3mr4419985eda.20.1652542327534; Sat, 14 May 2022 08:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652542327; cv=none; d=google.com; s=arc-20160816; b=Y8axfaTLlKFDQ7ObCdQaRaeyJDutDvNWafygWtlHVDbpN2pcSUxHgwbL4D6sSjCD+O zTW3Vf9rdYx9SPhTe6exVlvbbS84Kcdi8qP9kwZGnEJe7yiZSEN8UYwwUJgsCnWowJ79 5kpdmtJ21l1i+tFq2Hm3wgSfJlpoiYzabjarp6Wmz7iK2JGJZeKeYFuczH/msGOhg2gS jAHyklCNU1MA8cd2neAwnmf/bX5PqvDLjo9hLhpdbAl0qx+yOxrSBf4XAOkdESwNtBPj 7ilTyMiTLxRFzrvyWE8hUvWrzXUgB0pZkUtKZvVoBklP2bkehF5cDA/EtfVLTXRmDzv+ oyvQ== 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 :dkim-signature; bh=5KhXfs527JzazxkbgUO0ZwJYmRJ03o0qkfB6p6PBPEA=; b=K4W5Qsmgq8bZpjw+HGr56BqDnGrT7ofOd4m7XO0JNB0JeNjHRxW4f3BuZOW8mbMKXv h0KvwliCy5yT2aEw3ri6Q/7b72kZee57A9J756LrFsqnSXlxD7JxolMJ2puzOlSncbdA 31Yj619uzO0nQjIfqoNHJokVw5VAA4GKr5L81yyxApweptPsrSvLEUQFkmNRVjn7Kxzu aduFI/MZQUJ9zMAbQvqqitEqkC5tySW5kTfOVVlHf9v7xUdgaYlQluB/Jq7uugm7b6Ng k4hfAvdOOhs4TNMgnZTguzjjpaxdKAOJzp7o0TUqL0IDWg50AmvO9ZiiSoVaEGRgXyS6 9twg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dNzMKTQx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16-20020a056402525000b00425e9509cd3si5921055edd.60.2022.05.14.08.31.32; Sat, 14 May 2022 08:32:07 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dNzMKTQx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233333AbiENOdS (ORCPT + 99 others); Sat, 14 May 2022 10:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233336AbiENOdQ (ORCPT ); Sat, 14 May 2022 10:33:16 -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 CBD471CFC9 for ; Sat, 14 May 2022 07:33:15 -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 E722CB808D2 for ; Sat, 14 May 2022 14:33:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 542B0C34116; Sat, 14 May 2022 14:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652538792; bh=zKmbQrO0dGT4kPWfRXQOJRxWwZShgqPqnlD75es0YCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dNzMKTQx/H12/GR9GxPLyhUE3RvCWSS1YlF8RapFKERb1QiZe6yat8kb7QXo6tHnK IblqGPl56vN+QW+mDxbE25jveDYoCTwd4r9D9uW8gG6vb86pV9SoAPRoTkOcwoG0fj I7fbEljt6pu2yYFjQe/YIMKbqgGWtHPJcsHQupP9nhgBdPFy0imuqh27Rp6zQjqOp4 f6K7ukhwI6eCfxBLhPdGzo73Q0xhZvoxIMe24agcEWz1QnIz0vlrDpLH4Ze4fPCui1 afgTzFmAVTWRRURJNyvFEhkVk0sB/KNEp2lekgM/kG7Q3rSbJkWG33vFiy9GdFGGXF 1DR2hB678GENw== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 3/5] NFS: Don't report ENOSPC write errors twice Date: Sat, 14 May 2022 10:27:02 -0400 Message-Id: <20220514142704.4149-4-trondmy@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220514142704.4149-3-trondmy@kernel.org> References: <20220514142704.4149-1-trondmy@kernel.org> <20220514142704.4149-2-trondmy@kernel.org> <20220514142704.4149-3-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Trond Myklebust 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 --- 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.36.1