Skip to content

Commit cb793ff

Browse files
committed
Merge branch 'for-7.1/block' into for-next
* for-7.1/block: xfs: use bio_await in xfs_zone_gc_reset_sync block: add a bio_submit_or_kill helper block: factor out a bio_await helper block: unify the synchronous bi_end_io callbacks xfs: fix number of GC bvecs
2 parents cc91702 + 2d148a2 commit cb793ff

6 files changed

Lines changed: 73 additions & 77 deletions

File tree

block/bio.c

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,11 +1462,41 @@ void bio_iov_iter_unbounce(struct bio *bio, bool is_error, bool mark_dirty)
14621462
bio_iov_iter_unbounce_read(bio, is_error, mark_dirty);
14631463
}
14641464

1465-
static void submit_bio_wait_endio(struct bio *bio)
1465+
static void bio_wait_end_io(struct bio *bio)
14661466
{
14671467
complete(bio->bi_private);
14681468
}
14691469

1470+
/**
1471+
* bio_await - call a function on a bio, and wait until it completes
1472+
* @bio: the bio which describes the I/O
1473+
* @submit: function called to submit the bio
1474+
* @priv: private data passed to @submit
1475+
*
1476+
* Wait for the bio as well as any bio chained off it after executing the
1477+
* passed in callback @submit. The wait for the bio is set up before calling
1478+
* @submit to ensure that the completion is captured. If @submit is %NULL,
1479+
* submit_bio() is used instead to submit the bio.
1480+
*
1481+
* Note: this overrides the bi_private and bi_end_io fields in the bio.
1482+
*/
1483+
void bio_await(struct bio *bio, void *priv,
1484+
void (*submit)(struct bio *bio, void *priv))
1485+
{
1486+
DECLARE_COMPLETION_ONSTACK_MAP(done,
1487+
bio->bi_bdev->bd_disk->lockdep_map);
1488+
1489+
bio->bi_private = &done;
1490+
bio->bi_end_io = bio_wait_end_io;
1491+
bio->bi_opf |= REQ_SYNC;
1492+
if (submit)
1493+
submit(bio, priv);
1494+
else
1495+
submit_bio(bio);
1496+
blk_wait_io(&done);
1497+
}
1498+
EXPORT_SYMBOL_GPL(bio_await);
1499+
14701500
/**
14711501
* submit_bio_wait - submit a bio, and wait until it completes
14721502
* @bio: The &struct bio which describes the I/O
@@ -1480,19 +1510,30 @@ static void submit_bio_wait_endio(struct bio *bio)
14801510
*/
14811511
int submit_bio_wait(struct bio *bio)
14821512
{
1483-
DECLARE_COMPLETION_ONSTACK_MAP(done,
1484-
bio->bi_bdev->bd_disk->lockdep_map);
1485-
1486-
bio->bi_private = &done;
1487-
bio->bi_end_io = submit_bio_wait_endio;
1488-
bio->bi_opf |= REQ_SYNC;
1489-
submit_bio(bio);
1490-
blk_wait_io(&done);
1491-
1513+
bio_await(bio, NULL, NULL);
14921514
return blk_status_to_errno(bio->bi_status);
14931515
}
14941516
EXPORT_SYMBOL(submit_bio_wait);
14951517

