From patchwork Mon Jun 12 12:23:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 9780839 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 6675B60244 for ; Mon, 12 Jun 2017 12:23:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E5C626E49 for ; Mon, 12 Jun 2017 12:23:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4332D27FA1; Mon, 12 Jun 2017 12:23:40 +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 EE64826E49 for ; Mon, 12 Jun 2017 12:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752198AbdFLMXf (ORCPT ); Mon, 12 Jun 2017 08:23:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53546 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752062AbdFLMXd (ORCPT ); Mon, 12 Jun 2017 08:23:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E70A7C0587DA; Mon, 12 Jun 2017 12:23:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E70A7C0587DA Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jlayton@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E70A7C0587DA Received: from tleilax.poochiereds.net (ovpn-120-91.rdu2.redhat.com [10.10.120.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id A316082F82; Mon, 12 Jun 2017 12:23:31 +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, Chris Mason , Josef Bacik , David Sterba , "Darrick J . Wong" Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v6 10/13] ext4: add more robust reporting of metadata writeback errors Date: Mon, 12 Jun 2017 08:23:02 -0400 Message-Id: <20170612122316.13244-11-jlayton@redhat.com> In-Reply-To: <20170612122316.13244-1-jlayton@redhat.com> References: <20170612122316.13244-1-jlayton@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 12 Jun 2017 12:23:33 +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 ext4 uses the blockdev mapping for tracking metadata stored in the pagecache. Sample its wb_err when opening a file and store that in the f_md_wb_err field. Change ext4_sync_file to check for data errors first, and then check the blockdev mapping for metadata errors afterward. Note that because metadata writeback errors are only tracked on a per-device level, this does mean that we'll end up reporting an error on all open file descriptors when there is a metadata writeback failure. That's not ideal, but we can possibly improve upon it in the future. Signed-off-by: Jeff Layton --- fs/ext4/dir.c | 8 ++++++-- fs/ext4/file.c | 5 ++++- fs/ext4/fsync.c | 13 +++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index e8b365000d73..6bbb19510f74 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -611,9 +611,13 @@ static int ext4_dx_readdir(struct file *file, struct dir_context *ctx) static int ext4_dir_open(struct inode * inode, struct file * filp) { + int ret = 0; + if (ext4_encrypted_inode(inode)) - return fscrypt_get_encryption_info(inode) ? -EACCES : 0; - return 0; + ret = fscrypt_get_encryption_info(inode) ? -EACCES : 0; + if (!ret) + filp->f_md_wb_err = filemap_sample_wb_err(inode->i_sb->s_bdev->bd_inode->i_mapping); + return ret; } static int ext4_release_dir(struct inode *inode, struct file *filp) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 831fd6beebf0..fe0d6e01c4b7 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -435,7 +435,10 @@ static int ext4_file_open(struct inode * inode, struct file * filp) if (ret < 0) return ret; } - return dquot_file_open(inode, filp); + ret = dquot_file_open(inode, filp); + if (!ret) + filp->f_md_wb_err = filemap_sample_wb_err(sb->s_bdev->bd_inode->i_mapping); + return ret; } /* diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index 03d6259d8662..36363a6730d7 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c @@ -165,6 +165,19 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) err = filemap_report_wb_err(file); if (!ret) ret = err; + + /* + * Was there a metadata writeback error since last fsync? + * + * FIXME: ext4 tracks metadata with a whole-block device mapping. So, + * if there is any sort of metadata writeback error, we'll report an + * error on all open fds, even ones not associated with the inode + */ + err = filemap_report_md_wb_err(file, + inode->i_sb->s_bdev->bd_inode->i_mapping); + if (!ret) + ret = err; + trace_ext4_sync_file_exit(inode, ret); return ret; }