From patchwork Fri Jan 11 00:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757073 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 3AD80746 for ; Fri, 11 Jan 2019 00:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27F4429D45 for ; Fri, 11 Jan 2019 00:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C6F729D4B; Fri, 11 Jan 2019 00:09:49 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 5212929D46 for ; Fri, 11 Jan 2019 00:09:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730764AbfAKAJn (ORCPT ); Thu, 10 Jan 2019 19:09:43 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:52049 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730612AbfAKAJn (ORCPT ); Thu, 10 Jan 2019 19:09:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=CF3IJid2qFI0raopVYJxjaEmN/K4qbinFrb4gNjNeVs=; b=b22zYzvjWHh7 WNnZI0wqdnwFPa2t0xQksiQkPR0CErvp13GKxOjgLleFtcsw3t1fmq4yh4+dEIsD+Bxn35NyLfuxM SgmUxdg7GbSce90cl9YLcaccmmB6Iu73C74+wUYuwhG1he0i7FAquBltdOj4tuZKCf9cBnqRRPEWn BhtNB/fCSnVYwB7tvs9SUVWuLETdmQTgmrnHn/OpHdTJxAZUm35GlR21fvRVsMvyZSceHClpeM4fN zDPZtXCNfBu01n9SbQ79SVpi1G43Att/Ba5i5fjK6BqTNvmUATwVDRZyWpCj2SbDLBoP8cqS+mOtM JyVwZRmZBsjs9xStGNA1Pw==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkOA-000Dd4-HZ; Fri, 11 Jan 2019 01:09:31 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 544ABC0C76; Fri, 11 Jan 2019 01:09:12 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Greg Kroah-Hartman , Dan Williams Subject: [PATCH 1/8] sd: Rely on the driver core for asynchronous probing Date: Thu, 10 Jan 2019 16:08:51 -0800 Message-Id: <20190111000858.76261-2-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5gcbwrT1n5HtkR7dWmbxuNR602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASiYf7H/yBdfVu6BXKOqolT7xAqrDC6 /7DsWhDqWPbuTQTJsjWw5+0eZIpQIcK9yrSIoiC5DDnaemEOugg39OcBf2ZkFf0bc6TV99q4yFj4 jGRbN4cS9m3JKQpYnU+jEOY/WD7BAcwhXN3d5OI6tWyH6CLbyF0Zq4b1/7rjUzETJrWks4pbbQJq 6gWopI3ep45X19ZysgQ+31LcAX8eoFXAhohfegXGH2GIVQVglJFbK4kwHfB1Me6KZ/WZEd2U/PgK EgxQF7G4ajroXShVPl5s3ZFBlbFepFDIto51+D0l4QQ5Ys+fVM3O+MMiWkg2k+zlgTl6fJxyntEf hZCKje4Zr4yT9moj9LtPR5ewAVhSErI0q854skGDr1SFWz9TrEbQkE4CO4OSbq6BZA7tlM3svzio W0HZAy/J9bTIw9vYoi0algc0OEv2hoIHMMc5QHFZbPS/eVNU5HPmLAppMmniIF0L+EiBGSwjTgMJ Uw9gBr7ReBRhKYJF39mBDy0o4yOhuUNrp7FP05vH5VSt+/DeOUnMlFzHRyp04k80JGr6vsX+uFEK tCIOxIcOTnKqCuh6QNSdjxuaKs44aXfT36paehOqCvakOIunt1O8jJ+DX+l+PmxJCFvdxzgiQpci HL52w4Z4I9Sm4CLNexWS7cnKCQ52ET+y56IUaetULmjvMcjHTHbHsXKsD/8CYe6cueWFKTnk5tSD tOkxsWZnqDkrgStYx12aCdmJgllbwzHk4jQiO9qZ8HUvlDGYBjY8NoKnJR0yYYZX++hEKdoNnco5 zDg6HYuTCyYgL61SIkBTYWGbpPi0bx8ISvz9Q9saGF+esC1c5/CkleZr+iPwxlTgLz/dsiahQ1DF oGJGH4QvNFyCBdYIC7jIgUZ9aU8mEM3Y/YwX4HH5Yj6nKMh6HPtLA8eN4O9qHU4jHQlghcMYZg== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 As explained during the LSF/MM session about increasing SCSI disk probing concurrency, the problems with the current probing approach are as follows: - The driver core is unaware of asynchronous SCSI LUN probing. wait_for_device_probe() waits for all asynchronous probes except asynchronous SCSI disk probes. - There is unnecessary serialization between sd_probe() and sd_remove(). This can lead to a deadlock. Hence this patch that modifies the sd driver such that it uses the driver core framework for asynchronous probing. The async domains and get_device()/put_device() pairs that became superfluous due to this change are removed. This patch reduces the time needed for loading the scsi_debug kernel module with parameters delay=0 and max_luns=256 from 0.7s to 0.1s. In other words, this specific test runs about seven times faster. See also commit 3c31b52f96f7 ("scsi: async sd resume"). Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Cc: Dan Williams Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi.c | 14 -------------- drivers/scsi/scsi_pm.c | 22 ++-------------------- drivers/scsi/scsi_priv.h | 3 --- drivers/scsi/sd.c | 13 +++---------- 4 files changed, 5 insertions(+), 47 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 7675ff0ca2ea..fd040e6ce9c3 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -85,19 +85,6 @@ unsigned int scsi_logging_level; EXPORT_SYMBOL(scsi_logging_level); #endif -/* sd, scsi core and power management need to coordinate flushing async actions */ -ASYNC_DOMAIN(scsi_sd_probe_domain); -EXPORT_SYMBOL(scsi_sd_probe_domain); - -/* - * Separate domain (from scsi_sd_probe_domain) to maximize the benefit of - * asynchronous system resume operations. It is marked 'exclusive' to avoid - * being included in the async_synchronize_full() that is invoked by - * dpm_resume() - */ -ASYNC_DOMAIN_EXCLUSIVE(scsi_sd_pm_domain); -EXPORT_SYMBOL(scsi_sd_pm_domain); - /** * scsi_put_command - Free a scsi command block * @cmd: command block to free @@ -836,7 +823,6 @@ static void __exit exit_scsi(void) scsi_exit_devinfo(); scsi_exit_procfs(); scsi_exit_queue(); - async_unregister_domain(&scsi_sd_probe_domain); } subsys_initcall(init_scsi); diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index a2b4179bfdf7..46a2746618cc 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -55,9 +55,6 @@ static int scsi_dev_type_suspend(struct device *dev, const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; int err; - /* flush pending in-flight resume operations, suspend is synchronous */ - async_synchronize_full_domain(&scsi_sd_pm_domain); - err = scsi_device_quiesce(to_scsi_device(dev)); if (err == 0) { err = cb(dev, pm); @@ -150,18 +147,7 @@ static int scsi_bus_resume_common(struct device *dev, if (scsi_is_sdev_device(dev) && pm_runtime_suspended(dev)) blk_set_runtime_active(to_scsi_device(dev)->request_queue); - if (fn) { - async_schedule_domain(fn, dev, &scsi_sd_pm_domain); - - /* - * If a user has disabled async probing a likely reason - * is due to a storage enclosure that does not inject - * staggered spin-ups. For safety, make resume - * synchronous as well in that case. - */ - if (strncmp(scsi_scan_type, "async", 5) != 0) - async_synchronize_full_domain(&scsi_sd_pm_domain); - } else { + if (!fn) { pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -171,11 +157,7 @@ static int scsi_bus_resume_common(struct device *dev, static int scsi_bus_prepare(struct device *dev) { - if (scsi_is_sdev_device(dev)) { - /* sd probing uses async_schedule. Wait until it finishes. */ - async_synchronize_full_domain(&scsi_sd_probe_domain); - - } else if (scsi_is_host_device(dev)) { + if (scsi_is_host_device(dev)) { /* Wait until async scanning is finished */ scsi_complete_async_scans(); } diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 5f21547b2ad2..b1edf15704c0 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -174,9 +174,6 @@ static inline int scsi_autopm_get_host(struct Scsi_Host *h) { return 0; } static inline void scsi_autopm_put_host(struct Scsi_Host *h) {} #endif /* CONFIG_PM */ -extern struct async_domain scsi_sd_pm_domain; -extern struct async_domain scsi_sd_probe_domain; - /* scsi_dh.c */ #ifdef CONFIG_SCSI_DH void scsi_dh_add_device(struct scsi_device *sdev); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c6ca3d915925..c2ddb697fa90 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -561,6 +561,7 @@ static struct scsi_driver sd_template = { .name = "sd", .owner = THIS_MODULE, .probe = sd_probe, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, .remove = sd_remove, .shutdown = sd_shutdown, .pm = &sd_pm_ops, @@ -3278,12 +3279,8 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen) return 0; } -/* - * The asynchronous part of sd_probe - */ -static void sd_probe_async(void *data, async_cookie_t cookie) +static void sd_probe_part2(struct scsi_disk *sdkp) { - struct scsi_disk *sdkp = data; struct scsi_device *sdp; struct gendisk *gd; u32 index; @@ -3337,7 +3334,6 @@ static void sd_probe_async(void *data, async_cookie_t cookie) sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", sdp->removable ? "removable " : ""); scsi_autopm_put_device(sdp); - put_device(&sdkp->dev); } /** @@ -3429,8 +3425,7 @@ static int sd_probe(struct device *dev) get_device(dev); dev_set_drvdata(dev, sdkp); - get_device(&sdkp->dev); /* prevent release before async_schedule */ - async_schedule_domain(sd_probe_async, sdkp, &scsi_sd_probe_domain); + sd_probe_part2(sdkp); return 0; @@ -3465,8 +3460,6 @@ static int sd_remove(struct device *dev) devt = disk_devt(sdkp->disk); scsi_autopm_get_device(sdkp->device); - async_synchronize_full_domain(&scsi_sd_pm_domain); - async_synchronize_full_domain(&scsi_sd_probe_domain); device_del(&sdkp->dev); del_gendisk(sdkp->disk); sd_shutdown(dev); From patchwork Fri Jan 11 00:08:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757075 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 5C67717FB for ; Fri, 11 Jan 2019 00:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BF4129D45 for ; Fri, 11 Jan 2019 00:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4045029D46; Fri, 11 Jan 2019 00:09:49 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 725C129D48 for ; Fri, 11 Jan 2019 00:09:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730767AbfAKAJo (ORCPT ); Thu, 10 Jan 2019 19:09:44 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:52759 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730745AbfAKAJn (ORCPT ); Thu, 10 Jan 2019 19:09:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=K2uib3u4DVamrPIIwUTkz+pkBKStm8By8j4oDUlw+u8=; b=uuqnb/LLvmca lzc1iRIBzaEE23ezXsrjgsGGGuIa2224lPRg5r03VCgaNoIZk2Nz0MNZiEj+PuxBaVUINDDL39xIK wGyQsMncOh7LmeknBBiPB2hdS1koDJIELJkm0vAXEputFthY9Gns7YuUrufOcUXyuLgyAhVUVvKO1 TA0zjYwPPOamAkyLkhc27v2FWgSIe31rua0vOeQ18GMywJazAI9qm8sWaJmeR0AqZxhDgX33+51nm QwGEI8MyHjne1uD8h3q/U/x6VP1Lb3XxsdWaZzmC2tF9bFfOsgpCOApo3Jp8BwNG2otYrpdrElgP4 ZtK4fUKz15F7huAhTCkQ9Q==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkOB-000EWJ-SC; Fri, 11 Jan 2019 01:09:33 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id BA52AC0CBA; Fri, 11 Jan 2019 01:09:15 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Greg Kroah-Hartman Subject: [PATCH 2/8] sd: Inline sd_probe_part2() Date: Thu, 10 Jan 2019 16:08:52 -0800 Message-Id: <20190111000858.76261-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5mRqF73dqP5Ea+Y0/D3ev0N602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbYPg/zpkSiMTw4RmnfxRCXFU82axTVwUv6v8rWwOPbn8ST Ksl9SxC91yR06AZxhKQie9+9sv+uW/xhFRf3rOAhFEAZ5tLgtxeh4W43PRo1gyVBZhJdB8oBIQVB HyeF+GyojOI3mdswqRrDTMbSijPikzUjpLbYv+k6wc7gZffRufoNd/18byQB0A6J7qtkYo2nkoP/ 7uxT5ANOZNNW1Q/z0yLvsMb+uiAAjdbSeQ5TrAFR//DqOZ7gBtaFV3NEPd9B3ylJDm+BpEBBclKF yxopgN4JfSdG4+vA3R3fKJCA/m/fDy/eqb5U4J5qWPtxGNQJz01ZT5WcjXgWBH7ge3HxyrccvRl7 LodRnoQ8/VwOaw+gz/ZKpG7S9PROnRo5n5UgtCujFgev91YjBSdZpRhe7INkM1D8D0wcffXFPtzu Go+eFJImtabaGYRoWdcAtjC9P3i9WjZGJAIzYZtqMU+suvYw/oqKxut8n22EmYXyO9mTxzooD5Ah r8BGRVdIulpEDBffVZVjmVaNbG4ZJG7FpffEThehZ/3Sn7hZzEP4XCQ3yZ0iV46UQobqPq9SrCQE Vp5QrlXf2sy/BeCuDbq8vCrJPmnnTHzVkpybMK7ZTep4LgzIxvWSttCgFENoaO1z8Ne0ck6P4ivK dWmRJx+gSB86RrtoWRhQbd6uwmWnfvHzMN+TijfqOZ9HMosVlteOX1YnxfjVpVGUX1vpoC6DaIfV aCHpEB6cFH6WJxE4ZsRZAxiZD2DNN9mj7m/hVHgWqEQPQaFjs0TiNSw6H9vLEhPKpiPf5TQsMNI6 MlK6GNyFdCyORjI8REByHhtt5w9x+wFHvsTOaxf+rRw05s5dI0aJ1E5KXJyCQeUGgYht6YsEMysP ur9wmiDBurOy6iSaaLKoO66lWAKokRrthx6Fzk8rzf/Dx0IDFpN+tQK3+phIwX0nU7U2r1GMg/eI vaXRMGcRgSEM+CTzrJOUys6tZuM7jUXIESohoO51xWmU8etUgRDqEctNJfbZ+c9N3Z0HxJBOmJD6 3+ApY5U8n7UMxBNmKVHxB1f92AKjYEOxoBmok11u89pTKgJ27pjsIdKV+lkRbj/D0G3e0yQ+5x6u zUuZ1fOTU/gD7sT82ojbYoalL4LoE8AgSzw+KJWjcRvU7oMw8GjgBzy6WnRhNtWfHtfczcZZfAOZ IY0Rd7Dil8pf/jRgXiX48U11iVRTRQ0= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch does not change any functionality. Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 101 ++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 58 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c2ddb697fa90..289a0c8d0e82 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3279,63 +3279,6 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen) return 0; } -static void sd_probe_part2(struct scsi_disk *sdkp) -{ - struct scsi_device *sdp; - struct gendisk *gd; - u32 index; - struct device *dev; - - sdp = sdkp->device; - gd = sdkp->disk; - index = sdkp->index; - dev = &sdp->sdev_gendev; - - gd->major = sd_major((index & 0xf0) >> 4); - gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); - - gd->fops = &sd_fops; - gd->private_data = &sdkp->driver; - gd->queue = sdkp->device->request_queue; - - /* defaults, until the device tells us otherwise */ - sdp->sector_size = 512; - sdkp->capacity = 0; - sdkp->media_present = 1; - sdkp->write_prot = 0; - sdkp->cache_override = 0; - sdkp->WCE = 0; - sdkp->RCD = 0; - sdkp->ATO = 0; - sdkp->first_scan = 1; - sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; - - sd_revalidate_disk(gd); - - gd->flags = GENHD_FL_EXT_DEVT; - if (sdp->removable) { - gd->flags |= GENHD_FL_REMOVABLE; - gd->events |= DISK_EVENT_MEDIA_CHANGE; - } - - blk_pm_runtime_init(sdp->request_queue, dev); - device_add_disk(dev, gd, NULL); - if (sdkp->capacity) - sd_dif_config_host(sdkp); - - sd_revalidate_disk(gd); - - if (sdkp->security) { - sdkp->opal_dev = init_opal_dev(sdp, &sd_sec_submit); - if (sdkp->opal_dev) - sd_printk(KERN_NOTICE, sdkp, "supports TCG Opal\n"); - } - - sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", - sdp->removable ? "removable " : ""); - scsi_autopm_put_device(sdp); -} - /** * sd_probe - called during driver initialization and whenever a * new scsi device is attached to the system. It is called once @@ -3425,7 +3368,49 @@ static int sd_probe(struct device *dev) get_device(dev); dev_set_drvdata(dev, sdkp); - sd_probe_part2(sdkp); + gd->major = sd_major((index & 0xf0) >> 4); + gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); + + gd->fops = &sd_fops; + gd->private_data = &sdkp->driver; + gd->queue = sdkp->device->request_queue; + + /* defaults, until the device tells us otherwise */ + sdp->sector_size = 512; + sdkp->capacity = 0; + sdkp->media_present = 1; + sdkp->write_prot = 0; + sdkp->cache_override = 0; + sdkp->WCE = 0; + sdkp->RCD = 0; + sdkp->ATO = 0; + sdkp->first_scan = 1; + sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; + + sd_revalidate_disk(gd); + + gd->flags = GENHD_FL_EXT_DEVT; + if (sdp->removable) { + gd->flags |= GENHD_FL_REMOVABLE; + gd->events |= DISK_EVENT_MEDIA_CHANGE; + } + + blk_pm_runtime_init(sdp->request_queue, dev); + device_add_disk(dev, gd, NULL); + if (sdkp->capacity) + sd_dif_config_host(sdkp); + + sd_revalidate_disk(gd); + + if (sdkp->security) { + sdkp->opal_dev = init_opal_dev(sdp, &sd_sec_submit); + if (sdkp->opal_dev) + sd_printk(KERN_NOTICE, sdkp, "supports TCG Opal\n"); + } + + sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", + sdp->removable ? "removable " : ""); + scsi_autopm_put_device(sdp); return 0; From patchwork Fri Jan 11 00:08:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757067 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 B13EC746 for ; Fri, 11 Jan 2019 00:09:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0E3F29D46 for ; Fri, 11 Jan 2019 00:09:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9553629D5D; Fri, 11 Jan 2019 00:09:38 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 2B16F29D48 for ; Fri, 11 Jan 2019 00:09:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730653AbfAKAJh (ORCPT ); Thu, 10 Jan 2019 19:09:37 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:60051 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730612AbfAKAJh (ORCPT ); Thu, 10 Jan 2019 19:09:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=y5l395ZdmETlfN8cZOFN+LwmYbdYlcf3qD9xaILkLI0=; b=s4B3YmKs2+/m arbYaXHbgGGnpRgJUaVHLi3SBYUkge0wIqK4mDI61MWAWLBmBaR/rlRxuAPZbcJbdkD3T5FxTBP7U 6YiHLx8PsAusWKUF0BjEgs8VwT2JLOHBo7d2/sEXlB7EgXCWjnYbiqC1mMGA+Wkjph8Ay0wQdlv/N FA85Xgx/5qOHMCMZqhBQMc7dIrqgc1rvwVQemjJn/GgyKelYjrd9j2eNVNAeQ2p/FuGIuieWzdfx+ 77oaVHO7Lblz6mDTZMj/FK5D6HRiOL10IdZtWO/DJx0IlAmHKpigfeH8fp3nZP2xm/h3Bl3W6xL36 nchiWiraRxbLDwjpFSOQVg==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkOB-000Ddc-Id; Fri, 11 Jan 2019 01:09:32 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 85E08C0D14; Fri, 11 Jan 2019 01:09:18 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH 3/8] sd: Remove a local variable Date: Thu, 10 Jan 2019 16:08:53 -0800 Message-Id: <20190111000858.76261-4-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.03) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5rYI08XhlJcbr2JWmYLNcVJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbBu5YFz4Jx0uq4149LpZwrkOR4/HajlzkVhakIw7Ig6RAJ lmpPd1BHwQ+kdrsiFH2cfUiCXtJytJdYVIlBCNoVDlGCgaqAfI9rupd8CZz+HVNiLZt/QXQnOBRD +jq1HsJAQnsLO8OlL77d3bdz3iqGLBxW/GnuPUrqaPTNMRDeOCP1HaH27Qjry/056DPMnxd+Swxv aRjzxpV3vJPKQXRYGRQP6aoq2j5ibghWGduoTjg3ZbOPxovcwpgDatF7VXVEbF4rUil7pUnOksxs 7aZaj3hJxCWpajY6LYvBNWgpuOnE6wHyAbSyVXutrqMjgFIlz7WWm/p16OPcLYPdHAK7vqrauYnQ lgTtl087RrjX0eEI2EoZ8+/7zzZhzgY6klGcBiHQNaIxsZV6P9u0dfcPVf1qzaRUc3P3olRHLamM Qyb0mbZGjIHswS91OoTWbV0TVjUl1IhpqpL1ys0dPZdHkDkXGJvniGivX1Fq/UQDdcZCl4lfVnm2 hxV4736kvFu105zjbKsiPvrvVDH+VNpRclzFnL9mZb0jWXJhjtxPMCM76Y/SM8gaXNdGScJz4OXR jhdizhW8qsvGNuSd/HEJTZME04ufwuWPFEPdWrjfrhukQZS1mEULzQRpsB0euHpWTcUVh8zbZfcK ACLJrQoetW1xD7NPHFVkxC5YVnU16XMMgeYhi2d5qCVnOtDXhDXk7BUPP1haJIgTpSUEebIErbNe M6iidDaIJ4/68uIg9cw4Oh2LkwsmIC+tUiJAU2HwgBR30xDfQHtZy/Bf9JdHbvrKBGpI3fi306mn 7Q2BQRxwEiTVJqDh0qKoKsXx5lk3qtRz7SlCtdp5f9SVDcnPVkZi1FAqeGzQgF8SeqULJtsApjxw /ehSIEROg+hijQbpfj5sSQhb3cc4IkKXIhy+GYF0rkJbsdOWv4seI9QfnX0yZIM81CWbOkIhVXFL WPJO+eyolGM4l8rlxuGfhU+3k8+lrVLTNBgpy2LxbHpqloq8mG8yXCcEbxT2UdIuHji9IodMg2vu WMdu+65sFAzW X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch does not change any functionality. Signed-off-by: Martin K. Petersen [ bvanassche: extracted this patch from a larger patch ] Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 289a0c8d0e82..7afcf8f7e342 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1016,7 +1016,6 @@ static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) struct bio *bio = rq->bio; sector_t sector = blk_rq_pos(rq); unsigned int nr_sectors = blk_rq_sectors(rq); - unsigned int nr_bytes = blk_rq_bytes(rq); blk_status_t ret; if (sdkp->device->no_write_same) @@ -1056,7 +1055,7 @@ static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) */ rq->__data_len = sdp->sector_size; ret = scsi_init_io(cmd); - rq->__data_len = nr_bytes; + rq->__data_len = blk_rq_bytes(rq); return ret; } From patchwork Fri Jan 11 00:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757069 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 25EA71390 for ; Fri, 11 Jan 2019 00:09:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1283529D45 for ; Fri, 11 Jan 2019 00:09:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 069C929D48; Fri, 11 Jan 2019 00:09:42 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 E3B4A29D45 for ; Fri, 11 Jan 2019 00:09:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730760AbfAKAJk (ORCPT ); Thu, 10 Jan 2019 19:09:40 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:54713 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730612AbfAKAJk (ORCPT ); Thu, 10 Jan 2019 19:09:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=IHX9zKwX3g55rrqXd9lriJaP/RBKf2AZZIqlDU6K/Js=; b=ZYG3BY4fJRQr zfDzleZKgQKa7VvUTeuTi/paqF9tlLERhQVbguQbrnKz0RM7oUnmONoDlbkwswCt+J8O7npOTWdTW xTtKnZ37fxH/AmGytUDZIZ/6mr4L0pedKjww68myaRgrSTqebWe8K/bFykFYIPz7t9q27VWGgIfWm IE4SXzjoC/oHht9TaTzzpBwfBpzUN5IYeccG2JhQ7EJ2xQxDqnDh0a0I86rSLKwl5LcMk92OqaQbR jGu4x+Q9ytCrDH6/MWl8PDqa9rlptxzIie6n91UXlvrcaygDCjL04ZuwGla/QprEXI7qlygf5xOjS 3jOKp9X+72dHfq+reZHdZQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkOE-000EWU-6W; Fri, 11 Jan 2019 01:09:34 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id F2F4DC0D45; Fri, 11 Jan 2019 01:09:19 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH 4/8] sd: Be consistent about blocks vs. sectors Date: Thu, 10 Jan 2019 16:08:54 -0800 Message-Id: <20190111000858.76261-5-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00513703939434) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5jXrsfbW0YAePP61MVLqTrd602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbBu5YFz4Jx0uq4149LpZwrkOR4/HajlzkVhakIw7Ig6RAJ lmpPd1BHwQ+kdrsiFH2cfUiCXtJytJdYVIlBCNoVDlGCgaqAfI9rupd8CZz+HVNiLZt/QXQnOBRD +jq1HsJAQnsLO8OlL77d3bdz3iqGHPrilcqgC/vBWiouMtxrNCP1HaH27Qjry/056DPMnxd+Swxv aRjzxpV3vJPKQXRYdnrLabUgNzEO/QU0BfnnNDg3ZbOPxovcwpgDatF7VXVEbF4rUil7pUnOksxs 7aZaj3hJxCWpajY6LYvBNWgpuOnE6wHyAbSyVXutrqMjgFIlz7WWm/p16OPcLYPdHAK7vqrauYnQ lgTtl087RrjX0eEI2EoZ8+/7zzZhzgY6klGcBiHQNaIxsZV6P9u0dfcPCpDOcqQNioEzqLzLiIk4 HEcFBAvuf345Nnfstl8j+xb+3g9gkPulv+51ClEQ+Hg4gl/DsUQ1TVQibLlvhjffuqQBJ7TPMihJ UfmPOEFZaWMMYnXhfsZBupE3ropdJsWCES6o0yXgT60woyy/8De7jEVHEX0tIc2xkWXbaWtFGf8f SSeUyA5BNWn7HV+jYQ+bPPIKc+pi3RwDjjhJKjjVWjz2L0AxoH8/3TLMLGMkVy6/mN3KwGpOwZOZ 1Jlwah6tMpHpGBDqxwz+gMmeGHJLGbB5qPrmLnSSifG4ucd7W6WiLdGNCnvgpopfSu7WpHHCvfcA DmA9UAv1v+rYdrKgZW/u3aItGPEPwBw7xatDmEFQvy23SZXSfMZ7RzHGH1l2j3GMtYjHvvB91g3T ziZ91uWAMRAzhjb/Aigdq0fxIYhOL4nawG8z87Sn7OLOV4Lis3vxMFxvQI95yX1Uqc2NraLyHm3n 4a4AzXkeEvgQi2jtxOzzT/YWdmD8gywgB151tgZkcRkCnoMzps1w8ZlyWpuWa9TLRBg21otcGPr1 zYyDRfp0WSy7R6kupj1q3Dt9ZyCgxZHINA6A5+7T9o6by6TTlSa2Lh/bXHbr9KsH2f7CCey7HUjs wwJCoJUeO2iBpksPaDU3ZH1Nh3tobKAf6zEvuGslKTrRIXcXpFg5ivY= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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: "Martin K. Petersen" We have had several bugs due mixing sector and logical block size terminology. In the block layer, a sector is a 512-byte unit regardless of the logical block size of the underlying device. But the term "sector" is still widely used in sd.c when referring to logical block sized units. We previously introduced helper functions such as sectors_to_logical() and logical_to_sectors() to make the distinction clear. Use these to make the code in sd.c consistent wrt. logical blocks and block layer sectors. Use "lba" to describe a logical block address and "nr_blocks" when counting logical blocks. SBC uses "TRANSFER LENGTH" to describe the latter but this term was avoided to prevent confusion with the very similar DMA transfer size (->transfersize) which is counted in bytes. Signed-off-by: Martin K. Petersen [ bvanassche: ported this patch from kernel v4.11 to kernel v5.0 ] Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 169 +++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 86 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 7afcf8f7e342..9d625ce37259 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -818,8 +818,8 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) { struct scsi_device *sdp = cmd->device; struct request *rq = cmd->request; - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); unsigned int data_len = 24; char *buf; @@ -838,8 +838,8 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) buf = page_address(rq->special_vec.bv_page); put_unaligned_be16(6 + 16, &buf[0]); put_unaligned_be16(16, &buf[2]); - put_unaligned_be64(sector, &buf[8]); - put_unaligned_be32(nr_sectors, &buf[16]); + put_unaligned_be64(lba, &buf[8]); + put_unaligned_be32(nr_blocks, &buf[16]); cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; @@ -854,8 +854,8 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, { struct scsi_device *sdp = cmd->device; struct request *rq = cmd->request; - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); u32 data_len = sdp->sector_size; rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); @@ -870,8 +870,8 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, cmd->cmnd[0] = WRITE_SAME_16; if (unmap) cmd->cmnd[1] = 0x8; /* UNMAP */ - put_unaligned_be64(sector, &cmd->cmnd[2]); - put_unaligned_be32(nr_sectors, &cmd->cmnd[10]); + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; @@ -886,8 +886,8 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, { struct scsi_device *sdp = cmd->device; struct request *rq = cmd->request; - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); u32 data_len = sdp->sector_size; rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); @@ -902,8 +902,8 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, cmd->cmnd[0] = WRITE_SAME; if (unmap) cmd->cmnd[1] = 0x8; /* UNMAP */ - put_unaligned_be32(sector, &cmd->cmnd[2]); - put_unaligned_be16(nr_sectors, &cmd->cmnd[7]); + put_unaligned_be32(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; @@ -918,8 +918,8 @@ static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd) struct request *rq = cmd->request; struct scsi_device *sdp = cmd->device; struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); - u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9); - u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); if (!(rq->cmd_flags & REQ_NOUNMAP)) { switch (sdkp->zeroing_mode) { @@ -933,7 +933,7 @@ static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd) if (sdp->no_write_same) return BLK_STS_TARGET; - if (sdkp->ws16 || sector > 0xffffffff || nr_sectors > 0xffff) + if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) return sd_setup_write_same16_cmnd(cmd, false); return sd_setup_write_same10_cmnd(cmd, false); @@ -1014,8 +1014,8 @@ static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) struct scsi_device *sdp = cmd->device; struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); struct bio *bio = rq->bio; - sector_t sector = blk_rq_pos(rq); - unsigned int nr_sectors = blk_rq_sectors(rq); + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); blk_status_t ret; if (sdkp->device->no_write_same) @@ -1023,21 +1023,18 @@ static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) BUG_ON(bio_offset(bio) || bio_iovec(bio).bv_len != sdp->sector_size); - sector >>= ilog2(sdp->sector_size) - 9; - nr_sectors >>= ilog2(sdp->sector_size) - 9; - rq->timeout = SD_WRITE_SAME_TIMEOUT; - if (sdkp->ws16 || sector > 0xffffffff || nr_sectors > 0xffff) { + if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) { cmd->cmd_len = 16; cmd->cmnd[0] = WRITE_SAME_16; - put_unaligned_be64(sector, &cmd->cmnd[2]); - put_unaligned_be32(nr_sectors, &cmd->cmnd[10]); + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); } else { cmd->cmd_len = 10; cmd->cmnd[0] = WRITE_SAME; - put_unaligned_be32(sector, &cmd->cmnd[2]); - put_unaligned_be16(nr_sectors, &cmd->cmnd[7]); + put_unaligned_be32(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); } cmd->transfersize = sdp->sector_size; @@ -1082,9 +1079,9 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) struct scsi_device *sdp = SCpnt->device; struct gendisk *disk = rq->rq_disk; struct scsi_disk *sdkp = scsi_disk(disk); - sector_t block = blk_rq_pos(rq); + sector_t lba = blk_rq_pos(rq); sector_t threshold; - unsigned int this_count = blk_rq_sectors(rq); + unsigned int nr_blocks = blk_rq_sectors(rq); unsigned int dif, dix; unsigned char protect; blk_status_t ret; @@ -1097,10 +1094,10 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt, "%s: block=%llu, count=%d\n", - __func__, (unsigned long long)block, this_count)); + __func__, (unsigned long long)lba, nr_blocks)); if (!sdp || !scsi_device_online(sdp) || - block + blk_rq_sectors(rq) > get_capacity(disk)) { + lba + blk_rq_sectors(rq) > get_capacity(disk)) { SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "Finishing %u sectors\n", blk_rq_sectors(rq))); @@ -1125,18 +1122,18 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) threshold = get_capacity(disk) - SD_LAST_BUGGY_SECTORS * (sdp->sector_size / 512); - if (unlikely(sdp->last_sector_bug && block + this_count > threshold)) { - if (block < threshold) { + if (unlikely(sdp->last_sector_bug && lba + nr_blocks > threshold)) { + if (lba < threshold) { /* Access up to the threshold but not beyond */ - this_count = threshold - block; + nr_blocks = threshold - lba; } else { /* Access only a single hardware sector */ - this_count = sdp->sector_size / 512; + nr_blocks = sdp->sector_size / 512; } } SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "block=%llu\n", - (unsigned long long)block)); + (unsigned long long)lba)); /* * If we have a 1K hardware sectorsize, prevent access to single @@ -1150,31 +1147,31 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) * for this. */ if (sdp->sector_size == 1024) { - if ((block & 1) || (blk_rq_sectors(rq) & 1)) { + if ((lba & 1) || (blk_rq_sectors(rq) & 1)) { scmd_printk(KERN_ERR, SCpnt, "Bad block number requested\n"); return BLK_STS_IOERR; } - block = block >> 1; - this_count = this_count >> 1; + lba = lba >> 1; + nr_blocks = nr_blocks >> 1; } if (sdp->sector_size == 2048) { - if ((block & 3) || (blk_rq_sectors(rq) & 3)) { + if ((lba & 3) || (blk_rq_sectors(rq) & 3)) { scmd_printk(KERN_ERR, SCpnt, "Bad block number requested\n"); return BLK_STS_IOERR; } - block = block >> 2; - this_count = this_count >> 2; + lba = lba >> 2; + nr_blocks = nr_blocks >> 2; } if (sdp->sector_size == 4096) { - if ((block & 7) || (blk_rq_sectors(rq) & 7)) { + if ((lba & 7) || (blk_rq_sectors(rq) & 7)) { scmd_printk(KERN_ERR, SCpnt, "Bad block number requested\n"); return BLK_STS_IOERR; } - block = block >> 3; - this_count = this_count >> 3; + lba = lba >> 3; + nr_blocks = nr_blocks >> 3; } if (rq_data_dir(rq) == WRITE) { SCpnt->cmnd[0] = WRITE_6; @@ -1192,7 +1189,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "%s %d/%u 512 byte blocks.\n", (rq_data_dir(rq) == WRITE) ? - "writing" : "reading", this_count, + "writing" : "reading", nr_blocks, blk_rq_sectors(rq))); dix = scsi_prot_sg_count(SCpnt); @@ -1217,54 +1214,54 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) SCpnt->cmnd[10] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); /* LBA */ - SCpnt->cmnd[12] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; - SCpnt->cmnd[13] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0; - SCpnt->cmnd[14] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0; - SCpnt->cmnd[15] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0; - SCpnt->cmnd[16] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[17] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[18] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[19] = (unsigned char) block & 0xff; + SCpnt->cmnd[12] = sizeof(lba) > 4 ? (unsigned char) (lba >> 56) & 0xff : 0; + SCpnt->cmnd[13] = sizeof(lba) > 4 ? (unsigned char) (lba >> 48) & 0xff : 0; + SCpnt->cmnd[14] = sizeof(lba) > 4 ? (unsigned char) (lba >> 40) & 0xff : 0; + SCpnt->cmnd[15] = sizeof(lba) > 4 ? (unsigned char) (lba >> 32) & 0xff : 0; + SCpnt->cmnd[16] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[17] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[18] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[19] = (unsigned char) lba & 0xff; /* Expected Indirect LBA */ - SCpnt->cmnd[20] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[21] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[22] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[23] = (unsigned char) block & 0xff; + SCpnt->cmnd[20] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[21] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[22] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[23] = (unsigned char) lba & 0xff; /* Transfer length */ - SCpnt->cmnd[28] = (unsigned char) (this_count >> 24) & 0xff; - SCpnt->cmnd[29] = (unsigned char) (this_count >> 16) & 0xff; - SCpnt->cmnd[30] = (unsigned char) (this_count >> 8) & 0xff; - SCpnt->cmnd[31] = (unsigned char) this_count & 0xff; - } else if (sdp->use_16_for_rw || (this_count > 0xffff)) { + SCpnt->cmnd[28] = (unsigned char) (nr_blocks >> 24) & 0xff; + SCpnt->cmnd[29] = (unsigned char) (nr_blocks >> 16) & 0xff; + SCpnt->cmnd[30] = (unsigned char) (nr_blocks >> 8) & 0xff; + SCpnt->cmnd[31] = (unsigned char) nr_blocks & 0xff; + } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { SCpnt->cmnd[0] += READ_16 - READ_6; SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); - SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; - SCpnt->cmnd[3] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0; - SCpnt->cmnd[4] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0; - SCpnt->cmnd[5] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0; - SCpnt->cmnd[6] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[7] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[8] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[9] = (unsigned char) block & 0xff; - SCpnt->cmnd[10] = (unsigned char) (this_count >> 24) & 0xff; - SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff; - SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff; - SCpnt->cmnd[13] = (unsigned char) this_count & 0xff; + SCpnt->cmnd[2] = sizeof(lba) > 4 ? (unsigned char) (lba >> 56) & 0xff : 0; + SCpnt->cmnd[3] = sizeof(lba) > 4 ? (unsigned char) (lba >> 48) & 0xff : 0; + SCpnt->cmnd[4] = sizeof(lba) > 4 ? (unsigned char) (lba >> 40) & 0xff : 0; + SCpnt->cmnd[5] = sizeof(lba) > 4 ? (unsigned char) (lba >> 32) & 0xff : 0; + SCpnt->cmnd[6] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[7] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[8] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[9] = (unsigned char) lba & 0xff; + SCpnt->cmnd[10] = (unsigned char) (nr_blocks >> 24) & 0xff; + SCpnt->cmnd[11] = (unsigned char) (nr_blocks >> 16) & 0xff; + SCpnt->cmnd[12] = (unsigned char) (nr_blocks >> 8) & 0xff; + SCpnt->cmnd[13] = (unsigned char) nr_blocks & 0xff; SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0; - } else if ((this_count > 0xff) || (block > 0x1fffff) || + } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || scsi_device_protection(SCpnt->device) || SCpnt->device->use_10_for_rw) { SCpnt->cmnd[0] += READ_10 - READ_6; SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); - SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[5] = (unsigned char) block & 0xff; + SCpnt->cmnd[2] = (unsigned char) (lba >> 24) & 0xff; + SCpnt->cmnd[3] = (unsigned char) (lba >> 16) & 0xff; + SCpnt->cmnd[4] = (unsigned char) (lba >> 8) & 0xff; + SCpnt->cmnd[5] = (unsigned char) lba & 0xff; SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0; - SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff; - SCpnt->cmnd[8] = (unsigned char) this_count & 0xff; + SCpnt->cmnd[7] = (unsigned char) (nr_blocks >> 8) & 0xff; + SCpnt->cmnd[8] = (unsigned char) nr_blocks & 0xff; } else { if (unlikely(rq->cmd_flags & REQ_FUA)) { /* @@ -1278,13 +1275,13 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) return BLK_STS_IOERR; } - SCpnt->cmnd[1] |= (unsigned char) ((block >> 16) & 0x1f); - SCpnt->cmnd[2] = (unsigned char) ((block >> 8) & 0xff); - SCpnt->cmnd[3] = (unsigned char) block & 0xff; - SCpnt->cmnd[4] = (unsigned char) this_count; + SCpnt->cmnd[1] |= (unsigned char) ((lba >> 16) & 0x1f); + SCpnt->cmnd[2] = (unsigned char) ((lba >> 8) & 0xff); + SCpnt->cmnd[3] = (unsigned char) lba & 0xff; + SCpnt->cmnd[4] = (unsigned char) nr_blocks; SCpnt->cmnd[5] = 0; } - SCpnt->sdb.length = this_count * sdp->sector_size; + SCpnt->sdb.length = nr_blocks * sdp->sector_size; /* * We shouldn't disconnect in the middle of a sector, so with a dumb @@ -1292,7 +1289,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) * this many bytes between each connect / disconnect. */ SCpnt->transfersize = sdp->sector_size; - SCpnt->underflow = this_count << 9; + SCpnt->underflow = nr_blocks << 9; SCpnt->allowed = SD_MAX_RETRIES; /* From patchwork Fri Jan 11 00:08:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757061 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 4646317D2 for ; Fri, 11 Jan 2019 00:09:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FA0A29D45 for ; Fri, 11 Jan 2019 00:09:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2430D29D48; Fri, 11 Jan 2019 00:09:32 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 A70E729D46 for ; Fri, 11 Jan 2019 00:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730594AbfAKAJb (ORCPT ); Thu, 10 Jan 2019 19:09:31 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:59889 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728961AbfAKAJb (ORCPT ); Thu, 10 Jan 2019 19:09:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=d8m3+rK0K1hu3PZ7eLOdrdfrJcwAhPvQ4k/G5R3oDVE=; b=JFtgABqltL1S tyCg7YSFRUMr27hCB9I8lArfl58E+oBDBEXXWTuBkQ2Tg8ZED5u8OTFXmthx5moe1Prx+X19budhD BebzO5SYO87gm/5l/5nG3qprxTWmMi146eO2re+ke9PdXVLZ8aBia11+GeTFOa5umW+4jGe1U52z8 EDDx/awH8IBw1zybGlg1AiYDyt7jqrlBZC4MnXEklR8cgI9OzX5LBaFyyZSe1ivcjKb6TRNyVf1QN 069xL77MHFlXpi0U1UcUq3Bpp0NwVoimwKGWcXTnDhujyk15uRhbsdXygHupdWsFQ4cEWvPf4GY8i MNJqtXekQnKwko2q0edrRg==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkO6-000EWK-7K; Fri, 11 Jan 2019 01:09:26 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 548D7C0D50; Fri, 11 Jan 2019 01:09:21 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH 5/8] sd: Simplify misaligned I/O check Date: Thu, 10 Jan 2019 16:08:55 -0800 Message-Id: <20190111000858.76261-6-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5nYOMIUgyEQy9Drj/XkLUOR602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbBu5YFz4Jx0uq4149LpZwrkOR4/HajlzkVhakIw7Ig6RAJ lmpPd1BHwQ+kdrsiFH2cfUiCXtJytJdYVIlBCNoVDlGCgaqAfI9rupd8CZz+HVNiLZt/QXQnOBRD +jq1HsJAQnsLO8OlL77d3bdz3iqGDQHEUXu1TC4hgo7W9Jgo3SP1HaH27Qjry/056DPMnxd+Swxv aRjzxpV3vJPKQXRYdnrLabUgNzEO/QU0BfnnNDg3ZbOPxovcwpgDatF7VXVEbF4rUil7pUnOksxs 7aZaj3hJxCWpajY6LYvBNWgpuOnE6wHyAbSyVXutrqMjgFIlz7WWm/p16OPcLYPdHAK7vqrauYnQ lgTtl087RrjX0eEI2EoZ8+/7zzZhzgY6klGcBiHQNaIxsZV6P9u0dfcPVf1qzaRUc3P3olRHLamM Qyb0mbZGjIHswS91OoTWbV0TVjUl1IhpqpL1ys0dPZdHkDkXGJvniGivX1Fq/UQDdcZCl4lfVnm2 hxV4736kvFu105zjbKsiPvrvVDH+VNpRclzFnL9mZb0jWXJhjtxPMCM76Y/SM8gaXNdGScJz4OXR jhdizhW8qsvGNuSd/HEJZ6oWQryHP/RGml7WN6gTRs6kmFhUakh2u5Yn2EY6OaZWTcUVh8zbZfcK ACLJrQoetW1xD7NPHFVkxC5YVnU16XMMgeYhi2d5qCVnOtDXhDXk7BUPP1haJIgTpSUEebIErbNe M6iidDaIJ4/68uIg9cw4Oh2LkwsmIC+tUiJAU2HwgBR30xDfQHtZy/Bf9JdHXKrn95xUGqVe+Jct 7pBd4xxwEiTVJqDh0qKoKsXx5lk3qtRz7SlCtdp5f9SVDcnPVkZi1FAqeGzQgF8SeqULJtsApjxw /ehSIEROg+hijQbpfj5sSQhb3cc4IkKXIhy+GYF0rkJbsdOWv4seI9QfnX0yZIM81CWbOkIhVXFL WPJO+eyolGM4l8rlxuGfhU+3k8+lrVLTNBgpy2LxbHpqloq8mG8yXCcEbxT2UdIuHji9IodMg2vu WMdu+65sFAzW X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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: "Martin K. Petersen" Avoid open coding the checks for the supported logical block sizes and use a mask to check for misaligned I/O. Use our helper functions to scale lba and block count. Signed-off-by: Martin K. Petersen [ bvanassche: ported this patch from kernel v4.11 to kernel v5.0 ] Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 57 ++++++++++------------------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 9d625ce37259..0b609a3a207a 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1079,10 +1079,11 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) struct scsi_device *sdp = SCpnt->device; struct gendisk *disk = rq->rq_disk; struct scsi_disk *sdkp = scsi_disk(disk); - sector_t lba = blk_rq_pos(rq); + sector_t lba = sectors_to_logical(sdp, blk_rq_pos(rq)); sector_t threshold; - unsigned int nr_blocks = blk_rq_sectors(rq); + unsigned int nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); unsigned int dif, dix; + unsigned int mask = logical_to_sectors(sdp, 1) - 1; unsigned char protect; blk_status_t ret; @@ -1116,63 +1117,29 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) } /* - * Some SD card readers can't handle multi-sector accesses which touch - * the last one or two hardware sectors. Split accesses as needed. + * Some SD card readers can't handle accesses which touch the + * last one or two logical blocks. Split accesses as needed. */ - threshold = get_capacity(disk) - SD_LAST_BUGGY_SECTORS * - (sdp->sector_size / 512); + threshold = sdkp->capacity - SD_LAST_BUGGY_SECTORS; if (unlikely(sdp->last_sector_bug && lba + nr_blocks > threshold)) { if (lba < threshold) { /* Access up to the threshold but not beyond */ nr_blocks = threshold - lba; } else { - /* Access only a single hardware sector */ - nr_blocks = sdp->sector_size / 512; + /* Access only a single logical block */ + nr_blocks = 1; } } SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "block=%llu\n", (unsigned long long)lba)); - /* - * If we have a 1K hardware sectorsize, prevent access to single - * 512 byte sectors. In theory we could handle this - in fact - * the scsi cdrom driver must be able to handle this because - * we typically use 1K blocksizes, and cdroms typically have - * 2K hardware sectorsizes. Of course, things are simpler - * with the cdrom, since it is read-only. For performance - * reasons, the filesystems should be able to handle this - * and not force the scsi disk driver to use bounce buffers - * for this. - */ - if (sdp->sector_size == 1024) { - if ((lba & 1) || (blk_rq_sectors(rq) & 1)) { - scmd_printk(KERN_ERR, SCpnt, - "Bad block number requested\n"); - return BLK_STS_IOERR; - } - lba = lba >> 1; - nr_blocks = nr_blocks >> 1; - } - if (sdp->sector_size == 2048) { - if ((lba & 3) || (blk_rq_sectors(rq) & 3)) { - scmd_printk(KERN_ERR, SCpnt, - "Bad block number requested\n"); - return BLK_STS_IOERR; - } - lba = lba >> 2; - nr_blocks = nr_blocks >> 2; - } - if (sdp->sector_size == 4096) { - if ((lba & 7) || (blk_rq_sectors(rq) & 7)) { - scmd_printk(KERN_ERR, SCpnt, - "Bad block number requested\n"); - return BLK_STS_IOERR; - } - lba = lba >> 3; - nr_blocks = nr_blocks >> 3; + if ((blk_rq_pos(rq) & mask) || (blk_rq_sectors(rq) & mask)) { + scmd_printk(KERN_ERR, SCpnt, "request not aligned to the logical block size\n"); + return BLK_STS_IOERR; } + if (rq_data_dir(rq) == WRITE) { SCpnt->cmnd[0] = WRITE_6; From patchwork Fri Jan 11 00:08:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757071 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 F1CB41390 for ; Fri, 11 Jan 2019 00:09:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFED929D45 for ; Fri, 11 Jan 2019 00:09:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3CD129D5D; Fri, 11 Jan 2019 00:09:48 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 275B529D45 for ; Fri, 11 Jan 2019 00:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730755AbfAKAJm (ORCPT ); Thu, 10 Jan 2019 19:09:42 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:59741 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730754AbfAKAJl (ORCPT ); Thu, 10 Jan 2019 19:09:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=IIhY/3g3+6C0vj8e/ChtzJUg/eKG2BuNXCxmvUpvk4U=; b=JFIwXi0BO0pK Kab8WpNAn6SeqbzJHxtJcBVkl/b7nu8FhrKQ3nOudbfteO++j8NFP8eiRopYjMBhTl8ISG2tNi7RJ EFcJ87Gvr7EzUTXcy/RSCSyR1S4TWRUlJoeS6HGvPX6kjbPORDXp9nN2VKFhQP3Dey/uYMWODUc0F 5fgj0IYfvp2oKkQnh5NKuS4yG+jULm+ksqjVrIjnMAkHFkzVLvEF2V0BZ9I28KeVYCJk4lE4IzbD2 MChoOOBZSBbAwyoE1ycq9etRKVxoGx9Hhezothnr/WaUxq5HmWRmTS4LUrsqDM6nlVuapSavl4gAa vAIbpx4Sc8xNMPK9aXcLdQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkOH-000De2-55; Fri, 11 Jan 2019 01:09:37 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 801DBC0D61; Fri, 11 Jan 2019 01:09:22 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH 6/8] sd: Create helper functions for read/write commands Date: Thu, 10 Jan 2019 16:08:56 -0800 Message-Id: <20190111000858.76261-7-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00380385169448) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5pKxzwcEbc9G8FTEw8LhCPd602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbBu5YFz4Jx0uq4149LpZwrkOR4/HajlzkVhakIw7Ig6RAJ lmpPd1BHwQ+kdrsiFH2cfUiCXtJytJdYVIlBCNoVDlGCgaqAfI9rupd8CZz+HVNiLZt/QXQnOBRD +jq1HsJAQnsLO8OlL77d3bdz3iqG02nIsRjNan5jEiQKJWbmTyP1HaH27Qjry/056DPMnxd+Swxv aRjzxpV3vJPKQXRYGRQP6aoq2j5ibghWGduoTjg3ZbOPxovcwpgDatF7VXVEbF4rUil7pUnOksxs 7aZaj3hJxCWpajY6LYvBNWgpuOnE6wHyAbSyVXutrqMjgFIlz7WWm/p16OPcLYPdHAK7vqrauYnQ lgTtl087RrjX0eEI2EoZ8+/7zzZhzgY6klGcBiHQNaIxsZV6P9u0dfcPCpDOcqQNioEzqLzLiIk4 HEcFBAvuf345Nnfstl8j+xb+3g9gkPulv+51ClEQ+Hg4gl/DsUQ1TVQibLlvhjffuqQBJ7TPMihJ UfmPOEFZaWMMYnXhfsZBupE3ropdJsWCES6o0yXgT60woyy/8De7jEVHEX0tIc2xkWXbaWtFGf8f SSeUyA5BNWn7HV+jYQ+bPPIKc+pi3RwDjjhJKjjVWllgjBusKL/lG7HvJzGm7bVpG9x2dnGeSM5z lYrnQPitMpHpGBDqxwz+gMmeGHJLGbB5qPrmLnSSifG4ucd7W6WiLdGNCnvgpopfSu7WpHHCvfcA DmA9UAv1v+rYdrKgZW/u3aItGPEPwBw7xatDmEFQvy23SZXSfMZ7RzHGH1l2j3GMtYjHvvB91g3T ziZ91gd/5+ZnhpSYcoe+EE6OOxFOL4nawG8z87Sn7OLOV4Lis3vxMFxvQI95yX1Uqc2NraLyHm3n 4a4AzXkeEvgQi2jtxOzzT/YWdmD8gywgB151tgZkcRkCnoMzps1w8ZlyWpuWa9TLRBg21otcGPr1 zYyDRfp0WSy7R6kupj1q3Dt9ZyCgxZHINA6A5+7T9o6by6TTlSa2Lh/bXHbr9KsH2f7CCey7HUjs wwJCoJUeO2iBpksPaDU3ZH1Nh3tobKAf6zEvuGslKTrRIXcXpFg5ivY= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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: "Martin K. Petersen" Create a helper function for each of the 6, 10, 16 and 32-byte READ/WRITE variants and use those when setting up reads and writes. Signed-off-by: Martin K. Petersen [ bvanassche: ported this patch from kernel v4.11 to kernel v5.0 and made function names shorter. ] Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 167 +++++++++++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 75 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 0b609a3a207a..039b0c7f178e 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1073,6 +1073,83 @@ static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd) return BLK_STS_OK; } +static blk_status_t sd_setup_rw32_cmnd(struct scsi_cmnd *cmd, bool write, + sector_t lba, unsigned int nr_blocks, + unsigned char flags) +{ + cmd->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC); + if (unlikely(cmd->cmnd == NULL)) + return BLK_STS_RESOURCE; + + cmd->cmd_len = SD_EXT_CDB_SIZE; + memset(cmd->cmnd, 0, cmd->cmd_len); + + cmd->cmnd[0] = VARIABLE_LENGTH_CMD; + cmd->cmnd[7] = 0x18; /* Additional CDB len */ + cmd->cmnd[9] = write ? WRITE_32 : READ_32; + cmd->cmnd[10] = flags; + put_unaligned_be64(lba, &cmd->cmnd[12]); + put_unaligned_be32(lba, &cmd->cmnd[20]); /* Expected Indirect LBA */ + put_unaligned_be32(nr_blocks, &cmd->cmnd[28]); + + return BLK_STS_OK; +} + +static blk_status_t sd_setup_rw16_cmnd(struct scsi_cmnd *cmd, bool write, + sector_t lba, unsigned int nr_blocks, + unsigned char flags) +{ + cmd->cmd_len = 16; + cmd->cmnd[0] = write ? WRITE_16 : READ_16; + cmd->cmnd[1] = flags; + cmd->cmnd[14] = 0; + cmd->cmnd[15] = 0; + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); + + return BLK_STS_OK; +} + +static blk_status_t sd_setup_rw10_cmnd(struct scsi_cmnd *cmd, bool write, + sector_t lba, unsigned int nr_blocks, + unsigned char flags) +{ + cmd->cmd_len = 10; + cmd->cmnd[0] = write ? WRITE_10 : READ_10; + cmd->cmnd[1] = flags; + cmd->cmnd[6] = 0; + cmd->cmnd[9] = 0; + put_unaligned_be32(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); + + return BLK_STS_OK; +} + +static blk_status_t sd_setup_rw6_cmnd(struct scsi_cmnd *cmd, bool write, + sector_t lba, unsigned int nr_blocks, + unsigned char flags) +{ + if (unlikely(flags & 0x8)) { + /* + * This happens only if this drive failed 10byte rw + * command with ILLEGAL_REQUEST during operation and + * thus turned off use_10_for_rw. + */ + scmd_printk(KERN_ERR, cmd, "FUA write on READ/WRITE(6) drive\n"); + return BLK_STS_IOERR; + } + + cmd->cmd_len = 6; + cmd->cmnd[0] = write ? WRITE_6 : READ_6; + cmd->cmnd[1] = (lba >> 16) & 0x1f; + cmd->cmnd[2] = (lba >> 8) & 0xff; + cmd->cmnd[3] = lba & 0xff; + cmd->cmnd[4] = nr_blocks; + cmd->cmnd[5] = 0; + + return BLK_STS_OK; +} + static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) { struct request *rq = SCpnt->request; @@ -1084,7 +1161,8 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) unsigned int nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); unsigned int dif, dix; unsigned int mask = logical_to_sectors(sdp, 1) - 1; - unsigned char protect; + bool write = rq_data_dir(rq) == WRITE; + unsigned char protect, fua; blk_status_t ret; ret = scsi_init_io(SCpnt); @@ -1159,6 +1237,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) "writing" : "reading", nr_blocks, blk_rq_sectors(rq))); + fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; dix = scsi_prot_sg_count(SCpnt); dif = scsi_host_dif_capable(SCpnt->device->host, sdkp->protection_type); @@ -1168,86 +1247,24 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) protect = 0; if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { - SCpnt->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC); - - if (unlikely(!SCpnt->cmnd)) - return BLK_STS_RESOURCE; - - SCpnt->cmd_len = SD_EXT_CDB_SIZE; - memset(SCpnt->cmnd, 0, SCpnt->cmd_len); - SCpnt->cmnd[0] = VARIABLE_LENGTH_CMD; - SCpnt->cmnd[7] = 0x18; - SCpnt->cmnd[9] = (rq_data_dir(rq) == READ) ? READ_32 : WRITE_32; - SCpnt->cmnd[10] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); - - /* LBA */ - SCpnt->cmnd[12] = sizeof(lba) > 4 ? (unsigned char) (lba >> 56) & 0xff : 0; - SCpnt->cmnd[13] = sizeof(lba) > 4 ? (unsigned char) (lba >> 48) & 0xff : 0; - SCpnt->cmnd[14] = sizeof(lba) > 4 ? (unsigned char) (lba >> 40) & 0xff : 0; - SCpnt->cmnd[15] = sizeof(lba) > 4 ? (unsigned char) (lba >> 32) & 0xff : 0; - SCpnt->cmnd[16] = (unsigned char) (lba >> 24) & 0xff; - SCpnt->cmnd[17] = (unsigned char) (lba >> 16) & 0xff; - SCpnt->cmnd[18] = (unsigned char) (lba >> 8) & 0xff; - SCpnt->cmnd[19] = (unsigned char) lba & 0xff; - - /* Expected Indirect LBA */ - SCpnt->cmnd[20] = (unsigned char) (lba >> 24) & 0xff; - SCpnt->cmnd[21] = (unsigned char) (lba >> 16) & 0xff; - SCpnt->cmnd[22] = (unsigned char) (lba >> 8) & 0xff; - SCpnt->cmnd[23] = (unsigned char) lba & 0xff; - - /* Transfer length */ - SCpnt->cmnd[28] = (unsigned char) (nr_blocks >> 24) & 0xff; - SCpnt->cmnd[29] = (unsigned char) (nr_blocks >> 16) & 0xff; - SCpnt->cmnd[30] = (unsigned char) (nr_blocks >> 8) & 0xff; - SCpnt->cmnd[31] = (unsigned char) nr_blocks & 0xff; + ret = sd_setup_rw32_cmnd(SCpnt, write, lba, nr_blocks, + protect | fua); } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { - SCpnt->cmnd[0] += READ_16 - READ_6; - SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); - SCpnt->cmnd[2] = sizeof(lba) > 4 ? (unsigned char) (lba >> 56) & 0xff : 0; - SCpnt->cmnd[3] = sizeof(lba) > 4 ? (unsigned char) (lba >> 48) & 0xff : 0; - SCpnt->cmnd[4] = sizeof(lba) > 4 ? (unsigned char) (lba >> 40) & 0xff : 0; - SCpnt->cmnd[5] = sizeof(lba) > 4 ? (unsigned char) (lba >> 32) & 0xff : 0; - SCpnt->cmnd[6] = (unsigned char) (lba >> 24) & 0xff; - SCpnt->cmnd[7] = (unsigned char) (lba >> 16) & 0xff; - SCpnt->cmnd[8] = (unsigned char) (lba >> 8) & 0xff; - SCpnt->cmnd[9] = (unsigned char) lba & 0xff; - SCpnt->cmnd[10] = (unsigned char) (nr_blocks >> 24) & 0xff; - SCpnt->cmnd[11] = (unsigned char) (nr_blocks >> 16) & 0xff; - SCpnt->cmnd[12] = (unsigned char) (nr_blocks >> 8) & 0xff; - SCpnt->cmnd[13] = (unsigned char) nr_blocks & 0xff; - SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0; + ret = sd_setup_rw16_cmnd(SCpnt, write, lba, nr_blocks, + protect | fua); } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || scsi_device_protection(SCpnt->device) || SCpnt->device->use_10_for_rw) { - SCpnt->cmnd[0] += READ_10 - READ_6; - SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); - SCpnt->cmnd[2] = (unsigned char) (lba >> 24) & 0xff; - SCpnt->cmnd[3] = (unsigned char) (lba >> 16) & 0xff; - SCpnt->cmnd[4] = (unsigned char) (lba >> 8) & 0xff; - SCpnt->cmnd[5] = (unsigned char) lba & 0xff; - SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0; - SCpnt->cmnd[7] = (unsigned char) (nr_blocks >> 8) & 0xff; - SCpnt->cmnd[8] = (unsigned char) nr_blocks & 0xff; + ret = sd_setup_rw10_cmnd(SCpnt, write, lba, nr_blocks, + protect | fua); } else { - if (unlikely(rq->cmd_flags & REQ_FUA)) { - /* - * This happens only if this drive failed - * 10byte rw command with ILLEGAL_REQUEST - * during operation and thus turned off - * use_10_for_rw. - */ - scmd_printk(KERN_ERR, SCpnt, - "FUA write on READ/WRITE(6) drive\n"); - return BLK_STS_IOERR; - } - - SCpnt->cmnd[1] |= (unsigned char) ((lba >> 16) & 0x1f); - SCpnt->cmnd[2] = (unsigned char) ((lba >> 8) & 0xff); - SCpnt->cmnd[3] = (unsigned char) lba & 0xff; - SCpnt->cmnd[4] = (unsigned char) nr_blocks; - SCpnt->cmnd[5] = 0; + ret = sd_setup_rw6_cmnd(SCpnt, write, lba, nr_blocks, + protect | fua); } + + if (unlikely(ret != BLK_STS_OK)) + return ret; + SCpnt->sdb.length = nr_blocks * sdp->sector_size; /* From patchwork Fri Jan 11 00:08:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757063 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 F34B31390 for ; Fri, 11 Jan 2019 00:09:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E28D429D48 for ; Fri, 11 Jan 2019 00:09:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6F8129D4B; Fri, 11 Jan 2019 00:09:35 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 48E1E29D45 for ; Fri, 11 Jan 2019 00:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730715AbfAKAJe (ORCPT ); Thu, 10 Jan 2019 19:09:34 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:54109 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728961AbfAKAJe (ORCPT ); Thu, 10 Jan 2019 19:09:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=3nquZwTf5uObyzfwoq5HbGbSlzZjGxROA4+3JoEyCfQ=; b=cR1PwkpkAypg ejtOKL2zTsGSN/DiSU21MMJx8NZf+R4P2DQszg7vD1xaslnlIaqpik3LP2Y206OtUfOteo25myHpm k7D1XMReF2FOgTaU0PJE3ACg2JNSGz4cGy6XcUYkhGNWih8Bzv1s4qYCENbAsjznH4bjSGWYr63cz BQxUgi65GA5fatfam9PajssuFr+0NHhARN5dArkyt1lRIJChw8Bc/cIOBJ5QqkFRqP4emBElwSNkb dX767z2MOfmcFyUW2ronk/MjSa+9bYxtiRmyMP9CiKlVfdA8WatnpTA8Xsph5Qb3GIQkjstRkG98r zJcvHoBh2Pd0+bQ4mYuD5Q==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkO9-000De9-E5; Fri, 11 Jan 2019 01:09:30 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 01428C0D24; Fri, 11 Jan 2019 01:09:23 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH 7/8] sd: Clean up sd_setup_read_write_cmnd() Date: Thu, 10 Jan 2019 16:08:57 -0800 Message-Id: <20190111000858.76261-8-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00796386725486) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5uOTm7Qf0qFlGuBlR/VQAp9602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbBu5YFz4Jx0uq4149LpZwrkOR4/HajlzkVhakIw7Ig6RAJ lmpPd1BHwQ+kdrsiFH2cfUiCXtJytJdYVIlBCNoVDlGCgaqAfI9rupd8CZz+HVNiLZt/QXQnOBRD +jq1HsJAQnsLO8OlL77d3bdz3iqGuUAPbYKA53OTPGji3Wjf/iP1HaH27Qjry/056DPMnxd+Swxv aRjzxpV3vJPKQXRYGRQP6aoq2j5ibghWGduoTjg3ZbOPxovcwpgDatF7VXVEbF4rUil7pUnOksxs 7aZaj3hJxCWpajY6LYvBNWgpuOnE6wHyAbSyVXutrqMjgFIlz7WWm/p16OPcLYPdHAK7vqrauYnQ lgTtl087RrjX0eEI2EoZ8+/7zzZhzgY6klGcBiHQNaIxsZV6P9u0dfcPCpDOcqQNioEzqLzLiIk4 HEcFBAvuf345Nnfstl8j+xb+3g9gkPulv+51ClEQ+Hg4gl/DsUQ1TVQibLlvhjffuqQBJ7TPMihJ UfmPOEFZaWMMYnXhfsZBupE3ropdJsWCES6o0yXgT60woyy/8De7jEVHEX0tIc2xkWXbaWtFGf8f SSeUyA5BNWn7HV+jYQ+bPPIKc+pi3RwDjjhJKjjVWllgjBusKL/lG7HvJzGm7bUZxgFxljDG1yNa PBSs5ONmMpHpGBDqxwz+gMmeGHJLGbB5qPrmLnSSifG4ucd7W6WiLdGNCnvgpopfSu7WpHHCvfcA DmA9UAv1v+rYdrKgZW/u3aItGPEPwBw7xatDmEFQvy23SZXSfMZ7RzHGH1l2j3GMtYjHvvB91g3T ziZ91vT/MBiCVz5fUdn5QqTS0wlOL4nawG8z87Sn7OLOV4Lis3vxMFxvQI95yX1Uqc2NraLyHm3n 4a4AzXkeEvgQi2jtxOzzT/YWdmD8gywgB151tgZkcRkCnoMzps1w8ZlyWpuWa9TLRBg21otcGPr1 zYyDRfp0WSy7R6kupj1q3Dt9ZyCgxZHINA6A5+7T9o6by6TTlSa2Lh/bXHbr9KsH2f7CCey7HUjs wwJCoJUeO2iBpksPaDU3ZH1Nh3tobKAf6zEvuGslKTrRIXcXpFg5ivY= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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: "Martin K. Petersen" Rework sd_setup_read_write_cmnd() so it becomes more readable. Put all the sanity checking at the head of the function and sanitize the logged error messages. Move the legacy SCSI logging calls to the end of the functions and reduce conditional nesting. Signed-off-by: Martin K. Petersen [ bvanassche: ported this patch from kernel v4.11 to kernel v5.0 ] Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 80 +++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 52 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 039b0c7f178e..4e293e4c6823 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1154,12 +1154,11 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) { struct request *rq = SCpnt->request; struct scsi_device *sdp = SCpnt->device; - struct gendisk *disk = rq->rq_disk; - struct scsi_disk *sdkp = scsi_disk(disk); + struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); sector_t lba = sectors_to_logical(sdp, blk_rq_pos(rq)); sector_t threshold; unsigned int nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); - unsigned int dif, dix; + bool dif, dix; unsigned int mask = logical_to_sectors(sdp, 1) - 1; bool write = rq_data_dir(rq) == WRITE; unsigned char protect, fua; @@ -1168,29 +1167,21 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) ret = scsi_init_io(SCpnt); if (ret != BLK_STS_OK) return ret; + WARN_ON_ONCE(SCpnt != rq->special); - SCSI_LOG_HLQUEUE(1, - scmd_printk(KERN_INFO, SCpnt, - "%s: block=%llu, count=%d\n", - __func__, (unsigned long long)lba, nr_blocks)); - - if (!sdp || !scsi_device_online(sdp) || - lba + blk_rq_sectors(rq) > get_capacity(disk)) { - SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, - "Finishing %u sectors\n", - blk_rq_sectors(rq))); - SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, - "Retry with 0x%p\n", SCpnt)); + if (!scsi_device_online(sdp) || sdp->changed) { + scmd_printk(KERN_ERR, SCpnt, "device offline or changed\n"); return BLK_STS_IOERR; } - if (sdp->changed) { - /* - * quietly refuse to do anything to a changed disc until - * the changed bit has been reset - */ - /* printk("SCSI disk has been changed or is not present. Prohibiting further I/O.\n"); */ + if (blk_rq_pos(rq) + blk_rq_sectors(rq) > get_capacity(rq->rq_disk)) { + scmd_printk(KERN_ERR, SCpnt, "access beyond end of device\n"); + return BLK_STS_IOERR; + } + + if ((blk_rq_pos(rq) & mask) || (blk_rq_sectors(rq) & mask)) { + scmd_printk(KERN_ERR, SCpnt, "request not aligned to the logical block size\n"); return BLK_STS_IOERR; } @@ -1210,37 +1201,13 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) } } - SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "block=%llu\n", - (unsigned long long)lba)); - - if ((blk_rq_pos(rq) & mask) || (blk_rq_sectors(rq) & mask)) { - scmd_printk(KERN_ERR, SCpnt, "request not aligned to the logical block size\n"); - return BLK_STS_IOERR; - } - - if (rq_data_dir(rq) == WRITE) { - SCpnt->cmnd[0] = WRITE_6; - - if (blk_integrity_rq(rq)) - t10_pi_prepare(SCpnt->request, sdkp->protection_type); - - } else if (rq_data_dir(rq) == READ) { - SCpnt->cmnd[0] = READ_6; - } else { - scmd_printk(KERN_ERR, SCpnt, "Unknown command %d\n", req_op(rq)); - return BLK_STS_IOERR; - } - - SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, - "%s %d/%u 512 byte blocks.\n", - (rq_data_dir(rq) == WRITE) ? - "writing" : "reading", nr_blocks, - blk_rq_sectors(rq))); - fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; dix = scsi_prot_sg_count(SCpnt); dif = scsi_host_dif_capable(SCpnt->device->host, sdkp->protection_type); + if (write && dix) + t10_pi_prepare(SCpnt->request, sdkp->protection_type); + if (dif || dix) protect = sd_setup_protect_cmnd(SCpnt, dix, dif); else @@ -1253,8 +1220,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) ret = sd_setup_rw16_cmnd(SCpnt, write, lba, nr_blocks, protect | fua); } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || - scsi_device_protection(SCpnt->device) || - SCpnt->device->use_10_for_rw) { + sdp->use_10_for_rw || protect) { ret = sd_setup_rw10_cmnd(SCpnt, write, lba, nr_blocks, protect | fua); } else { @@ -1265,8 +1231,6 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) if (unlikely(ret != BLK_STS_OK)) return ret; - SCpnt->sdb.length = nr_blocks * sdp->sector_size; - /* * We shouldn't disconnect in the middle of a sector, so with a dumb * host adapter, it's safe to assume that we can at least transfer @@ -1275,6 +1239,18 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) SCpnt->transfersize = sdp->sector_size; SCpnt->underflow = nr_blocks << 9; SCpnt->allowed = SD_MAX_RETRIES; + SCpnt->sdb.length = nr_blocks * sdp->sector_size; + + SCSI_LOG_HLQUEUE(1, + scmd_printk(KERN_INFO, SCpnt, + "%s: block=%llu, count=%d\n", __func__, + (unsigned long long)blk_rq_pos(rq), + blk_rq_sectors(rq))); + SCSI_LOG_HLQUEUE(2, + scmd_printk(KERN_INFO, SCpnt, + "%s %d/%u 512 byte blocks.\n", + write ? "writing" : "reading", nr_blocks, + blk_rq_sectors(rq))); /* * This indicates that the command is ready from our end to be From patchwork Fri Jan 11 00:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757065 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 20F0B17D2 for ; Fri, 11 Jan 2019 00:09:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D28329D45 for ; Fri, 11 Jan 2019 00:09:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0165E29D48; Fri, 11 Jan 2019 00:09:35 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 7B7DC29D46 for ; Fri, 11 Jan 2019 00:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730735AbfAKAJf (ORCPT ); Thu, 10 Jan 2019 19:09:35 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:41467 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730612AbfAKAJe (ORCPT ); Thu, 10 Jan 2019 19:09:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=jLPJkF/Mx+BqNtZW0hUcK5P2eMW0JojCdcCM1rGCybo=; b=QZt+jGIR5Txx K49F3/nrrJjOSLUVDOJXjaRT+/N/oY0eHYHORIQIwfWfOTmLh8FkjW0jsVEJ3Rv8SvzoZMOh67MRX +r8S3uQ0ft9kAZhKUiNu//q7xRRnidN1uCAivfWNCUFhm5jtzvQV+uw9tTcMnZ5K7G7EjbqDWQQ8B lehw6X4EP46kzODutOfwpUX9d6CFaUoYCwzwsMWt8f5ZoU9u5YlmX7hcKznZYkqR8uYYt81FRZuCS 2lkX6zMLlX1QsK7/0S2KjF9CdlxYR1ifDhOhYzxUyaLSr9X2MFBI7C3UFhWzQ9phIIVlRkj4Loznc 5qkBbeXFjbnSviAfxaOwMQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkO9-000De3-E5; Fri, 11 Jan 2019 01:09:30 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 6ECE5C07A1; Fri, 11 Jan 2019 01:09:25 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH 8/8] sd: Rename 'SCpnt' into 'cmd' Date: Thu, 10 Jan 2019 16:08:58 -0800 Message-Id: <20190111000858.76261-9-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.000416019318998) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5vHfg4649HszYfxnou5yOpJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbBu5YFz4Jx0uq4149LpZwrkOR4/HajlzkVhakIw7Ig6RAJ lmpPd1BHwQ+kdrsiFH2cfUiCXtJytJdYVIlBCNoVDlGCgaqAfI9rupd8CZz+HVNiLZt/QXQnOBRD +jq1HsJAQnsLO8OlL77d3bdz3iqG0TDIcVwpd70NROueTbiAXCP1HaH27Qjry/056DPMnxd+Swxv aRjzxpV3vJPKQXRYGRQP6aoq2j5ibghWGduoTjg3ZbOPxovcwpgDatF7VXVEbF4rUil7pUnOksxs 7aZaj3hJxCWpajY6LYvBNWgpuOnE6wHyAbSyVXutrqMjgFIlz7WWm/p16OPcLYPdHAK7vqrauYnQ lgTtl087RrjX0eEI2EoZ8+/7zzZhzgY6klGcBiHQNaIxsZV6P9u0dfcPCpDOcqQNioEzqLzLiIk4 HEcFBAvuf345Nnfstl8j+xb+3g9gkPulv+51ClEQ+Hg4gl/DsUQ1TVQibLlvhjffuqQBJ7TPMihJ UfmPOEFZaWMMYnXhfsZBupE3ropdJsWCES6o0yXgT60woyy/8De7jEVHEX0tIc2xkWXbaWtFGf8f SSeUyA5BNWn7HV+jYQ+bPPIKc+pi3RwDjjhJKjjVWllgjBusKL/lG7HvJzGm7bVgYupAK0Tq6aCN x2SqwNUYMpHpGBDqxwz+gMmeGHJLGbB5qPrmLnSSifG4ucd7W6WiLdGNCnvgpopfSu7WpHHCvfcA DmA9UAv1v+rYdrKgZW/u3aItGPEPwBw7xatDmEFQvy23SZXSfMZ7RzHGH1l2j3GMtYjHvvB91g3T ziZ91loOnKklXxHMKY/ZMODEuZdOL4nawG8z87Sn7OLOV4Lis3vxMFxvQI95yX1Uqc2NraLyHm3n 4a4AzXkeEvgQi2jtxOzzT/YWdmD8gywgB151tgZkcRkCnoMzps1w8ZlyWpuWa9TLRBg21otcGPr1 zYyDRfp0WSy7R6kupj1q3Dt9ZyCgxZHINA6A5+7T9o6by6TTlSa2Lh/bXHbr9KsH2f7CCey7HUjs wwJCoJUeO2iBpksPaDU3ZH1Nh3tobKAf6zEvuGslKTrRIXcXpFg5ivY= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch makes the source code more uniform and does not change any functionality. Signed-off-by: Martin K. Petersen [ bvanassche: extracted this patch from a larger patch ] Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 4e293e4c6823..4e69f182a1e5 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1150,10 +1150,10 @@ static blk_status_t sd_setup_rw6_cmnd(struct scsi_cmnd *cmd, bool write, return BLK_STS_OK; } -static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) +static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) { - struct request *rq = SCpnt->request; - struct scsi_device *sdp = SCpnt->device; + struct request *rq = cmd->request; + struct scsi_device *sdp = cmd->device; struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); sector_t lba = sectors_to_logical(sdp, blk_rq_pos(rq)); sector_t threshold; @@ -1164,24 +1164,24 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) unsigned char protect, fua; blk_status_t ret; - ret = scsi_init_io(SCpnt); + ret = scsi_init_io(cmd); if (ret != BLK_STS_OK) return ret; - WARN_ON_ONCE(SCpnt != rq->special); + WARN_ON_ONCE(cmd != rq->special); if (!scsi_device_online(sdp) || sdp->changed) { - scmd_printk(KERN_ERR, SCpnt, "device offline or changed\n"); + scmd_printk(KERN_ERR, cmd, "device offline or changed\n"); return BLK_STS_IOERR; } if (blk_rq_pos(rq) + blk_rq_sectors(rq) > get_capacity(rq->rq_disk)) { - scmd_printk(KERN_ERR, SCpnt, "access beyond end of device\n"); + scmd_printk(KERN_ERR, cmd, "access beyond end of device\n"); return BLK_STS_IOERR; } if ((blk_rq_pos(rq) & mask) || (blk_rq_sectors(rq) & mask)) { - scmd_printk(KERN_ERR, SCpnt, "request not aligned to the logical block size\n"); + scmd_printk(KERN_ERR, cmd, "request not aligned to the logical block size\n"); return BLK_STS_IOERR; } @@ -1202,29 +1202,29 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) } fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; - dix = scsi_prot_sg_count(SCpnt); - dif = scsi_host_dif_capable(SCpnt->device->host, sdkp->protection_type); + dix = scsi_prot_sg_count(cmd); + dif = scsi_host_dif_capable(cmd->device->host, sdkp->protection_type); if (write && dix) - t10_pi_prepare(SCpnt->request, sdkp->protection_type); + t10_pi_prepare(cmd->request, sdkp->protection_type); if (dif || dix) - protect = sd_setup_protect_cmnd(SCpnt, dix, dif); + protect = sd_setup_protect_cmnd(cmd, dix, dif); else protect = 0; if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { - ret = sd_setup_rw32_cmnd(SCpnt, write, lba, nr_blocks, + ret = sd_setup_rw32_cmnd(cmd, write, lba, nr_blocks, protect | fua); } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { - ret = sd_setup_rw16_cmnd(SCpnt, write, lba, nr_blocks, + ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks, protect | fua); } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || sdp->use_10_for_rw || protect) { - ret = sd_setup_rw10_cmnd(SCpnt, write, lba, nr_blocks, + ret = sd_setup_rw10_cmnd(cmd, write, lba, nr_blocks, protect | fua); } else { - ret = sd_setup_rw6_cmnd(SCpnt, write, lba, nr_blocks, + ret = sd_setup_rw6_cmnd(cmd, write, lba, nr_blocks, protect | fua); } @@ -1236,18 +1236,18 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) * host adapter, it's safe to assume that we can at least transfer * this many bytes between each connect / disconnect. */ - SCpnt->transfersize = sdp->sector_size; - SCpnt->underflow = nr_blocks << 9; - SCpnt->allowed = SD_MAX_RETRIES; - SCpnt->sdb.length = nr_blocks * sdp->sector_size; + cmd->transfersize = sdp->sector_size; + cmd->underflow = nr_blocks << 9; + cmd->allowed = SD_MAX_RETRIES; + cmd->sdb.length = nr_blocks * sdp->sector_size; SCSI_LOG_HLQUEUE(1, - scmd_printk(KERN_INFO, SCpnt, + scmd_printk(KERN_INFO, cmd, "%s: block=%llu, count=%d\n", __func__, (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq))); SCSI_LOG_HLQUEUE(2, - scmd_printk(KERN_INFO, SCpnt, + scmd_printk(KERN_INFO, cmd, "%s %d/%u 512 byte blocks.\n", write ? "writing" : "reading", nr_blocks, blk_rq_sectors(rq)));