From patchwork Tue Dec 19 16:56:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J. Bruce Fields" X-Patchwork-Id: 10123747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 75487603B5 for ; Tue, 19 Dec 2017 16:56:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56C682891C for ; Tue, 19 Dec 2017 16:56:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B96E28B15; Tue, 19 Dec 2017 16:56:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAE322891C for ; Tue, 19 Dec 2017 16:56:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751107AbdLSQ4X (ORCPT ); Tue, 19 Dec 2017 11:56:23 -0500 Received: from fieldses.org ([173.255.197.46]:49834 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750916AbdLSQ4W (ORCPT ); Tue, 19 Dec 2017 11:56:22 -0500 Received: by fieldses.org (Postfix, from userid 2815) id 517092442; Tue, 19 Dec 2017 11:56:22 -0500 (EST) Date: Tue, 19 Dec 2017 11:56:22 -0500 From: "J. Bruce Fields" To: Benjamin Coddington Cc: linux-nfs@vger.kernel.org, hch@infradead.org, Trond Myklebust , Anna Schumaker Subject: Re: spurious sillyrename after O_DIRECT writes get ENOSPC Message-ID: <20171219165622.GC19967@fieldses.org> References: <20171208221626.GB22508@fieldses.org> <20171213171815.GB9205@fieldses.org> <9383ABA6-B994-4DB3-95F4-C0D6F59580F9@redhat.com> <20171214163654.GD9205@fieldses.org> <20171214185514.GE9205@fieldses.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171214185514.GE9205@fieldses.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Dec 14, 2017 at 01:55:14PM -0500, J. Bruce Fields wrote: > So actually what happens is if you do a direct io write where some > WRITEs succeed and the one fails, then this: > > if (test_bit(NFS_IOHDR_ERROR, &hdr->flags)) { > dreq->flags = 0; > dreq->error = hdr->error; > } > > clears the NFS_ODIRECT_DO_COMMIT flag, so nfs_direct_write_complete > never scheduels the commit calls. It looks like that leaves a bunch of > nfs_pages on some to-be-committed list, so we end up leaking a bunch of > stuff, with the most visible symptom being an unnecessarily sillyrename > on close. > > I can just remove that clear of dreq_flags and that fixes the problem, > but I doubt that's correct. Or, maybe it is. If *any* WRITE(s) involved in this write might need a commit or reschedule, then surely we should run nfs_direct_write_schedule_work and let it sort them out? I'm having trouble seeing why clearing that field partway through could ever be correct. Trond, Anna, does the following look right? --b. From a5ad80d2f239ed47eef7ad224db5eb6afba84062 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Fri, 15 Dec 2017 15:25:45 -0500 Subject: [PATCH] NFS: commit direct writes even if they fail partially If some of the WRITE calls making up an O_DIRECT write syscall fail, we neglect to commit, even if some of the WRITEs succeed. We also depend on the commit code to free the reference count on the nfs_page taken in the "if (request_commit)" case at the end of nfs_direct_write_completion(). The problem was originally noticed because ENOSPC's encountered partway through a write would result in a closed file being sillyrenamed when it should have been unlinked. Signed-off-by: J. Bruce Fields --- fs/nfs/direct.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index d2972d537469..8c10b0562e75 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -775,10 +775,8 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) spin_lock(&dreq->lock); - if (test_bit(NFS_IOHDR_ERROR, &hdr->flags)) { - dreq->flags = 0; + if (test_bit(NFS_IOHDR_ERROR, &hdr->flags)) dreq->error = hdr->error; - } if (dreq->error == 0) { nfs_direct_good_bytes(dreq, hdr); if (nfs_write_need_commit(hdr)) {