Skip to content

Commit 29125ed

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move guard_bio_eod to bio.c
This is bio layer functionality and not related to buffer heads. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1b4d4db commit 29125ed

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

block/bio.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,49 @@ void bio_truncate(struct bio *bio, unsigned new_size)
588588
bio->bi_iter.bi_size = new_size;
589589
}
590590

591+
/**
592+
* guard_bio_eod - truncate a BIO to fit the block device
593+
* @bio: bio to truncate
594+
*
595+
* This allows us to do IO even on the odd last sectors of a device, even if the
596+
* block size is some multiple of the physical sector size.
597+
*
598+
* We'll just truncate the bio to the size of the device, and clear the end of
599+
* the buffer head manually. Truly out-of-range accesses will turn into actual
600+
* I/O errors, this only handles the "we need to be able to do I/O at the final
601+
* sector" case.
602+
*/
603+
void guard_bio_eod(struct bio *bio)
604+
{
605+
sector_t maxsector;
606+
struct hd_struct *part;
607+
608+
rcu_read_lock();
609+
part = __disk_get_part(bio->bi_disk, bio->bi_partno);
610+
if (part)
611+
maxsector = part_nr_sects_read(part);
612+
else
613+
maxsector = get_capacity(bio->bi_disk);
614+
rcu_read_unlock();
615+
616+
if (!maxsector)
617+
return;
618+
619+
/*
620+
* If the *whole* IO is past the end of the device,
621+
* let it through, and the IO layer will turn it into
622+
* an EIO.
623+
*/
624+
if (unlikely(bio->bi_iter.bi_sector >= maxsector))
625+
return;
626+
627+
maxsector -= bio->bi_iter.bi_sector;
628+
if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
629+
return;
630+
631+
bio_truncate(bio, maxsector << 9);
632+
}
633+
591634
/**
592635
* bio_put - release a reference to a bio
593636
* @bio: bio to release reference to

fs/buffer.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,49 +3019,6 @@ static void end_bio_bh_io_sync(struct bio *bio)
30193019
bio_put(bio);
30203020
}
30213021

3022-
/*
3023-
* This allows us to do IO even on the odd last sectors
3024-
* of a device, even if the block size is some multiple
3025-
* of the physical sector size.
3026-
*
3027-
* We'll just truncate the bio to the size of the device,
3028-
* and clear the end of the buffer head manually.
3029-
*
3030-
* Truly out-of-range accesses will turn into actual IO
3031-
* errors, this only handles the "we need to be able to
3032-
* do IO at the final sector" case.
3033-
*/
3034-
void guard_bio_eod(struct bio *bio)
3035-
{
3036-
sector_t maxsector;
3037-
struct hd_struct *part;
3038-
3039-
rcu_read_lock();
3040-
part = __disk_get_part(bio->bi_disk, bio->bi_partno);
3041-
if (part)
3042-
maxsector = part_nr_sects_read(part);
3043-
else
3044-
maxsector = get_capacity(bio->bi_disk);
3045-
rcu_read_unlock();
3046-
3047-
if (!maxsector)
3048-
return;
3049-
3050-
/*
3051-
* If the *whole* IO is past the end of the device,
3052-
* let it through, and the IO layer will turn it into
3053-
* an EIO.
3054-
*/
3055-
if (unlikely(bio->bi_iter.bi_sector >= maxsector))
3056-
return;
3057-
3058-
maxsector -= bio->bi_iter.bi_sector;
3059-
if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
3060-
return;
3061-
3062-
bio_truncate(bio, maxsector << 9);
3063-
}
3064-
30653022
static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
30663023
enum rw_hint write_hint, struct writeback_control *wbc)
30673024
{

fs/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)
3838
/*
3939
* buffer.c
4040
*/
41-
extern void guard_bio_eod(struct bio *bio);
4241
extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len,
4342
get_block_t *get_block, struct iomap *iomap);
4443

include/linux/bio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ extern struct bio *bio_copy_user_iov(struct request_queue *,
471471
extern int bio_uncopy_user(struct bio *);
472472
void zero_fill_bio_iter(struct bio *bio, struct bvec_iter iter);
473473
void bio_truncate(struct bio *bio, unsigned new_size);
474+
void guard_bio_eod(struct bio *bio);
474475

475476
static inline void zero_fill_bio(struct bio *bio)
476477
{

0 commit comments

Comments
 (0)