Skip to content

Commit

Permalink
driver synchronization: make scsi_wait_scan more advanced
Browse files Browse the repository at this point in the history
There is currently only one way for userspace to say "wait for my storage
device to get ready for the modules I just loaded": to load the
scsi_wait_scan module. Expectations of userspace are that once this
module is loaded, all the (storage) devices for which the drivers
were loaded before the module load are present.

Now, there are some issues with the implementation, and the async
stuff got caught in the middle of this: The existing code only
waits for the scsy async probing to finish, but it did not take
into account at all that probing might not have begun yet.
(Russell ran into this problem on his computer and the fix works for him)

This patch fixes this more thoroughly than the previous "fix", which
had some bad side effects (namely, for kernel code that wanted to wait for
the scsi scan it would also do an async sync, which would deadlock if you did
it from async context already.. there's a report about that on lkml):
The patch makes the module first wait for all device driver probes, and then it
will wait for the scsi parallel scan to finish.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Tested-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Arjan van de Ven authored and Linus Torvalds committed Apr 22, 2009
1 parent 5dd559f commit d4d5291
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void wait_for_device_probe(void)
wait_event(probe_waitqueue, atomic_read(&probe_count) == 0);
async_synchronize_full();
}
EXPORT_SYMBOL_GPL(wait_for_device_probe);

/**
* driver_probe_device - attempt to bind device & driver together
Expand Down
2 changes: 0 additions & 2 deletions drivers/scsi/scsi_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ int scsi_complete_async_scans(void)
spin_unlock(&async_scan_lock);

kfree(data);
/* Synchronize async operations globally */
async_synchronize_full();
return 0;
}

Expand Down
11 changes: 11 additions & 0 deletions drivers/scsi/scsi_wait_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@
*/

#include <linux/module.h>
#include <linux/device.h>
#include <scsi/scsi_scan.h>

static int __init wait_scan_init(void)
{
/*
* First we need to wait for device probing to finish;
* the drivers we just loaded might just still be probing
* and might not yet have reached the scsi async scanning
*/
wait_for_device_probe();
/*
* and then we wait for the actual asynchronous scsi scan
* to finish.
*/
scsi_complete_async_scans();
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions include/linux/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ extern int (*platform_notify_remove)(struct device *dev);
extern struct device *get_device(struct device *dev);
extern void put_device(struct device *dev);

extern void wait_for_device_probe(void);

/* drivers/base/power/shutdown.c */
extern void device_shutdown(void);
Expand Down

0 comments on commit d4d5291

Please sign in to comment.