Skip to content

Commit 76c0021

Browse files
Liu Bokdave
authored andcommitted
Btrfs: use helper to simplify lock/unlock pages
Since we have a helper to set page bits, let lock_delalloc_pages and __unlock_for_delalloc use it. Signed-off-by: Liu Bo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent da2c700 commit 76c0021

File tree

1 file changed

+10
-64
lines changed

1 file changed

+10
-64
lines changed

fs/btrfs/extent_io.c

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,29 +1563,15 @@ static noinline void __unlock_for_delalloc(struct inode *inode,
15631563
struct page *locked_page,
15641564
u64 start, u64 end)
15651565
{
1566-
int ret;
1567-
struct page *pages[16];
15681566
unsigned long index = start >> PAGE_SHIFT;
15691567
unsigned long end_index = end >> PAGE_SHIFT;
1570-
unsigned long nr_pages = end_index - index + 1;
1571-
int i;
15721568

1569+
ASSERT(locked_page);
15731570
if (index == locked_page->index && end_index == index)
15741571
return;
15751572

1576-
while (nr_pages > 0) {
1577-
ret = find_get_pages_contig(inode->i_mapping, index,
1578-
min_t(unsigned long, nr_pages,
1579-
ARRAY_SIZE(pages)), pages);
1580-
for (i = 0; i < ret; i++) {
1581-
if (pages[i] != locked_page)
1582-
unlock_page(pages[i]);
1583-
put_page(pages[i]);
1584-
}
1585-
nr_pages -= ret;
1586-
index += ret;
1587-
cond_resched();
1588-
}
1573+
__process_pages_contig(inode->i_mapping, locked_page, index, end_index,
1574+
PAGE_UNLOCK, NULL);
15891575
}
15901576

15911577
static noinline int lock_delalloc_pages(struct inode *inode,
@@ -1594,59 +1580,19 @@ static noinline int lock_delalloc_pages(struct inode *inode,
15941580
u64 delalloc_end)
15951581
{
15961582
unsigned long index = delalloc_start >> PAGE_SHIFT;
1597-
unsigned long start_index = index;
1583+
unsigned long index_ret = index;
15981584
unsigned long end_index = delalloc_end >> PAGE_SHIFT;
1599-
unsigned long pages_locked = 0;
1600-
struct page *pages[16];
1601-
unsigned long nrpages;
16021585
int ret;
1603-
int i;
16041586

1605-
/* the caller is responsible for locking the start index */
1587+
ASSERT(locked_page);
16061588
if (index == locked_page->index && index == end_index)
16071589
return 0;
16081590

1609-
/* skip the page at the start index */
1610-
nrpages = end_index - index + 1;
1611-
while (nrpages > 0) {
1612-
ret = find_get_pages_contig(inode->i_mapping, index,
1613-
min_t(unsigned long,
1614-
nrpages, ARRAY_SIZE(pages)), pages);
1615-
if (ret == 0) {
1616-
ret = -EAGAIN;
1617-
goto done;
1618-
}
1619-
/* now we have an array of pages, lock them all */
1620-
for (i = 0; i < ret; i++) {
1621-
/*
1622-
* the caller is taking responsibility for
1623-
* locked_page
1624-
*/
1625-
if (pages[i] != locked_page) {
1626-
lock_page(pages[i]);
1627-
if (!PageDirty(pages[i]) ||
1628-
pages[i]->mapping != inode->i_mapping) {
1629-
ret = -EAGAIN;
1630-
unlock_page(pages[i]);
1631-
put_page(pages[i]);
1632-
goto done;
1633-
}
1634-
}
1635-
put_page(pages[i]);
1636-
pages_locked++;
1637-
}
1638-
nrpages -= ret;
1639-
index += ret;
1640-
cond_resched();
1641-
}
1642-
ret = 0;
1643-
done:
1644-
if (ret && pages_locked) {
1645-
__unlock_for_delalloc(inode, locked_page,
1646-
delalloc_start,
1647-
((u64)(start_index + pages_locked - 1)) <<
1648-
PAGE_SHIFT);
1649-
}
1591+
ret = __process_pages_contig(inode->i_mapping, locked_page, index,
1592+
end_index, PAGE_LOCK, &index_ret);
1593+
if (ret == -EAGAIN)
1594+
__unlock_for_delalloc(inode, locked_page, delalloc_start,
1595+
(u64)index_ret << PAGE_SHIFT);
16501596
return ret;
16511597
}
16521598

0 commit comments

Comments
 (0)