1518+
static void bio_endio_cb(struct bio *bio, void *priv)
1519+
{
1520+
bio_endio(bio);
1521+
}
1522+
1523+
/*
1524+
* Submit @bio synchronously, or call bio_endio on it if the current process
1525+
* is being killed.
1526+
*/
1527+
int bio_submit_or_kill(struct bio *bio, unsigned int flags)
1528+
{
1529+
if ((flags & BLKDEV_ZERO_KILLABLE) && fatal_signal_pending(current)) {
1530+
bio_await(bio, NULL, bio_endio_cb);
1531+
return -EINTR;
1532+
}
1533+
1534+
return submit_bio_wait(bio);
1535+
}
1536+
14961537
/**
14971538
* bdev_rw_virt - synchronously read into / write from kernel mapping
14981539
* @bdev: block device to access
@@ -1523,26 +1564,6 @@ int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
15231564
}
15241565
EXPORT_SYMBOL_GPL(bdev_rw_virt);
15251566

1526-
static void bio_wait_end_io(struct bio *bio)
1527-
{
1528-
complete(bio->bi_private);
1529-
bio_put(bio);
1530-
}
1531-
1532-
/*
1533-
* bio_await_chain - ends @bio and waits for every chained bio to complete
1534-
*/
1535-
void bio_await_chain(struct bio *bio)
1536-
{
1537-
DECLARE_COMPLETION_ONSTACK_MAP(done,
1538-
bio->bi_bdev->bd_disk->lockdep_map);
1539-
1540-
bio->bi_private = &done;
1541-
bio->bi_end_io = bio_wait_end_io;
1542-
bio_endio(bio);
1543-
blk_wait_io(&done);
1544-
}
1545-
15461567
void __bio_advance(struct bio *bio, unsigned bytes)
15471568
{
15481569
if (bio_integrity(bio))

block/blk-lib.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,7 @@ static int blkdev_issue_write_zeroes(struct block_device *bdev, sector_t sector,
155155
__blkdev_issue_write_zeroes(bdev, sector, nr_sects, gfp, &bio,
156156
flags, limit);
157157
if (bio) {
158-
if ((flags & BLKDEV_ZERO_KILLABLE) &&
159-
fatal_signal_pending(current)) {
160-
bio_await_chain(bio);
161-
blk_finish_plug(&plug);
162-
return -EINTR;
163-
}
164-
ret = submit_bio_wait(bio);
158+
ret = bio_submit_or_kill(bio, flags);
165159
bio_put(bio);
166160
}
167161
blk_finish_plug(&plug);
@@ -236,13 +230,7 @@ static int blkdev_issue_zero_pages(struct block_device *bdev, sector_t sector,
236230
blk_start_plug(&plug);
237231
__blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp, &bio, flags);
238232
if (bio) {
239-
if ((flags & BLKDEV_ZERO_KILLABLE) &&
240-
fatal_signal_pending(current)) {
241-
bio_await_chain(bio);
242-
blk_finish_plug(&plug);
243-
return -EINTR;
244-
}
245-
ret = submit_bio_wait(bio);
233+
ret = bio_submit_or_kill(bio, flags);
246234
bio_put(bio);
247235
}
248236
blk_finish_plug(&plug);

block/blk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool __blk_freeze_queue_start(struct request_queue *q,
5555
struct task_struct *owner);
5656
int __bio_queue_enter(struct request_queue *q, struct bio *bio);
5757
void submit_bio_noacct_nocheck(struct bio *bio, bool split);
58-
void bio_await_chain(struct bio *bio);
58+
int bio_submit_or_kill(struct bio *bio, unsigned int flags);
5959

6060
static inline bool blk_try_enter_queue(struct request_queue *q, bool pm)
6161
{

block/ioctl.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,19 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
153153
nr_sects = len >> SECTOR_SHIFT;
154154

155155
blk_start_plug(&plug);
156-
while (1) {
157-
if (fatal_signal_pending(current)) {
158-
if (prev)
159-
bio_await_chain(prev);
160-
err = -EINTR;
161-
goto out_unplug;
162-
}
156+
while (!fatal_signal_pending(current)) {
163157
bio = blk_alloc_discard_bio(bdev, &sector, &nr_sects,
164158
GFP_KERNEL);
165159
if (!bio)
166160
break;
167161
prev = bio_chain_and_submit(prev, bio);
168162
}
169163
if (prev) {
170-
err = submit_bio_wait(prev);
164+
err = bio_submit_or_kill(prev, BLKDEV_ZERO_KILLABLE);
171165
if (err == -EOPNOTSUPP)
172166
err = 0;
173167
bio_put(prev);
174168
}
175-
out_unplug:
176169
blk_finish_plug(&plug);
177170
fail:
178171
filemap_invalidate_unlock(bdev->bd_mapping);

fs/xfs/xfs_zone_gc.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ xfs_zone_gc_start_chunk(
670670
struct xfs_inode *ip;
671671
struct bio *bio;
672672
xfs_daddr_t daddr;
673-
unsigned int len;
674673
bool is_seq;
675674

676675
if (xfs_is_shutdown(mp))
@@ -685,15 +684,16 @@ xfs_zone_gc_start_chunk(
685684
return false;
686685
}
687686

688-
len = XFS_FSB_TO_B(mp, irec.rm_blockcount);
689-
bio = bio_alloc_bioset(bdev,
690-
min(howmany(len, XFS_GC_BUF_SIZE) + 1, XFS_GC_NR_BUFS),
691-
REQ_OP_READ, GFP_NOFS, &data->bio_set);
692-
687+
/*
688+
* Scratch allocation can wrap around to the same buffer again,
689+
* provision an extra bvec for that case.
690+
*/
691+
bio = bio_alloc_bioset(bdev, XFS_GC_NR_BUFS + 1, REQ_OP_READ, GFP_NOFS,
692+
&data->bio_set);
693693
chunk = container_of(bio, struct xfs_gc_bio, bio);
694694
chunk->ip = ip;
695695
chunk->offset = XFS_FSB_TO_B(mp, irec.rm_offset);
696-
chunk->len = len;
696+
chunk->len = XFS_FSB_TO_B(mp, irec.rm_blockcount);
697697
chunk->old_startblock =
698698
xfs_rgbno_to_rtb(iter->victim_rtg, irec.rm_startblock);
699699
chunk->new_daddr = daddr;
@@ -707,8 +707,9 @@ xfs_zone_gc_start_chunk(
707707
bio->bi_iter.bi_sector = xfs_rtb_to_daddr(mp, chunk->old_startblock);
708708
bio->bi_end_io = xfs_zone_gc_end_io;
709709
xfs_zone_gc_add_data(chunk);
710-
data->scratch_head = (data->scratch_head + len) % data->scratch_size;
711-
data->scratch_available -= len;
710+
data->scratch_head =
711+
(data->scratch_head + chunk->len) % data->scratch_size;
712+
data->scratch_available -= chunk->len;
712713

713714
XFS_STATS_INC(mp, xs_gc_read_calls);
714715

@@ -899,9 +900,10 @@ xfs_zone_gc_finish_reset(
899900

900901
static void
901902
xfs_submit_zone_reset_bio(
902-
struct xfs_rtgroup *rtg,
903-
struct bio *bio)
903+
struct bio *bio,
904+
void *priv)
904905
{
906+
struct xfs_rtgroup *rtg = priv;
905907
struct xfs_mount *mp = rtg_mount(rtg);
906908

907909
trace_xfs_zone_reset(rtg);
@@ -933,26 +935,16 @@ xfs_submit_zone_reset_bio(
933935
submit_bio(bio);
934936
}
935937

936-
static void xfs_bio_wait_endio(struct bio *bio)
937-
{
938-
complete(bio->bi_private);
939-
}
940-
941938
int
942939
xfs_zone_gc_reset_sync(
943940
struct xfs_rtgroup *rtg)
944941
{
945-
DECLARE_COMPLETION_ONSTACK(done);
946942
struct bio bio;
947943
int error;
948944

949945
bio_init(&bio, rtg_mount(rtg)->m_rtdev_targp->bt_bdev, NULL, 0,
950946
REQ_OP_ZONE_RESET | REQ_SYNC);
951-
bio.bi_private = &done;
952-
bio.bi_end_io = xfs_bio_wait_endio;
953-
xfs_submit_zone_reset_bio(rtg, &bio);
954-
wait_for_completion_io(&done);
955-
947+
bio_await(&bio, rtg, xfs_submit_zone_reset_bio);
956948
error = blk_status_to_errno(bio.bi_status);
957949
bio_uninit(&bio);
958950
return error;
@@ -989,7 +981,7 @@ xfs_zone_gc_reset_zones(
989981
chunk->data = data;
990982
WRITE_ONCE(chunk->state, XFS_GC_BIO_NEW);
991983
list_add_tail(&chunk->entry, &data->resetting);
992-
xfs_submit_zone_reset_bio(rtg, bio);
984+
xfs_submit_zone_reset_bio(bio, rtg);
993985
} while (next);
994986
}
995987

include/linux/bio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ extern void bio_uninit(struct bio *);
432432
void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf);
433433
void bio_reuse(struct bio *bio, blk_opf_t opf);
434434
void bio_chain(struct bio *, struct bio *);
435+
void bio_await(struct bio *bio, void *priv,
436+
void (*submit)(struct bio *bio, void *priv));
435437

436438
int __must_check bio_add_page(struct bio *bio, struct page *page, unsigned len,
437439
unsigned off);

0 commit comments

Comments
 (0)