From patchwork Mon Jun 4 19:31:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 10447247 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 3F23E601A1 for ; Mon, 4 Jun 2018 19:31:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F00729108 for ; Mon, 4 Jun 2018 19:31:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23D742911D; Mon, 4 Jun 2018 19:31:52 +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 AB52B29108 for ; Mon, 4 Jun 2018 19:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751219AbeFDTbt (ORCPT ); Mon, 4 Jun 2018 15:31:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58914 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751013AbeFDTbf (ORCPT ); Mon, 4 Jun 2018 15:31:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D606854E2; Mon, 4 Jun 2018 19:31:35 +0000 (UTC) Received: from max.home.com (unknown [10.36.118.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BE34ED177; Mon, 4 Jun 2018 19:31:34 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com, Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH v8 05/10] iomap: Generic inline data handling Date: Mon, 4 Jun 2018 21:31:18 +0200 Message-Id: <20180604193123.27655-6-agruenba@redhat.com> In-Reply-To: <20180604193123.27655-1-agruenba@redhat.com> References: <20180604193123.27655-1-agruenba@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 04 Jun 2018 19:31:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 04 Jun 2018 19:31:35 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'agruenba@redhat.com' RCPT:'' 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 Add generic inline data handling by adding a pointer to the inline data region to struct iomap. When handling a buffered IOMAP_INLINE write, iomap_write_begin will copy the current inline data from the inline data region into the page cache, and iomap_write_end will copy the changes in the page cache back to the inline data region. This doesn't cover inline data reads and direct I/O yet because so far, we have no users. Signed-off-by: Andreas Gruenbacher Reviewed-by: Christoph Hellwig --- fs/iomap.c | 56 +++++++++++++++++++++++++++++++++++++++---- include/linux/iomap.h | 1 + 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index a0d3b7742060..48cd67227811 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -108,6 +108,41 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len) truncate_pagecache_range(inode, max(pos, i_size), pos + len); } +static void +iomap_read_inline_data(struct page *page, struct iomap *iomap, loff_t size) +{ + void *data = iomap->inline_data; + void *addr; + + if (PageUptodate(page)) + return; + + BUG_ON(page->index); + BUG_ON(size > PAGE_SIZE - offset_in_page(data)); + + addr = kmap_atomic(page); + memcpy(addr, data, size); + memset(addr + size, 0, PAGE_SIZE - size); + kunmap_atomic(addr); + SetPageUptodate(page); +} + +static void +iomap_write_inline_data(struct inode *inode, struct page *page, + struct iomap *iomap, off_t pos, unsigned copied) +{ + void *data = iomap->inline_data; + void *addr; + + BUG_ON(pos + copied > PAGE_SIZE - offset_in_page(data)); + WARN_ON_ONCE(!PageUptodate(page)); + + addr = kmap_atomic(page); + memcpy(data + pos, addr + pos, copied); + kunmap_atomic(addr); + mark_inode_dirty(inode); +} + static int iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, struct page **pagep, struct iomap *iomap) @@ -125,6 +160,11 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, if (!page) return -ENOMEM; + if (iomap->type == IOMAP_INLINE) { + iomap_read_inline_data(page, iomap, inode->i_size); + goto out; + } + status = __block_write_begin_int(page, pos, len, NULL, iomap); if (unlikely(status)) { unlock_page(page); @@ -134,16 +174,23 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, iomap_write_failed(inode, pos, len); } +out: *pagep = page; return status; } static int iomap_write_end(struct inode *inode, loff_t pos, unsigned len, - unsigned copied, struct page *page) + unsigned copied, struct page *page, struct iomap *iomap) { int ret; + if (iomap->type == IOMAP_INLINE) { + iomap_write_inline_data(inode, page, iomap, pos, copied); + __generic_write_end(inode, pos, copied, page); + return copied; + } + ret = generic_write_end(NULL, inode->i_mapping, pos, len, copied, page, NULL); if (ret < len) @@ -200,7 +247,8 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, flush_dcache_page(page); - status = iomap_write_end(inode, pos, bytes, copied, page); + status = iomap_write_end(inode, pos, bytes, copied, page, + iomap); if (unlikely(status < 0)) break; copied = status; @@ -294,7 +342,7 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data, WARN_ON_ONCE(!PageUptodate(page)); - status = iomap_write_end(inode, pos, bytes, bytes, page); + status = iomap_write_end(inode, pos, bytes, bytes, page, iomap); if (unlikely(status <= 0)) { if (WARN_ON_ONCE(status == 0)) return -EIO; @@ -346,7 +394,7 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset, zero_user(page, offset, bytes); mark_page_accessed(page); - return iomap_write_end(inode, pos, bytes, bytes, page); + return iomap_write_end(inode, pos, bytes, bytes, page, iomap); } static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes, diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 918f14075702..c61113c71a60 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -47,6 +47,7 @@ struct iomap { u64 length; /* length of mapping, bytes */ u16 type; /* type of mapping */ u16 flags; /* flags for mapping */ + void *inline_data; /* inline data buffer */ struct block_device *bdev; /* block device for I/O */ struct dax_device *dax_dev; /* dax_dev for dax operations */ };