From patchwork Thu Feb 14 21:15:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 10813791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5A0417D5 for ; Thu, 14 Feb 2019 21:16:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93C212EFCF for ; Thu, 14 Feb 2019 21:16:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87AE72EFD9; Thu, 14 Feb 2019 21:16:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D6602EFCF for ; Thu, 14 Feb 2019 21:16:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436514AbfBNVQA (ORCPT ); Thu, 14 Feb 2019 16:16:00 -0500 Received: from mx2.suse.de ([195.135.220.15]:44250 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2392645AbfBNVQA (ORCPT ); Thu, 14 Feb 2019 16:16:00 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 425C3AE89; Thu, 14 Feb 2019 21:15:59 +0000 (UTC) Date: Thu, 14 Feb 2019 22:15:58 +0100 From: Jean Delvare To: linux-scsi@vger.kernel.org Cc: "James E.J. Bottomley" , "Martin K. Petersen" , Hannes Reinecke Subject: [PATCH] sd: disable logical block provisioning if 'lbpme' is not set Message-ID: <20190214221558.09174756@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-suse-linux-gnu) MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hannes Reinecke When evaluating the 'block limits' VPD page we need to check if the 'lbpme' (logical block provisioning management enable) bit is set in the READ CAPACITY (16) output. If it isn't we can safely assume that we cannot use DISCARD on this device. [JD: forward-ported to kernel v4.20] Signed-off-by: Hannes Reinecke Signed-off-by: Jean Delvare --- Hannes, please double-check that my forward-port is correct. drivers/scsi/sd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -411,6 +411,13 @@ provisioning_mode_store(struct device *d if (mode < 0) return -EINVAL; + /* + * If logical block provisioning isn't enabled we can only + * select 'disable' here. + */ + if (!sdkp->lbpme && mode != SD_LBP_DISABLE) + return -EINVAL; + sd_config_discard(sdkp, mode); return count; @@ -2942,8 +2949,10 @@ static void sd_read_block_limits(struct sdkp->max_ws_blocks = (u32)get_unaligned_be64(&buffer[36]); - if (!sdkp->lbpme) + if (!sdkp->lbpme) { + sd_config_discard(sdkp, SD_LBP_DISABLE); goto out; + } lba_count = get_unaligned_be32(&buffer[20]); desc_count = get_unaligned_be32(&buffer[24]);