dm: add uevent skeleton support
Subsystems (2)
PATCH 1/4 dm: add uevent skeleton support
In reply to a message not in the archiveThis patch adds a dm-uevent skeleton support to the Makefile, and the dm directory.
Signed-off-by Mike Anderson <[email protected]>
---
drivers/md/Kconfig | 6 ++++ drivers/md/Makefile | 4 ++ drivers/md/dm-uevent.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/dm-uevent.h | 41 +++++++++++++++++++++++++++ drivers/md/dm.c | 10 ++++++ 5 files changed, 133 insertions(+)
drivers/md/Kconfig +6 -0
@@ -276,4 +276,10 @@ config DM_DELAY If unsure, say N. +config DM_UEVENT + bool "DM uevents (EXPERIMENTAL)" + depends on BLK_DEV_DM && EXPERIMENTAL + ---help--- + Generate udev events for DM events. + endif # MD
drivers/md/Makefile +4 -0
@@ -48,6 +48,10 @@ ifeq ($(CONFIG_ALTIVEC),y) altivec_flags := -maltivec -mabi=altivec endif +ifeq ($(CONFIG_DM_UEVENT),y) +dm-mod-objs += dm-uevent.o +endif + targets += raid6int1.c $(obj)/raid6int1.c: UNROLL := 1 $(obj)/raid6int1.c: $(src)/raid6int.uc $(src)/unroll.pl FORCE
drivers/md/dm-uevent.c new file +72 -0
72 lines not on this page · raw message
drivers/md/dm-uevent.h new file +41 -0
41 lines not on this page · raw message
drivers/md/dm.c +10 -0
@@ -7,6 +7,7 @@#include "dm.h" #include "dm-bio-list.h" +#include "dm-uevent.h" #include <linux/init.h> #include <linux/module.h>
@@ -151,6 +152,14 @@ static int __init local_init(void)return r; } + r =dm_uevent_init (); +if (r <0 ) { +kmem_cache_destroy (_tio_cache); +kmem_cache_destroy (_io_cache); +unregister_blkdev (_major, _name); +return r; + } +if (!_major) _major = r;
@@ -159,6 +168,7 @@ static int __init local_init(void)static void local_exit (void ) { +dm_uevent_exit ();kmem_cache_destroy (_tio_cache);kmem_cache_destroy (_io_cache);unregister_blkdev (_major, _name);
PATCH 2/4 dm: add uevent functions
In reply to a message not in the archiveThis 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]>
---
drivers/md/dm-uevent.c | 110 ++++++++++++++++++++++++++++++++++++++++++ drivers/md/dm-uevent.h | 18 ++++++ drivers/md/dm.c | 28 ++++++++++ include/linux/device-mapper.h | 2 4 files changed, 158 insertions(+)
drivers/md/dm-uevent.c +110 -0
@@ -27,6 +27,16 @@#define DM_MSG_PREFIX "uevent" +static struct { +enum dm_uevent_type type; +enum kobject_action action; +char *name; +} dm_uevent_type_names[] = { + {DM_UEVENT_UNKNOWN ,KOBJ_CHANGE ,"UNKNOWN" }, + {DM_UEVENT_PATH_FAILED ,KOBJ_CHANGE ,"PATH_FAILED" }, + {DM_UEVENT_PATH_REINSTATED ,KOBJ_CHANGE ,"PATH_REINSTATED" }, +}; +static struct kmem_cache *_dme_cache;struct dm_uevent {
@@ -55,6 +65,106 @@ static struct dm_uevent *dm_uevent_allocreturn evt; } +static struct dm_uevent *dm_build_path_uevent (struct mapped_device *md, +enum kobject_action action, +const char *dm_action, +const char *path, +int nr_valid_paths) +{ +struct dm_uevent *evt; + + evt =dm_uevent_alloc (md); +if (!evt) { +DMERR ("%s: dm_uevent_alloc() failed" , __FUNCTION__); + goto out_nomem; + } + + evt->action = action; + +if (add_uevent_var (&evt->ku_env,"DM_ACTION=%s" , dm_action)) { +DMERR ("%s: add_uevent_var() for DM_ACTION failed" , + __FUNCTION__); + goto out_add; + } + +if (add_uevent_var (&evt->ku_env,"DM_SEQNUM=%u" , +dm_next_uevent_seq (md))) { +DMERR ("%s: add_uevent_var() for DM_SEQNUM failed" , + __FUNCTION__); + goto out_add; + } + +if (add_uevent_var (&evt->ku_env,"DM_PATH=%s" , path)) { +DMERR ("%s: add_uevent_var() for DM_PATH failed" , + __FUNCTION__); + goto out_add; + } + +if (add_uevent_var (&evt->ku_env,"DM_PATHS=%d" , nr_valid_paths)) { +DMERR ("%s: add_uevent_var() for DM_PATHS failed" , + __FUNCTION__); + goto out_add; + } + +return evt; + +out_add: +dm_uevent_free (evt); +out_nomem: +return ERR_PTR (-ENOMEM ); +} + +/** +* dm_send_uevents - send uevents for given list +* +* @events: list of events to send +* @kobj: kobject generating event +* +**/ +void dm_send_uevents (struct list_head *events,struct kobject *kobj) +{ +int r; +struct dm_uevent *evt, *next; + +list_for_each_entry_safe (evt, next, events, elist) { +list_del_init (&evt->elist); + r =kobject_uevent_env (kobj, evt->action, evt->ku_env.envp); +if (r) +DMERR ("%s: kobject_uevent_env failed" , __FUNCTION__); +dm_uevent_free (evt); + } +} +EXPORT_SYMBOL_GPL (dm_send_uevents); + +/** +* dm_path_uevent - called to create a new path event and queue it +* +* @evt_type: path event type enum +* @t: pointer to a dm_table +* @path: string containing pathname +* @nr_valid_paths: number of valid paths remaining +* +**/ +void dm_path_uevent (enum dm_uevent_type evt_type,struct dm_table *t, +const char *path,int nr_valid_paths) +{ +struct mapped_device *md =dm_table_get_md (t); +struct dm_uevent *evt; + +if (evt_type <ARRAY_SIZE (dm_uevent_type_names)) { + evt =dm_build_path_uevent (md, + dm_uevent_type_names[evt_type].action, + dm_uevent_type_names[evt_type].name, + path, + nr_valid_paths); +if (!IS_ERR (evt)) +dm_uevent_add (md, &evt->elist); + }else +DMERR ("%s: Invalid evt_type %d" , __FUNCTION__, evt_type); +dm_put (md); +} +EXPORT_SYMBOL_GPL (dm_path_uevent); +int dm_uevent_init (void ) { _dme_cache =KMEM_CACHE (dm_uevent,0 );
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_UNKNOWN , +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 evt_type,struct dm_table *t, +const char *path,int 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 evt_type, +struct dm_table *t,const char *path, +int 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
@@ -991,6 +994,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)
@@ -1087,8 +1093,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); }
@@ -1505,6 +1519,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);
@@ -1516,6 +1535,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.
PATCH 3/4 dm: add name and uuid env values
In reply to a message not in the archiveThis patch obtains DM_NAME and DM_UUID from the dm hash cell structure.
Signed-off-by Mike Anderson <[email protected]>
---
drivers/md/dm-ioctl.c | 33 +++++++++++++++++++++++++++++++++ drivers/md/dm-uevent.c | 12 ++++++++++++ include/linux/device-mapper.h | 1 + 3 files changed, 46 insertions(+)
drivers/md/dm-ioctl.c +33 -0
@@ -15,6 +15,7 @@#include <linux/slab.h> #include <linux/dm-ioctl.h> #include <linux/hdreg.h> +#include <linux/kobject.h> #include <asm/uaccess.h>
@@ -1515,3 +1516,35 @@ void dm_interface_exit(void)dm_hash_exit (); } + +int dm_ue_uuid_name_get (struct kobj_uevent_env *env,struct mapped_device *md) +{ +int r =0 ; +struct hash_cell *hc; + +if (!md) +return -ENXIO ; + +dm_get (md); +down_write (&_hash_lock); + hc =dm_get_mdptr (md); +if (!hc || hc->md != md) { + r = -ENXIO ; + goto out; + } + +if (add_uevent_var (env,"DM_NAME=%s" , hc->name)) { + r = -ENOMEM ; + goto out; + } + +if (add_uevent_var (env,"DM_UUID=%s" , hc->uuid)) { + r = -ENOMEM ; + goto out; + } + +out: +up_write (&_hash_lock); +dm_put (md); +return r; +}
drivers/md/dm-uevent.c +12 -0
@@ -128,6 +128,18 @@ void dm_send_uevents(struct list_head *elist_for_each_entry_safe (evt, next, events, elist) {list_del_init (&evt->elist); + +/* +* Need to get the uuid here for now. Context of previous +* var adds and locking used for hash_cell not compatable. +*/ +if (dm_ue_uuid_name_get (&evt->ku_env, evt->md)) { +DMERR ("%s: dm_ue_uuid_name_get() failed" , + __FUNCTION__); +dm_uevent_free (evt); +continue ; + } + r =kobject_uevent_env (kobj, evt->action, evt->ku_env.envp);if (r)DMERR ("%s: kobject_uevent_env failed" , __FUNCTION__);
include/linux/device-mapper.h +1 -0
@@ -185,6 +185,7 @@ uint32_t dm_get_event_nr(struct mapped_dint 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); +int dm_ue_uuid_name_get (struct kobj_uevent_env *env,struct mapped_device *md);/* * Info functions.
PATCH 4/4 dm: add calls for path event functions
In reply to a message not in the archiveThis patch adds calls to dm_path_event for a failed path and a reinstated path.
Signed-off-by Mike Anderson <[email protected]>
---
drivers/md/dm-mpath.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/md/dm-mpath.c +7 -0
@@ -10,6 +10,7 @@#include "dm-hw-handler.h" #include "dm-bio-list.h" #include "dm-bio-record.h" +#include "dm-uevent.h" #include <linux/ctype.h> #include <linux/init.h>
@@ -834,6 +835,9 @@ static int fail_path(struct pgpath *pgpaif (pgpath == m->current_pgpath) m->current_pgpath =NULL ; +dm_path_uevent (DM_UEVENT_PATH_FAILED , m->ti->table, + pgpath->path.dev->name, m->nr_valid_paths); +queue_work (kmultipathd, &m->trigger_event); out:
@@ -873,6 +877,9 @@ static int reinstate_path(struct pgpathif (!m->nr_valid_paths++ && m->queue_size)queue_work (kmultipathd, &m->process_queued_ios); +dm_path_uevent (DM_UEVENT_PATH_REINSTATED , m->ti->table, + pgpath->path.dev->name, m->nr_valid_paths); +queue_work (kmultipathd, &m->trigger_event); out: