From patchwork Mon Mar 21 12:27:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 8632251 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9123EC0553 for ; Mon, 21 Mar 2016 12:27:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B488E2013D for ; Mon, 21 Mar 2016 12:27:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CFC1B20120 for ; Mon, 21 Mar 2016 12:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755277AbcCUM1h (ORCPT ); Mon, 21 Mar 2016 08:27:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:45344 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755912AbcCUM1d (ORCPT ); Mon, 21 Mar 2016 08:27:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5DD44ABD3; Mon, 21 Mar 2016 12:27:31 +0000 (UTC) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH] sd: fixup capacity calculation for 4k drives Date: Mon, 21 Mar 2016 13:27:29 +0100 Message-Id: <1458563249-91200-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP in sd_read_capacity() the sdkp->capacity field changes its meaning: after the call to read_capacity_XX() it carries the _unscaled_ values, making the comparison between the original value and the new value always false for drives with a sector size != 512. So introduce a 'new_capacity' carrying the new, scaled, capacity. Signed-off-by: Hannes Reinecke --- drivers/scsi/sd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 5a5457a..fbb8daa 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2312,8 +2312,13 @@ got_data: } blk_queue_logical_block_size(sdp->request_queue, sector_size); + /* + * Note: up to this point sdkp->capacity carries the + * _unscaled_ capacity (cf the scaling after this block). + */ { char cap_str_2[10], cap_str_10[10]; + size_t new_capacity = sdkp->capacity >> (ilog2(sector_size) - 9); string_get_size(sdkp->capacity, sector_size, STRING_UNITS_2, cap_str_2, sizeof(cap_str_2)); @@ -2321,7 +2326,7 @@ got_data: STRING_UNITS_10, cap_str_10, sizeof(cap_str_10)); - if (sdkp->first_scan || old_capacity != sdkp->capacity) { + if (sdkp->first_scan || old_capacity != new_capacity) { sd_printk(KERN_NOTICE, sdkp, "%llu %d-byte logical blocks: (%s/%s)\n", (unsigned long long)sdkp->capacity,