Skip to content

Commit b7c44ed

Browse files
committed
block: manipulate bio->bi_flags through helpers
Some places use helpers now, others don't. We only have the 'is set' helper, add helpers for setting and clearing flags too. It was a bit of a mess of atomic vs non-atomic access. With BIO_UPTODATE gone, we don't have any risk of concurrent access to the flags. So relax the restriction and don't make any of them atomic. The flags that do have serialization issues (reffed and chained), we already handle those separately. Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 4246a0b commit b7c44ed

File tree

11 files changed

+33
-20
lines changed

11 files changed

+33
-20
lines changed

block/bio.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static void bio_chain_endio(struct bio *bio)
311311
*/
312312
static inline void bio_inc_remaining(struct bio *bio)
313313
{
314-
bio->bi_flags |= (1 << BIO_CHAIN);
314+
bio_set_flag(bio, BIO_CHAIN);
315315
smp_mb__before_atomic();
316316
atomic_inc(&bio->__bi_remaining);
317317
}
@@ -495,7 +495,7 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
495495
if (unlikely(!bvl))
496496
goto err_free;
497497

498-
bio->bi_flags |= 1 << BIO_OWNS_VEC;
498+
bio_set_flag(bio, BIO_OWNS_VEC);
499499
} else if (nr_iovecs) {
500500
bvl = bio->bi_inline_vecs;
501501
}
@@ -580,7 +580,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
580580
* so we don't set nor calculate new physical/hw segment counts here
581581
*/
582582
bio->bi_bdev = bio_src->bi_bdev;
583-
bio->bi_flags |= 1 << BIO_CLONED;
583+
bio_set_flag(bio, BIO_CLONED);
584584
bio->bi_rw = bio_src->bi_rw;
585585
bio->bi_iter = bio_src->bi_iter;
586586
bio->bi_io_vec = bio_src->bi_io_vec;
@@ -829,7 +829,7 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
829829

830830
/* If we may be able to merge these biovecs, force a recount */
831831
if (bio->bi_vcnt > 1 && (BIOVEC_PHYS_MERGEABLE(bvec-1, bvec)))
832-
bio->bi_flags &= ~(1 << BIO_SEG_VALID);
832+
bio_clear_flag(bio, BIO_SEG_VALID);
833833

834834
done:
835835
return len;
@@ -1390,7 +1390,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
13901390
if (iter->type & WRITE)
13911391
bio->bi_rw |= REQ_WRITE;
13921392

1393-
bio->bi_flags |= (1 << BIO_USER_MAPPED);
1393+
bio_set_flag(bio, BIO_USER_MAPPED);
13941394

13951395
/*
13961396
* subtle -- if __bio_map_user() ended up bouncing a bio,
@@ -1770,7 +1770,7 @@ static inline bool bio_remaining_done(struct bio *bio)
17701770
BUG_ON(atomic_read(&bio->__bi_remaining) <= 0);
17711771

17721772
if (atomic_dec_and_test(&bio->__bi_remaining)) {
1773-
clear_bit(BIO_CHAIN, &bio->bi_flags);
1773+
bio_clear_flag(bio, BIO_CHAIN);
17741774
return true;
17751775
}
17761776

@@ -1866,7 +1866,7 @@ void bio_trim(struct bio *bio, int offset, int size)
18661866
if (offset == 0 && size == bio->bi_iter.bi_size)
18671867
return;
18681868

1869-
clear_bit(BIO_SEG_VALID, &bio->bi_flags);
1869+
bio_clear_flag(bio, BIO_SEG_VALID);
18701870

18711871
bio_advance(bio, offset << 9);
18721872

block/blk-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
146146
bio->bi_error = error;
147147

148148
if (unlikely(rq->cmd_flags & REQ_QUIET))
149-
set_bit(BIO_QUIET, &bio->bi_flags);
149+
bio_set_flag(bio, BIO_QUIET);
150150

151151
bio_advance(bio, nbytes);
152152

block/blk-map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
9494
return PTR_ERR(bio);
9595

9696
if (map_data && map_data->null_mapped)
97-
bio->bi_flags |= (1 << BIO_NULL_MAPPED);
97+
bio_set_flag(bio, BIO_NULL_MAPPED);
9898

9999
if (bio->bi_iter.bi_size != iter->count) {
100100
/*

block/blk-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void blk_recount_segments(struct request_queue *q, struct bio *bio)
116116
bio->bi_next = nxt;
117117
}
118118

119-
bio->bi_flags |= (1 << BIO_SEG_VALID);
119+
bio_set_flag(bio, BIO_SEG_VALID);
120120
}
121121
EXPORT_SYMBOL(blk_recount_segments);
122122

block/bounce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static int must_snapshot_stable_pages(struct request_queue *q, struct bio *bio)
186186
if (!bdi_cap_stable_pages_required(&q->backing_dev_info))
187187
return 0;
188188

189-
return test_bit(BIO_SNAP_STABLE, &bio->bi_flags);
189+
return bio_flagged(bio, BIO_SNAP_STABLE);
190190
}
191191
#else
192192
static int must_snapshot_stable_pages(struct request_queue *q, struct bio *bio)

drivers/md/raid1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ static void make_request(struct mddev *mddev, struct bio * bio)
11571157
* non-zero, then it is the number of not-completed requests.
11581158
*/
11591159
bio->bi_phys_segments = 0;
1160-
clear_bit(BIO_SEG_VALID, &bio->bi_flags);
1160+
bio_clear_flag(bio, BIO_SEG_VALID);
11611161

