Skip to content

Commit

Permalink
block: switch partition lookup to use struct block_device
Browse files Browse the repository at this point in the history
Use struct block_device to lookup partitions on a disk.  This removes
all usage of struct hd_struct from the I/O path.

Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Acked-by: Coly Li <[email protected]>			[bcache]
Acked-by: Chao Yu <[email protected]>			[f2fs]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Dec 1, 2020
1 parent cb8432d commit 8446fe9
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 137 deletions.
4 changes: 2 additions & 2 deletions block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,12 @@ void bio_truncate(struct bio *bio, unsigned new_size)
void guard_bio_eod(struct bio *bio)
{
sector_t maxsector;
struct hd_struct *part;
struct block_device *part;

rcu_read_lock();
part = __disk_get_part(bio->bi_disk, bio->bi_partno);
if (part)
maxsector = bdev_nr_sectors(part->bdev);
maxsector = bdev_nr_sectors(part);
else
maxsector = get_capacity(bio->bi_disk);
rcu_read_unlock();
Expand Down
66 changes: 30 additions & 36 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,9 @@ static int __init setup_fail_make_request(char *str)
}
__setup("fail_make_request=", setup_fail_make_request);

static bool should_fail_request(struct hd_struct *part, unsigned int bytes)
static bool should_fail_request(struct block_device *part, unsigned int bytes)
{
return part->bdev->bd_make_it_fail &&
should_fail(&fail_make_request, bytes);
return part->bd_make_it_fail && should_fail(&fail_make_request, bytes);
}

static int __init fail_make_request_debugfs(void)
Expand All @@ -684,27 +683,27 @@ late_initcall(fail_make_request_debugfs);

#else /* CONFIG_FAIL_MAKE_REQUEST */

static inline bool should_fail_request(struct hd_struct *part,
static inline bool should_fail_request(struct block_device *part,
unsigned int bytes)
{
return false;
}

#endif /* CONFIG_FAIL_MAKE_REQUEST */

static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part)
static inline bool bio_check_ro(struct bio *bio, struct block_device *part)
{
const int op = bio_op(bio);

if (part->bdev->bd_read_only && op_is_write(op)) {
if (part->bd_read_only && op_is_write(op)) {
char b[BDEVNAME_SIZE];

if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
return false;

WARN_ONCE(1,
"Trying to write to read-only block-device %s (partno %d)\n",
bio_devname(bio, b), part->partno);
bio_devname(bio, b), part->bd_partno);
/* Older lvm-tools actually trigger this */
return false;
}
Expand All @@ -714,8 +713,7 @@ static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part)

static noinline int should_fail_bio(struct bio *bio)
{
if (should_fail_request(bio->bi_disk->part0->bd_part,
bio->bi_iter.bi_size))
if (should_fail_request(bio->bi_disk->part0, bio->bi_iter.bi_size))
return -EIO;
return 0;
}
Expand Down Expand Up @@ -744,7 +742,7 @@ static inline int bio_check_eod(struct bio *bio, sector_t maxsector)
*/
static inline int blk_partition_remap(struct bio *bio)
{
struct hd_struct *p;
struct block_device *p;
int ret = -EIO;

rcu_read_lock();
Expand All @@ -757,12 +755,12 @@ static inline int blk_partition_remap(struct bio *bio)
goto out;

if (bio_sectors(bio)) {
if (bio_check_eod(bio, bdev_nr_sectors(p->bdev)))
if (bio_check_eod(bio, bdev_nr_sectors(p)))
goto out;
bio->bi_iter.bi_sector += p->bdev->bd_start_sect;
trace_block_bio_remap(bio->bi_disk->queue, bio, part_devt(p),
bio->bi_iter.bi_sector += p->bd_start_sect;
trace_block_bio_remap(bio->bi_disk->queue, bio, p->bd_dev,
bio->bi_iter.bi_sector -
p->bdev->bd_start_sect);
p->bd_start_sect);
}
bio->bi_partno = 0;
ret = 0;
Expand Down Expand Up @@ -832,7 +830,7 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio)
if (unlikely(blk_partition_remap(bio)))
goto end_io;
} else {
if (unlikely(bio_check_ro(bio, bio->bi_disk->part0->bd_part)))
if (unlikely(bio_check_ro(bio, bio->bi_disk->part0)))
goto end_io;
if (unlikely(bio_check_eod(bio, get_capacity(bio->bi_disk))))
goto end_io;
Expand Down Expand Up @@ -1204,7 +1202,7 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *
return ret;

if (rq->rq_disk &&
should_fail_request(rq->rq_disk->part0->bd_part, blk_rq_bytes(rq)))
should_fail_request(rq->rq_disk->part0, blk_rq_bytes(rq)))
return BLK_STS_IOERR;

if (blk_crypto_insert_cloned_request(rq))
Expand Down Expand Up @@ -1263,17 +1261,18 @@ unsigned int blk_rq_err_bytes(const struct request *rq)
}
EXPORT_SYMBOL_GPL(blk_rq_err_bytes);

