[v2,4/7] scsi: sr: runtime pm when ODD is open/closed

Message ID 1343122665-18711-5-git-send-email-aaron.lu@amd.com
State Not Applicable
Delegated to: David Miller
Headers show

Commit Message

Aaron Lu July 24, 2012, 9:37 a.m.
The ODD can either be runtime resumed by the user or by a software
request. And for the latter part, we only support runtime resume the ODD
when the eject request is received. We did this in sr's block ioctl
function, this looks ugly.

Change this by runtime resuming the ODD in its open function and runtime
suspending it in its release function.

The downside of this approach is that in old distros with old udisk
daemon, the ODD will be polled by udisk daemon so open/close will
constantly be called, which will cause the ODD frequently resume from
suspend state, breaking the effect of power saving. User with such a
distro is advised to issue a udisk command to inhibit polling of the
disk like this:
$ udisks --inhibit-polling /dev/sr0
And since newer kernel has in kernel polling, there is no problem
regarding ODD's event report.

Signed-off-by: Aaron Lu <aaron.lu@amd.com>
 drivers/scsi/sr.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)


diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index e54945a..2aa50c3 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -152,8 +152,12 @@  static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
 	if (scsi_device_get(cd->device))
 		goto out_put;
+	if (scsi_autopm_get_device(cd->device))
+		goto out_pm;
 	goto out;
+ out_pm:
+	scsi_device_put(cd->device);
 	kref_put(&cd->kref, sr_kref_release);
 	cd = NULL;
@@ -169,6 +173,7 @@  static void scsi_cd_put(struct scsi_cd *cd)
 	kref_put(&cd->kref, sr_kref_release);
+	scsi_autopm_put_device(sdev);
@@ -652,10 +657,6 @@  static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 	void __user *argp = (void __user *)arg;
 	int ret;
-	/* Make sure the ODD is not suspended */
-	if (scsi_autopm_get_device(sdev))
-		return -EACCES;
@@ -687,7 +688,6 @@  static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
-	scsi_autopm_put_device(sdev);
 	return ret;