From patchwork Wed Nov 30 20:29:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 9454861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 270AC6074E for ; Wed, 30 Nov 2016 20:29:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BA862015F for ; Wed, 30 Nov 2016 20:29:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1090228497; Wed, 30 Nov 2016 20:29:37 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 7A81B284A3 for ; Wed, 30 Nov 2016 20:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757922AbcK3U3g (ORCPT ); Wed, 30 Nov 2016 15:29:36 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:47323 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757998AbcK3U3e (ORCPT ); Wed, 30 Nov 2016 15:29:34 -0500 X-IronPort-AV: E=Sophos;i="5.31,574,1473091200"; d="scan'";a="41649619" Received: from mail-co1nam03lp0018.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) ([216.32.181.18]) by ob1.hgst.iphmx.com with ESMTP; 01 Dec 2016 04:29:34 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8H6eO8BT9UzmmWGwF3Z2XLY+s71AErSI7nnxDqMbUWA=; b=JhNJxJqTHxkwbPi77ChcmhTa7aDIRd+p64S8X0afL7jX7dEyaa3vYWJuBl2AqRjZDCPgUNx7RGQ2csE9OXDuunS9sBgfsGNDxH8CnAiNyBRzr6bxsom7749z602Dl+frAf+6+OD+k9J1PKTHLNQUsZ9tyeunC2lhIuVCYeoHT8c= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Chaitanya.Kulkarni@wdc.com; Received: from ztester-Precision-T3600.hgst.com (199.255.44.5) by CO2PR04MB2184.namprd04.prod.outlook.com (10.166.93.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Wed, 30 Nov 2016 20:29:31 +0000 From: Chaitanya Kulkarni To: axboe@fb.com Cc: martin.petersen@oracle.com, keith.busch@intel.com, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, Chaitanya Kulkarni Subject: [PATCH V2 5/5] nvmet: add support for the Write Zeroes command Date: Wed, 30 Nov 2016 12:29:02 -0800 Message-Id: <1480537742-15190-5-git-send-email-chaitanya.kulkarni@hgst.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1480537742-15190-1-git-send-email-chaitanya.kulkarni@hgst.com> References: <1480537742-15190-1-git-send-email-chaitanya.kulkarni@hgst.com> MIME-Version: 1.0 X-Originating-IP: [199.255.44.5] X-ClientProxiedBy: BY2PR06CA0019.namprd06.prod.outlook.com (10.166.106.157) To CO2PR04MB2184.namprd04.prod.outlook.com (10.166.93.154) X-MS-Office365-Filtering-Correlation-Id: 9dd85fa9-9548-49c4-5ee1-08d4195f97ba X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CO2PR04MB2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67ae4PwRMVOVaYV9Iu0UeUmTCq9gV5lZXzRxcsW0F16GPv1k7ZKeQzEc=; 20:hx1TKqTcsqVchkst49JTwlblAZ2UxywUq4ofm3Fp1alWtIswN7aMACAEhU4JRz0g+GlvkhYD03kg0PL713MOtbyDqBI6tVVIKDStvYrRt7nKVaJqIsMsZZdOoEIi6soovsEzC07QKYBJVM6wYpAsFFpxYLsd0fOTUCKQgX0/lzQ4XQwY9FmjqOh8C9sCZAr+ab0aFhj9lkQZSNfcPfvbw35ui/gTV+1jvq32yoWNN+GThUoRkbwT9QU9JOTZskndK4jUvHyWlzrZWxw3FhpRfpErwiLKdI9jPylHhooNzIQl7OPsD2Z3lK6UL1rvnjOQWGjxzza/XwO7I02gAFF0C9ezPNUwfHNnDamIc3U9mOm8TSCwlkKeM7LS/EIGr7F/EABwFzy2a1WD3kZ4kGM6969S9q1Cst5T5KmnoF+IGFbIO/UFhm+fq3lc4f7FwcNAYRPHtN7/wTsU5QQfBGQRE51rXaXFuHcq9ZtH53yB6wDt9MW9zYPcsCdf6Qlhmzf7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(79135771888625); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:CO2PR04MB2184; BCL:0; PCL:0; RULEID:; SRVR:CO2PR04MB2184; X-Microsoft-Exchange-Diagnostics: 1; CO2PR04MB2184; 4:ScVwppmqQddK9Be4fr4+6NSdl+znaolBd+2g9nY+MSsLSJN6pCE1PNDEWwjR8SFJoD/HnyiJWV+0wiYLM+nyf/Q4mA0hcr96r9pzx3psy3TNaDouXlUX4fMT6JfNNhoecVJllN8UlfS5ZoRmDixAnMJXQmrob/YrVken/35ccHd+5N0rnnosY43l1USjDQmUA6xv8YIViLzduLd+2T9IJ2uReBJF2oXZyTI+NvaW+MC+q4q/jw9kbaKnrC19wu2zWGvyg2nmXt+93uOIShM7zQ/fXqtip48uZRVxE2W0zInx2gAe7qDxEfCEMJ9ysz/I+D3q3B1GTDh/IIH8VnzDXrs4fU/rHyHysGo3Elu7vMow1BCruG4Drx/j7t3lMZepOfiKF/BAu9gTF6V+nhzyjiit55EaXyV7W0ftCIvVyLoZu1grhpFUU0enffaWLF75oBcy9bHU3+YUnDIslrUZpMN0Jaqnn02Hzw5XyJa0VxjQNq1Vqmsmr54PwHNhOFEkRbpFoMl1cGLTfrXyYn8YDCWeduLIz7Ps7sfSp7u/Yg/WLAOo1MLbvT7hHmV8Lri7ahPEEzCQYQRXnB1YOlNgOPSu2DCWNLxi86qfVMuRpc2XfpGlQMpWjjfmSr1//CWjx4MzwKSawQXl2Jcqbc3R1w== X-Forefront-PRVS: 0142F22657 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(92566002)(81156014)(81166006)(68736007)(38730400001)(2950100002)(39410400001)(50226002)(42882006)(39450400002)(8676002)(733004)(69596002)(6486002)(66066001)(6666003)(50986999)(47776003)(101416001)(76176999)(106356001)(107886002)(33646002)(42186005)(2361001)(53416004)(2351001)(4326007)(36756003)(5003940100001)(189998001)(105586002)(4001430100002)(2906002)(5660300001)(6916009)(3846002)(6116002)(97736004)(305945005)(48376002)(7736002)(50466002)(110136003)(7846002)(7099028)(5005270100013)(21314002); DIR:OUT; SFP:1102; SCL:1; SRVR:CO2PR04MB2184; H:ztester-Precision-T3600.hgst.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: wdc.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR04MB2184; 23:0SdAjKd+ojVBnKoW2VTOStFlxzv8aD437Aj+h7G3W?= =?us-ascii?Q?R9zXS6j0Jq9it0jPcrCkUyoJ/RWZLLarkK654aQ8sxTmT9wDEVinkOX8iOz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jih52h0/GpFg9qaHxl5mktimmZbEz8QED/n8pxOxZUaqqMFzmQ==; 24:yqRzz0ol/89fgFV3GU70IMQ2s19ii7ESkLcLzTZnuKeyO5TNSraViyB+DJyb2YQCnR2Tj8rOViJmr7g748P1WBUN7hJ9TD18UFLpVw9uZzc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CO2PR04MB2184; 7:WzRQ1Te+cVIZXUo1hB7z0l+nDKZOShGKHOImz0y2ydy26EN6d3pukxuQdPTsY7LU5kEIG6dqR2qqNRTNzmvao+cjeDt7lzfDwu/R6H0kOIiCWSbDFKJA0zOb04a3WtxPrc344RfnIX/cnTHuaM5E9F+8IeuSpl1ftpT8ryOe9g7nERlPmcucgK+izK2KryqGvvdFQzsIs71bEikbOdA4QcFpfI21cV9ifNP4QqSXu+Wfn0e/ffq1G2oqGGXrRMM6eAYU6jLSY6ay2QoElbS1p/OoImSXBCnEOUsjmvZT41E9y99LV/ZKdISkrgjwB/kpjaYSVXic0BF2zsPaOFEeW7nqCY8sTQo5bp8HBs18ucn9DPeBv1xT3PjuPlutm6v2WgSEY4jVLWOF1jo8tZYwu3MFvuROhx3qnOuYGs5NMW6wR117AzMygLtGmvoMialycdRS6vUacjk0eqAmxT9HYQ==; 20:uB+VJ0b8gtohk/l4rc0CK0IhP8k/ICEa57H+s721ZK1fOfVOWbnvkgcDVfCh8VNNcXSQ4AYLB5vn7+gV2mBs6gEayQEvbjcgNVM9KocxETihPSzKXGjX0OAG/qXZGxTUOE3OCFi+iqQFdaQLVBXGBHvY9YUDQJ+d3/A4vqx2pzksmNWlIS22j3jfH96ne1sRB7Pp6hZZT8fasUaYeTaJB8G5efFfSv8UOCyMGKqoKrehmKVxZc++qg7ig1QDvT2p X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2016 20:29:31.9502 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR04MB2184 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for handling write zeroes command on target. Call into __blkdev_issue_zeroout, which the block layer expands into the best suitable variant of zeroing the LBAs. Allow write zeroes operation to deallocate the LBAs when calling __blkdev_issue_zeroout. Signed-off-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig --- drivers/nvme/target/admin-cmd.c | 3 ++- drivers/nvme/target/io-cmd.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 6fe4c48..ec1ad2a 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -237,7 +237,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) id->maxcmd = cpu_to_le16(NVMET_MAX_CMD); id->nn = cpu_to_le32(ctrl->subsys->max_nsid); - id->oncs = cpu_to_le16(NVME_CTRL_ONCS_DSM); + id->oncs = cpu_to_le16(NVME_CTRL_ONCS_DSM | + NVME_CTRL_ONCS_WRITE_ZEROES); /* XXX: don't report vwc if the underlying device is write through */ id->vwc = NVME_CTRL_VWC_PRESENT; diff --git a/drivers/nvme/target/io-cmd.c b/drivers/nvme/target/io-cmd.c index ef52b1e..b3d21b0 100644 --- a/drivers/nvme/target/io-cmd.c +++ b/drivers/nvme/target/io-cmd.c @@ -172,6 +172,32 @@ static void nvmet_execute_dsm(struct nvmet_req *req) } } +static void nvmet_execute_write_zeroes(struct nvmet_req *req) +{ + struct nvme_write_zeroes_cmd *write_zeroes = &req->cmd->write_zeroes; + struct bio *bio = NULL; + u16 status = NVME_SC_SUCCESS; + sector_t sector; + sector_t nr_sector; + + sector = le64_to_cpu(write_zeroes->slba) << + (req->ns->blksize_shift - 9); + nr_sector = (((sector_t)le32_to_cpu(write_zeroes->length)) << + (req->ns->blksize_shift - 9)) + 1; + + if (__blkdev_issue_zeroout(req->ns->bdev, sector, nr_sector, + GFP_KERNEL, &bio, true)) + status = NVME_SC_INTERNAL | NVME_SC_DNR; + + if (bio) { + bio->bi_private = req; + bio->bi_end_io = nvmet_bio_done; + submit_bio(bio); + } else { + nvmet_req_complete(req, status); + } +} + int nvmet_parse_io_cmd(struct nvmet_req *req) { struct nvme_command *cmd = req->cmd; @@ -209,6 +235,9 @@ int nvmet_parse_io_cmd(struct nvmet_req *req) req->data_len = le32_to_cpu(cmd->dsm.nr + 1) * sizeof(struct nvme_dsm_range); return 0; + case nvme_cmd_write_zeroes: + req->execute = nvmet_execute_write_zeroes; + return 0; default: pr_err("nvmet: unhandled cmd %d\n", cmd->common.opcode); return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;