From patchwork Wed May 31 12:45:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 9756859 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 CF7FF60390 for ; Wed, 31 May 2017 12:47:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C358221E5A for ; Wed, 31 May 2017 12:47:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7A45283C9; Wed, 31 May 2017 12:47:32 +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 57AD221E5A for ; Wed, 31 May 2017 12:47:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751408AbdEaMqE (ORCPT ); Wed, 31 May 2017 08:46:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54662 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbdEaMqB (ORCPT ); Wed, 31 May 2017 08:46:01 -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 3DB309782F; Wed, 31 May 2017 12:45:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3DB309782F Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jlayton@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3DB309782F Received: from tleilax.poochiereds.net (ovpn-120-5.rdu2.redhat.com [10.10.120.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 240567E8FA; Wed, 31 May 2017 12:45:55 +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 11/17] fs: add f_md_wb_err field to struct file for tracking metadata errors Date: Wed, 31 May 2017 08:45:34 -0400 Message-Id: <20170531124540.8782-12-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.39]); Wed, 31 May 2017 12:45:56 +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 Some filesystems (particularly local ones) keep a different mapping for metadata writeback. Add a second errseq_t to struct file for tracking metadata writeback errors. Also add a new function for checking a mapping of the caller's choosing vs. the f_md_wb_err value. Signed-off-by: Jeff Layton --- include/linux/fs.h | 3 +++ include/trace/events/filemap.h | 23 ++++++++++------------- mm/filemap.c | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index f483c23866c4..df1d68e3605a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -871,6 +871,7 @@ struct file { struct list_head f_tfile_llink; #endif /* #ifdef CONFIG_EPOLL */ struct address_space *f_mapping; + errseq_t f_md_wb_err; /* optional metadata wb error tracking */ } __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */ struct file_handle { @@ -2549,6 +2550,8 @@ extern int filemap_fdatawrite_range(struct address_space *mapping, extern int filemap_check_errors(struct address_space *mapping); extern int __must_check filemap_report_wb_err(struct file *file); +extern int __must_check filemap_report_md_wb_err(struct file *file, + struct address_space *mapping); extern void __filemap_set_wb_err(struct address_space *mapping, int err); /** diff --git a/include/trace/events/filemap.h b/include/trace/events/filemap.h index 2af66920f267..6e0d78c01a2e 100644 --- a/include/trace/events/filemap.h +++ b/include/trace/events/filemap.h @@ -79,12 +79,11 @@ TRACE_EVENT(filemap_set_wb_err, ); TRACE_EVENT(filemap_report_wb_err, - TP_PROTO(struct file *file, errseq_t old), + TP_PROTO(struct address_space *mapping, errseq_t old, errseq_t new), - TP_ARGS(file, old), + TP_ARGS(mapping, old, new), TP_STRUCT__entry( - __field(struct file *, file); __field(unsigned long, i_ino) __field(dev_t, s_dev) __field(errseq_t, old) @@ -92,20 +91,18 @@ TRACE_EVENT(filemap_report_wb_err, ), TP_fast_assign( - __entry->file = file; - __entry->i_ino = file->f_mapping->host->i_ino; - if (file->f_mapping->host->i_sb) - __entry->s_dev = file->f_mapping->host->i_sb->s_dev; + __entry->i_ino = mapping->host->i_ino; + if (mapping->host->i_sb) + __entry->s_dev = mapping->host->i_sb->s_dev; else - __entry->s_dev = file->f_mapping->host->i_rdev; + __entry->s_dev = mapping->host->i_rdev; __entry->old = old; - __entry->new = file->f_wb_err; + __entry->new = new; ), - TP_printk("file=%p dev=%d:%d ino=0x%lx old=0x%x new=0x%x", - __entry->file, MAJOR(__entry->s_dev), - MINOR(__entry->s_dev), __entry->i_ino, __entry->old, - __entry->new) + TP_printk("dev=%d:%d ino=0x%lx old=0x%x new=0x%x", + MAJOR(__entry->s_dev), MINOR(__entry->s_dev), + __entry->i_ino, __entry->old, __entry->new) ); #endif /* _TRACE_FILEMAP_H */ diff --git a/mm/filemap.c b/mm/filemap.c index 38a14dc825ad..0edf0234973e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -631,21 +631,20 @@ EXPORT_SYMBOL(__filemap_set_wb_err); * value is protected by the f_lock since we must ensure that it reflects * the latest value swapped in for this file descriptor. */ -int filemap_report_wb_err(struct file *file) +static int __filemap_report_wb_err(errseq_t *cursor, spinlock_t *lock, + struct address_space *mapping) { int err = 0; - errseq_t old = READ_ONCE(file->f_wb_err); - struct address_space *mapping = file->f_mapping; + errseq_t old = READ_ONCE(*cursor); /* Locklessly handle the common case where nothing has changed */ if (errseq_check(&mapping->wb_err, old)) { /* Something changed, must use slow path */ - spin_lock(&file->f_lock); - old = file->f_wb_err; - err = errseq_check_and_advance(&mapping->wb_err, - &file->f_wb_err); - trace_filemap_report_wb_err(file, old); - spin_unlock(&file->f_lock); + spin_lock(lock); + old = *cursor; + err = errseq_check_and_advance(&mapping->wb_err, cursor); + trace_filemap_report_wb_err(mapping, old, *cursor); + spin_unlock(lock); } /* Now clear the AS_* flags if any are set */ @@ -656,9 +655,32 @@ int filemap_report_wb_err(struct file *file) return err; } +EXPORT_SYMBOL(__filemap_report_wb_err); + +int filemap_report_wb_err(struct file *file) +{ + return __filemap_report_wb_err(&file->f_wb_err, &file->f_lock, + file->f_mapping); +} EXPORT_SYMBOL(filemap_report_wb_err); /** + * filemap_report_md_wb_err - report wb error (if any) that was previously set + * @file: struct file on which the error is being reported + * @mapping: pointer to metadata mapping to check + * + * Many filesystems keep inode metadata in the pagecache, and will use the + * cache to write it back to the backing store. This function is for these + * callers to track metadata writeback. + */ +int filemap_report_md_wb_err(struct file *file, struct address_space *mapping) +{ + return __filemap_report_wb_err(&file->f_md_wb_err, &file->f_lock, + mapping); +} +EXPORT_SYMBOL(filemap_report_md_wb_err); + +/** * replace_page_cache_page - replace a pagecache page with a new one * @old: page to be replaced * @new: page to replace with