From patchwork Thu Jan 11 21:15:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 10158591 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 383D0605BA for ; Thu, 11 Jan 2018 21:15:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ACCA2883F for ; Thu, 11 Jan 2018 21:15:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FA3A28831; Thu, 11 Jan 2018 21:15:50 +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 B015728859 for ; Thu, 11 Jan 2018 21:15:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932987AbeAKVPs (ORCPT ); Thu, 11 Jan 2018 16:15:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38540 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932960AbeAKVPr (ORCPT ); Thu, 11 Jan 2018 16:15:47 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F815780F0; Thu, 11 Jan 2018 21:15:47 +0000 (UTC) Received: from max.home.com (ovpn-117-99.ams2.redhat.com [10.36.117.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29BD08517; Thu, 11 Jan 2018 21:15:44 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com, Christoph Hellwig Cc: Andreas Gruenbacher , linux-fsdevel@vger.kernel.org Subject: [PATCH 08/10] iomap: New iomap_written operation Date: Thu, 11 Jan 2018 22:15:02 +0100 Message-Id: <20180111211506.328-9-agruenba@redhat.com> In-Reply-To: <20180111211506.328-1-agruenba@redhat.com> References: <20180111211506.328-1-agruenba@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 11 Jan 2018 21:15:47 +0000 (UTC) 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 a callback to iomap_file_buffered_write that's called whenever writing to a page has completed. This is needed for implementing data journaling: in the data journaling case, pages are written into the journal before being written back to their proper on-disk locations. (So far, the only user of iomap_file_buffered_write is xfs, which doesn't do data journaling.) Signed-off-by: Andreas Gruenbacher --- fs/iomap.c | 21 +++++++++++++++++++-- include/linux/iomap.h | 9 +++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index 47d29ccffaef..98903be66c35 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -149,11 +149,21 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len, return ret; } +struct iomap_write_data { + struct iov_iter *iter; + const struct iomap_ops *ops; +}; + static loff_t iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, struct iomap *iomap) { - struct iov_iter *i = data; + struct iomap_write_data *d = data; + struct iov_iter *i = d->iter; + void (*iomap_written)(struct inode *inode, struct page *page, + unsigned int offset, unsigned int length, + unsigned int written) = + d->ops->iomap_written; long status = 0; ssize_t written = 0; unsigned int flags = AOP_FLAG_NOFS; @@ -198,6 +208,9 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, flush_dcache_page(page); + if (iomap_written) + iomap_written(inode, page, offset, bytes, copied); + status = iomap_write_end(inode, pos, bytes, copied, page); if (unlikely(status < 0)) break; @@ -235,10 +248,14 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *iter, { struct inode *inode = iocb->ki_filp->f_mapping->host; loff_t pos = iocb->ki_pos, ret = 0, written = 0; + struct iomap_write_data data = { + .iter = iter, + .ops = ops, + }; while (iov_iter_count(iter)) { ret = iomap_apply(inode, pos, iov_iter_count(iter), - IOMAP_WRITE, ops, iter, iomap_write_actor); + IOMAP_WRITE, ops, &data, iomap_write_actor); if (ret <= 0) break; pos += ret; diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 19a07de28212..042b8c8df44b 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -61,6 +61,8 @@ struct iomap { #define IOMAP_DIRECT (1 << 4) /* direct I/O */ #define IOMAP_NOWAIT (1 << 5) /* Don't wait for writeback */ +struct page; + struct iomap_ops { /* * Return the existing mapping at pos, or reserve space starting at @@ -70,6 +72,13 @@ struct iomap_ops { int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length, unsigned flags, struct iomap *iomap); + /* + * Called after writing to a page has completed. + */ + void (*iomap_written)(struct inode *inode, struct page *page, + unsigned int offset, unsigned int length, + unsigned int written); + /* * Commit and/or unreserve space previous allocated using iomap_begin. * Written indicates the length of the successful write operation which