Received: by 10.213.65.68 with SMTP id h4csp448996imn; Tue, 13 Mar 2018 09:23:13 -0700 (PDT) X-Google-Smtp-Source: AG47ELuRR4f+Ae3PHB6C1A4+HUDFMZgOUvSDu65ijjSxX0CyNRJuYirEaXSdL+81909/KsU24y3Y X-Received: by 2002:a17:902:ab89:: with SMTP id f9-v6mr1051790plr.369.1520958193897; Tue, 13 Mar 2018 09:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520958193; cv=none; d=google.com; s=arc-20160816; b=zI2Ro82akCuVaKFOOfelZvuV11PScuK0G4uydJJ8cE97ipmssXHPXf4g2nJdDh1tzB Kk8MrDHaejCVLSKasGcMJmO8nSKhExg7+YLk35WTX68d1WzeQgXC7VoZR8gzpS0L8Y5o E7I6Xxs2ExRSlACZyLNHI92tPceKQs0fTGdmE482DTXaNSNLZKn+WZIg2eRTpXxbAoiW 9r4ZTzmpyOIKw2gv19JGhMcvS4e6IUXboIaQ/TrysoUewclpmnc3u2rM7hohqgmvfGpB 3yau2czMqTPXMU3ZkCThH3ogRo0yz8vlrR1EYxPsDkbfEiCqjc1MYNZhofejeu8E48Fb 1DsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VPuwkOsvHtT5dY4Z2qhSiVHQOrvvmLRP9WScoONf+y8=; b=jbVWBZ+cRs18GDaHlqKAU05+EH1jujrUJA0xXh+HOu3EQu5QYNFGajbKJxVCF5XYlX 0FV5JzVbEAQyJuP/mk/eqa26lE4giiVSURC1i54IjiDEMuS/p5UtqkBL7MIN53CZ9j7W 6LfePJ6ZzmEi9i5x+uvDYYJqQ6nj+EbII5UJdsOxrKp1UaO9GagE02KcGxquPmUZ3jqJ uEv3BOXbfcU/HyC2ylYiYFV2wBCRTcKLqS8xaOVfZmOpkhHUAtCAUevWO+dH4D3enHeC Q+vJIBVIahjiFquLfYGcjnmeKGXNZKAYxwBiVnct+NE38KgN1FIF253x+0nAM5QG0z66 IkIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4-v6si326643plr.365.2018.03.13.09.22.59; Tue, 13 Mar 2018 09:23:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933899AbeCMQVN (ORCPT + 99 others); Tue, 13 Mar 2018 12:21:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:32820 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933775AbeCMPe3 (ORCPT ); Tue, 13 Mar 2018 11:34:29 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0198C1032; Tue, 13 Mar 2018 15:34:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Scott Mayhew , Trond Myklebust Subject: [PATCH 4.15 146/146] NFS: Fix unstable write completion Date: Tue, 13 Mar 2018 16:25:13 +0100 Message-Id: <20180313152331.331679814@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152320.439085687@linuxfoundation.org> References: <20180313152320.439085687@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Trond Myklebust commit c4f24df942a181699c5bab01b8e5e82b925f77f3 upstream. We do want to respect the FLUSH_SYNC argument to nfs_commit_inode() to ensure that all outstanding COMMIT requests to the inode in question are complete. Currently we may exit early from both nfs_commit_inode() and nfs_write_inode() even if there are COMMIT requests in flight, or unstable writes on the commit list. In order to get the right semantics w.r.t. sync_inode(), we don't need to have nfs_commit_inode() reset the inode dirty flags when called from nfs_wb_page() and/or nfs_wb_all(). We just need to ensure that nfs_write_inode() leaves them in the right state if there are outstanding commits, or stable pages. Reported-by: Scott Mayhew Fixes: dc4fd9ab01ab ("nfs: don't wait on commit in nfs_commit_inode()...") Cc: stable@vger.kernel.org # v4.14+ Signed-off-by: Trond Myklebust Signed-off-by: Greg Kroah-Hartman --- fs/nfs/write.c | 83 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 40 deletions(-) --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1878,40 +1878,43 @@ int nfs_generic_commit_list(struct inode return status; } -int nfs_commit_inode(struct inode *inode, int how) +static int __nfs_commit_inode(struct inode *inode, int how, + struct writeback_control *wbc) { LIST_HEAD(head); struct nfs_commit_info cinfo; int may_wait = how & FLUSH_SYNC; - int error = 0; - int res; + int ret, nscan; nfs_init_cinfo_from_inode(&cinfo, inode); nfs_commit_begin(cinfo.mds); - res = nfs_scan_commit(inode, &head, &cinfo); - if (res) - error = nfs_generic_commit_list(inode, &head, how, &cinfo); + for (;;) { + ret = nscan = nfs_scan_commit(inode, &head, &cinfo); + if (ret <= 0) + break; + ret = nfs_generic_commit_list(inode, &head, how, &cinfo); + if (ret < 0) + break; + ret = 0; + if (wbc && wbc->sync_mode == WB_SYNC_NONE) { + if (nscan < wbc->nr_to_write) + wbc->nr_to_write -= nscan; + else + wbc->nr_to_write = 0; + } + if (nscan < INT_MAX) + break; + cond_resched(); + } nfs_commit_end(cinfo.mds); - if (res == 0) - return res; - if (error < 0) - goto out_error; - if (!may_wait) - goto out_mark_dirty; - error = wait_on_commit(cinfo.mds); - if (error < 0) - return error; - return res; -out_error: - res = error; - /* Note: If we exit without ensuring that the commit is complete, - * we must mark the inode as dirty. Otherwise, future calls to - * sync_inode() with the WB_SYNC_ALL flag set will fail to ensure - * that the data is on the disk. - */ -out_mark_dirty: - __mark_inode_dirty(inode, I_DIRTY_DATASYNC); - return res; + if (ret || !may_wait) + return ret; + return wait_on_commit(cinfo.mds); +} + +int nfs_commit_inode(struct inode *inode, int how) +{ + return __nfs_commit_inode(inode, how, NULL); } EXPORT_SYMBOL_GPL(nfs_commit_inode); @@ -1921,11 +1924,11 @@ int nfs_write_inode(struct inode *inode, int flags = FLUSH_SYNC; int ret = 0; - /* no commits means nothing needs to be done */ - if (!atomic_long_read(&nfsi->commit_info.ncommit)) - return ret; - if (wbc->sync_mode == WB_SYNC_NONE) { + /* no commits means nothing needs to be done */ + if (!atomic_long_read(&nfsi->commit_info.ncommit)) + goto check_requests_outstanding; + /* Don't commit yet if this is a non-blocking flush and there * are a lot of outstanding writes for this mapping. */ @@ -1936,16 +1939,16 @@ int nfs_write_inode(struct inode *inode, flags = 0; } - ret = nfs_commit_inode(inode, flags); - if (ret >= 0) { - if (wbc->sync_mode == WB_SYNC_NONE) { - if (ret < wbc->nr_to_write) - wbc->nr_to_write -= ret; - else - wbc->nr_to_write = 0; - } - return 0; - } + ret = __nfs_commit_inode(inode, flags, wbc); + if (!ret) { + if (flags & FLUSH_SYNC) + return 0; + } else if (atomic_long_read(&nfsi->commit_info.ncommit)) + goto out_mark_dirty; + +check_requests_outstanding: + if (!atomic_read(&nfsi->commit_info.rpcs_out)) + return ret; out_mark_dirty: __mark_inode_dirty(inode, I_DIRTY_DATASYNC); return ret;