Commit 5b3597e4 authored by Eric Sandeen's avatar Eric Sandeen Committed by Nathan Scott

[XFS] Fix for large allocation groups, so that extent

sizes will not overflow pagebuf lengths.

SGI Modid: xfs-linux:xfs-kern:164827a
parent 97b6a0d4
...@@ -407,8 +407,10 @@ map_unwritten( ...@@ -407,8 +407,10 @@ map_unwritten(
offset <<= PAGE_CACHE_SHIFT; offset <<= PAGE_CACHE_SHIFT;
offset += p_offset; offset += p_offset;
pb = pagebuf_lookup(iomapp->iomap_target, /* get an "empty" pagebuf to manage IO completion
iomapp->iomap_offset, iomapp->iomap_bsize, 0); * Proper values will be set before returning */
pb = pagebuf_lookup(iomapp->iomap_target, 0, 0, 0);
if (!pb) if (!pb)
return -EAGAIN; return -EAGAIN;
...@@ -471,6 +473,11 @@ map_unwritten( ...@@ -471,6 +473,11 @@ map_unwritten(
nblocks += bs; nblocks += bs;
atomic_add(bs, &pb->pb_io_remaining); atomic_add(bs, &pb->pb_io_remaining);
convert_page(inode, page, iomapp, pb, startio, all_bh); convert_page(inode, page, iomapp, pb, startio, all_bh);
/* stop if converting the next page might add
* enough blocks that the corresponding byte
* count won't fit in our ulong page buf length */
if (nblocks >= ((ULONG_MAX - PAGE_SIZE) >> block_bits))
goto enough;
} }
if (tindex == tlast && if (tindex == tlast &&
...@@ -481,16 +488,20 @@ map_unwritten( ...@@ -481,16 +488,20 @@ map_unwritten(
nblocks += bs; nblocks += bs;
atomic_add(bs, &pb->pb_io_remaining); atomic_add(bs, &pb->pb_io_remaining);
convert_page(inode, page, iomapp, pb, startio, all_bh); convert_page(inode, page, iomapp, pb, startio, all_bh);
if (nblocks >= ((ULONG_MAX - PAGE_SIZE) >> block_bits))
goto enough;
} }
} }
} }
enough:
size = nblocks; /* NB: using 64bit number here */ size = nblocks; /* NB: using 64bit number here */
size <<= block_bits; /* convert fsb's to byte range */ size <<= block_bits; /* convert fsb's to byte range */
XFS_BUF_DATAIO(pb); XFS_BUF_DATAIO(pb);
XFS_BUF_ASYNC(pb); XFS_BUF_ASYNC(pb);
XFS_BUF_SET_SIZE(pb, size); XFS_BUF_SET_SIZE(pb, size);
XFS_BUF_SET_COUNT(pb, size);
XFS_BUF_SET_OFFSET(pb, offset); XFS_BUF_SET_OFFSET(pb, offset);
XFS_BUF_SET_FSPRIVATE(pb, LINVFS_GET_VP(inode)); XFS_BUF_SET_FSPRIVATE(pb, LINVFS_GET_VP(inode));
XFS_BUF_SET_IODONE_FUNC(pb, linvfs_unwritten_convert); XFS_BUF_SET_IODONE_FUNC(pb, linvfs_unwritten_convert);
...@@ -925,8 +936,10 @@ linvfs_get_block_core( ...@@ -925,8 +936,10 @@ linvfs_get_block_core(
} }
if (blocks) { if (blocks) {
size = (iomap.iomap_bsize - iomap.iomap_delta); loff_t iosize;
bh_result->b_size = min_t(ssize_t, size, blocks << inode->i_blkbits); iosize = (iomap.iomap_bsize - iomap.iomap_delta);
bh_result->b_size =
(ssize_t)min(iosize, (loff_t)(blocks << inode->i_blkbits));
} }
return 0; return 0;
......
...@@ -66,27 +66,26 @@ typedef enum { ...@@ -66,27 +66,26 @@ typedef enum {
/* /*
* xfs_iomap_t: File system I/O map * xfs_iomap_t: File system I/O map
* *
* The iomap_bn, iomap_offset and iomap_length fields are expressed in disk blocks. * The iomap_bn field is expressed in 512-byte blocks, and is where the
* The iomap_length field specifies the size of the underlying backing store * mapping starts on disk.
* for the particular mapping.
* *
* The iomap_bsize, iomap_size and iomap_delta fields are in bytes and indicate * The iomap_offset, iomap_bsize and iomap_delta fields are in bytes.
* the size of the mapping, the number of bytes that are valid to access * iomap_offset is the offset of the mapping in the file itself.
* (read or write), and the offset into the mapping, given the offset * iomap_bsize is the size of the mapping, iomap_delta is the
* supplied to the file I/O map routine. iomap_delta is the offset of the * desired data's offset into the mapping, given the offset supplied
* desired data from the beginning of the mapping. * to the file I/O map routine.
* *
* When a request is made to read beyond the logical end of the object, * When a request is made to read beyond the logical end of the object,
* iomap_size may be set to 0, but iomap_offset and iomap_length should be set to * iomap_size may be set to 0, but iomap_offset and iomap_length should be set
* the actual amount of underlying storage that has been allocated, if any. * to the actual amount of underlying storage that has been allocated, if any.
*/ */
typedef struct xfs_iomap { typedef struct xfs_iomap {
xfs_daddr_t iomap_bn; xfs_daddr_t iomap_bn; /* first 512b blk of mapping */
xfs_buftarg_t *iomap_target; xfs_buftarg_t *iomap_target;
loff_t iomap_offset; loff_t iomap_offset; /* offset of mapping, bytes */
size_t iomap_delta; loff_t iomap_bsize; /* size of mapping, bytes */
size_t iomap_bsize; size_t iomap_delta; /* offset into mapping, bytes */
iomap_flags_t iomap_flags; iomap_flags_t iomap_flags;
} xfs_iomap_t; } xfs_iomap_t;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment