Skip to content

Commit

Permalink
Send uevents for write_protect changes
Browse files Browse the repository at this point in the history
Whenever a block device changes it's read-only attribute
notify the userspace about it.

Signed-off-by: Hannes Reinecke <[email protected]>
Signed-off-by: Nikanth Karthikesan <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
hreinecke authored and Jens Axboe committed Sep 11, 2009
1 parent d58b85e commit e3264a4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,16 @@ void put_disk(struct gendisk *disk)

EXPORT_SYMBOL(put_disk);

static void set_disk_ro_uevent(struct gendisk *gd, int ro)
{
char event[] = "DISK_RO=1";
char *envp[] = { event, NULL };

if (!ro)
event[8] = '0';
kobject_uevent_env(&disk_to_dev(gd)->kobj, KOBJ_CHANGE, envp);
}

void set_device_ro(struct block_device *bdev, int flag)
{
bdev->bd_part->policy = flag;
Expand All @@ -1227,8 +1237,12 @@ void set_disk_ro(struct gendisk *disk, int flag)
struct disk_part_iter piter;
struct hd_struct *part;

disk_part_iter_init(&piter, disk,
DISK_PITER_INCL_EMPTY | DISK_PITER_INCL_PART0);
if (disk->part0.policy != flag) {
set_disk_ro_uevent(disk, flag);
disk->part0.policy = flag;
}

disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter)))
part->policy = flag;
disk_part_iter_exit(&piter);
Expand Down

0 comments on commit e3264a4

Please sign in to comment.