dm: uevent generate events
Subsystems (2)
Alasdair G Kergon
maintainerPATCH 3/4 dm: uevent generate events
From: Mike Anderson <[email protected]>
This patch adds support for the dm_path_event dm_send_event functions which create and send udev events.
Signed-off-by Mike Anderson <[email protected]>
Signed-off-by Alasdair G Kergon <[email protected]>
---
Documentation/device-mapper/dm-uevent.txt | 97 +++++++++++++++++++ drivers/md/dm-uevent.c | 150 ++++++++++++++++++++++++++++++ drivers/md/dm-uevent.h | 18 +++ drivers/md/dm.c | 28 +++++ include/linux/device-mapper.h | 2 5 files changed, 295 insertions(+)
Documentation/device-mapper/dm-uevent.txt new file +97 -0
@@ -0,0 +1,97 @@ +The device-mapper uevent code adds the capability to device-mapper to create +and send kobject uevents (uevents). Previously device-mapper events were only +available through the ioctl interface. The advantage of the uevents interface +is the event contains environment attributes providing increased context for +the event avoiding the need to query the state of the device-mapper device after +the event is received. + +There are two functions currently for device-mapper events. The first function +listed creates the event and the second function sends the event(s). + +void dm_path_uevent(enum dm_uevent_type event_type, struct dm_target *ti, + const char *path, unsigned nr_valid_paths) + +void dm_send_uevents(struct list_head *events, struct kobject *kobj) + + +The variables added to the uevent environment are: + +Variable Name: DM_TARGET +Uevent Action(s): KOBJ_CHANGE +Type: string +Description: +Value: Name of device-mapper target that generated the event. + +Variable Name: DM_ACTION +Uevent Action(s): KOBJ_CHANGE +Type: string +Description: +Value: Device-mapper specific action that caused the uevent action. + PATH_FAILED - A path has failed. + PATH_REINSTATED - A path has been reinstated. + +Variable Name: DM_SEQNUM +Uevent Action(s): KOBJ_CHANGE +Type: unsigned integer +Description: A sequence number for this specific device-mapper device. +Value: Valid unsigned integer range. + +Variable Name: DM_PATH +Uevent Action(s): KOBJ_CHANGE +Type: string +Description: Major and minor number of the path device pertaining to this +event. +Value: Path name in the form of "Major:Minor" + +Variable Name: DM_NR_VALID_PATHS +Uevent Action(s): KOBJ_CHANGE +Type: unsigned integer +Description: +Value: Valid unsigned integer range. + +Variable Name: DM_NAME +Uevent Action(s): KOBJ_CHANGE +Type: string +Description: Name of the device-mapper device. +Value: Name + +Variable Name: DM_UUID +Uevent Action(s): KOBJ_CHANGE +Type: string +Description: UUID of the device-mapper device. +Value: UUID. (Empty string if there isn't one.) + +An example of the uevents generated as captured by udevmonitor is shown +below. + +1.) Path failure. +UEVENT[1192521009.711215] change@/block/dm-3 +ACTION=change +DEVPATH=/block/dm-3 +SUBSYSTEM=block +DM_TARGET=multipath +DM_ACTION=PATH_FAILED +DM_SEQNUM=1 +DM_PATH=8:32 +DM_NR_VALID_PATHS=0 +DM_NAME=mpath2 +DM_UUID=mpath-35333333000002328 +MINOR=3 +MAJOR=253 +SEQNUM=1130 + +2.) Path reinstate. +UEVENT[1192521132.989927] change@/block/dm-3 +ACTION=change +DEVPATH=/block/dm-3 +SUBSYSTEM=block +DM_TARGET=multipath +DM_ACTION=PATH_REINSTATED +DM_SEQNUM=2 +DM_PATH=8:32 +DM_NR_VALID_PATHS=1 +DM_NAME=mpath2 +DM_UUID=mpath-35333333000002328 +MINOR=3 +MAJOR=253 +SEQNUM=1131
drivers/md/dm-uevent.c +150 -0
174 lines not on this page · raw message
drivers/md/dm-uevent.h +18 -0
@@ -21,10 +21,19 @@#ifndef DM_UEVENT_H #define DM_UEVENT_H +enum dm_uevent_type { +DM_UEVENT_PATH_FAILED , +DM_UEVENT_PATH_REINSTATED , +}; +#ifdef CONFIG_DM_UEVENT extern int dm_uevent_init (void );extern void dm_uevent_exit (void ); +extern void dm_send_uevents (struct list_head *events,struct kobject *kobj); +extern void dm_path_uevent (enum dm_uevent_type event_type, +struct dm_target *ti,const char *path, +unsigned nr_valid_paths);#else
@@ -35,6 +44,15 @@ static inline int dm_uevent_init(void)static inline void dm_uevent_exit (void ) { } +static inline void dm_send_uevents (struct list_head *events, +struct kobject *kobj) +{ +} +static inline void dm_path_uevent (enum dm_uevent_type event_type, +struct dm_target *ti,const char *path, +unsigned nr_valid_paths) +{ +}#endif /* CONFIG_DM_UEVENT */
drivers/md/dm.c +28 -0
@@ -113,6 +113,9 @@ struct mapped_device {*/ atomic_t event_nr;wait_queue_head_t eventq; +atomic_t uevent_seq; +struct list_head uevent_list; +spinlock_t uevent_lock;/* Protect access to uevent_list */ /* * freeze/thaw support require holding onto a super block
@@ -985,6 +988,9 @@ static struct mapped_device *alloc_dev(iatomic_set (&md->holders,1 );atomic_set (&md->open_count,0 );atomic_set (&md->event_nr,0 ); +atomic_set (&md->uevent_seq,0 ); +INIT_LIST_HEAD (&md->uevent_list); +spin_lock_init (&md->uevent_lock); md->queue =blk_alloc_queue (GFP_KERNEL );if (!md->queue)
@@ -1083,8 +1089,16 @@ static void free_dev(struct mapped_devic*/ static void event_callback (void *context) { +unsigned long flags; +LIST_HEAD (uevents);struct mapped_device *md = (struct mapped_device *) context; +spin_lock_irqsave (&md->uevent_lock, flags); +list_splice_init (&md->uevent_list, &uevents); +spin_unlock_irqrestore (&md->uevent_lock, flags); + +dm_send_uevents (&uevents, &md->disk->kobj); +atomic_inc (&md->event_nr);wake_up (&md->eventq); }
@@ -1502,6 +1516,11 @@ out:/*----------------------------------------------------------------- * Event notification. *---------------------------------------------------------------*/ +uint32_t dm_next_uevent_seq (struct mapped_device *md) +{ +return atomic_add_return (1 , &md->uevent_seq); +} +uint32_t dm_get_event_nr (struct mapped_device *md) {return atomic_read (&md->event_nr);
@@ -1513,6 +1532,15 @@ int dm_wait_event(struct mapped_device * (event_nr != atomic_read(&md->event_nr))); } +void dm_uevent_add (struct mapped_device *md,struct list_head *elist) +{ +unsigned long flags; + +spin_lock_irqsave (&md->uevent_lock, flags); +list_add (elist, &md->uevent_list); +spin_unlock_irqrestore (&md->uevent_lock, flags); +} +/* * The gendisk is only valid as long as you have a reference * count on 'md'.
include/linux/device-mapper.h +2 -0
@@ -183,6 +183,8 @@ int dm_resume(struct mapped_device *md);*/ uint32_t dm_get_event_nr (struct mapped_device *md);int dm_wait_event (struct mapped_device *md,int event_nr); +uint32_t dm_next_uevent_seq (struct mapped_device *md); +void dm_uevent_add (struct mapped_device *md,struct list_head *elist);/* * Info functions.