diff options
author | Tejun Heo <tj@kernel.org> | 2008-09-03 03:03:02 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-10-09 02:56:06 -0400 |
commit | e71bf0d0ee89e51b92776391c5634938236977d5 (patch) | |
tree | 9fc62352a40ad388deebdd8ed497cab926cf0470 /drivers/block | |
parent | f331c0296f2a9fee0d396a70598b954062603015 (diff) |
block: fix disk->part[] dereferencing race
disk->part[] is protected by its matching bdev's lock. However,
non-critical accesses like collecting stats and printing out sysfs and
proc information used to be performed without any locking. As
partitions can come and go dynamically, partitions can go away
underneath those non-critical accesses. As some of those accesses are
writes, this theoretically can lead to silent corruption.
This patch fixes the race by using RCU for the partition array and dev
reference counter to hold partitions.
* Rename disk->part[] to disk->__part[] to make sure no one outside
genhd layer proper accesses it directly.
* Use RCU for disk->__part[] dereferencing.
* Implement disk_{get|put}_part() which can be used to get and put
partitions from gendisk respectively.
* Iterators are implemented to help iterate through all partitions
safely.
* Functions which require RCU readlock are marked with _rcu suffix.
* Use disk_put_part() in __blkdev_put() instead of directly putting
the contained kobject.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/aoe/aoecmd.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c index 885d1409521f..84c03d65dcc5 100644 --- a/drivers/block/aoe/aoecmd.c +++ b/drivers/block/aoe/aoecmd.c | |||
@@ -757,11 +757,15 @@ diskstats(struct gendisk *disk, struct bio *bio, ulong duration, sector_t sector | |||
757 | const int rw = bio_data_dir(bio); | 757 | const int rw = bio_data_dir(bio); |
758 | struct hd_struct *part; | 758 | struct hd_struct *part; |
759 | 759 | ||
760 | part = disk_map_sector(disk, sector); | 760 | rcu_read_lock(); |
761 | |||
762 | part = disk_map_sector_rcu(disk, sector); | ||
761 | all_stat_inc(disk, part, ios[rw], sector); | 763 | all_stat_inc(disk, part, ios[rw], sector); |
762 | all_stat_add(disk, part, ticks[rw], duration, sector); | 764 | all_stat_add(disk, part, ticks[rw], duration, sector); |
763 | all_stat_add(disk, part, sectors[rw], n_sect, sector); | 765 | all_stat_add(disk, part, sectors[rw], n_sect, sector); |
764 | all_stat_add(disk, part, io_ticks, duration, sector); | 766 | all_stat_add(disk, part, io_ticks, duration, sector); |
767 | |||
768 | rcu_read_unlock(); | ||
765 | } | 769 | } |
766 | 770 | ||
767 | void | 771 | void |