From: Aaron Lu <aaron.lu@amd.com>
To: Jeff Garzik <jgarzik@pobox.com>,
Alan Stern <stern@rowland.harvard.edu>,
Lin Ming <minggr@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org,
Aaron Lu <aaron.lwe@gmail.com>, Aaron Lu <aaron.lu@amd.com>
Subject: [PATCH 2/5] scsi: sr: runtime pm when ODD is open/closed
Date: Mon, 23 Jul 2012 14:49:37 +0800 [thread overview]
Message-ID: <1343026180-22236-3-git-send-email-aaron.lu@amd.com> (raw)
In-Reply-To: <1343026180-22236-1-git-send-email-aaron.lu@amd.com>
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 | 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)
kref_get(&cd->kref);
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);
+
out_put:
kref_put(&cd->kref, sr_kref_release);
cd = NULL;
@@ -169,6 +176,8 @@ static void scsi_cd_put(struct scsi_cd *cd)
mutex_lock(&sr_ref_mutex);
kref_put(&cd->kref, sr_kref_release);
scsi_device_put(sdev);
+ pm_runtime_mark_last_busy(&cd->device->sdev_gendev);
+ pm_runtime_put_autosuspend(&cd->device->sdev_gendev);
mutex_unlock(&sr_ref_mutex);
}
@@ -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;
- }
-
mutex_lock(&sr_mutex);
/*
@@ -692,8 +694,6 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
out:
mutex_unlock(&sr_mutex);
- pm_runtime_mark_last_busy(&cd->device->sdev_gendev);
- pm_runtime_put_autosuspend(&cd->device->sdev_gendev);
return ret;
}
--
1.7.11.3
next prev parent reply other threads:[~2012-07-23 6:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-23 6:49 [PATCH 0/5] Fix for ZPODD Aaron Lu
2012-07-23 6:49 ` [PATCH 1/5] scsi: sr: fix for sr suspend and resume Aaron Lu
2012-07-23 14:50 ` Alan Stern
2012-07-23 6:49 ` Aaron Lu [this message]
2012-07-23 14:57 ` [PATCH 2/5] scsi: sr: runtime pm when ODD is open/closed Alan Stern
2012-07-23 6:49 ` [PATCH 3/5] scsi: sr: block events when runtime suspended Aaron Lu
2012-07-23 6:49 ` [PATCH 4/5] scsi: pm: use runtime resume callback if available Aaron Lu
2012-07-23 14:36 ` Sergei Shtylyov
2012-07-23 23:30 ` Aaron Lu
2012-07-23 6:49 ` [PATCH 5/5] block: genhd: add an interface to set disk's poll interval Aaron Lu
2012-07-23 18:43 ` Betty Dall
2012-07-23 23:52 ` Aaron Lu
2012-07-24 18:55 ` Betty Dall
2012-07-25 2:47 ` Aaron Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343026180-22236-3-git-send-email-aaron.lu@amd.com \
--to=aaron.lu@amd.com \
--cc=aaron.lwe@gmail.com \
--cc=jgarzik@pobox.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=minggr@gmail.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).