linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Jens@suse.cz, "Axboe <axboe"@kernel.dk
Cc: Christoph Hellwig <hch@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: [PATCH 3/3] bdi: Fix warnings in __mark_inode_dirty for /dev/zero and friends
Date: Fri, 17 Sep 2010 00:44:11 +0200	[thread overview]
Message-ID: <1284677051-28564-4-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1284677051-28564-1-git-send-email-jack@suse.cz>

Inodes of devices such as /dev/zero can get dirty for example via utime(2)
syscall or due to atime update. Backing device of such inodes (zero_bdi, etc.)
is however unable to handle dirty inodes and thus __mark_inode_dirty complains.
In fact, inode should be rather dirtied against backing device of the
filesystem holding it. This is generally a good rule except for filesystems
such as 'bdev' or 'mtd_inodefs'. Inodes in these pseudofilesystems are
referenced from ordinary filesystem inodes and carry mapping with real data of
the device. Thus for these inodes we have to use
inode->i_mapping->backing_dev_info as we did so far. We distinguish these
filesystems by checking whether sb->s_bdi points to a non-trivial backing
device or not.

Example: Assume we have an ext3 filesystem on /dev/sda1 mounted on /. There's a
device inode A described by a path "/dev/sdb" on this filesystem. This inode
will be dirtied against backing device "8:0" after this patch. bdev filesystem
contains block device inode B coupled with our inode A. When someone modifies a
page of /dev/sdb, it's B that gets dirtied and the dirtying happens against the
backing device "8:16". Thus both inodes get filed to a correct bdi list.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/fs-writeback.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 49fd41a..7dad208 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -52,8 +52,6 @@ struct wb_writeback_work {
 #define CREATE_TRACE_POINTS
 #include <trace/events/writeback.h>
 
-#define inode_to_bdi(inode)	((inode)->i_mapping->backing_dev_info)
-
 /*
  * We don't actually have pdflush, but this one is exported though /proc...
  */
@@ -71,6 +69,27 @@ int writeback_in_progress(struct backing_dev_info *bdi)
 	return test_bit(BDI_writeback_running, &bdi->state);
 }
 
+static inline struct backing_dev_info *inode_to_bdi(struct inode *inode)
+{
+	struct super_block *sb = inode->i_sb;
+	struct backing_dev_info *bdi = inode->i_mapping->backing_dev_info;
+
+	/*
+	 * For inodes on standard filesystems, we use superblock's bdi. For
+	 * inodes on virtual filesystems, we want to use inode mapping's bdi
+	 * because they can possibly point to something useful (think about
+	 * block_dev filesystem).
+	 */
+	if (sb->s_bdi && sb->s_bdi != &noop_backing_dev_info) {
+		/* Some device inodes could play dirty tricks. Catch them... */
+		WARN(bdi != sb->s_bdi && bdi_cap_writeback_dirty(bdi),
+			"Dirtiable inode bdi %s != sb bdi %s\n",
+			bdi->name, sb->s_bdi->name);
+		return sb->s_bdi;
+	}
+	return bdi;
+}
+
 /* Wakeup flusher thread or forker thread to fork it. Requires bdi->wb_lock. */
 static void _bdi_wakeup_flusher(struct backing_dev_info *bdi)
 {
-- 
1.6.4.2


  parent reply	other threads:[~2010-09-16 22:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-16 22:44 [PATCH 0/3] BDI handling fixes Jan Kara
2010-09-16 22:44 ` [PATCH 1/3] bdi: Initialize noop_backing_dev_info properly Jan Kara
2010-09-16 22:44 ` [PATCH 2/3] char: Mark /dev/zero and /dev/kmem as not capable of writeback Jan Kara
2010-09-16 22:44 ` Jan Kara [this message]
2010-09-16 23:47 ` [PATCH 0/3] BDI handling fixes Christoph Hellwig
2010-09-17 12:52   ` Jan Kara
2010-09-17 13:44     ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2010-09-20 15:44 [PATCH 0/3 RESEND] " Jan Kara
2010-09-20 15:44 ` [PATCH 3/3] bdi: Fix warnings in __mark_inode_dirty for /dev/zero and friends Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284677051-28564-4-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc="Axboe <axboe"@kernel.dk \
    --cc=Jens@suse.cz \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).