static void update_io_ticks(struct hd_struct *part, unsigned long now, bool end)
static void update_io_ticks(struct block_device *part, unsigned long now,
bool end)
{
unsigned long stamp;
again:
stamp = READ_ONCE(part->bdev->bd_stamp);
stamp = READ_ONCE(part->bd_stamp);
if (unlikely(stamp != now)) {
if (likely(cmpxchg(&part->bdev->bd_stamp, stamp, now) == stamp))
if (likely(cmpxchg(&part->bd_stamp, stamp, now) == stamp))
__part_stat_add(part, io_ticks, end ? now - stamp : 1);
}
if (part->partno) {
part = part_to_disk(part)->part0->bd_part;
if (part->bd_partno) {
part = bdev_whole(part);
goto again;
}
}
Expand All @@ -1282,11 +1281,9 @@ static void blk_account_io_completion(struct request *req, unsigned int bytes)
{
if (req->part && blk_do_io_stat(req)) {
const int sgrp = op_stat_group(req_op(req));
struct hd_struct *part;

part_stat_lock();
part = req->part;
part_stat_add(part, sectors[sgrp], bytes >> 9);
part_stat_add(req->part, sectors[sgrp], bytes >> 9);
part_stat_unlock();
}
}
Expand All @@ -1301,14 +1298,11 @@ void blk_account_io_done(struct request *req, u64 now)
if (req->part && blk_do_io_stat(req) &&
!(req->rq_flags & RQF_FLUSH_SEQ)) {
const int sgrp = op_stat_group(req_op(req));
struct hd_struct *part;

part_stat_lock();
part = req->part;

update_io_ticks(part, jiffies, true);
part_stat_inc(part, ios[sgrp]);
part_stat_add(part, nsecs[sgrp], now - req->start_time_ns);
update_io_ticks(req->part, jiffies, true);
part_stat_inc(req->part, ios[sgrp]);
part_stat_add(req->part, nsecs[sgrp], now - req->start_time_ns);
part_stat_unlock();
}
}
Expand All @@ -1325,7 +1319,7 @@ void blk_account_io_start(struct request *rq)
part_stat_unlock();
}

static unsigned long __part_start_io_acct(struct hd_struct *part,
static unsigned long __part_start_io_acct(struct block_device *part,
unsigned int sectors, unsigned int op)
{
const int sgrp = op_stat_group(op);
Expand All @@ -1341,7 +1335,7 @@ static unsigned long __part_start_io_acct(struct hd_struct *part,
return now;
}

unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part,
unsigned long part_start_io_acct(struct gendisk *disk, struct block_device **part,
struct bio *bio)
{
*part = disk_map_sector_rcu(disk, bio->bi_iter.bi_sector);
Expand All @@ -1353,11 +1347,11 @@ EXPORT_SYMBOL_GPL(part_start_io_acct);
unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
unsigned int op)
{
return __part_start_io_acct(disk->part0->bd_part, sectors, op);
return __part_start_io_acct(disk->part0, sectors, op);
}
EXPORT_SYMBOL(disk_start_io_acct);

static void __part_end_io_acct(struct hd_struct *part, unsigned int op,
static void __part_end_io_acct(struct block_device *part, unsigned int op,
unsigned long start_time)
{
const int sgrp = op_stat_group(op);
Expand All @@ -1371,7 +1365,7 @@ static void __part_end_io_acct(struct hd_struct *part, unsigned int op,
part_stat_unlock();
}

void part_end_io_acct(struct hd_struct *part, struct bio *bio,
void part_end_io_acct(struct block_device *part, struct bio *bio,
unsigned long start_time)
{
__part_end_io_acct(part, bio_op(bio), start_time);
Expand All @@ -1381,7 +1375,7 @@ EXPORT_SYMBOL_GPL(part_end_io_acct);
void disk_end_io_acct(struct gendisk *disk, unsigned int op,
unsigned long start_time)
{
__part_end_io_acct(disk->part0->bd_part, op, start_time);
__part_end_io_acct(disk->part0, op, start_time);
}
EXPORT_SYMBOL(disk_end_io_acct);

Expand Down
2 changes: 1 addition & 1 deletion block/blk-flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void blk_flush_queue_rq(struct request *rq, bool add_front)

static void blk_account_io_flush(struct request *rq)
{
struct hd_struct *part = rq->rq_disk->part0->bd_part;
struct block_device *part = rq->rq_disk->part0;

part_stat_lock();
part_stat_inc(part, ios[STAT_FLUSH]);
Expand Down
9 changes: 5 additions & 4 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void blk_mq_hctx_clear_pending(struct blk_mq_hw_ctx *hctx,
}

struct mq_inflight {
struct hd_struct *part;
struct block_device *part;
unsigned int inflight[2];
};

Expand All @@ -111,7 +111,8 @@ static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx,
return true;
}

unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part)
unsigned int blk_mq_in_flight(struct request_queue *q,
struct block_device *part)
{
struct mq_inflight mi = { .part = part };

Expand All @@ -120,8 +121,8 @@ unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part)
return mi.inflight[0] + mi.inflight[1];
}

void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
unsigned int inflight[2])
void blk_mq_in_flight_rw(struct request_queue *q, struct block_device *part,
unsigned int inflight[2])
{
struct mq_inflight mi = { .part = part };

Expand Down
7 changes: 4 additions & 3 deletions block/blk-mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx)
return hctx->nr_ctx && hctx->tags;
}

unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part);
void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
unsigned int inflight[2]);
unsigned int blk_mq_in_flight(struct request_queue *q,
struct block_device *part);
void blk_mq_in_flight_rw(struct request_queue *q, struct block_device *part,
unsigned int inflight[2]);

static inline void blk_mq_put_dispatch_budget(struct request_queue *q)
{
Expand Down
4 changes: 2 additions & 2 deletions block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static inline void elevator_exit(struct request_queue *q,
__elevator_exit(q, e);
}

struct hd_struct *__disk_get_part(struct gendisk *disk, int partno);
struct block_device *__disk_get_part(struct gendisk *disk, int partno);

ssize_t part_size_show(struct device *dev, struct device_attribute *attr,
char *buf);
Expand Down Expand Up @@ -348,7 +348,7 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q);
static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {}
#endif

struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector);
struct block_device *disk_map_sector_rcu(struct gendisk *disk, sector_t sector);

int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
void blk_free_devt(dev_t devt);
Expand Down
Loading

0 comments on commit 8446fe9

Please sign in to comment.