11621162
if (rw == READ) {
11631163
/*
@@ -2711,7 +2711,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
27112711
/* remove last page from this bio */
27122712
bio->bi_vcnt--;
27132713
bio->bi_iter.bi_size -= len;
2714-
__clear_bit(BIO_SEG_VALID, &bio->bi_flags);
2714+
bio_clear_flag(bio, BIO_SEG_VALID);
27152715
}
27162716
goto bio_full;
27172717
}

drivers/md/raid10.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ static void __make_request(struct mddev *mddev, struct bio *bio)
12161216
* non-zero, then it is the number of not-completed requests.
12171217
*/
12181218
bio->bi_phys_segments = 0;
1219-
clear_bit(BIO_SEG_VALID, &bio->bi_flags);
1219+
bio_clear_flag(bio, BIO_SEG_VALID);
12201220

12211221
if (rw == READ) {
12221222
/*
@@ -3353,7 +3353,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
33533353
/* remove last page from this bio */
33543354
bio2->bi_vcnt--;
33553355
bio2->bi_iter.bi_size -= len;
3356-
__clear_bit(BIO_SEG_VALID, &bio2->bi_flags);
3356+
bio_clear_flag(bio2, BIO_SEG_VALID);
33573357
}
33583358
goto bio_full;
33593359
}
@@ -4433,7 +4433,7 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,
44334433
/* Remove last page from this bio */
44344434
bio2->bi_vcnt--;
44354435
bio2->bi_iter.bi_size -= len;
4436-
__clear_bit(BIO_SEG_VALID, &bio2->bi_flags);
4436+
bio_clear_flag(bio2, BIO_SEG_VALID);
44374437
}
44384438
goto bio_full;
44394439
}

drivers/md/raid5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4850,7 +4850,7 @@ static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
48504850
rcu_read_unlock();
48514851
raid_bio->bi_next = (void*)rdev;
48524852
align_bi->bi_bdev = rdev->bdev;
4853-
__clear_bit(BIO_SEG_VALID, &align_bi->bi_flags);
4853+
bio_clear_flag(align_bi, BIO_SEG_VALID);
48544854

48554855
if (!bio_fits_rdev(align_bi) ||
48564856
is_badblock(rdev, align_bi->bi_iter.bi_sector,

fs/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,7 @@ static void end_bio_bh_io_sync(struct bio *bio)
29612961
{
29622962
struct buffer_head *bh = bio->bi_private;
29632963

2964-
if (unlikely (test_bit(BIO_QUIET,&bio->bi_flags)))
2964+
if (unlikely(bio_flagged(bio, BIO_QUIET)))
29652965
set_bit(BH_Quiet, &bh->b_state);
29662966

29672967
bh->b_end_io(bh, !bio->bi_error);

include/linux/bio.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,21 @@ static inline void bio_cnt_set(struct bio *bio, unsigned int count)
304304
atomic_set(&bio->__bi_cnt, count);
305305
}
306306

307+
static inline bool bio_flagged(struct bio *bio, unsigned int bit)
308+
{
309+
return (bio->bi_flags & (1UL << bit)) != 0;
310+
}
311+
312+
static inline void bio_set_flag(struct bio *bio, unsigned int bit)
313+
{
314+
bio->bi_flags |= (1UL << bit);
315+
}
316+
317+
static inline void bio_clear_flag(struct bio *bio, unsigned int bit)
318+
{
319+
bio->bi_flags &= ~(1UL << bit);
320+
}
321+
307322
enum bip_flags {
308323
BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */
309324
BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */

0 commit comments

Comments
 (0)