From patchwork Wed Nov 16 06:50:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 9430967 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 B77BC6021C for ; Wed, 16 Nov 2016 06:51:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A77FF28DEC for ; Wed, 16 Nov 2016 06:51:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C68528E01; Wed, 16 Nov 2016 06:51:14 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 E9E2128DEC for ; Wed, 16 Nov 2016 06:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752199AbcKPGvN (ORCPT ); Wed, 16 Nov 2016 01:51:13 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33582 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbcKPGvN (ORCPT ); Wed, 16 Nov 2016 01:51:13 -0500 Received: by mail-pf0-f194.google.com with SMTP id 144so9293690pfv.0 for ; Tue, 15 Nov 2016 22:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JV7rAFwm8XkGJPbDlCWNSz3/fxvpLtV4VztbEKEjCwc=; b=YFRCQs+laNvPWdBM84XFj/7Mo3G4dc6kq0Sd0C+3vhn1Mlez52ZVPUsW1Dp3DdYyKH HcIcbI3MPfunl442s4ZBtZBTmCHsT5/2y9WsWJo9Mr0aP7awl7+tT9j9zkmlDViKhcIp /aexlj2jyT/k8MJoJENvvZar6+BeNTGAFG2yYJDUBGCPJYcJdVeVDZTsu2mH/tc/wZ3I 5CTlK+weSziEvZu0wexs7uhgNHySwjGyq3cQzRxd8WdDS6hBjVW2WqKuDrMj3dIUyQip wNGjPI3OH8RH7E9c2iWQsNIVMboFs6LcE9pYwlLndB4uSAIrohB1ly7AB2fmssORHdwK mfnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JV7rAFwm8XkGJPbDlCWNSz3/fxvpLtV4VztbEKEjCwc=; b=KUeT48p3L92NZOtaa7Mo7jV3DttkgbLucdu5XCWwYDb0tv0KM73uJCU3cs5j2G6dQ8 xPKAA4ZC1xYwdeA1bYgJOjRbOuSxOc1SDbpZZl3Bor26wgNZSA3orXch2w5HejlxtCti IfNDCGWCpHeumeDS2D1c3yB5Nln2PWOKYQJXl81hAkGRQSke+yiLfvHFOUdDpcD7bvSe t8hCZgInvhCEwQ5ABVFSvFOLdzYl2XIxUlhtH8BsRb8+5oUEQMThniIiUFZog61XbPMw zp+ymahZDe7MsJqkcA6rlm1GZEiDo32vGIQX75TZHohrL54DQzukAG7BJBPhRSiKBhfM /fxQ== X-Gm-Message-State: ABUngvcMCf2VfISOr+2NSnaeYKK6idubkFu4lSHv1VaDSwq72XxmK1Da1UuLVAm0m5Dyig== X-Received: by 10.98.15.5 with SMTP id x5mr2346502pfi.140.1479279072318; Tue, 15 Nov 2016 22:51:12 -0800 (PST) Received: from ztester-Precision-T3600.hgst.com (sjc00ib2.hgst.com. [199.255.44.5]) by smtp.googlemail.com with ESMTPSA id 16sm30902972pfk.54.2016.11.15.22.51.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Nov 2016 22:51:11 -0800 (PST) From: Chaitanya Kulkarni X-Google-Original-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 5/5] nvmet: add support for the Write Zeroes command Date: Tue, 15 Nov 2016 22:50:39 -0800 Message-Id: <1479279039-25818-6-git-send-email-chaitanya.kulkarni@hgst.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1479279039-25818-1-git-send-email-chaitanya.kulkarni@hgst.com> References: <1479279039-25818-1-git-send-email-chaitanya.kulkarni@hgst.com> 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. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/admin-cmd.c | 3 ++- drivers/nvme/target/io-cmd.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 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..7d4b022 100644 --- a/drivers/nvme/target/io-cmd.c +++ b/drivers/nvme/target/io-cmd.c @@ -172,6 +172,37 @@ 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, false)) + status = NVME_SC_INTERNAL | NVME_SC_DNR; + + if (bio) { + bio->bi_private = req; + bio->bi_end_io = nvmet_bio_done; + if (status) { + bio->bi_error = -EIO; + bio_endio(bio); + } else { + 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 +240,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;