From patchwork Wed Nov 7 06:31:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 10671937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E38915E9 for ; Wed, 7 Nov 2018 06:32:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F4672B6DF for ; Wed, 7 Nov 2018 06:32:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03D7B2B729; Wed, 7 Nov 2018 06:32:29 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 A131F2B6DF for ; Wed, 7 Nov 2018 06:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730373AbeKGQBX (ORCPT ); Wed, 7 Nov 2018 11:01:23 -0500 Received: from ipmail03.adl2.internode.on.net ([150.101.137.141]:1838 "EHLO ipmail03.adl2.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730268AbeKGQBW (ORCPT ); Wed, 7 Nov 2018 11:01:22 -0500 Received: from ppp59-167-129-252.static.internode.on.net (HELO dastard) ([59.167.129.252]) by ipmail03.adl2.internode.on.net with ESMTP; 07 Nov 2018 17:01:34 +1030 Received: from discord.disaster.area ([192.168.1.111]) by dastard with esmtp (Exim 4.80) (envelope-from ) id 1gKHNE-00086n-5i; Wed, 07 Nov 2018 17:31:32 +1100 Received: from dave by discord.disaster.area with local (Exim 4.91) (envelope-from ) id 1gKHNE-0001jA-41; Wed, 07 Nov 2018 17:31:32 +1100 From: Dave Chinner To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 12/16] iomap: zero-around in iomap_page_mkwrite Date: Wed, 7 Nov 2018 17:31:23 +1100 Message-Id: <20181107063127.3902-13-david@fromorbit.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181107063127.3902-1-david@fromorbit.com> References: <20181107063127.3902-1-david@fromorbit.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Chinner When we take a write fault over a page in a block size > page size filesystem, we may have to issue zero-around to initialise all the pages in the block that mmap is writing to. This is essentially the same as the zero-around in the buffered write path, with the added complexity that we have to drop the page lock on the page that was passed to iomap_page_mkwrite_actor(). Signed-off-by: Dave Chinner --- fs/iomap.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/fs/iomap.c b/fs/iomap.c index 41922fc775c4..7aacd48c593e 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1183,7 +1183,46 @@ iomap_page_mkwrite_actor(struct inode *inode, loff_t pos, loff_t length, void *data, struct iomap *iomap) { struct page *page = data; - int ret; + loff_t ret; + + /* + * if we need to zero-around, we have to unlock the page we were given. + * No big deal, we just have to repeat the "is this page ours" checks + * after relocking it + */ + if (iomap_need_zero_around(iomap)) { + loff_t size; + + /* + * This only happens for block size > page size, so the file + * offset of a page fault should always be page aligned. + */ + WARN_ON(offset_in_page(pos)); + + unlock_page(page); + ret = iomap_zero_around(inode, pos, length, iomap); + lock_page(page); + size = i_size_read(inode); + if ((page->mapping != inode->i_mapping) || + (page_offset(page) > size)) { + /* We overload EFAULT to mean page got truncated */ + return -EFAULT; + } + + if (page_offset(page) != pos) { + /* it moved in the file! */ + return -EFAULT; + } + + /* return failure now if zeroing had an error */ + if (ret) + return ret; + + /* trim down the length is we straddle EOF. */ + if (((page->index + 1) << PAGE_SHIFT) > size) + length = offset_in_page(size); + + } if (iomap->flags & IOMAP_F_BUFFER_HEAD) { ret = __block_write_begin_int(page, pos, length, NULL, iomap);