md: close race between removing and adding a device.
authorNeilBrown <neilb@suse.de>
Tue, 11 Dec 2012 02:35:54 +0000 (13:35 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 11 Dec 2012 02:35:54 +0000 (13:35 +1100)
commita7a3f08dc24690ae00c75cfe4b4701a970dd0155
treebc9174cc50feba550a33148e661dc57ac37950dd
parent1f3c9907b8037de7b9635b0b471572ea8758bcd1
md: close race between removing and adding a device.

When we remove a device from an md array, the final removal of
the "dev-XX" sys entry is run asynchronously.
If we then re-add that device immediately before the worker thread
gets to run, we can end up trying to add the "dev-XX" sysfs entry back
before it has been removed.

So in both places where we add a device, call
  flush_workqueue(md_misc_wq);
before taking the md lock (as holding the md lock can prevent removal
to complete).

Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/md.c