Re: [PATCH] md: Avoid a deadlock when removing a device from an mdarray via sysfs.

From: Neil Brown
Date: Mon Apr 02 2007 - 04:53:42 EST


On Monday April 2, akpm@xxxxxxxxxxxxxxxxxxxx wrote:
>
> What guarantees that *rdev is still valid when delayed_delete() runs?

Because that is how kobjects and krefs work. There is an embedded
refcount etc etc..

>
> And what guarantees that the md module hasn't been rmmodded when
> delayed_delete() tries to run?

Good point. Nothing. Maybe this patch is needed.

Thanks,
NeilBrown

---------------------------
Avoid a deadlock when removing a device from an md array via sysfs. - fix

Make sure any delayed_delete calls finish before module unload.
For simplicity, flush the queue when we stop the array.

Signed-off-by: Neil Brown <neilb@xxxxxxx>

### Diffstat output
./drivers/md/md.c | 3 +++
1 file changed, 3 insertions(+)

diff .prev/drivers/md/md.c ./drivers/md/md.c
--- .prev/drivers/md/md.c 2007-04-02 17:38:46.000000000 +1000
+++ ./drivers/md/md.c 2007-04-02 18:49:24.000000000 +1000
@@ -3410,6 +3410,9 @@ static int do_md_stop(mddev_t * mddev, i
sysfs_remove_link(&mddev->kobj, nm);
}

+ /* make sure all delayed_delete calls have finished */
+ flush_scheduled_work();
+
export_array(mddev);

mddev->array_size = 0;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/