Skip to content

Commit

Permalink
block: misc updates
Browse files Browse the repository at this point in the history
This patch makes the following misc updates in preparation for
disk->part dereference fix and extended block devt support.

* implment part_to_disk()

* fix comment about gendisk->part indexing

* rename get_part() to disk_map_sector()

* don't use n which is always zero while printing disk information in
  diskstats_show()

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
htejun authored and Jens Axboe committed Oct 9, 2008
1 parent 88e3412 commit 310a2c1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
7 changes: 4 additions & 3 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void drive_stat_acct(struct request *rq, int new_io)
if (!blk_fs_request(rq) || !rq->rq_disk)
return;

part = get_part(rq->rq_disk, rq->sector);
part = disk_map_sector(rq->rq_disk, rq->sector);
if (!new_io)
__all_stat_inc(rq->rq_disk, part, merges[rw], rq->sector);
else {
Expand Down Expand Up @@ -1557,7 +1557,8 @@ static int __end_that_request_first(struct request *req, int error,
}

if (blk_fs_request(req) && req->rq_disk) {
struct hd_struct *part = get_part(req->rq_disk, req->sector);
struct hd_struct *part =
disk_map_sector(req->rq_disk, req->sector);
const int rw = rq_data_dir(req);

all_stat_add(req->rq_disk, part, sectors[rw],
Expand Down Expand Up @@ -1745,7 +1746,7 @@ static void end_that_request_last(struct request *req, int error)
if (disk && blk_fs_request(req) && req != &req->q->bar_rq) {
unsigned long duration = jiffies - req->start_time;
const int rw = rq_data_dir(req);
struct hd_struct *part = get_part(disk, req->sector);
struct hd_struct *part = disk_map_sector(disk, req->sector);

__all_stat_inc(disk, part, ios[rw], req->sector);
__all_stat_add(disk, part, ticks[rw], duration, req->sector);
Expand Down
4 changes: 2 additions & 2 deletions block/blk-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ static int attempt_merge(struct request_queue *q, struct request *req,
elv_merge_requests(q, req, next);

if (req->rq_disk) {
struct hd_struct *part
= get_part(req->rq_disk, req->sector);
struct hd_struct *part =
disk_map_sector(req->rq_disk, req->sector);
disk_round_stats(req->rq_disk);
req->rq_disk->in_flight--;
if (part) {
Expand Down
4 changes: 2 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ static int diskstats_show(struct seq_file *s, void *v)
{
struct gendisk *gp = v;
char buf[BDEVNAME_SIZE];
int n = 0;
int n;

/*
if (&gp->dev.kobj.entry == block_class.devices.next)
Expand All @@ -582,7 +582,7 @@ static int diskstats_show(struct seq_file *s, void *v)
disk_round_stats(gp);
preempt_enable();
seq_printf(s, "%4d %4d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n",
gp->major, n + gp->first_minor, disk_name(gp, n, buf),
gp->major, gp->first_minor, disk_name(gp, 0, buf),
disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]),
(unsigned long long)disk_stat_read(gp, sectors[0]),
jiffies_to_msecs(disk_stat_read(gp, ticks[0])),
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/aoe/aoecmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ diskstats(struct gendisk *disk, struct bio *bio, ulong duration, sector_t sector
const int rw = bio_data_dir(bio);
struct hd_struct *part;

part = get_part(disk, sector);
part = disk_map_sector(disk, sector);
all_stat_inc(disk, part, ios[rw], sector);
all_stat_add(disk, part, ticks[rw], duration, sector);
all_stat_add(disk, part, sectors[rw], n_sect, sector);
Expand Down
13 changes: 10 additions & 3 deletions include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct gendisk {
int minors; /* maximum number of minors, =1 for
* disks that can't be partitioned. */
char disk_name[32]; /* name of major driver */
struct hd_struct **part; /* [indexed by minor] */
struct hd_struct **part; /* [indexed by minor - 1] */
struct block_device_operations *fops;
struct request_queue *queue;
void *private_data;
Expand Down Expand Up @@ -145,14 +145,21 @@ struct gendisk {
#endif
};

static inline struct gendisk *part_to_disk(struct hd_struct *part)
{
if (likely(part))
return dev_to_disk((part)->dev.parent);
return NULL;
}

/*
* Macros to operate on percpu disk statistics:
*
* The __ variants should only be called in critical sections. The full
* variants disable/enable preemption.
*/
static inline struct hd_struct *get_part(struct gendisk *gendiskp,
sector_t sector)
static inline struct hd_struct *disk_map_sector(struct gendisk *gendiskp,
sector_t sector)
{
struct hd_struct *part;
int i;
Expand Down

0 comments on commit 310a2c1

Please sign in to comment.