From patchwork Fri May 6 18:03:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 9035281 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 754BD9F1D3 for ; Fri, 6 May 2016 18:06:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8A07C20272 for ; Fri, 6 May 2016 18:06:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A171120274 for ; Fri, 6 May 2016 18:06:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758791AbcEFSFi (ORCPT ); Fri, 6 May 2016 14:05:38 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:38468 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932338AbcEFSD5 (ORCPT ); Fri, 6 May 2016 14:03:57 -0400 Received: by mail-wm0-f45.google.com with SMTP id g17so89901678wme.1 for ; Fri, 06 May 2016 11:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kCvCFLtHBYyV3bV93TWHNMpmmxrYujOrKs3QH+kO2NI=; b=H9mQPnmPB41hRvmmYoZw5QoPAURXLBvY2JDbRg5KTsbs5IdmVO/4I4Z5N7uyNKQwLs NneuDL8NEfsUP82ToQWia9gKTqyU+Hbg1Ra4/4I/ij4B/xF61EqB1T1jeVu3G+4uuf8t gnyD4ba1hEDazooFfqOX9s7thpyH3EejuD9sc= 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:mime-version:content-transfer-encoding; bh=kCvCFLtHBYyV3bV93TWHNMpmmxrYujOrKs3QH+kO2NI=; b=fLLGggpeFPZcnmKEl9udajhlhUrvoCrAL54DfFMGJbeIRRPHNQ9PezZggE2N9pe+py ViHAV2HUvyccsHKq54fRf6mkq/Uosl1DBGqxoovbHLrbImXcaEF8UBTPlARMcfT136Re D8UYZv6bq7LasQzGpcoqr+9xm+ezMDRjeCwPwJCXXPWtajYLZgxZKmjw4V3OZn8EFKH0 2VOgzJb8757bM4j6FWgfSEzvXTjy7bddXxXurSzNOZAjIjk7LidUNYPMjFztj8UMU1iE Uo2gijz64K47HezuCmXBEitWOop/Fk4LF0s3juyiiDJqoUKl0JZskdwFiBRG4Gr3c+Tv /LjQ== X-Gm-Message-State: AOPr4FWx+SdN2myA3hG7j+HENYXSqB9BljDNsG+R8uqcHBpswZJG4YoiBWreYnr7fpFm/A== X-Received: by 10.28.161.198 with SMTP id k189mr10905538wme.23.1462557836623; Fri, 06 May 2016 11:03:56 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id kz1sm16076559wjc.46.2016.05.06.11.03.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 May 2016 11:03:55 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 24/28] lightnvm: remove mgt targets on mgt removal Date: Fri, 6 May 2016 20:03:17 +0200 Message-Id: <1462557801-24974-25-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462557801-24974-1-git-send-email-m@bjorling.me> References: <1462557801-24974-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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 Targets associated with a device manager are not freed on device removal. They have to be manually removed before shutdown. Make sure any outstanding targets are freed upon shutdown. Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 69 ++++++++++++++++++++++++++++++------------------ include/linux/lightnvm.h | 1 + 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 1873a3b..d3af771 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -596,13 +596,52 @@ err_fmtype: return ret; } +static void nvm_remove_target(struct nvm_target *t) +{ + struct nvm_tgt_type *tt = t->type; + struct gendisk *tdisk = t->disk; + struct request_queue *q = tdisk->queue; + + lockdep_assert_held(&nvm_lock); + + del_gendisk(tdisk); + blk_cleanup_queue(q); + + if (tt->exit) + tt->exit(tdisk->private_data); + + put_disk(tdisk); + + list_del(&t->list); + kfree(t); +} + +static void nvm_free_mgr(struct nvm_dev *dev) +{ + struct nvm_target *tgt, *tmp; + + if (!dev->mt) + return; + + down_write(&nvm_lock); + list_for_each_entry_safe(tgt, tmp, &nvm_targets, list) { + if (tgt->dev != dev) + continue; + + nvm_remove_target(tgt); + } + up_write(&nvm_lock); + + dev->mt->unregister_mgr(dev); + dev->mt = NULL; +} + static void nvm_free(struct nvm_dev *dev) { if (!dev) return; - if (dev->mt) - dev->mt->unregister_mgr(dev); + nvm_free_mgr(dev); kfree(dev->lptbl); kfree(dev->lun_map); @@ -808,6 +847,7 @@ static int nvm_create_target(struct nvm_dev *dev, t->type = tt; t->disk = tdisk; + t->dev = dev; down_write(&nvm_lock); list_add_tail(&t->list, &nvm_targets); @@ -823,26 +863,6 @@ err_t: return -ENOMEM; } -static void nvm_remove_target(struct nvm_target *t) -{ - struct nvm_tgt_type *tt = t->type; - struct gendisk *tdisk = t->disk; - struct request_queue *q = tdisk->queue; - - lockdep_assert_held(&nvm_lock); - - del_gendisk(tdisk); - blk_cleanup_queue(q); - - if (tt->exit) - tt->exit(tdisk->private_data); - - put_disk(tdisk); - - list_del(&t->list); - kfree(t); -} - static int __nvm_configure_create(struct nvm_ioctl_create *create) { struct nvm_dev *dev; @@ -1231,10 +1251,7 @@ static long nvm_ioctl_dev_factory(struct file *file, void __user *arg) return -EINVAL; } - if (dev->mt) { - dev->mt->unregister_mgr(dev); - dev->mt = NULL; - } + nvm_free_mgr(dev); if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) return nvm_dev_factory(dev, fact.flags); diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index 0e8e019..cde31ff 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -200,6 +200,7 @@ struct nvm_id { struct nvm_target { struct list_head list; + struct nvm_dev *dev; struct nvm_tgt_type *type; struct gendisk *disk; };