Skip to content

Commit abed516

Browse files
committed
Merge tag 'block-5.12-2021-03-27' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: - Fix regression from this merge window with the xarray partition change, which allowed partition counts that overflow the u8 that holds the partition number (Ming) - Fix zone append warning (Johannes) - Segmentation count fix for multipage bvecs (David) - Partition scan fix (Chris) * tag 'block-5.12-2021-03-27' of git://git.kernel.dk/linux-block: block: don't create too many partitions block: support zone append bvecs block: recalculate segment count for multi-segment discards correctly block: clear GD_NEED_PART_SCAN later in bdev_disk_changed
2 parents e8cfe8f + e82fc78 commit abed516

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

block/bio.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ void bio_release_pages(struct bio *bio, bool mark_dirty)
949949
}
950950
EXPORT_SYMBOL_GPL(bio_release_pages);
951951

952-
static int bio_iov_bvec_set(struct bio *bio, struct iov_iter *iter)
952+
static void __bio_iov_bvec_set(struct bio *bio, struct iov_iter *iter)
953953
{
954954
WARN_ON_ONCE(bio->bi_max_vecs);
955955

@@ -959,11 +959,26 @@ static int bio_iov_bvec_set(struct bio *bio, struct iov_iter *iter)
959959
bio->bi_iter.bi_size = iter->count;
960960
bio_set_flag(bio, BIO_NO_PAGE_REF);
961961
bio_set_flag(bio, BIO_CLONED);
962+
}
962963

964+
static int bio_iov_bvec_set(struct bio *bio, struct iov_iter *iter)
965+
{
966+
__bio_iov_bvec_set(bio, iter);
963967
iov_iter_advance(iter, iter->count);
964968
return 0;
965969
}
966970

971+
static int bio_iov_bvec_set_append(struct bio *bio, struct iov_iter *iter)
972+
{
973+
struct request_queue *q = bio->bi_bdev->bd_disk->queue;
974+
struct iov_iter i = *iter;
975+
976+
iov_iter_truncate(&i, queue_max_zone_append_sectors(q) << 9);
977+
__bio_iov_bvec_set(bio, &i);
978+
iov_iter_advance(iter, i.count);
979+
return 0;
980+
}
981+
967982
#define PAGE_PTRS_PER_BVEC (sizeof(struct bio_vec) / sizeof(struct page *))
968983

969984
/**
@@ -1094,8 +1109,8 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
10941109
int ret = 0;
10951110

10961111
if (iov_iter_is_bvec(iter)) {
1097-
if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND))
1098-
return -EINVAL;
1112+
if (bio_op(bio) == REQ_OP_ZONE_APPEND)
1113+
return bio_iov_bvec_set_append(bio, iter);
10991114
return bio_iov_bvec_set(bio, iter);
11001115
}
11011116

block/blk-merge.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ unsigned int blk_recalc_rq_segments(struct request *rq)
382382
switch (bio_op(rq->bio)) {
383383
case REQ_OP_DISCARD:
384384
case REQ_OP_SECURE_ERASE:
385+
if (queue_max_discard_segments(rq->q) > 1) {
386+
struct bio *bio = rq->bio;
387+
388+
for_each_bio(bio)
389+
nr_phys_segs++;
390+
return nr_phys_segs;
391+
}
392+
return 1;
385393
case REQ_OP_WRITE_ZEROES:
386394
return 0;
387395
case REQ_OP_WRITE_SAME:

block/partitions/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
322322
const char *dname;
323323
int err;
324324

325+
/*
326+
* disk_max_parts() won't be zero, either GENHD_FL_EXT_DEVT is set
327+
* or 'minors' is passed to alloc_disk().
328+
*/
329+
if (partno >= disk_max_parts(disk))
330+
return ERR_PTR(-EINVAL);
331+
325332
/*
326333
* Partitions are not supported on zoned block devices that are used as
327334
* such.

fs/block_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,13 +1240,13 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
12401240

12411241
lockdep_assert_held(&bdev->bd_mutex);
12421242

1243-
clear_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
1244-
12451243
rescan:
12461244
ret = blk_drop_partitions(bdev);
12471245
if (ret)
12481246
return ret;
12491247

1248+
clear_bit(GD_NEED_PART_SCAN, &disk->state);
1249+
12501250
/*
12511251
* Historically we only set the capacity to zero for devices that
12521252
* support partitions (independ of actually having partitions created).

0 commit comments

Comments
 (0)