mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 10:57:46 +00:00
xfs: simplify xfs_aops_discard_page
Instead of looking at the buffer heads to see if a block is delalloc just call xfs_bmap_punch_delalloc_range on the whole page - this will leave any non-delalloc block intact and handle the iteration for us. As a side effect one more place stops caring about buffer heads and we can remove the xfs_check_page_type function entirely. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
parent
8b2e77c163
commit
0362572138
1 changed files with 9 additions and 76 deletions
|
@ -710,49 +710,6 @@ xfs_map_at_offset(
|
||||||
clear_buffer_unwritten(bh);
|
clear_buffer_unwritten(bh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Test if a given page contains at least one buffer of a given @type.
|
|
||||||
* If @check_all_buffers is true, then we walk all the buffers in the page to
|
|
||||||
* try to find one of the type passed in. If it is not set, then the caller only
|
|
||||||
* needs to check the first buffer on the page for a match.
|
|
||||||
*/
|
|
||||||
STATIC bool
|
|
||||||
xfs_check_page_type(
|
|
||||||
struct page *page,
|
|
||||||
unsigned int type,
|
|
||||||
bool check_all_buffers)
|
|
||||||
{
|
|
||||||
struct buffer_head *bh;
|
|
||||||
struct buffer_head *head;
|
|
||||||
|
|
||||||
if (PageWriteback(page))
|
|
||||||
return false;
|
|
||||||
if (!page->mapping)
|
|
||||||
return false;
|
|
||||||
if (!page_has_buffers(page))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bh = head = page_buffers(page);
|
|
||||||
do {
|
|
||||||
if (buffer_unwritten(bh)) {
|
|
||||||
if (type == XFS_IO_UNWRITTEN)
|
|
||||||
return true;
|
|
||||||
} else if (buffer_delay(bh)) {
|
|
||||||
if (type == XFS_IO_DELALLOC)
|
|
||||||
return true;
|
|
||||||
} else if (buffer_dirty(bh) && buffer_mapped(bh)) {
|
|
||||||
if (type == XFS_IO_OVERWRITE)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we are only checking the first buffer, we are done now. */
|
|
||||||
if (!check_all_buffers)
|
|
||||||
break;
|
|
||||||
} while ((bh = bh->b_this_page) != head);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
STATIC void
|
STATIC void
|
||||||
xfs_vm_invalidatepage(
|
xfs_vm_invalidatepage(
|
||||||
struct page *page,
|
struct page *page,
|
||||||
|
@ -784,9 +741,6 @@ xfs_vm_invalidatepage(
|
||||||
* transaction. Indeed - if we get ENOSPC errors, we have to be able to do this
|
* transaction. Indeed - if we get ENOSPC errors, we have to be able to do this
|
||||||
* truncation without a transaction as there is no space left for block
|
* truncation without a transaction as there is no space left for block
|
||||||
* reservation (typically why we see a ENOSPC in writeback).
|
* reservation (typically why we see a ENOSPC in writeback).
|
||||||
*
|
|
||||||
* This is not a performance critical path, so for now just do the punching a
|
|
||||||
* buffer head at a time.
|
|
||||||
*/
|
*/
|
||||||
STATIC void
|
STATIC void
|
||||||
xfs_aops_discard_page(
|
xfs_aops_discard_page(
|
||||||
|
@ -794,47 +748,26 @@ xfs_aops_discard_page(
|
||||||
{
|
{
|
||||||
struct inode *inode = page->mapping->host;
|
struct inode *inode = page->mapping->host;
|
||||||
struct xfs_inode *ip = XFS_I(inode);
|
struct xfs_inode *ip = XFS_I(inode);
|
||||||
struct buffer_head *bh, *head;
|
struct xfs_mount *mp = ip->i_mount;
|
||||||
loff_t offset = page_offset(page);
|
loff_t offset = page_offset(page);
|
||||||
|
xfs_fileoff_t start_fsb = XFS_B_TO_FSBT(mp, offset);
|
||||||
|
int error;
|
||||||
|
|
||||||
if (!xfs_check_page_type(page, XFS_IO_DELALLOC, true))
|
if (XFS_FORCED_SHUTDOWN(mp))
|
||||||
goto out_invalidate;
|
goto out_invalidate;
|
||||||
|
|
||||||
if (XFS_FORCED_SHUTDOWN(ip->i_mount))
|
xfs_alert(mp,
|
||||||
goto out_invalidate;
|
|
||||||
|
|
||||||
xfs_alert(ip->i_mount,
|
|
||||||
"page discard on page "PTR_FMT", inode 0x%llx, offset %llu.",
|
"page discard on page "PTR_FMT", inode 0x%llx, offset %llu.",
|
||||||
page, ip->i_ino, offset);
|
page, ip->i_ino, offset);
|
||||||
|
|
||||||
xfs_ilock(ip, XFS_ILOCK_EXCL);
|
xfs_ilock(ip, XFS_ILOCK_EXCL);
|
||||||
bh = head = page_buffers(page);
|
error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
|
||||||
do {
|
PAGE_SIZE / i_blocksize(inode));
|
||||||
int error;
|
|
||||||
xfs_fileoff_t start_fsb;
|
|
||||||
|
|
||||||
if (!buffer_delay(bh))
|
|
||||||
goto next_buffer;
|
|
||||||
|
|
||||||
start_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
|
|
||||||
error = xfs_bmap_punch_delalloc_range(ip, start_fsb, 1);
|
|
||||||
if (error) {
|
|
||||||
/* something screwed, just bail */
|
|
||||||
if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
|
|
||||||
xfs_alert(ip->i_mount,
|
|
||||||
"page discard unable to remove delalloc mapping.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
next_buffer:
|
|
||||||
offset += i_blocksize(inode);
|
|
||||||
|
|
||||||
} while ((bh = bh->b_this_page) != head);
|
|
||||||
|
|
||||||
xfs_iunlock(ip, XFS_ILOCK_EXCL);
|
xfs_iunlock(ip, XFS_ILOCK_EXCL);
|
||||||
|
if (error && !XFS_FORCED_SHUTDOWN(mp))
|
||||||
|
xfs_alert(mp, "page discard unable to remove delalloc mapping.");
|
||||||
out_invalidate:
|
out_invalidate:
|
||||||
xfs_vm_invalidatepage(page, 0, PAGE_SIZE);
|
xfs_vm_invalidatepage(page, 0, PAGE_SIZE);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in a new issue