From patchwork Fri Jun 4 17:21:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 454461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40C5BC4743E for ; Fri, 4 Jun 2021 17:21:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D61961417 for ; Fri, 4 Jun 2021 17:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbhFDRXH (ORCPT ); Fri, 4 Jun 2021 13:23:07 -0400 Received: from mail-mw2nam08on2127.outbound.protection.outlook.com ([40.107.101.127]:19296 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229690AbhFDRXH (ORCPT ); Fri, 4 Jun 2021 13:23:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FwZYQ/VwOQZvVJC7IwG/jrxUnjoFuPcgTFKsyYtpVIMRmscDPeqSA4DAwxJA1ygm2SYZj5SuE8pGCK5K+Eb1i9V3F6utTCXRkHXPMwJuGLwoi7oZQ4VTKqq5idO9nPgYTLgCJouQWUcQ7ufHQo6Esgl0SYqNf0atukafVGNq7dSwUq8Q0uMZ3A2eK9BdTZl1kzKd7FoyadHVUYb/whuUm6HI57iMqY75ZfgyrefBCOxETsgPk56dWMLlZmqf3RfFVfg/VQ434ZIyMW3UsSG2SB9angJQ3PkzszxU9zBhEKW6NZ9ApN6HC5YPeIkFkDSaDsgWByql+nvE3+kA60dLzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WZuHQNdNcN6DuCV27VUBpQsCYnsSVs6U9q1ufy1MyTU=; b=AvLOwwpQNLNBMRyek8CMXSu+gkR+l/DcG7iR+PB4t/5RzY12Q/BPiSAu3ioKw8K57A+OYySDK5B+Vf7iV348TV41riC4fjCIdf23DlUUjITEqtstuZAgrb6jYFX/mhS61SiDnTCLsnfkc/3I3PoL93um6rE61VSGtFMO3ypmf50On92c22a7y7xfxM/U3te+MT482HiBpYhPCmv3whvdphiLdBdBKbv8sqmyFLlV4mBKYNclXDr/f4vfN7NQz5id3nQE95ZktRWmVsU1a7Q2F0CgNebxqDa7Xquz5O9YKD7QwOnWyCIj/P3j8nKGSwWPu0vqZUBINbyKBDfuP+m0QA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WZuHQNdNcN6DuCV27VUBpQsCYnsSVs6U9q1ufy1MyTU=; b=LCZCv/ON5h2hVwB5iIvLkM8jxhhPSLyXRHMXF/2f2Uu0zpdvk6bppWnGCzv5dvEaxnkg/+Mq3grHQFyYIpceizc0wFIS1nXMhGHI62b1wV8PewuQxkUqM/9YRev+zAKqk0r/Zn6SH9cmzJFVuFjbL0iTQvowHcDAsOn1iUW5rPY= Authentication-Results: microsoft.com; dkim=none (message not signed) header.d=none;microsoft.com; dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1514.namprd21.prod.outlook.com (2603:10b6:5:22d::11) by DM5PR2101MB1111.namprd21.prod.outlook.com (2603:10b6:4:a6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9; Fri, 4 Jun 2021 17:21:19 +0000 Received: from DM6PR21MB1514.namprd21.prod.outlook.com ([fe80::fdb1:c8ac:5a1f:8588]) by DM6PR21MB1514.namprd21.prod.outlook.com ([fe80::fdb1:c8ac:5a1f:8588%6]) with mapi id 15.20.4219.012; Fri, 4 Jun 2021 17:21:18 +0000 From: Michael Kelley To: kys@microsoft.com, martin.petersen@oracle.com, longli@microsoft.com, wei.liu@kernel.org, jejb@linux.ibm.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Cc: mikelley@microsoft.com Subject: [PATCH 1/3] scsi: storvsc: Miscellaneous code cleanups Date: Fri, 4 Jun 2021 10:21:01 -0700 Message-Id: <1622827263-12516-1-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [131.107.160.144] X-ClientProxiedBy: MWHPR04CA0052.namprd04.prod.outlook.com (2603:10b6:300:6c::14) To DM6PR21MB1514.namprd21.prod.outlook.com (2603:10b6:5:22d::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mhkdev.corp.microsoft.com (131.107.160.144) by MWHPR04CA0052.namprd04.prod.outlook.com (2603:10b6:300:6c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Fri, 4 Jun 2021 17:21:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 45711ae1-dc2e-432a-c90e-08d9277d2a7a X-MS-TrafficTypeDiagnostic: DM5PR2101MB1111: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dH6xzKdcaP6/zjw+DRpmMcn6DSjkuaJ9x4eOfMbgQkUWU32r2otzYkOi6hxmKr+EEHGYWJdAytV9jji8DxP2wX7eXW4pTqCK2hr90YuK5gyebXJbHr7dQzyl/Rr4vdyhPzvCTgt7Van1RVuJ/H26RPM3L9XG2cyGLdTIiy2JSZJMR145pFz2XKrVQ4f+qLo9Y19tUXmwYg15UvyXQBr7da887fiKFBwUmJw5YCk52Og22p9Iw8pP4a7oJ7801YaKSJqBGL6uRFynS5e1SQ5B0ZGvM+j8MNtm1i2LCnnz9iCckuYeKItAhG9+J1dO+R7yMnS2e8cqVByih6yS86jsxZ7u8tT1jVUvpVb8SGeDmMl3onLztLT3Bd7e02Masb6HSdKeJdzX+9ywXt0cRPIfnoAAqAHNNxuOYvsTIJvH+d6j7opifrUoeeMH5tkplFUZ/WRdM2kSTXAJ8H1QMYiCMIcHfrWGTHKo8bOjiJGUf3g3YxN0hBM73keKjCDvspl6w/F5+9pIbAG3xN7rBMVTdKusW1889rvAiTdGXHRnGldIE6RAEGn6m+D2PXUySaelwdvOQ2OmUOne+X0F/YgZpmVg7qu5Usk4I04ZS+d4nLZWnjLlFKz4oBUsUuuCFv9NqDt0EvKsIMg3L7LYW9JxH4q3Z3SR7sYf9kNBmTZc2oCnkP3X1aE49H2yO461W2GUIygoj5+CFg5MeGzaXvdVYQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR21MB1514.namprd21.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(83380400001)(6486002)(2616005)(107886003)(86362001)(478600001)(956004)(5660300002)(82960400001)(82950400001)(8936002)(36756003)(186003)(2906002)(66556008)(66946007)(66476007)(26005)(16526019)(8676002)(38350700002)(6666004)(4326008)(316002)(38100700002)(52116002)(7696005)(10290500003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ctb8Vc0iuMLhXAnH1gzHV44KMVxJBqCN7KxEOr35nRlFY3bdZT9yVrFDN+mY3zG1XeAy8Dx/cWMZ28H/lbqIPoCxtFL7+xBRzyIPbSb5tsA59Z3iBnDwhQaNVXNuGLqAPiw77pEbPIiRwgqO+SBoUgCQFBYGaZBlpdMXwSW6WWAUj42+C87EYa+HGIY86IKLmm494hnwte68ZeoCxG6eUMTzHuRuZIKXyJH70TmuXKFvmIzIXdB662u9nlMHxrmKRExxVaDes2V0TOMBNdEMq/wxtDF11qQgZsCQek7nQCV21gWzmQ3TktSSeMOsPE5oQKECCHrzf4MI+PgfpLeVzlsJpDJUcSkdCtgkBimg3dieQDOhYt9mpQTAKQsMdLZarlKFWka0jZZB/57/mOvFrCYRdGjp8MjHXvSsVEqsDnkOYSuuK+dYREDhOjtqD7SSbL8qZ1Wb07NrkmrnpiwWuYokyN0stLGxVZOFR+p/WxEsZdnKmFoYlKqp0FigDbzV5ul1hVFu9CwbfO8hJ6fwtA+rore4rd/LabaPRGpHSzTWWIRZ5Ef6GLyH4GAUjUSclzriMdNO4ObvmxjvmPkjxqb+7Ww8lykGy0tCDDRWqafXnchf7opgRt0Tb/YvNUzB4tWi84E/6Nfd/16OAwryosYxQr+TUGUyThHb+HCUjqveUXS/rJ5fKVN1hFFrU3QXrmYgJsnAoNoZB7b8zizhkK7N8HHnFw2UO81/y9SOKqRj4VGdne8p4He79TgEovKalYhH1z12kXq5WCZiZykMyHKP7nXtUtFmkWOn4QXLTcDl+8VDK3NKrYEnWT3r1+oJqTiYxJ1DavePWkmxDgQvnPjfDthKMpC0DQgpH6HN3UXO+amxHs9at/3GX7IL//40kZr9SzaHHqqByxDLT2a6O2YNpkMVr1NI2fQm0OiJJfRNyYKPZJl+0wuheNP+vjseXhuhj6NoW02ECQOtMA5kCGTdvEHHF0dTeABP33jvuLupDw7pEU4yfK7AAGARzYw76yzbp38gFkK4iVbisslgLB3t8smdQjm8644XsvZZ35jV7UB7dXgl4TDu7LKhCgPNT7TgSNGt+BVyt+iNxzd7sYdDrqIhX8Ak1/Vd6YGuSazRPol2/CzCefFy0XfuqfXPfjHMnoiaVG30z/HFkEUHvQY9OJGHiXCTwm3MmC8t0sSZmXK4xokJJqYAXfgUlSpoRESjy9eoLMavgHdYJkyPCUAnEPVdKzj1m9wNtRtjQg4EGA+hrwiDz7H60DHxwu+/YvLFfJYL2nKI3dpOIcW35o8b27csePXPpla3E34yGKB82WTuyVXAuN4/7lej4KLi X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45711ae1-dc2e-432a-c90e-08d9277d2a7a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1514.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2021 17:21:18.8035 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xgKDhutaSC3Krkd6lVFk05BCMoDqPkpTA9lGV0BbQtxpxru+JlgoLoA8naldqIu+a10UknqR+4/p2Texd494tw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1111 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org As general cleanup and in preparation for subsequent patches: * Use min() instead of open coding * Use set_host_byte() and status_byte() instead of open coding access to scsi_status field * Collapse nested "if" statements to reduce indentation * Fix other indentation * Remove extra blank lines No functional changes. Signed-off-by: Michael Kelley --- drivers/scsi/storvsc_drv.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index e6718a7..9996e8b 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -1160,17 +1160,16 @@ static void storvsc_on_io_completion(struct storvsc_device *stor_device, vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS; } - /* Copy over the status...etc */ stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status; stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status; - /* Validate sense_info_length (from Hyper-V) */ - if (vstor_packet->vm_srb.sense_info_length > sense_buffer_size) - vstor_packet->vm_srb.sense_info_length = sense_buffer_size; - - stor_pkt->vm_srb.sense_info_length = - vstor_packet->vm_srb.sense_info_length; + /* + * Copy over the sense_info_length, but limit to the known max + * size if Hyper-V returns a bad value. + */ + stor_pkt->vm_srb.sense_info_length = min_t(u8, sense_buffer_size, + vstor_packet->vm_srb.sense_info_length); if (vstor_packet->vm_srb.scsi_status != 0 || vstor_packet->vm_srb.srb_status != SRB_STATUS_SUCCESS) @@ -1180,33 +1179,26 @@ static void storvsc_on_io_completion(struct storvsc_device *stor_device, vstor_packet->vm_srb.scsi_status, vstor_packet->vm_srb.srb_status); - if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) { - /* CHECK_CONDITION */ - if (vstor_packet->vm_srb.srb_status & - SRB_STATUS_AUTOSENSE_VALID) { - /* autosense data available */ - - storvsc_log(device, STORVSC_LOGGING_WARN, - "stor pkt %p autosense data valid - len %d\n", - request, vstor_packet->vm_srb.sense_info_length); + if (status_byte(vstor_packet->vm_srb.scsi_status) == CHECK_CONDITION + && (vstor_packet->vm_srb.srb_status & SRB_STATUS_AUTOSENSE_VALID)) { - memcpy(request->cmd->sense_buffer, - vstor_packet->vm_srb.sense_data, - vstor_packet->vm_srb.sense_info_length); + storvsc_log(device, STORVSC_LOGGING_WARN, + "stor pkt %p autosense data valid - len %d\n", + request, vstor_packet->vm_srb.sense_info_length); - } + memcpy(request->cmd->sense_buffer, + vstor_packet->vm_srb.sense_data, + stor_pkt->vm_srb.sense_info_length); } stor_pkt->vm_srb.data_transfer_length = - vstor_packet->vm_srb.data_transfer_length; + vstor_packet->vm_srb.data_transfer_length; storvsc_command_completion(request, stor_device); if (atomic_dec_and_test(&stor_device->num_outstanding_req) && stor_device->drain_notify) wake_up(&stor_device->waiting_to_drain); - - } static void storvsc_on_receive(struct storvsc_device *stor_device, @@ -1675,7 +1667,7 @@ static bool storvsc_scsi_cmd_ok(struct scsi_cmnd *scmnd) * this. So, don't send it. */ case SET_WINDOW: - scmnd->result = DID_ERROR << 16; + set_host_byte(scmnd, DID_ERROR); allowed = false; break; default: From patchwork Fri Jun 4 17:21:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 454460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9957BC4743D for ; Fri, 4 Jun 2021 17:21:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81F4961415 for ; Fri, 4 Jun 2021 17:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbhFDRXJ (ORCPT ); Fri, 4 Jun 2021 13:23:09 -0400 Received: from mail-mw2nam08on2127.outbound.protection.outlook.com ([40.107.101.127]:19296 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230185AbhFDRXI (ORCPT ); Fri, 4 Jun 2021 13:23:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J4XTuvxCBuInM9yZepcGN3ehwm+BdCBFTNvnLIdPynuX8BRSNdO5h0MEuBpB80+B06pZRFRgmBA3NwZlbG9Jj0bo6YqRycv5fsa0U99kHkNZmsrRVt8bIx/FcJJKL+wfxIabpE4pY0HLu/0H5vojDs7BJkVtCOEWNm31gopD90q71mFxkK6fw23zIEWSVy46KjyWFkvodlOxoby3IF07C7BJqoBooubPT1zoA679enHmrqRxVlpwXGDLQ3P6H2QGoCJIr2Vx1ekAap4Utb9+Wu3AkYZXCeFYk/tIL4zvR7sqE764BBweiQu0R9vHVIrZaaVYjNfhm6Vu4z6DUOy2fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ikvPagxwkKa5Rup2swZvXUX7cJCo2X9dx2/yGuqTMME=; b=lP40dP/UGE6+8dJebrFHMCXa3qflC+3PRi1g1TveUarg42s4lP7/2y6/NDg7BRkCC4pqVca5V+m1Rz8WOCPPO+Izcu9GzMhXbcp9BylDQyL1EEC9lb/d6FZbIbfLRFzW020ILZHC9u2KzZ8g1KwALM0nFcvN0qXtyCB3QpBmdweZVAcxAxJX0cdco8cR9a+EMwgjp0vGtFPUw0EfYDnDRnmrAePIOWCP6LEDldjrDb2M1s/PB92C9XK6Gbo8/xt3KYHmxAqR8Aukm/HBgtMt6y4G/tvB/VC9fbtAbIogKj9lruFDJtSQWVNZE5+wOJNt0q6+C7yp3Vt61v+6QNQNfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ikvPagxwkKa5Rup2swZvXUX7cJCo2X9dx2/yGuqTMME=; b=E7aUd4LAXICzrpQGRz1SG+XOtTyNoJtDj3Rn+OvN8IAOlY5KUbGZaedlE4hXD+CGZr2Gfs7vQ/oq5NAngUakjwE1bajjG057tiTPVlWEizAIflF+6lgqNEqy8d4FMGfE8padfh1GjVatTm1gk7cC1o3NIkeCpRZl+QpLp/cK9kg= Authentication-Results: microsoft.com; dkim=none (message not signed) header.d=none;microsoft.com; dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1514.namprd21.prod.outlook.com (2603:10b6:5:22d::11) by DM5PR2101MB1111.namprd21.prod.outlook.com (2603:10b6:4:a6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9; Fri, 4 Jun 2021 17:21:20 +0000 Received: from DM6PR21MB1514.namprd21.prod.outlook.com ([fe80::fdb1:c8ac:5a1f:8588]) by DM6PR21MB1514.namprd21.prod.outlook.com ([fe80::fdb1:c8ac:5a1f:8588%6]) with mapi id 15.20.4219.012; Fri, 4 Jun 2021 17:21:20 +0000 From: Michael Kelley To: kys@microsoft.com, martin.petersen@oracle.com, longli@microsoft.com, wei.liu@kernel.org, jejb@linux.ibm.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Cc: mikelley@microsoft.com Subject: [PATCH 3/3] scsi: storvsc: Correctly handle multiple flags in srb_status Date: Fri, 4 Jun 2021 10:21:03 -0700 Message-Id: <1622827263-12516-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622827263-12516-1-git-send-email-mikelley@microsoft.com> References: <1622827263-12516-1-git-send-email-mikelley@microsoft.com> X-Originating-IP: [131.107.160.144] X-ClientProxiedBy: MWHPR04CA0052.namprd04.prod.outlook.com (2603:10b6:300:6c::14) To DM6PR21MB1514.namprd21.prod.outlook.com (2603:10b6:5:22d::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mhkdev.corp.microsoft.com (131.107.160.144) by MWHPR04CA0052.namprd04.prod.outlook.com (2603:10b6:300:6c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Fri, 4 Jun 2021 17:21:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1b70761-d317-4e5b-0587-08d9277d2bb6 X-MS-TrafficTypeDiagnostic: DM5PR2101MB1111: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ed26oTbOdB2rliGQ7Fqhaqa605ZZNQ8IfrzFErkxcqFW8mHwoDFWntDbKFAb3/fwWABFsBtbsCf6+xxtvUMfBxMdJaMhOGzhlOLPbrkJB+1gWJkgLEwNXKoXZXnlqzNl79Mhuuxm6pWowmR+D/UKvXgHOwofB1tKdx8rMjSQrgwOvby14Wjfs9gH0Hl7lbSOcprte91rW1sfRX6oUk46cQm2/w7J3h7cNz+aKAoCGS3u45gOr2XuB9G6OrJ5uOv79s7KEGugB2IHxZWRYCoNfp+dRb/14DXEI37UggIqkR211uOPPI42BbYea39ZjRQwE5XdRgmUqehTeGUXB/BJ+zr5U9Wrs+8PVzhIJfk2HkglEFGss/uF0I2uongdy8Wy70pIAwdOL0mOM0eQFqv6YH6jrJ1BFIwW0CNwhBLieya16YbkGSPRGGj5YxmhNSvzLOxlmQU6oKnDcc3GykZtWjhLyKqKMTxqse+9cg2NvXeDF5vcJDAb7uh9MeqM9f9CzjsrZ7P9k3Ddmvcl3NM9NZBqYpeV4eUpI+MHa8KP/lJCarxWcVShrpVZjlf8PAI1WNea7qvu75npkp/vlw9QF6JMXCPkiurRPCHIL1kjskwZLLY1wIYIjtYtvtZFGQ3a4gE3HO/6rNo+eE863N6/TukivijJl2LpwVkdYpjda8/0QtuhWjGlmiwq1tQPXujKXoa9ztkSZxF9owVNlovGNQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR21MB1514.namprd21.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(83380400001)(6486002)(2616005)(107886003)(86362001)(478600001)(956004)(5660300002)(82960400001)(82950400001)(8936002)(36756003)(186003)(2906002)(66556008)(66946007)(66476007)(26005)(16526019)(8676002)(38350700002)(6666004)(4326008)(316002)(38100700002)(52116002)(7696005)(10290500003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DvWOxvdSTiJamK5n2B3hHsQeFmswBFIlWNYtysOqQ5osabF4t/X4yLLqG5v6qu7irowYXjTJmVpIK7OIjK5FAPryjTIjhPOUM9hLBc2yJ/qwchJtVYkV1Qksmg1SD+H+L2uSmuGc3r18UzKS/IBQZxKzIJmu8eYXu8gtkS71wyaqPKGQaM3kDryOSRpgWj9kjHEdnKjGaf7e9L0wpY/Q1E4PC0TaPKTyEMTDIf+RUq7ACeK2RMDtslgmBA8G/yj2aDr9mVsxdqAn4hAw10SAerqCDOeINilh5Fe8QSkMaz7JxVyPcd2PHlBkHrVDLUi3A/UyAeii0ODTnG4YGESt+nzk1WGXuND76Qslp+fSJVAh7mMqpODck7w+kAGD9MQz+T26sb8Qr+H/NfDdIjett6Ztde+1Uxc5U58lf6s9RiuZQ3TNVUDZxvaZYJNnxhjlHon3fI9pncGcPk9V/0FCzWWFk/VuGvhsj7GFyQiZlFgjUfT7CAW2IvywGgzjAPh9TICJVcFfR+OVIJqClWxH9f8itYTDfGinaxJXY9JpXhdTQguZbtVTneI1TsQQiRJakUR815VFuHkfQc978JrEfeAnyWXXTj4U1SDvl2CN2vfHrQ6Q0tV94+gL6IqcaV49wav7JZ7P+KN+Bcgn5AFGVHn2xCdvMVOoA9o6LB62nA4qTyEL6SR4+9bSggr01JrB6D7dNWY8NPRze/R2/M8zegkEXIzrBLNbr5LlelNjAjUGDp0DqLco0MBeatUeXceYFrApcN1251SHmls+d0uR2aCPMUsTIWRyqgg0QiEXi+fajC7H0LAalxWxoFJbgH/+jVXntl9c2hT6KJVPcQnJgQ0Fbe08dHq+mFtZE42Ju32TImBVl7jivPk3CT3rDGpkOzCxhjKxuDEp/opm7rJbqmAGDvgEMdFrlFtXrGlZaFxWdVeKIY9IH484yW8m44uMcpXOt43cTlYQTJe/Dao8aHx/Lus09l4q6RG7P81Zgu/QPtXxswyfyMPeDkZYVUOsnhW1urguKNF37nPTGZAmBDzIcYkFg7w1B6c+tFc+SnYf/l3pM4/BPzol7J+5O5jC2/URIsJc7RDZYDQnjartFwbX2ieQ4jPLtZ5V2SLKYo7KCIEPntgrFFn8lfvYFRBNTrjNtFd2Nx79HgzOf1hNH6D39+QYULw5pDFEe1RkULfqAY0LyxIfo+187ADPcd1Vt00euk68taaJ5uj9/G8t4UoK+pX62micMlaFb5LQleep7wdEmbYalQqCw/zm3g9/pQ48XW7jfR7BaNTIwkGTp1A21DmpujL5Bdie7b2+H4dOxXXNpo6eb3Y+uYalIviK X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1b70761-d317-4e5b-0587-08d9277d2bb6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1514.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2021 17:21:20.8644 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cQYxqCEelw0uS1qU+/RqsxFuttqteDmTy3F/EFKT6VZ2hXvbcqQvxL0Miyj1D1Ah+6V9fsy7g1r8Vme5LOOUbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1111 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Hyper-V is observed to sometimes set multiple flags in the srb_status, such as ABORTED and ERROR. Current code in storvsc_handle_error() handles only a single flag being set, and does nothing when multiple flags are set. Fix this by changing the case statement into a series of "if" statements testing individual flags. The functionality for handling each flag is unchanged. Signed-off-by: Michael Kelley --- drivers/scsi/storvsc_drv.c | 61 +++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index fff9441..e96d2aa 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -1009,17 +1009,40 @@ static void storvsc_handle_error(struct vmscsi_request *vm_srb, struct storvsc_scan_work *wrk; void (*process_err_fn)(struct work_struct *work); struct hv_host_device *host_dev = shost_priv(host); - bool do_work = false; - switch (SRB_STATUS(vm_srb->srb_status)) { - case SRB_STATUS_ERROR: + /* + * In some situations, Hyper-V sets multiple bits in the + * srb_status, such as ABORTED and ERROR. So process them + * individually, with the most specific bits first. + */ + + if (vm_srb->srb_status & SRB_STATUS_INVALID_LUN) { + set_host_byte(scmnd, DID_NO_CONNECT); + process_err_fn = storvsc_remove_lun; + goto do_work; + } + + if (vm_srb->srb_status & SRB_STATUS_ABORTED) { + if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID && + /* Capacity data has changed */ + (asc == 0x2a) && (ascq == 0x9)) { + process_err_fn = storvsc_device_scan; + /* + * Retry the I/O that triggered this. + */ + set_host_byte(scmnd, DID_REQUEUE); + goto do_work; + } + } + + if (vm_srb->srb_status & SRB_STATUS_ERROR) { /* * Let upper layer deal with error when * sense message is present. */ - if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID) - break; + return; + /* * If there is an error; offline the device since all * error recovery strategies would have already been @@ -1032,37 +1055,19 @@ static void storvsc_handle_error(struct vmscsi_request *vm_srb, set_host_byte(scmnd, DID_PASSTHROUGH); break; /* - * On Some Windows hosts TEST_UNIT_READY command can return - * SRB_STATUS_ERROR, let the upper level code deal with it - * based on the sense information. + * On some Hyper-V hosts TEST_UNIT_READY command can + * return SRB_STATUS_ERROR. Let the upper level code + * deal with it based on the sense information. */ case TEST_UNIT_READY: break; default: set_host_byte(scmnd, DID_ERROR); } - break; - case SRB_STATUS_INVALID_LUN: - set_host_byte(scmnd, DID_NO_CONNECT); - do_work = true; - process_err_fn = storvsc_remove_lun; - break; - case SRB_STATUS_ABORTED: - if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID && - (asc == 0x2a) && (ascq == 0x9)) { - do_work = true; - process_err_fn = storvsc_device_scan; - /* - * Retry the I/O that triggered this. - */ - set_host_byte(scmnd, DID_REQUEUE); - } - break; } + return; - if (!do_work) - return; - +do_work: /* * We need to schedule work to process this error; schedule it. */