(paddr = bio_iter_phys((bio), (iter)), 1); \
bio_advance_iter_single((bio), (iter), (blocksize)))
-/* Initialize a bvec_iter to the size of the specified bio. */
-static inline struct bvec_iter init_bvec_iter_for_bio(struct bio *bio)
+/* Can only be called on a non-cloned bio. */
+static inline u32 bio_get_size(struct bio *bio)
{
struct bio_vec *bvec;
- u32 bio_size = 0;
+ u32 ret = 0;
int i;
bio_for_each_bvec_all(bvec, bio, i)
- bio_size += bvec->bv_len;
+ ret += bvec->bv_len;
+ return ret;
+}
+
+/* Initialize a bvec_iter to the size of the specified bio. */
+static inline struct bvec_iter init_bvec_iter_for_bio(struct bio *bio)
+{
+ const u32 bio_size = bio_get_size(bio);
return (struct bvec_iter) {
.bi_sector = 0,
static void rbio_update_error_bitmap(struct btrfs_raid_bio *rbio, struct bio *bio)
{
int total_sector_nr = get_bio_sector_nr(rbio, bio);
- u32 bio_size = 0;
- struct bio_vec *bvec;
- int i;
-
- bio_for_each_bvec_all(bvec, bio, i)
- bio_size += bvec->bv_len;
+ const u32 bio_size = bio_get_size(bio);
/*
* Since we can have multiple bios touching the error_bitmap, we cannot
*
* Instead use set_bit() for each bit, as set_bit() itself is atomic.
*/
- for (i = total_sector_nr; i < total_sector_nr +
+ for (int i = total_sector_nr; i < total_sector_nr +
(bio_size >> rbio->bioc->fs_info->sectorsize_bits); i++)
set_bit(i, rbio->error_bitmap);
}
{
struct scrub_stripe *stripe = bbio->private;
struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
- struct bio_vec *bvec;
int sector_nr = calc_sector_number(stripe, bio_first_bvec_all(&bbio->bio));
- u32 bio_size = 0;
- int i;
+ const u32 bio_size = bio_get_size(&bbio->bio);
ASSERT(sector_nr < stripe->nr_sectors);
- bio_for_each_bvec_all(bvec, &bbio->bio, i)
- bio_size += bvec->bv_len;
-
if (bbio->bio.bi_status) {
scrub_bitmap_set_io_error(stripe, sector_nr,
bio_size >> fs_info->sectorsize_bits);
static void scrub_read_endio(struct btrfs_bio *bbio)
{
struct scrub_stripe *stripe = bbio->private;
- struct bio_vec *bvec;
int sector_nr = calc_sector_number(stripe, bio_first_bvec_all(&bbio->bio));
int num_sectors;
- u32 bio_size = 0;
- int i;
+ const u32 bio_size = bio_get_size(&bbio->bio);
ASSERT(sector_nr < stripe->nr_sectors);
- bio_for_each_bvec_all(bvec, &bbio->bio, i)
- bio_size += bvec->bv_len;
num_sectors = bio_size >> stripe->bg->fs_info->sectorsize_bits;
if (bbio->bio.bi_status) {
{
struct scrub_stripe *stripe = bbio->private;
struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
- struct bio_vec *bvec;
int sector_nr = calc_sector_number(stripe, bio_first_bvec_all(&bbio->bio));
- u32 bio_size = 0;
- int i;
-
- bio_for_each_bvec_all(bvec, &bbio->bio, i)
- bio_size += bvec->bv_len;
+ const u32 bio_size = bio_get_size(&bbio->bio);
if (bbio->bio.bi_status) {
unsigned long flags;
bitmap_set(&stripe->write_error_bitmap, sector_nr,
bio_size >> fs_info->sectorsize_bits);
spin_unlock_irqrestore(&stripe->write_error_lock, flags);
- for (i = 0; i < (bio_size >> fs_info->sectorsize_bits); i++)
+ for (int i = 0; i < (bio_size >> fs_info->sectorsize_bits); i++)
btrfs_dev_stat_inc_and_print(stripe->dev,
BTRFS_DEV_STAT_WRITE_ERRS);
}