diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-08-07 14:14:32 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2013-11-08 11:02:31 -0500 |
commit | 6678d83f18386eb103f8345024e52c5abe61725c (patch) | |
tree | a40f84cb760584da430b4471b3cdad91db8e9831 /fs/bio.c | |
parent | e0ce0eacb3197ad6e4ae37006c73af9411f97ecc (diff) |
block: Consolidate duplicated bio_trim() implementations
Someone cut and pasted md's md_trim_bio() into xen-blkfront.c. Come on,
we should know better than this.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Neil Brown <neilb@suse.de>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/bio.c')
-rw-r--r-- | fs/bio.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -1805,6 +1805,52 @@ struct bio_pair *bio_split(struct bio *bi, int first_sectors) | |||
1805 | EXPORT_SYMBOL(bio_split); | 1805 | EXPORT_SYMBOL(bio_split); |
1806 | 1806 | ||
1807 | /** | 1807 | /** |
1808 | * bio_trim - trim a bio | ||
1809 | * @bio: bio to trim | ||
1810 | * @offset: number of sectors to trim from the front of @bio | ||
1811 | * @size: size we want to trim @bio to, in sectors | ||
1812 | */ | ||
1813 | void bio_trim(struct bio *bio, int offset, int size) | ||
1814 | { | ||
1815 | /* 'bio' is a cloned bio which we need to trim to match | ||
1816 | * the given offset and size. | ||
1817 | * This requires adjusting bi_sector, bi_size, and bi_io_vec | ||
1818 | */ | ||
1819 | int i; | ||
1820 | struct bio_vec *bvec; | ||
1821 | int sofar = 0; | ||
1822 | |||
1823 | size <<= 9; | ||
1824 | if (offset == 0 && size == bio->bi_size) | ||
1825 | return; | ||
1826 | |||
1827 | clear_bit(BIO_SEG_VALID, &bio->bi_flags); | ||
1828 | |||
1829 | bio_advance(bio, offset << 9); | ||
1830 | |||
1831 | bio->bi_size = size; | ||
1832 | |||
1833 | /* avoid any complications with bi_idx being non-zero*/ | ||
1834 | if (bio->bi_idx) { | ||
1835 | memmove(bio->bi_io_vec, bio->bi_io_vec+bio->bi_idx, | ||
1836 | (bio->bi_vcnt - bio->bi_idx) * sizeof(struct bio_vec)); | ||
1837 | bio->bi_vcnt -= bio->bi_idx; | ||
1838 | bio->bi_idx = 0; | ||
1839 | } | ||
1840 | /* Make sure vcnt and last bv are not too big */ | ||
1841 | bio_for_each_segment(bvec, bio, i) { | ||
1842 | if (sofar + bvec->bv_len > size) | ||
1843 | bvec->bv_len = size - sofar; | ||
1844 | if (bvec->bv_len == 0) { | ||
1845 | bio->bi_vcnt = i; | ||
1846 | break; | ||
1847 | } | ||
1848 | sofar += bvec->bv_len; | ||
1849 | } | ||
1850 | } | ||
1851 | EXPORT_SYMBOL_GPL(bio_trim); | ||
1852 | |||
1853 | /** | ||
1808 | * bio_sector_offset - Find hardware sector offset in bio | 1854 | * bio_sector_offset - Find hardware sector offset in bio |
1809 | * @bio: bio to inspect | 1855 | * @bio: bio to inspect |
1810 | * @index: bio_vec index | 1856 | * @index: bio_vec index |