Skip to content

Commit 5792a28

Browse files
neilbrownLinus Torvalds
authored andcommitted
[PATCH] md: avoid a deadlock when removing a device from an md array via sysfs
A device can be removed from an md array via e.g. echo remove > /sys/block/md3/md/dev-sde/state This will try to remove the 'dev-sde' subtree which will deadlock since commit e7b0d26 With this patch we run the kobject_del via schedule_work so as to avoid the deadlock. Cc: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 456a09d commit 5792a28

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

drivers/md/md.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,12 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
13781378
return err;
13791379
}
13801380

1381+
static void delayed_delete(struct work_struct *ws)
1382+
{
1383+
mdk_rdev_t *rdev = container_of(ws, mdk_rdev_t, del_work);
1384+
kobject_del(&rdev->kobj);
1385+
}
1386+
13811387
static void unbind_rdev_from_array(mdk_rdev_t * rdev)
13821388
{
13831389
char b[BDEVNAME_SIZE];
@@ -1390,7 +1396,12 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev)
13901396
printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b));
13911397
rdev->mddev = NULL;
13921398
sysfs_remove_link(&rdev->kobj, "block");
1393-
kobject_del(&rdev->kobj);
1399+
1400+
/* We need to delay this, otherwise we can deadlock when
1401+
* writing to 'remove' to "dev/state"
1402+
*/
1403+
INIT_WORK(&rdev->del_work, delayed_delete);
1404+
schedule_work(&rdev->del_work);
13941405
}
13951406

13961407
/*
@@ -3389,6 +3400,9 @@ static int do_md_stop(mddev_t * mddev, int mode)
33893400
sysfs_remove_link(&mddev->kobj, nm);
33903401
}
33913402

3403+
/* make sure all delayed_delete calls have finished */
3404+
flush_scheduled_work();
3405+
33923406
export_array(mddev);
33933407

33943408
mddev->array_size = 0;

include/linux/raid/md_k.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct mdk_rdev_s
104104
* for reporting to userspace and storing
105105
* in superblock.
106106
*/
107+
struct work_struct del_work; /* used for delayed sysfs removal */
107108
};
108109

109110
struct mddev_s

0 commit comments

Comments
 (0)