fs: Add helper to clean bdev aliases under a bh and use it
authorJan Kara <jack@suse.cz>
Fri, 4 Nov 2016 17:08:15 +0000 (18:08 +0100)
committerJens Axboe <axboe@fb.com>
Fri, 4 Nov 2016 20:34:47 +0000 (14:34 -0600)
Add a helper function that clears buffer heads from a block device
aliasing passed bh. Use this helper function from filesystems instead of
the original unmap_underlying_metadata() to save some boiler plate code
and also have a better name for the functionalily since it is not
unmapping anything for a *long* time.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@fb.com>
fs/buffer.c
fs/ext4/inode.c
fs/ext4/page-io.c
fs/mpage.c
fs/ntfs/aops.c
fs/ntfs/file.c
fs/ocfs2/aops.c
fs/ufs/balloc.c
fs/ufs/inode.c
include/linux/buffer_head.h

index f8beca55240a2ef048a4a6c4021082588ded3079..912d70169fca0f0b3621b055b5986e0b58fd682f 100644 (file)
@@ -1821,8 +1821,7 @@ int __block_write_full_page(struct inode *inode, struct page *page,
                        if (buffer_new(bh)) {
                                /* blockdev mappings never come here */
                                clear_buffer_new(bh);
-                               unmap_underlying_metadata(bh->b_bdev,
-                                                       bh->b_blocknr);
+                               clean_bdev_bh_alias(bh);
                        }
                }
                bh = bh->b_this_page;
