Skip to content

Commit

Permalink
genhd: send async notification on media change
Browse files Browse the repository at this point in the history
Send an uevent to user space to indicate that a media change event has
occurred.

Signed-off-by: Kristen Carlson Accardi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kaccardi authored and Linus Torvalds committed May 24, 2007
1 parent 86ce18d commit 8ce7ad7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,27 @@ struct seq_operations diskstats_op = {
.show = diskstats_show
};

static void media_change_notify_thread(struct work_struct *work)
{
struct gendisk *gd = container_of(work, struct gendisk, async_notify);
char event[] = "MEDIA_CHANGE=1";
char *envp[] = { event, NULL };

/*
* set enviroment vars to indicate which event this is for
* so that user space will know to go check the media status.
*/
kobject_uevent_env(&gd->kobj, KOBJ_CHANGE, envp);
put_device(gd->driverfs_dev);
}

void genhd_media_change_notify(struct gendisk *disk)
{
get_device(disk->driverfs_dev);
schedule_work(&disk->async_notify);
}
EXPORT_SYMBOL_GPL(genhd_media_change_notify);

struct gendisk *alloc_disk(int minors)
{
return alloc_disk_node(minors, -1);
Expand Down Expand Up @@ -725,6 +746,8 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
kobj_set_kset_s(disk,block_subsys);
kobject_init(&disk->kobj);
rand_initialize_disk(disk);
INIT_WORK(&disk->async_notify,
media_change_notify_thread);
}
return disk;
}
Expand Down
4 changes: 3 additions & 1 deletion include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct partition {
#include <linux/smp.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/workqueue.h>

struct partition {
unsigned char boot_ind; /* 0x80 - active */
Expand Down Expand Up @@ -139,6 +140,7 @@ struct gendisk {
#else
struct disk_stats dkstats;
#endif
struct work_struct async_notify;
};

/* Structure for sysfs attributes on block devices */
Expand Down Expand Up @@ -420,7 +422,7 @@ extern struct gendisk *alloc_disk_node(int minors, int node_id);
extern struct gendisk *alloc_disk(int minors);
extern struct kobject *get_disk(struct gendisk *disk);
extern void put_disk(struct gendisk *disk);

extern void genhd_media_change_notify(struct gendisk *disk);
extern void blk_register_region(dev_t dev, unsigned long range,
struct module *module,
struct kobject *(*probe)(dev_t, int *, void *),
Expand Down

0 comments on commit 8ce7ad7

Please sign in to comment.