2015-05-11 22:56:16

by Asai Thambi SP

[permalink] [raw]
Subject: [PATCH 8/9] mtip32xx: abort secure erase operation if the device is mounted

Signed-off-by: Sam Bradshaw <[email protected]>
Signed-off-by: Asai Thambi S P <[email protected]>
---
drivers/block/mtip32xx/mtip32xx.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 0b223e3..f8c12e1 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -2147,6 +2147,18 @@ static int exec_drive_taskfile(struct driver_data *dd,
fis.lba_hi,
fis.device);

+ /* Check for secure erase while fs mounted */
+ if ((fis.command == ATA_CMD_SEC_ERASE_PREP) ||
+ (fis.command == ATA_CMD_SEC_ERASE_UNIT) ||
+ (fis.command == 0xFC && fis.features == 0x12)) {
+ if (dd->bdev && dd->bdev->bd_holders > 0) {
+ dev_warn(&dd->pdev->dev, "Drive erase aborted due to non-zero refcount (%d)\n",
+ dd->bdev->bd_holders);
+ err = -ERESTARTSYS;
+ goto abort;
+ }
+ }
+
/* check for erase mode support during secure erase.*/
if ((fis.command == ATA_CMD_SEC_ERASE_UNIT) && outbuf &&
(outbuf[0] & MTIP_SEC_ERASE_MODE)) {
--
1.7.1


2015-05-12 15:46:35

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH 8/9] mtip32xx: abort secure erase operation if the device is mounted

On 05/11/2015 06:56 PM, Asai Thambi SP wrote:
> Signed-off-by: Sam Bradshaw <[email protected]>
> Signed-off-by: Asai Thambi S P <[email protected]>
> ---
> drivers/block/mtip32xx/mtip32xx.c | 12 ++++++++++++
> 1 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
> index 0b223e3..f8c12e1 100644
> --- a/drivers/block/mtip32xx/mtip32xx.c
> +++ b/drivers/block/mtip32xx/mtip32xx.c
> @@ -2147,6 +2147,18 @@ static int exec_drive_taskfile(struct driver_data *dd,
> fis.lba_hi,
> fis.device);
>
> + /* Check for secure erase while fs mounted */
> + if ((fis.command == ATA_CMD_SEC_ERASE_PREP) ||
> + (fis.command == ATA_CMD_SEC_ERASE_UNIT) ||
> + (fis.command == 0xFC && fis.features == 0x12)) {
> + if (dd->bdev && dd->bdev->bd_holders > 0) {
> + dev_warn(&dd->pdev->dev, "Drive erase aborted due to non-zero refcount (%d)\n",
> + dd->bdev->bd_holders);
> + err = -ERESTARTSYS;
> + goto abort;
> + }
> + }

I don't like this. If you want to do something like this, why not claim
before these commands and unclaim after? If the claim fails, fail the
command.


--
Jens Axboe

2015-05-13 00:39:23

by Asai Thambi SP

[permalink] [raw]
Subject: Re: [PATCH 8/9] mtip32xx: abort secure erase operation if the device is mounted

On 5/12/2015 8:46 AM, Jens Axboe wrote:
> On 05/11/2015 06:56 PM, Asai Thambi SP wrote:
>> Signed-off-by: Sam Bradshaw <[email protected]>
>> Signed-off-by: Asai Thambi S P <[email protected]>
>> ---
>> drivers/block/mtip32xx/mtip32xx.c | 12 ++++++++++++
>> 1 files changed, 12 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
>> index 0b223e3..f8c12e1 100644
>> --- a/drivers/block/mtip32xx/mtip32xx.c
>> +++ b/drivers/block/mtip32xx/mtip32xx.c
>> @@ -2147,6 +2147,18 @@ static int exec_drive_taskfile(struct driver_data *dd,
>> fis.lba_hi,
>> fis.device);
>>
>> + /* Check for secure erase while fs mounted */
>> + if ((fis.command == ATA_CMD_SEC_ERASE_PREP) ||
>> + (fis.command == ATA_CMD_SEC_ERASE_UNIT) ||
>> + (fis.command == 0xFC && fis.features == 0x12)) {
>> + if (dd->bdev && dd->bdev->bd_holders > 0) {
>> + dev_warn(&dd->pdev->dev, "Drive erase aborted due to non-zero refcount (%d)\n",
>> + dd->bdev->bd_holders);
>> + err = -ERESTARTSYS;
>> + goto abort;
>> + }
>> + }
>
> I don't like this. If you want to do something like this, why not claim before these commands and unclaim after? If the claim fails, fail the command.
>
Not aware of bd_claim(). Thanks for the input. I will look into that.

--
Regards,
Asai