[RFC PATCH 51/79] fs: stop relying on mapping field of struct page, get it from context
From: jglisse
Date: Wed Apr 04 2018 - 15:22:07 EST
From: JÃrÃme Glisse <jglisse@xxxxxxxxxx>
Holy grail, remove all usage of mapping field of struct page inside
common fs code. This is the manual conversion patch (so much can be
done with coccinelle).
Signed-off-by: JÃrÃme Glisse <jglisse@xxxxxxxxxx>
Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Cc: Jens Axboe <axboe@xxxxxxxxx>
Cc: Tejun Heo <tj@xxxxxxxxxx>
Cc: Jan Kara <jack@xxxxxxx>
Cc: Josef Bacik <jbacik@xxxxxx>
Cc: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx>
---
fs/buffer.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 39d8c7315b55..3c424b7af5af 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -570,7 +570,9 @@ void write_boundary_block(struct block_device *bdev,
void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode)
{
struct address_space *mapping = inode->i_mapping;
- struct address_space *buffer_mapping = bh->b_page->mapping;
+ struct address_space *buffer_mapping;
+
+ buffer_mapping = fs_page_mapping_get_with_bh(bh->b_page, bh);
mark_buffer_dirty(bh);
if (!mapping->private_data) {
@@ -1138,10 +1140,13 @@ EXPORT_SYMBOL(mark_buffer_dirty);
void mark_buffer_write_io_error(struct address_space *mapping,
struct page *page, struct buffer_head *bh)
{
+ BUG_ON(page != bh->b_page);
+ BUG_ON(mapping != bh->b_page->mapping);
+
set_buffer_write_io_error(bh);
/* FIXME: do we need to set this in both places? */
- if (bh->b_page && !page_is_truncated(bh->b_page, bh->b_page->mapping))
- mapping_set_error(bh->b_page->mapping, -EIO);
+ if (bh->b_page && !page_is_truncated(page, mapping))
+ mapping_set_error(mapping, -EIO);
if (bh->b_assoc_map)
mapping_set_error(bh->b_assoc_map, -EIO);
}
@@ -1172,7 +1177,10 @@ void __bforget(struct super_block *sb, struct buffer_head *bh)
{
clear_buffer_dirty(bh);
if (bh->b_assoc_map) {
- struct address_space *buffer_mapping = bh->b_page->mapping;
+ struct address_space *buffer_mapping;
+
+ buffer_mapping = sb->s_bdev->bd_inode->i_mapping;
+ BUG_ON(buffer_mapping != bh->b_page->mapping);
spin_lock(&buffer_mapping->private_lock);
list_del_init(&bh->b_assoc_buffers);
@@ -1543,7 +1551,7 @@ void create_empty_buffers(struct address_space *mapping, struct page *page,
} while (bh);
tail->b_this_page = head;
- spin_lock(&page->mapping->private_lock);
+ spin_lock(&mapping->private_lock);
if (PageUptodate(page) || PageDirty(page)) {
bh = head;
do {
@@ -1555,7 +1563,7 @@ void create_empty_buffers(struct address_space *mapping, struct page *page,
} while (bh != head);
}
attach_page_buffers(page, head);
- spin_unlock(&page->mapping->private_lock);
+ spin_unlock(&mapping->private_lock);
}
EXPORT_SYMBOL(create_empty_buffers);
@@ -1833,7 +1841,7 @@ int __block_write_full_page(struct inode *inode, struct page *page,
} while ((bh = bh->b_this_page) != head);
SetPageError(page);
BUG_ON(PageWriteback(page));
- mapping_set_error(page->mapping, err);
+ mapping_set_error(inode->i_mapping, err);
set_page_writeback(page);
do {
struct buffer_head *next = bh->b_this_page;
@@ -2541,7 +2549,7 @@ static void attach_nobh_buffers(struct address_space *mapping,
BUG_ON(!PageLocked(page));
- spin_lock(&page->mapping->private_lock);
+ spin_lock(&mapping->private_lock);
bh = head;
do {
if (PageDirty(page))
@@ -2551,7 +2559,7 @@ static void attach_nobh_buffers(struct address_space *mapping,
bh = bh->b_this_page;
} while (bh != head);
attach_page_buffers(page, head);
- spin_unlock(&page->mapping->private_lock);
+ spin_unlock(&mapping->private_lock);
}
/*
--
2.14.3