[PATCH 2/5] scsi: sr: runtime pm when ODD is open/closed

From: Aaron Lu
Date: Mon Jul 23 2012 - 02:50:56 EST

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@xxxxxxx>
drivers/scsi/sr.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 5f4d19a..f7a7635 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -152,8 +152,15 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
if (scsi_device_get(cd->device))
goto out_put;
+ if (pm_runtime_get_sync(&cd->device->sdev_gendev) < 0) {
+ pm_runtime_put_noidle(&cd->device->sdev_gendev);
+ goto out_pm;
+ }
goto out;

+ out_pm:
+ scsi_device_put(cd->device);
kref_put(&cd->kref, sr_kref_release);
cd = NULL;
@@ -169,6 +176,8 @@ static void scsi_cd_put(struct scsi_cd *cd)
kref_put(&cd->kref, sr_kref_release);
+ pm_runtime_mark_last_busy(&cd->device->sdev_gendev);
+ pm_runtime_put_autosuspend(&cd->device->sdev_gendev);

@@ -654,13 +663,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 */
- ret = pm_runtime_get_sync(&sdev->sdev_gendev);
- if (ret < 0) {
- pm_runtime_put_noidle(&sdev->sdev_gendev);
- return -EACCES;
- }

@@ -692,8 +694,6 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,

- pm_runtime_mark_last_busy(&cd->device->sdev_gendev);
- pm_runtime_put_autosuspend(&cd->device->sdev_gendev);
return ret;


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/