From patchwork Wed May 31 12:45:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 9756851 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 97B0060390 for ; Wed, 31 May 2017 12:46:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B1FF201BD for ; Wed, 31 May 2017 12:46:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F80F201F3; Wed, 31 May 2017 12:46:43 +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=unavailable 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 1EE12283BA for ; Wed, 31 May 2017 12:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751452AbdEaMqJ (ORCPT ); Wed, 31 May 2017 08:46:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55993 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbdEaMqH (ORCPT ); Wed, 31 May 2017 08:46:07 -0400 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 5590A80E4A; Wed, 31 May 2017 12:45:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5590A80E4A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jlayton@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5590A80E4A Received: from tleilax.poochiereds.net (ovpn-120-5.rdu2.redhat.com [10.10.120.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3406180DEC; Wed, 31 May 2017 12:45:50 +0000 (UTC) From: Jeff Layton To: Andrew Morton , Al Viro , Jan Kara , tytso@mit.edu, axboe@kernel.dk, mawilcox@microsoft.com, ross.zwisler@linux.intel.com, corbet@lwn.net Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v5 07/17] mm: add filemap_fdatawait_range_since and filemap_write_and_wait_range_since Date: Wed, 31 May 2017 08:45:30 -0400 Message-Id: <20170531124540.8782-8-jlayton@redhat.com> In-Reply-To: <20170531124540.8782-1-jlayton@redhat.com> References: <20170531124540.8782-1-jlayton@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.25]); Wed, 31 May 2017 12:45:51 +0000 (UTC) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add new filemap_*wait* variants that take a "since" value and return an error if one occurred since that sample point. Signed-off-by: Jeff Layton --- include/linux/fs.h | 9 ++++++++ mm/filemap.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 2f3bcf4eb73b..7d1bd3163d99 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2516,12 +2516,21 @@ extern int write_inode_now(struct inode *, int); extern int filemap_fdatawrite(struct address_space *); extern int filemap_flush(struct address_space *); extern int filemap_fdatawait(struct address_space *); +extern int filemap_fdatawait_since(struct address_space *, errseq_t); extern void filemap_fdatawait_keep_errors(struct address_space *); extern int filemap_fdatawait_range(struct address_space *, loff_t lstart, loff_t lend); +extern int filemap_fdatawait_range_since(struct address_space *mapping, + loff_t start_byte, loff_t end_byte, + errseq_t since); extern int filemap_write_and_wait(struct address_space *mapping); +extern int filemap_write_and_wait_since(struct address_space *mapping, + errseq_t since); extern int filemap_write_and_wait_range(struct address_space *mapping, loff_t lstart, loff_t lend); +extern int filemap_write_and_wait_range_since(struct address_space *mapping, + loff_t start_byte, loff_t end_byte, + errseq_t since); extern int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start, loff_t end, int sync_mode); extern int filemap_fdatawrite_range(struct address_space *mapping, diff --git a/mm/filemap.c b/mm/filemap.c index 97dc28f853fc..38a14dc825ad 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -431,6 +431,14 @@ int filemap_fdatawait_range(struct address_space *mapping, loff_t start_byte, } EXPORT_SYMBOL(filemap_fdatawait_range); +int filemap_fdatawait_range_since(struct address_space *mapping, loff_t start_byte, + loff_t end_byte, errseq_t since) +{ + __filemap_fdatawait_range(mapping, start_byte, end_byte); + return filemap_check_wb_err(mapping, since); +} +EXPORT_SYMBOL(filemap_fdatawait_range_since); + /** * filemap_fdatawait_keep_errors - wait for writeback without clearing errors * @mapping: address space structure to wait for @@ -476,6 +484,17 @@ int filemap_fdatawait(struct address_space *mapping) } EXPORT_SYMBOL(filemap_fdatawait); +int filemap_fdatawait_since(struct address_space *mapping, errseq_t since) +{ + loff_t i_size = i_size_read(mapping->host); + + if (i_size == 0) + return 0; + + return filemap_fdatawait_range_since(mapping, 0, i_size - 1, since); +} +EXPORT_SYMBOL(filemap_fdatawait_since); + int filemap_write_and_wait(struct address_space *mapping) { int err = 0; @@ -501,6 +520,31 @@ int filemap_write_and_wait(struct address_space *mapping) } EXPORT_SYMBOL(filemap_write_and_wait); +int filemap_write_and_wait_since(struct address_space *mapping, errseq_t since) +{ + int err = 0; + + if ((!dax_mapping(mapping) && mapping->nrpages) || + (dax_mapping(mapping) && mapping->nrexceptional)) { + err = filemap_fdatawrite(mapping); + /* + * Even if the above returned error, the pages may be + * written partially (e.g. -ENOSPC), so we wait for it. + * But the -EIO is special case, it may indicate the worst + * thing (e.g. bug) happened, so we avoid waiting for it. + */ + if (err != -EIO) { + int err2 = filemap_fdatawait_since(mapping, since); + if (!err) + err = err2; + } + } else { + err = filemap_check_wb_err(mapping, since); + } + return err; +} +EXPORT_SYMBOL(filemap_write_and_wait_since); + /** * filemap_write_and_wait_range - write out & wait on a file range * @mapping: the address_space for the pages @@ -535,6 +579,29 @@ int filemap_write_and_wait_range(struct address_space *mapping, } EXPORT_SYMBOL(filemap_write_and_wait_range); +int filemap_write_and_wait_range_since(struct address_space *mapping, + loff_t lstart, loff_t lend, errseq_t since) +{ + int err = 0; + + if ((!dax_mapping(mapping) && mapping->nrpages) || + (dax_mapping(mapping) && mapping->nrexceptional)) { + err = __filemap_fdatawrite_range(mapping, lstart, lend, + WB_SYNC_ALL); + /* See comment of filemap_write_and_wait() */ + if (err != -EIO) { + int err2 = filemap_fdatawait_range_since(mapping, + lstart, lend, since); + if (!err) + err = err2; + } + } else { + err = filemap_check_wb_err(mapping, since); + } + return err; +} +EXPORT_SYMBOL(filemap_write_and_wait_range_since); + void __filemap_set_wb_err(struct address_space *mapping, int err) { errseq_t eseq = __errseq_set(&mapping->wb_err, err);