From patchwork Wed Jun 21 21:33:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 9803009 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 3312F6086C for ; Wed, 21 Jun 2017 21:33:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CF7427FB1 for ; Wed, 21 Jun 2017 21:33:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1182128111; Wed, 21 Jun 2017 21:33:39 +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=-1.9 required=2.0 tests=BAYES_00 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 306E12844E for ; Wed, 21 Jun 2017 21:33:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751946AbdFUVdZ (ORCPT ); Wed, 21 Jun 2017 17:33:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58806 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751798AbdFUVdZ (ORCPT ); Wed, 21 Jun 2017 17:33:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EBE8741A23; Wed, 21 Jun 2017 21:33:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EBE8741A23 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mchristi@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EBE8741A23 Received: from rh2.redhat.com (ovpn-123-144.rdu2.redhat.com [10.10.123.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ECA65D961; Wed, 21 Jun 2017 21:33:24 +0000 (UTC) From: Mike Christie To: bryantly@linux.vnet.ibm.com, pkalever@redhat.com, target-devel@vger.kernel.org, nab@linux-iscsi.org Cc: Mike Christie Subject: [PATCH 12/12] target: rename target_free_device to target_destroy_device and cleanup callers Date: Wed, 21 Jun 2017 16:33:11 -0500 Message-Id: <1498080791-13565-13-git-send-email-mchristi@redhat.com> In-Reply-To: <1498080791-13565-1-git-send-email-mchristi@redhat.com> References: <1498080791-13565-1-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 21 Jun 2017 21:33:25 +0000 (UTC) Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This renames target_free_device to target_destroy_device to reflect most of the function is tearing down resources setup during target_configure_device. I think it also makes goto/error handling nicer in that it follows other unwinding in the kernel where the goto takes you to a block of code that releases what was previously setup instead of having one mega function that can detect multiple states of setup. We now know that if you have done target_alloc_device but configure failed or was not run you can just do target_free_device like is done in target_core_make_subdev and core_dev_setup_virtual_lun0. If target_configure device has been run successfully then you run target_destroy_device. We then do not need the DF_CONFIGURED check in what is now target_destroy_device. Signed-off-by: Mike Christie --- drivers/target/target_core_configfs.c | 2 +- drivers/target/target_core_device.c | 29 ++++++++++++++++------------- drivers/target/target_core_internal.h | 1 + 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 9b8abd5..15043d34 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -2233,7 +2233,7 @@ static void target_core_dev_release(struct config_item *item) struct se_device *dev = container_of(dev_cg, struct se_device, dev_group); - target_free_device(dev); + target_destroy_device(dev); } /* diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 3743d47..8cc2b07 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -1050,7 +1050,7 @@ int target_configure_device(struct se_device *dev) return ret; } -static void target_free_device_call_rcu(struct rcu_head *p) +static void __target_free_device(struct rcu_head *p) { struct se_device *dev = container_of(p, struct se_device, rcu_head); @@ -1059,23 +1059,26 @@ static void target_free_device_call_rcu(struct rcu_head *p) void target_free_device(struct se_device *dev) { + call_rcu(&dev->rcu_head, __target_free_device); +} + +void target_destroy_device(struct se_device *dev) +{ struct se_hba *hba = dev->se_hba; WARN_ON(!list_empty(&dev->dev_sep_list)); - if (dev->dev_flags & DF_CONFIGURED) { - destroy_workqueue(dev->tmr_wq); + destroy_workqueue(dev->tmr_wq); - dev->transport->destroy_device(dev); + dev->transport->destroy_device(dev); - mutex_lock(&device_mutex); - idr_remove(&devices_idr, dev->dev_index); - mutex_unlock(&device_mutex); + mutex_lock(&device_mutex); + idr_remove(&devices_idr, dev->dev_index); + mutex_unlock(&device_mutex); - spin_lock(&hba->device_lock); - hba->dev_count--; - spin_unlock(&hba->device_lock); - } + spin_lock(&hba->device_lock); + hba->dev_count--; + spin_unlock(&hba->device_lock); core_alua_free_lu_gp_mem(dev); core_alua_set_lba_map(dev, NULL, 0, 0); @@ -1085,7 +1088,7 @@ void target_free_device(struct se_device *dev) if (dev->transport->free_prot) dev->transport->free_prot(dev); - call_rcu(&dev->rcu_head, target_free_device_call_rcu); + target_free_device(dev); } int core_dev_setup_virtual_lun0(void) @@ -1131,7 +1134,7 @@ void core_dev_release_virtual_lun0(void) return; if (g_lun0_dev) - target_free_device(g_lun0_dev); + target_destroy_device(g_lun0_dev); core_delete_hba(hba); } diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index f30e8ac..812527f 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -84,6 +84,7 @@ void core_dev_free_initiator_node_lun_acl(struct se_portal_group *, struct se_device *target_alloc_device(struct se_hba *hba, const char *name); int target_configure_device(struct se_device *dev); void target_free_device(struct se_device *); +void target_destroy_device(struct se_device *); int target_for_each_device(int (*fn)(struct se_device *dev, void *data), void *data);