From patchwork Wed Nov 25 12:42:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 7698891 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 02E48BF90C for ; Wed, 25 Nov 2015 12:44:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 217F1208ED for ; Wed, 25 Nov 2015 12:44:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34DBB208EA for ; Wed, 25 Nov 2015 12:44:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753132AbbKYMoE (ORCPT ); Wed, 25 Nov 2015 07:44:04 -0500 Received: from mail-pa0-f65.google.com ([209.85.220.65]:36223 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752577AbbKYMoC (ORCPT ); Wed, 25 Nov 2015 07:44:02 -0500 Received: by pabfh17 with SMTP id fh17so6986884pab.3; Wed, 25 Nov 2015 04:44:01 -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=JRUfrydgno4Y4sGU8FGw420JK4KVGXuiBpjadsNpC2U=; b=nMJ2RyRFE6u91WU541TZ1YbgKqFN8ANI/ESWG4k4NflJuGEKgR7/8ghQRURY/i0id2 /ntU4yMbeQ8cljKn4lPvjc2fhLapyWntq2eRri5OMByHwcK2yV2B4p/8pek5BQqIA3X1 fiT8C8RwSh2m0WCOV5fuN6MvIJNwvZbKOM+3lFHxoe/2D4aUkkuasgrnK/njBO9s9kOy lEegv874gP44L+wBpC7vbHECruwmBK6SBpi5DfkJ0OeMm4p7dWboSCw5D3OtW+tue7dp 2zMo8ogq5T4LvrMeLfuimbjyRk/9nQdjHrWClu5cWuobty5nqgKr3JwS27Giiq9bl0vR u4BA== X-Received: by 10.98.17.14 with SMTP id z14mr31319882pfi.55.1448455441887; Wed, 25 Nov 2015 04:44:01 -0800 (PST) Received: from localhost.localdomain.com ([111.204.49.2]) by smtp.gmail.com with ESMTPSA id c1sm21318930pas.1.2015.11.25.04.43.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Nov 2015 04:44:01 -0800 (PST) From: Wenwei Tao To: mb@lightnvm.io, keith.busch@intel.com, axboe@fb.com Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 3/3] nvme: change the interface between nvme and lightnvm Date: Wed, 25 Nov 2015 20:42:56 +0800 Message-Id: <1448455376-5020-4-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1448455376-5020-1-git-send-email-ww.tao0320@gmail.com> References: <1448455376-5020-1-git-send-email-ww.tao0320@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When nvme devices were removed, we need to handle the targets build upon them properly: remove the existing targets, block creations of new ones. To do this clean up job well, we need to change the interface between nvme and lightnvm. Signed-off-by: Wenwei Tao --- drivers/nvme/host/lightnvm.c | 17 ++++++++++++++++- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/pci.c | 10 ++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c index e0b7b95..3f4ffb7 100644 --- a/drivers/nvme/host/lightnvm.c +++ b/drivers/nvme/host/lightnvm.c @@ -468,6 +468,14 @@ static void nvme_nvm_dev_dma_free(void *pool, void *ppa_list, dma_pool_free(pool, ppa_list, dma_handler); } +static void nvme_nvm_dev_remove(struct request_queue *q) +{ + struct nvme_ns *ns = q->queuedata; + + kref_put(&ns->kref, nvme_free_ns); + +} + static struct nvm_dev_ops nvme_nvm_dev_ops = { .identity = nvme_nvm_identity, @@ -482,13 +490,20 @@ static struct nvm_dev_ops nvme_nvm_dev_ops = { .destroy_dma_pool = nvme_nvm_destroy_dma_pool, .dev_dma_alloc = nvme_nvm_dev_dma_alloc, .dev_dma_free = nvme_nvm_dev_dma_free, + .dev_remove = nvme_nvm_dev_remove, .max_phys_sect = 64, }; int nvme_nvm_register(struct request_queue *q, char *disk_name) { - return nvm_register(q, disk_name, &nvme_nvm_dev_ops); + int ret; + struct nvme_ns *ns = q->queuedata; + + ret = nvm_register(q, disk_name, &nvme_nvm_dev_ops); + if (!ret) + kref_get(&ns->kref); + return ret; } void nvme_nvm_unregister(struct request_queue *q, char *disk_name) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index fdb4e5b..251ec9d 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -116,6 +116,7 @@ static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector) return (sector >> (ns->lba_shift - 9)); } +void nvme_free_ns(struct kref *kref); int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, void *buf, unsigned bufflen); int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 8187df2..f63223d 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1960,13 +1960,10 @@ static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode, #endif static void nvme_free_dev(struct kref *kref); -static void nvme_free_ns(struct kref *kref) +void nvme_free_ns(struct kref *kref) { struct nvme_ns *ns = container_of(kref, struct nvme_ns, kref); - if (ns->type == NVME_NS_LIGHTNVM) - nvme_nvm_unregister(ns->queue, ns->disk->disk_name); - spin_lock(&dev_list_lock); ns->disk->private_data = NULL; spin_unlock(&dev_list_lock); @@ -2533,6 +2530,11 @@ static void nvme_ns_remove(struct nvme_ns *ns) { bool kill = nvme_io_incapable(ns->dev) && !blk_queue_dying(ns->queue); + if (ns->type == NVME_NS_LIGHTNVM) { + nvme_nvm_unregister(ns->queue, ns->disk->disk_name); + ns->type = 0; + } + if (kill) blk_set_queue_dying(ns->queue); if (ns->disk->flags & GENHD_FL_UP)