From patchwork Mon Jul 6 11:12:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6722041 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 001A0C05AC for ; Mon, 6 Jul 2015 11:12:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23E7F2069F for ; Mon, 6 Jul 2015 11:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2CD2D20698 for ; Mon, 6 Jul 2015 11:12:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754386AbbGFLMO (ORCPT ); Mon, 6 Jul 2015 07:12:14 -0400 Received: from cantor2.suse.de ([195.135.220.15]:37251 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754126AbbGFLMN (ORCPT ); Mon, 6 Jul 2015 07:12:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9CFFEADDE; Mon, 6 Jul 2015 11:12:12 +0000 (UTC) From: Hannes Reinecke To: James Bottomley Cc: Christoph Hellwig , linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCHv2] sd: retry READ CAPACITY for ALUA state transition Date: Mon, 6 Jul 2015 13:12:10 +0200 Message-Id: <1436181130-82905-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.2 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 During ALUA state transitions the device might return a sense code 02/04/0a (Logical unit not accessible, asymmetric access state transition). As this is a transient error we should just retry the READ CAPACITY call after 1 second until the state transition finishes and the correct capacity can be returned. At the same time we should break out of the loop after 2 minutes to avoid unbounded retries. Signed-off-by: Hannes Reinecke --- drivers/scsi/sd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 3b2fcb4..f45b8fe 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1934,6 +1934,7 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp, #endif #define READ_CAPACITY_RETRIES_ON_RESET 10 +#define READ_CAPACITY_RETRIES_ON_TRANSITION 120 static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, unsigned char *buffer) @@ -1943,6 +1944,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, int sense_valid = 0; int the_result; int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET; + int transition_retries = READ_CAPACITY_RETRIES_ON_TRANSITION; unsigned int alignment; unsigned long long lba; unsigned sector_size; @@ -1981,6 +1983,15 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, * give it one more chance */ if (--reset_retries > 0) continue; + if (sense_valid && + sshdr.sense_key == NOT_READY && + sshdr.asc == 0x04 && sshdr.ascq == 0x0A) { + /* ALUA state transition; retry after delay */ + if (--transition_retries > 0) { + msleep(1000); + continue; + } + } } retries--; @@ -2039,6 +2050,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, int sense_valid = 0; int the_result; int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET; + int transition_retries = READ_CAPACITY_RETRIES_ON_TRANSITION; sector_t lba; unsigned sector_size; @@ -2063,6 +2075,15 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, * give it one more chance */ if (--reset_retries > 0) continue; + if (sense_valid && + sshdr.sense_key == NOT_READY && + sshdr.asc == 0x04 && sshdr.ascq == 0x0A) { + /* ALUA state transition; retry after delay */ + if (--transition_retries > 0) { + msleep(1000); + continue; + } + } } retries--;