[XFS] clean up the xfs_offset_to_map interface Currently we pass a struct
page and a relative offset into that page around, and returns the current xfs_iomap_t if the block at the specified offset fits into it, or a NULL pointer otherwise. This patch passed the full 64bit offset into the inode that all callers have anyway, and changes the return value to a simple boolean. Also the function gets a more descriptive name: xfs_iomap_valid. SGI-PV: 947118 SGI-Modid: xfs-linux-melb:xfs-kern:203825a Signed-off-by: Christoph Hellwig <hch@sgi.com> Signed-off-by: Nathan Scott <nathans@sgi.com>
This commit is contained in:
committed by
Nathan Scott
parent
10ce444428
commit
1defeac9d4
@@ -228,29 +228,13 @@ xfs_map_blocks(
|
|||||||
return -error;
|
return -error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
STATIC inline int
|
||||||
* Finds the corresponding mapping in block @map array of the
|
xfs_iomap_valid(
|
||||||
* given @offset within a @page.
|
|
||||||
*/
|
|
||||||
STATIC xfs_iomap_t *
|
|
||||||
xfs_offset_to_map(
|
|
||||||
struct page *page,
|
|
||||||
xfs_iomap_t *iomapp,
|
xfs_iomap_t *iomapp,
|
||||||
unsigned long offset)
|
loff_t offset)
|
||||||
{
|
{
|
||||||
xfs_off_t full_offset; /* offset from start of file */
|
return offset >= iomapp->iomap_offset &&
|
||||||
|
offset < iomapp->iomap_offset + iomapp->iomap_bsize;
|
||||||
ASSERT(offset < PAGE_CACHE_SIZE);
|
|
||||||
|
|
||||||
full_offset = page->index; /* NB: using 64bit number */
|
|
||||||
full_offset <<= PAGE_CACHE_SHIFT; /* offset from file start */
|
|
||||||
full_offset += offset; /* offset from page start */
|
|
||||||
|
|
||||||
if (full_offset < iomapp->iomap_offset)
|
|
||||||
return NULL;
|
|
||||||
if (iomapp->iomap_offset + (iomapp->iomap_bsize -1) >= full_offset)
|
|
||||||
return iomapp;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -461,31 +445,23 @@ xfs_add_to_ioend(
|
|||||||
|
|
||||||
STATIC void
|
STATIC void
|
||||||
xfs_map_at_offset(
|
xfs_map_at_offset(
|
||||||
struct page *page,
|
|
||||||
struct buffer_head *bh,
|
struct buffer_head *bh,
|
||||||
unsigned long offset,
|
loff_t offset,
|
||||||
int block_bits,
|
int block_bits,
|
||||||
xfs_iomap_t *iomapp,
|
xfs_iomap_t *iomapp)
|
||||||
xfs_ioend_t *ioend)
|
|
||||||
{
|
{
|
||||||
xfs_daddr_t bn;
|
xfs_daddr_t bn;
|
||||||
xfs_off_t delta;
|
|
||||||
int sector_shift;
|
int sector_shift;
|
||||||
|
|
||||||
ASSERT(!(iomapp->iomap_flags & IOMAP_HOLE));
|
ASSERT(!(iomapp->iomap_flags & IOMAP_HOLE));
|
||||||
ASSERT(!(iomapp->iomap_flags & IOMAP_DELAY));
|
ASSERT(!(iomapp->iomap_flags & IOMAP_DELAY));
|
||||||
ASSERT(iomapp->iomap_bn != IOMAP_DADDR_NULL);
|
ASSERT(iomapp->iomap_bn != IOMAP_DADDR_NULL);
|
||||||
|
|
||||||
delta = page->index;
|
|
||||||
delta <<= PAGE_CACHE_SHIFT;
|
|
||||||
delta += offset;
|
|
||||||
delta -= iomapp->iomap_offset;
|
|
||||||
delta >>= block_bits;
|
|
||||||
|
|
||||||
sector_shift = block_bits - BBSHIFT;
|
sector_shift = block_bits - BBSHIFT;
|
||||||
bn = iomapp->iomap_bn >> sector_shift;
|
bn = (iomapp->iomap_bn >> sector_shift) +
|
||||||
bn += delta;
|
((offset - iomapp->iomap_offset) >> block_bits);
|
||||||
BUG_ON(!bn && !(iomapp->iomap_flags & IOMAP_REALTIME));
|
|
||||||
|
ASSERT(bn || (iomapp->iomap_flags & IOMAP_REALTIME));
|
||||||
ASSERT((bn << sector_shift) >= iomapp->iomap_bn);
|
ASSERT((bn << sector_shift) >= iomapp->iomap_bn);
|
||||||
|
|
||||||
lock_buffer(bh);
|
lock_buffer(bh);
|
||||||
@@ -569,8 +545,10 @@ xfs_probe_unmapped_cluster(
|
|||||||
if (tindex == tlast) {
|
if (tindex == tlast) {
|
||||||
pg_offset =
|
pg_offset =
|
||||||
i_size_read(inode) & (PAGE_CACHE_SIZE - 1);
|
i_size_read(inode) & (PAGE_CACHE_SIZE - 1);
|
||||||
if (!pg_offset)
|
if (!pg_offset) {
|
||||||
|
done = 1;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
pg_offset = PAGE_CACHE_SIZE;
|
pg_offset = PAGE_CACHE_SIZE;
|
||||||
|
|
||||||
@@ -585,6 +563,7 @@ xfs_probe_unmapped_cluster(
|
|||||||
}
|
}
|
||||||
|
|
||||||
total += len;
|
total += len;
|
||||||
|
tindex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pagevec_release(&pvec);
|
pagevec_release(&pvec);
|
||||||
@@ -638,19 +617,19 @@ xfs_convert_page(
|
|||||||
struct inode *inode,
|
struct inode *inode,
|
||||||
struct page *page,
|
struct page *page,
|
||||||
loff_t tindex,
|
loff_t tindex,
|
||||||
xfs_iomap_t *iomapp,
|
xfs_iomap_t *mp,
|
||||||
xfs_ioend_t **ioendp,
|
xfs_ioend_t **ioendp,
|
||||||
struct writeback_control *wbc,
|
struct writeback_control *wbc,
|
||||||
int startio,
|
int startio,
|
||||||
int all_bh)
|
int all_bh)
|
||||||
{
|
{
|
||||||
struct buffer_head *bh, *head;
|
struct buffer_head *bh, *head;
|
||||||
xfs_iomap_t *mp = iomapp, *tmp;
|
|
||||||
unsigned long p_offset, end_offset;
|
unsigned long p_offset, end_offset;
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
int bbits = inode->i_blkbits;
|
int bbits = inode->i_blkbits;
|
||||||
int len, page_dirty;
|
int len, page_dirty;
|
||||||
int count = 0, done = 0, uptodate = 1;
|
int count = 0, done = 0, uptodate = 1;
|
||||||
|
xfs_off_t f_offset = page_offset(page);
|
||||||
|
|
||||||
if (page->index != tindex)
|
if (page->index != tindex)
|
||||||
goto fail;
|
goto fail;
|
||||||
@@ -703,15 +682,15 @@ xfs_convert_page(
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tmp = xfs_offset_to_map(page, mp, p_offset);
|
|
||||||
if (!tmp) {
|
if (!xfs_iomap_valid(mp, f_offset + p_offset)) {
|
||||||
done = 1;
|
done = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ASSERT(!(tmp->iomap_flags & IOMAP_HOLE));
|
ASSERT(!(mp->iomap_flags & IOMAP_HOLE));
|
||||||
ASSERT(!(tmp->iomap_flags & IOMAP_DELAY));
|
ASSERT(!(mp->iomap_flags & IOMAP_DELAY));
|
||||||
|
|
||||||
xfs_map_at_offset(page, bh, p_offset, bbits, tmp, *ioendp);
|
xfs_map_at_offset(bh, f_offset + p_offset, bbits, mp);
|
||||||
if (startio) {
|
if (startio) {
|
||||||
xfs_add_to_ioend(inode, bh, p_offset,
|
xfs_add_to_ioend(inode, bh, p_offset,
|
||||||
type, ioendp, done);
|
type, ioendp, done);
|
||||||
@@ -805,15 +784,14 @@ xfs_page_state_convert(
|
|||||||
int unmapped) /* also implies page uptodate */
|
int unmapped) /* also implies page uptodate */
|
||||||
{
|
{
|
||||||
struct buffer_head *bh, *head;
|
struct buffer_head *bh, *head;
|
||||||
xfs_iomap_t *iomp, iomap;
|
xfs_iomap_t iomap;
|
||||||
xfs_ioend_t *ioend = NULL, *iohead = NULL;
|
xfs_ioend_t *ioend = NULL, *iohead = NULL;
|
||||||
loff_t offset;
|
loff_t offset;
|
||||||
unsigned long p_offset = 0;
|
unsigned long p_offset = 0;
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
__uint64_t end_offset;
|
__uint64_t end_offset;
|
||||||
pgoff_t end_index, last_index, tlast;
|
pgoff_t end_index, last_index, tlast;
|
||||||
int flags, len, err, done = 1;
|
int flags, len, err, iomap_valid = 0, uptodate = 1;
|
||||||
int uptodate = 1;
|
|
||||||
int page_dirty, count = 0, trylock_flag = 0;
|
int page_dirty, count = 0, trylock_flag = 0;
|
||||||
|
|
||||||
/* wait for other IO threads? */
|
/* wait for other IO threads? */
|
||||||
@@ -854,11 +832,9 @@ xfs_page_state_convert(
|
|||||||
p_offset = p_offset ? roundup(p_offset, len) : PAGE_CACHE_SIZE;
|
p_offset = p_offset ? roundup(p_offset, len) : PAGE_CACHE_SIZE;
|
||||||
page_dirty = p_offset / len;
|
page_dirty = p_offset / len;
|
||||||
|
|
||||||
iomp = NULL;
|
|
||||||
bh = head = page_buffers(page);
|
bh = head = page_buffers(page);
|
||||||
offset = page_offset(page);
|
offset = page_offset(page);
|
||||||
|
|
||||||
/* TODO: fix up "done" variable and iomap pointer (boolean) */
|
|
||||||
/* TODO: cleanup count and page_dirty */
|
/* TODO: cleanup count and page_dirty */
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -867,14 +843,16 @@ xfs_page_state_convert(
|
|||||||
if (!buffer_uptodate(bh))
|
if (!buffer_uptodate(bh))
|
||||||
uptodate = 0;
|
uptodate = 0;
|
||||||
if (!(PageUptodate(page) || buffer_uptodate(bh)) && !startio) {
|
if (!(PageUptodate(page) || buffer_uptodate(bh)) && !startio) {
|
||||||
done = 1;
|
/*
|
||||||
|
* the iomap is actually still valid, but the ioend
|
||||||
|
* isn't. shouldn't happen too often.
|
||||||
|
*/
|
||||||
|
iomap_valid = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iomp) {
|
if (iomap_valid)
|
||||||
iomp = xfs_offset_to_map(page, &iomap, p_offset);
|
iomap_valid = xfs_iomap_valid(&iomap, offset);
|
||||||
done = (iomp == NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First case, map an unwritten extent and prepare for
|
* First case, map an unwritten extent and prepare for
|
||||||
@@ -894,22 +872,20 @@ xfs_page_state_convert(
|
|||||||
flags |= trylock_flag;
|
flags |= trylock_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iomp) {
|
if (!iomap_valid) {
|
||||||
done = 1;
|
|
||||||
err = xfs_map_blocks(inode, offset, len, &iomap,
|
err = xfs_map_blocks(inode, offset, len, &iomap,
|
||||||
flags);
|
flags);
|
||||||
if (err)
|
if (err)
|
||||||
goto error;
|
goto error;
|
||||||
iomp = xfs_offset_to_map(page, &iomap,
|
iomap_valid = xfs_iomap_valid(&iomap, offset);
|
||||||
p_offset);
|
|
||||||
done = (iomp == NULL);
|
|
||||||
}
|
}
|
||||||
if (iomp) {
|
if (iomap_valid) {
|
||||||
xfs_map_at_offset(page, bh, p_offset,
|
xfs_map_at_offset(bh, offset,
|
||||||
inode->i_blkbits, iomp, ioend);
|
inode->i_blkbits, &iomap);
|
||||||
if (startio) {
|
if (startio) {
|
||||||
xfs_add_to_ioend(inode, bh, p_offset,
|
xfs_add_to_ioend(inode, bh, p_offset,
|
||||||
type, &ioend, done);
|
type, &ioend,
|
||||||
|
!iomap_valid);
|
||||||
} else {
|
} else {
|
||||||
set_buffer_dirty(bh);
|
set_buffer_dirty(bh);
|
||||||
unlock_buffer(bh);
|
unlock_buffer(bh);
|
||||||
@@ -917,8 +893,6 @@ xfs_page_state_convert(
|
|||||||
}
|
}
|
||||||
page_dirty--;
|
page_dirty--;
|
||||||
count++;
|
count++;
|
||||||
} else {
|
|
||||||
done = 1;
|
|
||||||
}
|
}
|
||||||
} else if ((buffer_uptodate(bh) || PageUptodate(page)) &&
|
} else if ((buffer_uptodate(bh) || PageUptodate(page)) &&
|
||||||
(unmapped || startio)) {
|
(unmapped || startio)) {
|
||||||
@@ -931,7 +905,7 @@ xfs_page_state_convert(
|
|||||||
* was found, and we are in a path where we
|
* was found, and we are in a path where we
|
||||||
* need to write the whole page out.
|
* need to write the whole page out.
|
||||||
*/
|
*/
|
||||||
if (!iomp) {
|
if (!iomap_valid) {
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
size = xfs_probe_unmapped_cluster(
|
size = xfs_probe_unmapped_cluster(
|
||||||
@@ -939,21 +913,19 @@ xfs_page_state_convert(
|
|||||||
err = xfs_map_blocks(inode, offset,
|
err = xfs_map_blocks(inode, offset,
|
||||||
size, &iomap,
|
size, &iomap,
|
||||||
BMAPI_WRITE|BMAPI_MMAP);
|
BMAPI_WRITE|BMAPI_MMAP);
|
||||||
if (err) {
|
if (err)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
iomap_valid = xfs_iomap_valid(&iomap,
|
||||||
iomp = xfs_offset_to_map(page, &iomap,
|
offset);
|
||||||
p_offset);
|
|
||||||
done = (iomp == NULL);
|
|
||||||
}
|
}
|
||||||
if (iomp) {
|
if (iomap_valid) {
|
||||||
xfs_map_at_offset(page, bh, p_offset,
|
xfs_map_at_offset(bh, offset,
|
||||||
inode->i_blkbits, iomp,
|
inode->i_blkbits,
|
||||||
ioend);
|
&iomap);
|
||||||
if (startio) {
|
if (startio) {
|
||||||
xfs_add_to_ioend(inode,
|
xfs_add_to_ioend(inode,
|
||||||
bh, p_offset, type,
|
bh, p_offset, type,
|
||||||
&ioend, done);
|
&ioend, !iomap_valid);
|
||||||
} else {
|
} else {
|
||||||
set_buffer_dirty(bh);
|
set_buffer_dirty(bh);
|
||||||
unlock_buffer(bh);
|
unlock_buffer(bh);
|
||||||
@@ -961,8 +933,6 @@ xfs_page_state_convert(
|
|||||||
}
|
}
|
||||||
page_dirty--;
|
page_dirty--;
|
||||||
count++;
|
count++;
|
||||||
} else {
|
|
||||||
done = 1;
|
|
||||||
}
|
}
|
||||||
} else if (startio) {
|
} else if (startio) {
|
||||||
if (buffer_uptodate(bh) &&
|
if (buffer_uptodate(bh) &&
|
||||||
@@ -970,14 +940,14 @@ xfs_page_state_convert(
|
|||||||
ASSERT(buffer_mapped(bh));
|
ASSERT(buffer_mapped(bh));
|
||||||
xfs_add_to_ioend(inode,
|
xfs_add_to_ioend(inode,
|
||||||
bh, p_offset, type,
|
bh, p_offset, type,
|
||||||
&ioend, done);
|
&ioend, !iomap_valid);
|
||||||
page_dirty--;
|
page_dirty--;
|
||||||
count++;
|
count++;
|
||||||
} else {
|
} else {
|
||||||
done = 1;
|
iomap_valid = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done = 1;
|
iomap_valid = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -992,11 +962,11 @@ xfs_page_state_convert(
|
|||||||
if (startio)
|
if (startio)
|
||||||
xfs_start_page_writeback(page, wbc, 1, count);
|
xfs_start_page_writeback(page, wbc, 1, count);
|
||||||
|
|
||||||
if (ioend && iomp && !done) {
|
if (ioend && iomap_valid) {
|
||||||
offset = (iomp->iomap_offset + iomp->iomap_bsize - 1) >>
|
offset = (iomap.iomap_offset + iomap.iomap_bsize - 1) >>
|
||||||
PAGE_CACHE_SHIFT;
|
PAGE_CACHE_SHIFT;
|
||||||
tlast = min_t(pgoff_t, offset, last_index);
|
tlast = min_t(pgoff_t, offset, last_index);
|
||||||
xfs_cluster_write(inode, page->index + 1, iomp, &ioend,
|
xfs_cluster_write(inode, page->index + 1, &iomap, &ioend,
|
||||||
wbc, startio, unmapped, tlast);
|
wbc, startio, unmapped, tlast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user