Commit b7db9956 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

block: move policy from disk to part0

Move disk->policy to part0->policy.  Implement and use get_disk_ro().
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent e5610521
...@@ -757,7 +757,7 @@ static ssize_t disk_ro_show(struct device *dev, ...@@ -757,7 +757,7 @@ static ssize_t disk_ro_show(struct device *dev,
{ {
struct gendisk *disk = dev_to_disk(dev); struct gendisk *disk = dev_to_disk(dev);
return sprintf(buf, "%d\n", disk->policy ? 1 : 0); return sprintf(buf, "%d\n", get_disk_ro(disk) ? 1 : 0);
} }
static ssize_t disk_capability_show(struct device *dev, static ssize_t disk_capability_show(struct device *dev,
...@@ -1090,10 +1090,7 @@ EXPORT_SYMBOL(put_disk); ...@@ -1090,10 +1090,7 @@ EXPORT_SYMBOL(put_disk);
void set_device_ro(struct block_device *bdev, int flag) void set_device_ro(struct block_device *bdev, int flag)
{ {
if (bdev->bd_contains != bdev) bdev->bd_part->policy = flag;
bdev->bd_part->policy = flag;
else
bdev->bd_disk->policy = flag;
} }
EXPORT_SYMBOL(set_device_ro); EXPORT_SYMBOL(set_device_ro);
...@@ -1103,8 +1100,8 @@ void set_disk_ro(struct gendisk *disk, int flag) ...@@ -1103,8 +1100,8 @@ void set_disk_ro(struct gendisk *disk, int flag)
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct hd_struct *part;
disk->policy = flag; disk_part_iter_init(&piter, disk,
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY); DISK_PITER_INCL_EMPTY | DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter))) while ((part = disk_part_iter_next(&piter)))
part->policy = flag; part->policy = flag;
disk_part_iter_exit(&piter); disk_part_iter_exit(&piter);
...@@ -1116,10 +1113,7 @@ int bdev_read_only(struct block_device *bdev) ...@@ -1116,10 +1113,7 @@ int bdev_read_only(struct block_device *bdev)
{ {
if (!bdev) if (!bdev)
return 0; return 0;
else if (bdev->bd_contains != bdev) return bdev->bd_part->policy;
return bdev->bd_part->policy;
else
return bdev->bd_disk->policy;
} }
EXPORT_SYMBOL(bdev_read_only); EXPORT_SYMBOL(bdev_read_only);
......
...@@ -1113,7 +1113,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) ...@@ -1113,7 +1113,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
if (write) { if (write) {
/* disk has become write protected */ /* disk has become write protected */
if (cd->disk->policy) { if (get_disk_ro(cd->disk)) {
cdrom_end_request(drive, 0); cdrom_end_request(drive, 0);
return ide_stopped; return ide_stopped;
} }
......
...@@ -548,7 +548,7 @@ static int __dev_status(struct mapped_device *md, struct dm_ioctl *param) ...@@ -548,7 +548,7 @@ static int __dev_status(struct mapped_device *md, struct dm_ioctl *param)
*/ */
param->open_count = dm_open_count(md); param->open_count = dm_open_count(md);
if (disk->policy) if (get_disk_ro(disk))
param->flags |= DM_READONLY_FLAG; param->flags |= DM_READONLY_FLAG;
param->event_nr = dm_get_event_nr(md); param->event_nr = dm_get_event_nr(md);
......
...@@ -375,7 +375,7 @@ int add_partition(struct gendisk *disk, int partno, ...@@ -375,7 +375,7 @@ int add_partition(struct gendisk *disk, int partno,
p->start_sect = start; p->start_sect = start;
p->nr_sects = len; p->nr_sects = len;
p->partno = partno; p->partno = partno;
p->policy = disk->policy; p->policy = get_disk_ro(disk);
dname = dev_name(ddev); dname = dev_name(ddev);
if (isdigit(dname[strlen(dname) - 1])) if (isdigit(dname[strlen(dname) - 1]))
......
...@@ -145,7 +145,6 @@ struct gendisk { ...@@ -145,7 +145,6 @@ struct gendisk {
struct kobject *slave_dir; struct kobject *slave_dir;
struct timer_rand_state *random; struct timer_rand_state *random;
int policy;
atomic_t sync_io; /* RAID */ atomic_t sync_io; /* RAID */
unsigned long stamp; unsigned long stamp;
...@@ -403,6 +402,11 @@ extern struct block_device *bdget_disk(struct gendisk *disk, int partno); ...@@ -403,6 +402,11 @@ extern struct block_device *bdget_disk(struct gendisk *disk, int partno);
extern void set_device_ro(struct block_device *bdev, int flag); extern void set_device_ro(struct block_device *bdev, int flag);
extern void set_disk_ro(struct gendisk *disk, int flag); extern void set_disk_ro(struct gendisk *disk, int flag);
static inline int get_disk_ro(struct gendisk *disk)
{
return disk->part0.policy;
}
/* drivers/char/random.c */ /* drivers/char/random.c */
extern void add_disk_randomness(struct gendisk *disk); extern void add_disk_randomness(struct gendisk *disk);
extern void rand_initialize_disk(struct gendisk *disk); extern void rand_initialize_disk(struct gendisk *disk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment