aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm.c
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2009-01-05 22:05:10 -0500
committerAlasdair G Kergon <agk@redhat.com>2009-01-05 22:05:10 -0500
commitd58168763f74d1edbc296d7038c60efe6493fdd4 (patch)
tree03866d641211fe16961a5b8aab6d9132bf07d9c8 /drivers/md/dm.c
parentab4c1424882be9cd70b89abf2b484add355712fa (diff)
dm table: rework reference counting
Rework table reference counting. The existing code uses a reference counter. When the last reference is dropped and the counter reaches zero, the table destructor is called. Table reference counters are acquired/released from upcalls from other kernel code (dm_any_congested, dm_merge_bvec, dm_unplug_all). If the reference counter reaches zero in one of the upcalls, the table destructor is called from almost random kernel code. This leads to various problems: * dm_any_congested being called under a spinlock, which calls the destructor, which calls some sleeping function. * the destructor attempting to take a lock that is already taken by the same process. * stale reference from some other kernel code keeps the table constructed, which keeps some devices open, even after successful return from "dmsetup remove". This can confuse lvm and prevent closing of underlying devices or reusing device minor numbers. The patch changes reference counting so that the table destructor can be called only at predetermined places. The table has always exactly one reference from either mapped_device->map or hash_cell->new_map. After this patch, this reference is not counted in table->holders. A pair of dm_create_table/dm_destroy_table functions is used for table creation/destruction. Temporary references from the other code increase table->holders. A pair of dm_table_get/dm_table_put functions is used to manipulate it. When the table is about to be destroyed, we wait for table->holders to reach 0. Then, we call the table destructor. We use active waiting with msleep(1), because the situation happens rarely (to one user in 5 years) and removing the device isn't performance-critical task: the user doesn't care if it takes one tick more or not. This way, the destructor is called only at specific points (dm_table_destroy function) and the above problems associated with lazy destruction can't happen. Finally remove the temporary protection added to dm_any_congested(). Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r--drivers/md/dm.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index dd953b189f45..9f9aa64f7336 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -977,8 +977,6 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
977 struct mapped_device *md = congested_data; 977 struct mapped_device *md = congested_data;
978 struct dm_table *map; 978 struct dm_table *map;
979 979
980 atomic_inc(&md->pending);
981
982 if (!test_bit(DMF_BLOCK_IO, &md->flags)) { 980 if (!test_bit(DMF_BLOCK_IO, &md->flags)) {
983 map = dm_get_table(md); 981 map = dm_get_table(md);
984 if (map) { 982 if (map) {
@@ -987,10 +985,6 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
987 } 985 }
988 } 986 }
989 987
990 if (!atomic_dec_return(&md->pending))
991 /* nudge anyone waiting on suspend queue */
992 wake_up(&md->wait);
993
994 return r; 988 return r;
995} 989}
996 990
@@ -1250,10 +1244,12 @@ static int __bind(struct mapped_device *md, struct dm_table *t)
1250 1244
1251 if (md->suspended_bdev) 1245 if (md->suspended_bdev)
1252 __set_size(md, size); 1246 __set_size(md, size);
1253 if (size == 0) 1247
1248 if (!size) {
1249 dm_table_destroy(t);
1254 return 0; 1250 return 0;
1251 }
1255 1252
1256 dm_table_get(t);
1257 dm_table_event_callback(t, event_callback, md); 1253 dm_table_event_callback(t, event_callback, md);
1258 1254
1259 write_lock(&md->map_lock); 1255 write_lock(&md->map_lock);
@@ -1275,7 +1271,7 @@ static void __unbind(struct mapped_device *md)
1275 write_lock(&md->map_lock); 1271 write_lock(&md->map_lock);
1276 md->map = NULL; 1272 md->map = NULL;
1277 write_unlock(&md->map_lock); 1273 write_unlock(&md->map_lock);
1278 dm_table_put(map); 1274 dm_table_destroy(map);
1279} 1275}
1280 1276
1281/* 1277/*