From patchwork Tue Nov 24 16:03:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 7692021 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 535A9BF90C for ; Tue, 24 Nov 2015 16:03:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61510207A0 for ; Tue, 24 Nov 2015 16:03:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE133207A2 for ; Tue, 24 Nov 2015 16:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752960AbbKXQD3 (ORCPT ); Tue, 24 Nov 2015 11:03:29 -0500 Received: from mail-pa0-f66.google.com ([209.85.220.66]:35783 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751797AbbKXQD2 (ORCPT ); Tue, 24 Nov 2015 11:03:28 -0500 Received: by padhk6 with SMTP id hk6so3146587pad.2; Tue, 24 Nov 2015 08:03:28 -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; bh=eWvOh3vttjUJ/4aH2wZ6aAc3GH6pcD4pUPz1PrgNcbg=; b=BSonxHL3APAumPq/8riu82qs3vUOmLhf4V9+fD5Yesk9NnrW2HqonmudPTH3lDAgsJ 4rSnqV9UtRa7Bwk6UF/pxFLlxa1bMKWr9u2DzN1c0oNJlWz1lsNMm/6hHIKmPFFePUNX EpbXMqH+wokweyfBaJpJbIFVnE3LWjp7lC4AIaBHvEE+j3Q0NIa9nGT8KWymACc9PwB3 a2IqANH22/SLIUNHbZMYcBO4yGwuVLWYR4W4jseZdN87sBl35m7fnIPl0PZ57fZqlJF6 v2XxIepXedEMlBhcSm+Rk+r+Uk9gWfGFe9v/8NR9mjwXcV/MhLuSGXMVNI0x/t3b54Gz F/vQ== X-Received: by 10.66.120.47 with SMTP id kz15mr20296140pab.84.1448381007925; Tue, 24 Nov 2015 08:03:27 -0800 (PST) Received: from localhost.localdomain ([114.250.88.45]) by smtp.gmail.com with ESMTPSA id g79sm15234675pfj.13.2015.11.24.08.03.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Nov 2015 08:03:27 -0800 (PST) From: Wenwei Tao To: mb@lightnvm.io Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH] lightnvm: remove targets when corresponding nvm device exit Date: Wed, 25 Nov 2015 00:03:08 +0800 Message-Id: <1448380988-3988-1-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 2.5.1.windows.1 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=ham 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 the target should be unreachable when underlying device was gone. Signed-off-by: Wenwei Tao --- drivers/lightnvm/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index f659e60..b95c6c4 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -278,10 +278,18 @@ err: return ret; } +static void nvm_remove_target(struct nvm_target *t); + static void nvm_exit(struct nvm_dev *dev) { + struct nvm_target *t, *n; + if (dev->ppalist_pool) dev->ops->destroy_dma_pool(dev->ppalist_pool); + down_write(&nvm_lock); + list_for_each_entry_safe(t, n, &dev->online_targets, list) + nvm_remove_target(t); + up_write(&nvm_lock); nvm_free(dev); pr_info("nvm: successfully unloaded\n"); @@ -496,13 +504,13 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create) static int __nvm_configure_remove(struct nvm_ioctl_remove *remove) { - struct nvm_target *t = NULL; + struct nvm_target *n, *t = NULL; struct nvm_dev *dev; int ret = -1; down_write(&nvm_lock); list_for_each_entry(dev, &nvm_devices, devices) - list_for_each_entry(t, &dev->online_targets, list) { + list_for_each_entry_safe(t, n, &dev->online_targets, list) { if (!strcmp(remove->tgtname, t->disk->disk_name)) { nvm_remove_target(t); ret = 0;