PM/Hibernate: Wait for SCSI devices scan to complete during resume
authorRafael J. Wysocki <rjw@sisk.pl>
Sun, 12 Apr 2009 18:06:56 +0000 (20:06 +0200)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 13 Apr 2009 18:37:07 +0000 (11:37 -0700)
There is a race between resume from hibernation and the asynchronous
scanning of SCSI devices and to prevent it from happening we need to
call scsi_complete_async_scans() during resume from hibernation.

In addition, if the resume from hibernation is userland-driven, it's
better to wait for all device probes in the kernel to complete before
attempting to open the resume device.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/scsi/scsi_priv.h
drivers/scsi/scsi_wait_scan.c
include/scsi/scsi_scan.h [new file with mode: 0644]
kernel/power/disk.c
kernel/power/user.c

index e1850904ff7383a3b85a713865d26db66de39c45..fbc83bebdd8efaef5aefaaf40fa5f78d72d42224 100644 (file)
@@ -38,9 +38,6 @@ static inline void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
        { };
 #endif
 
-/* scsi_scan.c */
-int scsi_complete_async_scans(void);
-
 /* scsi_devinfo.c */
 extern int scsi_get_device_flags(struct scsi_device *sdev,
                                 const unsigned char *vendor,
index 8a636103083d40c66d1d0326a3a9421c9c6bed58..2f21af21269a76eefc7ca070e05eb2aee4acc133 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #include <linux/module.h>
-#include "scsi_priv.h"
+#include <scsi/scsi_scan.h>
 
 static int __init wait_scan_init(void)
 {
diff --git a/include/scsi/scsi_scan.h b/include/scsi/scsi_scan.h
new file mode 100644 (file)
index 0000000..7889888
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _SCSI_SCSI_SCAN_H
+#define _SCSI_SCSI_SCAN_H
+
+#ifdef CONFIG_SCSI
+/* drivers/scsi/scsi_scan.c */
+extern int scsi_complete_async_scans(void);
+#else
+static inline int scsi_complete_async_scans(void) { return 0; }
+#endif
+
+#endif /* _SCSI_SCSI_SCAN_H */
index 5f21ab2bbcdf0cf5c85985f8612f923ad6ad3d03..0854770b63b9c8b42db6b2727aed6155d3e701c2 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/console.h>
 #include <linux/cpu.h>
 #include <linux/freezer.h>
+#include <scsi/scsi_scan.h>
 #include <asm/suspend.h>
 
 #include "power.h"
@@ -644,6 +645,13 @@ static int software_resume(void)
        if (noresume)
                return 0;
 
+       /*
+        * We can't depend on SCSI devices being available after loading one of
+        * their modules if scsi_complete_async_scans() is not called and the
+        * resume device usually is a SCSI one.
+        */
+       scsi_complete_async_scans();
+
        /*
         * name_to_dev_t() below takes a sysfs buffer mutex when sysfs
         * is configured into the kernel. Since the regular hibernate
index 6c85359364f2bcfd31bb06e77ec0eda7585e08dc..ed97375daae9326ecf2b4864ff9368f1491f642a 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/cpu.h>
 #include <linux/freezer.h>
 #include <linux/smp_lock.h>
+#include <scsi/scsi_scan.h>
 
 #include <asm/uaccess.h>
 
@@ -92,6 +93,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
        filp->private_data = data;
        memset(&data->handle, 0, sizeof(struct snapshot_handle));
        if ((filp->f_flags & O_ACCMODE) == O_RDONLY) {
+               /* Hibernating.  The image device should be accessible. */
                data->swap = swsusp_resume_device ?
                        swap_type_of(swsusp_resume_device, 0, NULL) : -1;
                data->mode = O_RDONLY;
@@ -99,6 +101,13 @@ static int snapshot_open(struct inode *inode, struct file *filp)
                if (error)
                        pm_notifier_call_chain(PM_POST_HIBERNATION);
        } else {
+               /*
+                * Resuming.  We may need to wait for the image device to
+                * appear.
+                */
+               wait_for_device_probe();
+               scsi_complete_async_scans();
+
                data->swap = -1;
                data->mode = O_WRONLY;
                error = pm_notifier_call_chain(PM_RESTORE_PREPARE);