From d93364722a95994d42cdec2d248f51b44cfc6e4b Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Sun, 23 May 2010 14:21:38 -0400 Subject: [PATCH 5/6] dm ioctl: introduce dm_get_verified_mdptr Factor all appropriate consumers of dm_get_mdptr() to use the dm_get_verified_mdptr() rather than duplicate code. Signed-off-by: Mike Snitzer --- drivers/md/dm-ioctl.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) v2: adjusted patch relative to changes earlier in the patchset Index: linux-2.6/drivers/md/dm-ioctl.c =================================================================== --- linux-2.6.orig/drivers/md/dm-ioctl.c +++ linux-2.6/drivers/md/dm-ioctl.c @@ -174,6 +174,19 @@ static void free_cell(struct hash_cell * } } +static struct hash_cell *dm_get_verified_mdptr(struct mapped_device *md) +{ + struct hash_cell *hc; + + hc = dm_get_mdptr(md); + if (!hc || hc->md != md) { + DMWARN("device has been removed from the dev hash table."); + return NULL; + } + + return hc; +} + /* * The kdev_t and uuid of a device can never change once it is * initially inserted. @@ -546,11 +559,9 @@ static struct dm_table *dm_get_inactive_ struct dm_table *table = NULL; down_read(&_hash_lock); - hc = dm_get_mdptr(md); - if (!hc || hc->md != md) { - DMWARN("device has been removed from the dev hash table."); + hc = dm_get_verified_mdptr(md); + if (!hc) goto out; - } table = hc->new_map; if (table) @@ -876,9 +887,8 @@ static int do_resume(struct dm_ioctl *pa dm_lock_resume(md); down_write(&_hash_lock); - hc = dm_get_mdptr(md); - if (!hc || hc->md != md) { - DMWARN("device has been removed from the dev hash table."); + hc = dm_get_verified_mdptr(md); + if (!hc) { up_write(&_hash_lock); r = -ENXIO; goto out; @@ -1227,9 +1237,8 @@ static int table_load(struct dm_ioctl *p /* stage inactive table */ down_write(&_hash_lock); - hc = dm_get_mdptr(md); - if (!hc || hc->md != md) { - DMWARN("device has been removed from the dev hash table."); + hc = dm_get_verified_mdptr(md); + if (!hc) { dm_table_destroy(t); up_write(&_hash_lock); if (initial_table_load) @@ -1278,9 +1287,8 @@ static int table_clear(struct dm_ioctl * dm_lock_md_type(md); /* May need to clear md's type */ down_write(&_hash_lock); - hc = dm_get_mdptr(md); - if (!hc || hc->md != md) { - DMWARN("device has been removed from the dev hash table."); + hc = dm_get_verified_mdptr(md); + if (!hc) { up_write(&_hash_lock); r = -ENXIO; goto out; @@ -1737,8 +1745,8 @@ int dm_copy_name_and_uuid(struct mapped_ return -ENXIO; mutex_lock(&dm_hash_cells_mutex); - hc = dm_get_mdptr(md); - if (!hc || hc->md != md) { + hc = dm_get_verified_mdptr(md); + if (!hc) { r = -ENXIO; goto out; }