From patchwork Tue Jan 14 16:12:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11332601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE3D01398 for ; Tue, 14 Jan 2020 16:12:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BBC52187F for ; Tue, 14 Jan 2020 16:12:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OkrfZS8N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BBC52187F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 868588E000B; Tue, 14 Jan 2020 11:12:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 83F918E0009; Tue, 14 Jan 2020 11:12:53 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E3038E000B; Tue, 14 Jan 2020 11:12:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id 49F178E0009 for ; Tue, 14 Jan 2020 11:12:53 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 19B27181AC9C6 for ; Tue, 14 Jan 2020 16:12:53 +0000 (UTC) X-FDA: 76376733426.07.field02_363fbcd6d721b X-Spam-Summary: 2,0,0,4e87ee070e6fd774,d41d8cd98f00b204,batv+ea884c299640eab8340e+5987+infradead.org+hch@bombadil.srs.infradead.org,:linux-xfs@vger.kernel.org:linux-fsdevel@vger.kernel.org:longman@redhat.com:peterz@infradead.org:tglx@linutronix.de:mingo@redhat.com:will@kernel.org:akpm@linux-foundation.org:linux-ext4@vger.kernel.org:cluster-devel@redhat.com:linux-kernel@vger.kernel.org:,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2903:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3871:3872:3874:4321:5007:6261:6653:8660:9036:10004:11026:11658:11914:12043:12048:12160:12291:12296:12297:12438:12517:12519:12555:12683:12895:13148:13230:13894:14096:14110:14181:14394:14721:21080:21451:21627:21990:30034:30054,0,RBL:198.137.202.133:@bombadil.srs.infradead.org:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn, MSBL:0,D X-HE-Tag: field02_363fbcd6d721b X-Filterd-Recvd-Size: 5379 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jan 2020 16:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gE1ExdwCpfYksx1sroYSdgpkjqJWhJqvmDoS1LitSEk=; b=OkrfZS8NRZAUrCzKeBJ9qWvRAB 2p1eoX14Slhqy2MdQbUQPF0HUA7/g5EN85LDdIwsd3BB9W7/vFoDRbIUV1u3p8uRTNQdFA89yhgL0 9jVm1PJqp35970u4WIuAU8p6kNZs2ZRtGJh3MVPfizmEgVpisfkPS5RqCDD065W+lOkbgH/N4b1Bz 7rnYRufVoQXMjKefjP7lJXcCL1F7uOU+daZA/kor/TTYgisnaIvGQhJJN6++IY5+4HY49K2j6A2Mh gq2BDx44Hr656RZ6OjOd0CKj3XN1ffkbrMPs0HMihU+PDNmbAhTVWrX7qp1DCYhsdIKw9HUpFhaEO Ej399QhQ==; Received: from [2001:4bb8:18c:4f54:fcbb:a92b:61e1:719] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1irOo4-0000AR-W5; Tue, 14 Jan 2020 16:12:41 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Waiman Long , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Will Deacon , Andrew Morton , linux-ext4@vger.kernel.org, cluster-devel@redhat.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/12] gfs2: fix O_SYNC write handling Date: Tue, 14 Jan 2020 17:12:18 +0100 Message-Id: <20200114161225.309792-6-hch@lst.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114161225.309792-1-hch@lst.de> References: <20200114161225.309792-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Don't ignore the return value from generic_write_sync for the direct to buffered I/O callback case when written is non-zero. Also don't bother to call generic_write_sync for the pure direct I/O case, as iomap_dio_rw already takes care of that. Signed-off-by: Christoph Hellwig --- fs/gfs2/file.c | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 21d032c4b077..86c0e61407b6 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -847,7 +847,7 @@ static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from) struct file *file = iocb->ki_filp; struct inode *inode = file_inode(file); struct gfs2_inode *ip = GFS2_I(inode); - ssize_t written = 0, ret; + ssize_t ret = 0; ret = gfs2_rsqa_alloc(ip); if (ret) @@ -882,52 +882,51 @@ static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from) loff_t pos, endbyte; ssize_t buffered; - written = gfs2_file_direct_write(iocb, from); - if (written < 0 || !iov_iter_count(from)) + ret = gfs2_file_direct_write(iocb, from); + if (ret < 0 || !iov_iter_count(from)) goto out_unlock; current->backing_dev_info = inode_to_bdi(inode); - ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops); + buffered = iomap_file_buffered_write(iocb, from, + &gfs2_iomap_ops); current->backing_dev_info = NULL; - if (unlikely(ret < 0)) + if (unlikely(buffered <= 0)) { + if (buffered < 0) + ret = buffered; goto out_unlock; - buffered = ret; + } /* * We need to ensure that the page cache pages are written to * disk and invalidated to preserve the expected O_DIRECT - * semantics. + * semantics. If the writeback or invalidate fails only report + * the direct I/O range as we don't know if the buffered pages + * made it to disk. */ pos = iocb->ki_pos; endbyte = pos + buffered - 1; ret = filemap_write_and_wait_range(mapping, pos, endbyte); - if (!ret) { - iocb->ki_pos += buffered; - written += buffered; - invalidate_mapping_pages(mapping, - pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - } else { - /* - * We don't know how much we wrote, so just return - * the number of bytes which were direct-written - */ - } + if (ret) + goto out_unlock; + + invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, + endbyte >> PAGE_SHIFT); + ret += buffered; } else { current->backing_dev_info = inode_to_bdi(inode); ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops); current->backing_dev_info = NULL; - if (likely(ret > 0)) - iocb->ki_pos += ret; + if (unlikely(ret <= 0)) + goto out_unlock; } + iocb->ki_pos += ret; + inode_unlock(inode); + return generic_write_sync(iocb, ret); + out_unlock: inode_unlock(inode); - if (likely(ret > 0)) { - /* Handle various SYNC-type writes */ - ret = generic_write_sync(iocb, ret); - } - return written ? written : ret; + return ret; } static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,