@@ -2068,8 +2067,7 @@ int __block_write_begin_int(struct page *page, loff_t pos, unsigned len,
                        }
 
                        if (buffer_new(bh)) {
-                               unmap_underlying_metadata(bh->b_bdev,
-                                                       bh->b_blocknr);
+                               clean_bdev_bh_alias(bh);
                                if (PageUptodate(page)) {
                                        clear_buffer_new(bh);
                                        set_buffer_uptodate(bh);
@@ -2709,7 +2707,7 @@ int nobh_write_begin(struct address_space *mapping,
                if (!buffer_mapped(bh))
                        is_mapped_to_disk = 0;
                if (buffer_new(bh))
-                       unmap_underlying_metadata(bh->b_bdev, bh->b_blocknr);
+                       clean_bdev_bh_alias(bh);
                if (PageUptodate(page)) {
                        set_buffer_uptodate(bh);
                        continue;
index 7c7cc4ae4b8e6df59c18f434bf01058108beb293..2f8127601befc0f47bace3080ff6ec1975935d43 100644 (file)
@@ -1123,8 +1123,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
                        if (err)
                                break;
                        if (buffer_new(bh)) {
-                               unmap_underlying_metadata(bh->b_bdev,
-                                                         bh->b_blocknr);
+                               clean_bdev_bh_alias(bh);
                                if (PageUptodate(page)) {
                                        clear_buffer_new(bh);
                                        set_buffer_uptodate(bh);
index e0b3b54cdef32651d32685bc6cfe56ae23602dcf..f28fd6483e0453c8f0bff5ea352d54344b8e0669 100644 (file)
@@ -457,7 +457,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
                }
                if (buffer_new(bh)) {
                        clear_buffer_new(bh);
-                       unmap_underlying_metadata(bh->b_bdev, bh->b_blocknr);
+                       clean_bdev_bh_alias(bh);
                }
                set_buffer_async_write(bh);
                nr_to_submit++;
index 98fc11aa7e0b725b56154f44c37d11c842397df9..28af984a3d96f11f8848d0c5e04911773a3cc0f8 100644 (file)
@@ -555,8 +555,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
                if (mpd->get_block(inode, block_in_file, &map_bh, 1))
                        goto confused;
                if (buffer_new(&map_bh))
-                       unmap_underlying_metadata(map_bh.b_bdev,
-                                               map_bh.b_blocknr);
+                       clean_bdev_bh_alias(&map_bh);
                if (buffer_boundary(&map_bh)) {
                        boundary_block = map_bh.b_blocknr;
                        boundary_bdev = map_bh.b_bdev;
index d0cf6fee5c77fe0aa6c04046731bab12ed649be5..cc91856b5e2d926a6ac27166bfdb2156e29f7d9e 100644 (file)
@@ -765,7 +765,7 @@ lock_retry_remap:
                        }
                        // TODO: Instantiate the hole.
                        // clear_buffer_new(bh);
-                       // unmap_underlying_metadata(bh->b_bdev, bh->b_blocknr);
+                       // clean_bdev_bh_alias(bh);
                        ntfs_error(vol->sb, "Writing into sparse regions is "
                                        "not supported yet. Sorry.");
                        err = -EOPNOTSUPP;
index bf72a2c58b75b4d2a5de956a00d1eb59af2039bb..99510d811a8c87bbaba51419a63816a7036ece89 100644 (file)
@@ -740,8 +740,7 @@ map_buffer_cached:
                                        set_buffer_uptodate(bh);
                                if (unlikely(was_hole)) {
                                        /* We allocated the buffer. */
-                                       unmap_underlying_metadata(bh->b_bdev,
-                                                       bh->b_blocknr);
+                                       clean_bdev_bh_alias(bh);
                                        if (bh_end <= pos || bh_pos >= end)
                                                mark_buffer_dirty(bh);
                                        else
@@ -784,7 +783,7 @@ map_buffer_cached:
                                continue;
                        }
                        /* We allocated the buffer. */
-                       unmap_underlying_metadata(bh->b_bdev, bh->b_blocknr);
+                       clean_bdev_bh_alias(bh);
                        /*
                         * If the buffer is fully outside the write, zero it,
                         * set it uptodate, and mark it dirty so it gets
index c5c5b9748ea3b886d03bdcef6830f39d1b9ca14f..e8f65eefffca81a9dfa2163cd544698107fdaca1 100644 (file)
@@ -630,7 +630,7 @@ int ocfs2_map_page_blocks(struct page *page, u64 *p_blkno,
 
                if (!buffer_mapped(bh)) {
                        map_bh(bh, inode->i_sb, *p_blkno);
-                       unmap_underlying_metadata(bh->b_bdev, bh->b_blocknr);
+                       clean_bdev_bh_alias(bh);
                }
 
                if (PageUptodate(page)) {
index b035af54f538324f7904267228632177fd92fa13..a0376a2c1c29c7adc4a7a60976efd0bf49c8c9dd 100644 (file)
@@ -307,8 +307,7 @@ static void ufs_change_blocknr(struct inode *inode, sector_t beg,
                             (unsigned long long)(pos + newb), pos);
 
                        bh->b_blocknr = newb + pos;
-                       unmap_underlying_metadata(bh->b_bdev,
-                                                 bh->b_blocknr);
+                       clean_bdev_bh_alias(bh);
                        mark_buffer_dirty(bh);
                        ++j;
                        bh = bh->b_this_page;
index 190d64be22ed8c8ba0e2212673ea39ff017d3302..45ceb94e89e42a362d633a35d2861e2808910e1a 100644 (file)
@@ -1070,8 +1070,7 @@ static int ufs_alloc_lastblock(struct inode *inode, loff_t size)
 
        if (buffer_new(bh)) {
               clear_buffer_new(bh);
-              unmap_underlying_metadata(bh->b_bdev,
-                                        bh->b_blocknr);
+              clean_bdev_bh_alias(bh);
               /*
                * we do not zeroize fragment, because of
                * if it maped to hole, it already contains zeroes
index 9c9c73ce7d4f8f438710e56175f467b91e337803..d1ab91fc6d43e30ee26a6922ff285f3fc6f48235 100644 (file)
@@ -171,6 +171,10 @@ int sync_mapping_buffers(struct address_space *mapping);
 void unmap_underlying_metadata(struct block_device *bdev, sector_t block);
 void clean_bdev_aliases(struct block_device *bdev, sector_t block,
                        sector_t len);
+static inline void clean_bdev_bh_alias(struct buffer_head *bh)
+{
+       clean_bdev_aliases(bh->b_bdev, bh->b_blocknr, 1);
+}
 
 void mark_buffer_async_write(struct buffer_head *bh);
 void __wait_on_buffer(struct buffer_head *);