Skip to content

Commit 98f3328

Browse files
Kiyoshi Uedakergon
authored andcommitted
dm ioctl: release _hash_lock between devices in remove_all
This patch changes dm_hash_remove_all() to release _hash_lock when removing a device. After removing the device, dm_hash_remove_all() takes _hash_lock and searches the hash from scratch again. This patch is a preparation for the next patch, which changes device deletion code to wait for md reference to be 0. Without this patch, the wait in the next patch may cause AB-BA deadlock: CPU0 CPU1 ----------------------------------------------------------------------- dm_hash_remove_all() down_write(_hash_lock) table_status() md = find_device() dm_get(md) <increment md->holders> dm_get_live_or_inactive_table() dm_get_inactive_table() down_write(_hash_lock) <in the md deletion code> <wait for md->holders to be 0> Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com> Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com> Cc: stable@kernel.org Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent abdc568 commit 98f3328

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

‎drivers/md/dm-ioctl.c‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -249,40 +249,46 @@ static void __hash_remove(struct hash_cell *hc)
249249

250250
static void dm_hash_remove_all(int keep_open_devices)
251251
{
252-
int i, dev_skipped, dev_removed;
252+
int i, dev_skipped;
253253
struct hash_cell *hc;
254-
struct list_head *tmp, *n;
254+
struct mapped_device *md;
255+
256+
retry:
257+
dev_skipped = 0;
255258

256259
down_write(&_hash_lock);
257260

258-
retry:
259-
dev_skipped = dev_removed = 0;
260261
for (i = 0; i < NUM_BUCKETS; i++) {
261-
list_for_each_safe (tmp, n, _name_buckets + i) {
262-
hc = list_entry(tmp, struct hash_cell, name_list);
262+
list_for_each_entry(hc, _name_buckets + i, name_list) {
263+
md = hc->md;
264+
dm_get(md);
263265

264-
if (keep_open_devices &&
265-
dm_lock_for_deletion(hc->md)) {
266+
if (keep_open_devices && dm_lock_for_deletion(md)) {
267+
dm_put(md);
266268
dev_skipped++;
267269
continue;
268270
}
271+
269272
__hash_remove(hc);
270-
dev_removed = 1;
271-
}
272-
}
273273

274-
/*
275-
* Some mapped devices may be using other mapped devices, so if any
276-
* still exist, repeat until we make no further progress.
277-
*/
278-
if (dev_skipped) {
279-
if (dev_removed)
280-
goto retry;
274+
up_write(&_hash_lock);
281275

282-
DMWARN("remove_all left %d open device(s)", dev_skipped);
276+
dm_put(md);
277+
278+
/*
279+
* Some mapped devices may be using other mapped
280+
* devices, so repeat until we make no further
281+
* progress. If a new mapped device is created
282+
* here it will also get removed.
283+
*/
284+
goto retry;
285+
}
283286
}
284287

285288
up_write(&_hash_lock);
289+
290+
if (dev_skipped)
291+
DMWARN("remove_all left %d open device(s)", dev_skipped);
286292
}
287293

288294
static struct mapped_device *dm_hash_rename(struct dm_ioctl *param,

0 commit comments

Comments
 (0)