Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754366Ab2FYIOW (ORCPT ); Mon, 25 Jun 2012 04:14:22 -0400 Received: from mga02.intel.com ([134.134.136.20]:19357 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754122Ab2FYIOS (ORCPT ); Mon, 25 Jun 2012 04:14:18 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.67,352,1309762800"; d="scan'208";a="157814349" From: Lin Ming To: Jeff Garzik , Aaron Lu , Holger Macht , Matthew Garrett , Alan Cox , David Woodhouse , Dan Williams Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH v6 11/11] [SCSI] sr: make sure ODD is in resumed state in block ioctl Date: Mon, 25 Jun 2012 16:13:12 +0800 Message-Id: <1340611992-41457-12-git-send-email-ming.m.lin@intel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1340611992-41457-1-git-send-email-ming.m.lin@intel.com> References: <1340611992-41457-1-git-send-email-ming.m.lin@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1324 Lines: 46 From: Aaron Lu When application tries to access the ODD's block device by ioctl, make sure ODD is in an active state. Signed-off-by: Aaron Lu Signed-off-by: Lin Ming --- drivers/scsi/sr.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 72488c2..3da0879 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -654,6 +654,13 @@ 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); /* @@ -685,6 +692,8 @@ 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.10 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/