Use uevent for thin pool events
Subsystems (2)
cover Use uevent for thin pool events
uevents both let us attach additional info to the event, and also allow interested user processes to receive them without having to create and manage threads to sit in DEV_WAIT ioctls for each target we're interested in.
dm-mpath already supports generating uevents. This patchset generalizes this code a little to allow another target to also generate uevents, dm-thin, as a first step for what we might like to do for all targets' events. DEV_WAIT ioctl support is unchanged.
Andy Grover (5):
dm: Do not export dm_send_uevents
dm: Move multipath-specific stuff out of dm-uevent.c
dm: Inline dm_build_path_uevent into dm_path_uevent
dm: Add uevent support for dm-thin
dm: Update dm-uevent.txt
Documentation/device-mapper/dm-uevent.txt | 48 ++++++++++++++++--- drivers/md/dm-mpath.c | 56 +++++++++++++++++++++++ drivers/md/dm-thin.c | 18 ++++++++ drivers/md/dm-uevent.c | 76 +++---------------------------- drivers/md/dm-uevent.h | 30 +++++++++--- drivers/md/dm.c | 1 + 6 files changed, 147 insertions(+), 82 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/5 dm: Do not export dm_send_uevents
Since dm-uevent.c (if CONFIG_DM_UEVENT) is part of the same module as where dm_sent_uevents is called, it does not need to be exported.
--- drivers/md/dm-uevent.c | 1 - 1 file changed, 1 deletion(-)
drivers/md/dm-uevent.c +0 -1
@@ -169,7 +169,6 @@ uevent_free:dm_uevent_free (event); } } -EXPORT_SYMBOL_GPL (dm_send_uevents);/** * dm_path_uevent - called to create a new path event and queue it
Signature · 1 line
2.5.0
PATCH 2/5 dm: Move multipath-specific stuff out of dm-uevent.c
In reply to Andy GroverThere's a little bit of mpath-specific stuff that is in dm-uevent.c, because all current uevents want to attach DM_PATH and DM_NR_VALID_PATHS variables to the uevent. Makes sense since all currently defined DM uevents are for dm-mpath, but is not true for future uevents. Move the addition of these to dm-mpath.c and expose a few lower-level functions, dm_build_uevent, dm_uevent_add and dm_uevent_free, for other dm targets to build their own uevents.
--- drivers/md/dm-mpath.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/dm-uevent.c | 75 +++++--------------------------------------------- drivers/md/dm-uevent.h | 30 ++++++++++++++++---- drivers/md/dm.c | 1 + 4 files changed, 103 insertions(+), 74 deletions(-)
drivers/md/dm-mpath.c +71 -0
@@ -29,6 +29,15 @@#define DM_PG_INIT_DELAY_MSECS 2000#define DM_PG_INIT_DELAY_DEFAULT ((unsigned) -1) +static const struct { +enum dm_uevent_type type; +enum kobject_action action; +char *name; +} _dm_mpath_uevent_type_names[] = { + {DM_UEVENT_PATH_FAILED ,KOBJ_CHANGE ,"PATH_FAILED" }, + {DM_UEVENT_PATH_REINSTATED ,KOBJ_CHANGE ,"PATH_REINSTATED" }, +}; +/* Path properties */ struct pgpath {struct list_head list;
@@ -968,6 +977,68 @@ static void multipath_dtr(struct dm_target *ti)free_multipath (m); } +static struct dm_uevent *dm_build_path_uevent (struct mapped_device *md, +struct dm_target *ti, +enum kobject_action action, +const char *dm_action, +const char *path, +unsigned nr_valid_paths) +{ +struct dm_uevent *event; + + event =dm_build_uevent (md, ti, action, dm_action); +if (IS_ERR (event)) +return event; + +if (add_uevent_var (&event->ku_env,"DM_PATH=%s" , path)) { +DMERR ("%s: add_uevent_var() for DM_PATH failed" , __func__); + goto err_add; + } + +if (add_uevent_var (&event->ku_env,"DM_NR_VALID_PATHS=%d" , + nr_valid_paths)) { +DMERR ("%s: add_uevent_var() for DM_NR_VALID_PATHS failed" , + __func__); + goto err_add; + } + +return event; + +err_add: +dm_uevent_free (event); +return ERR_PTR (-ENOMEM ); +} + +/** +* dm_path_uevent - called to create a new path event and queue it +* +* @event_type: path event type enum +* @ti: pointer to a dm_target +* @path: string containing pathname +* @nr_valid_paths: number of valid paths remaining +* +*/ +static void dm_path_uevent (enum dm_uevent_type event_type,struct dm_target *ti, +const char *path,unsigned nr_valid_paths) +{ +struct mapped_device *md =dm_table_get_md (ti->table); +struct dm_uevent *event; + +if (event_type >=ARRAY_SIZE (_dm_mpath_uevent_type_names)) { +DMERR ("%s: Invalid event_type %d" , __func__, event_type); +return ; + } + + event =dm_build_path_uevent (md, ti, + _dm_mpath_uevent_type_names[event_type].action, + _dm_mpath_uevent_type_names[event_type].name, + path, nr_valid_paths); +if (IS_ERR (event)) +return ; + +dm_uevent_add (md, &event->elist); +} +/* * Take a path out of use. */
drivers/md/dm-uevent.c +7 -68
110 lines not on this page · raw message
drivers/md/dm-uevent.h +24 -6
@@ -21,6 +21,17 @@#ifndef DM_UEVENT_H #define DM_UEVENT_H +#include <linux/dm-ioctl.h> // for DM_*_LEN + +struct dm_uevent { +struct mapped_device *md; +enum kobject_action action; +struct kobj_uevent_env ku_env; +struct list_head elist; +char name[DM_NAME_LEN ]; +char uuid[DM_UUID_LEN ]; +}; +enum dm_uevent_type {DM_UEVENT_PATH_FAILED , DM_UEVENT_PATH_REINSTATED,
@@ -31,9 +42,11 @@ enum dm_uevent_type {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); +struct dm_uevent *dm_build_uevent (struct mapped_device *md, +struct dm_target *ti, +enum kobject_action action, +const char *dm_action); +void dm_uevent_free (struct dm_uevent *event);#else
@@ -48,9 +61,14 @@ 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) +static inline struct dm_uevent *dm_build_uevent (struct mapped_device *md, +struct dm_target *ti, +enum kobject_action action, +const char *dm_action) +{ +return ERR_PTR (-ENOMEM ); +} +static void dm_uevent_free (struct dm_uevent *event) { }
drivers/md/dm.c +1 -0
@@ -3473,6 +3473,7 @@ void dm_uevent_add(struct mapped_device *md, struct list_head *elist)list_add (elist, &md->uevent_list);spin_unlock_irqrestore (&md->uevent_lock, flags); } +EXPORT_SYMBOL_GPL (dm_uevent_add);/* * The gendisk is only valid as long as you have a reference
Signature · 1 line
2.5.0
PATCH 3/5 dm: Inline dm_build_path_uevent into dm_path_uevent
In reply to Andy GroverSince it's no longer an API boundary we can consolidate these two functions.
--- drivers/md/dm-mpath.c | 59 +++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 37 deletions(-)
drivers/md/dm-mpath.c +22 -37
@@ -977,38 +977,6 @@ static void multipath_dtr(struct dm_target *ti)free_multipath (m); } -static struct dm_uevent *dm_build_path_uevent (struct mapped_device *md, -struct dm_target *ti, -enum kobject_action action, -const char *dm_action, -const char *path, -unsigned nr_valid_paths) -{ -struct dm_uevent *event; - - event =dm_build_uevent (md, ti, action, dm_action); -if (IS_ERR (event)) -return event; - -if (add_uevent_var (&event->ku_env,"DM_PATH=%s" , path)) { -DMERR ("%s: add_uevent_var() for DM_PATH failed" , __func__); - goto err_add; - } - -if (add_uevent_var (&event->ku_env,"DM_NR_VALID_PATHS=%d" , - nr_valid_paths)) { -DMERR ("%s: add_uevent_var() for DM_NR_VALID_PATHS failed" , - __func__); - goto err_add; - } - -return event; - -err_add: -dm_uevent_free (event); -return ERR_PTR (-ENOMEM ); -} -/** * dm_path_uevent - called to create a new path event and queue it *
@@ -1029,14 +997,31 @@ static void dm_path_uevent(enum dm_uevent_type event_type, struct dm_target *ti,return ; } - event =dm_build_path_uevent (md, ti, - _dm_mpath_uevent_type_names[event_type].action, - _dm_mpath_uevent_type_names[event_type].name, - path, nr_valid_paths); -if (IS_ERR (event)) + event =dm_build_uevent (md, + ti, + _dm_mpath_uevent_type_names[event_type].action, + _dm_mpath_uevent_type_names[event_type].name); +if (IS_ERR (event)) { +DMERR ("%s: dm_build_uevent() failed" , __func__);return ; + } + +if (add_uevent_var (&event->ku_env,"DM_PATH=%s" , path)) { +DMERR ("%s: add_uevent_var() for DM_PATH failed" , __func__); + goto err; + } + +if (add_uevent_var (&event->ku_env,"DM_NR_VALID_PATHS=%d" , + nr_valid_paths)) { +DMERR ("%s: add_uevent_var() for DM_NR_VALID_PATHS failed" , + __func__); + goto err; + }dm_uevent_add (md, &event->elist); +return ; +err: +dm_uevent_free (event); }/*
Signature · 1 line
2.5.0
PATCH 4/5 dm: Add uevent support for dm-thin
In reply to Andy GroverCreate a uevent before calling dm_table_event() when either data or metadata low water are hit, as well as when pool mode changes.
--- drivers/md/dm-thin.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/md/dm-thin.c +18 -0
@@ -7,6 +7,7 @@#include "dm-thin-metadata.h" #include "dm-bio-prison.h" #include "dm.h" +#include "dm-uevent.h" #include <linux/device-mapper.h> #include <linux/dm-io.h>
@@ -1345,6 +1346,20 @@ static int commit(struct pool *pool)return r; } +static void add_thin_uevent (struct dm_target *ti,char *name) +{ +struct mapped_device *md =dm_table_get_md (ti->table); +struct dm_uevent *event; + + event =dm_build_uevent (md, ti,KOBJ_CHANGE , name); +if (IS_ERR (event)) { +DMERR ("%s: dm_build_uevent() failed" , __func__); +return ; + } + +dm_uevent_add (md, &event->elist); +} +static void check_low_water_mark (struct pool *pool,dm_block_t free_blocks) {unsigned long flags;
@@ -1355,6 +1370,7 @@ static void check_low_water_mark(struct pool *pool, dm_block_t free_blocks)spin_lock_irqsave (&pool->lock, flags); pool->low_water_triggered = true;spin_unlock_irqrestore (&pool->lock, flags); +add_thin_uevent (pool->ti,"THIN_LOW_WATER_DATA" );dm_table_event (pool->ti->table); } }
@@ -2331,6 +2347,7 @@ static enum pool_mode get_pool_mode(struct pool *pool)static void notify_of_pool_mode_change (struct pool *pool,const char *new_mode) { +add_thin_uevent (pool->ti,"THIN_POOL_MODE" );dm_table_event (pool->ti->table);DMINFO ("%s: switching pool to %s mode" ,dm_device_name (pool->pool_md), new_mode);
@@ -3026,6 +3043,7 @@ static void metadata_low_callback(void *context)DMWARN ("%s: reached low water mark for metadata device: sending event." ,dm_device_name (pool->pool_md)); +add_thin_uevent (pool->ti,"THIN_LOW_WATER_METADATA" );dm_table_event (pool->ti->table); }
Signature · 1 line
2.5.0
PATCH 5/5 dm: Update dm-uevent.txt
In reply to Andy GroverDocument the current dm uevent API, as modified by this patchset.
--- Documentation/device-mapper/dm-uevent.txt | 48 ++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-)
Documentation/device-mapper/dm-uevent.txt +41 -7
@@ -1,18 +1,52 @@ 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 +available through the ioctl interface. The advantages of the uevents interface +are 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. +the event is received, and uevents are poll()-able in userspace, whereas the +ioctl event interface is not. -There are two functions currently for device-mapper events. The first function -listed creates the event and the second function sends the event(s). +There are five functions DM targets should use. -void dm_path_uevent(enum dm_uevent_type event_type, struct dm_target *ti, - const char *path, unsigned nr_valid_paths) +struct dm_uevent *dm_build_uevent(struct mapped_device *md, + struct dm_target *ti, + enum kobject_action action, + const char *dm_action) + +Construct a dm uevent. + +int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) + +Optionally add event-specific data to the generated uevent. e.g. dm-mpath's +PATH_FAILED and PATH_REINSTATED uevents add path and number-of-remaining-paths +vars. + +void dm_uevent_add(struct mapped_device *md, struct list_head *elist) + +Hand off the uevent to the device's list of pending events. + +void dm_uevent_free(struct dm_uevent *event) + +Something went wrong, free the uevent instead of queueing it. + +void dm_table_event(struct dm_table *t) + +Triggers sending of queued uevents as well as waking up processes waiting on +the ioctl. + + +The device-mapper uevent code also supplies three functions for device-mapper core +to call: + +int dm_uevent_init(void) +void dm_uevent_exit(void) + +Setup and teardown. void dm_send_uevents(struct list_head *events, struct kobject *kobj) +Actually send the uevents (called indirectly from dm_table_event, above). + The variables added to the uevent environment are:
Signature · 1 line
2.5.0