diff options
| author | Christoph Hellwig <hch@lst.de> | 2015-04-08 14:01:35 -0400 |
|---|---|---|
| committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2015-04-14 15:28:41 -0400 |
| commit | 9ac8928e6a3e1ed02e632e45aa766129fe6b1802 (patch) | |
| tree | ea516680cc5f811df862966bb43cfbe3e34dfb26 /drivers/xen | |
| parent | 2c336e3a2e1728d9b3116422655832184dc7046c (diff) | |
target: simplify the target template registration API
Instead of calling target_fabric_configfs_init() +
target_fabric_configfs_register() / target_fabric_configfs_deregister()
target_fabric_configfs_free() from every target driver, rewrite the API
so that we have simple register/unregister functions that operate on
a const operations vector.
This patch also fixes a memory leak in several target drivers. Several
target drivers namely called target_fabric_configfs_deregister()
without calling target_fabric_configfs_free().
A large part of this patch is based on earlier changes from
Bart Van Assche <bart.vanassche@sandisk.com>.
(v2: Add a new TF_CIT_SETUP_DRV macro so that the core configfs code
can declare attributes as either core only or for drivers)
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/xen')
| -rw-r--r-- | drivers/xen/xen-scsiback.c | 74 |
1 files changed, 13 insertions, 61 deletions
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index 61653a03a8f5..f8a1bd741b5d 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c | |||
| @@ -205,8 +205,7 @@ static LIST_HEAD(scsiback_free_pages); | |||
| 205 | static DEFINE_MUTEX(scsiback_mutex); | 205 | static DEFINE_MUTEX(scsiback_mutex); |
| 206 | static LIST_HEAD(scsiback_list); | 206 | static LIST_HEAD(scsiback_list); |
| 207 | 207 | ||
| 208 | /* Local pointer to allocated TCM configfs fabric module */ | 208 | static const struct target_core_fabric_ops scsiback_ops; |
| 209 | static struct target_fabric_configfs *scsiback_fabric_configfs; | ||
| 210 | 209 | ||
| 211 | static void scsiback_get(struct vscsibk_info *info) | 210 | static void scsiback_get(struct vscsibk_info *info) |
| 212 | { | 211 | { |
| @@ -1901,7 +1900,7 @@ scsiback_make_tpg(struct se_wwn *wwn, | |||
| 1901 | tpg->tport = tport; | 1900 | tpg->tport = tport; |
| 1902 | tpg->tport_tpgt = tpgt; | 1901 | tpg->tport_tpgt = tpgt; |
| 1903 | 1902 | ||
| 1904 | ret = core_tpg_register(&scsiback_fabric_configfs->tf_ops, wwn, | 1903 | ret = core_tpg_register(&scsiback_ops, wwn, |
| 1905 | &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); | 1904 | &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); |
| 1906 | if (ret < 0) { | 1905 | if (ret < 0) { |
| 1907 | kfree(tpg); | 1906 | kfree(tpg); |
| @@ -1943,7 +1942,9 @@ static int scsiback_check_false(struct se_portal_group *se_tpg) | |||
| 1943 | return 0; | 1942 | return 0; |
| 1944 | } | 1943 | } |
| 1945 | 1944 | ||
| 1946 | static struct target_core_fabric_ops scsiback_ops = { | 1945 | static const struct target_core_fabric_ops scsiback_ops = { |
| 1946 | .module = THIS_MODULE, | ||
| 1947 | .name = "xen-pvscsi", | ||
| 1947 | .get_fabric_name = scsiback_get_fabric_name, | 1948 | .get_fabric_name = scsiback_get_fabric_name, |
| 1948 | .get_fabric_proto_ident = scsiback_get_fabric_proto_ident, | 1949 | .get_fabric_proto_ident = scsiback_get_fabric_proto_ident, |
| 1949 | .tpg_get_wwn = scsiback_get_fabric_wwn, | 1950 | .tpg_get_wwn = scsiback_get_fabric_wwn, |
| @@ -1990,62 +1991,10 @@ static struct target_core_fabric_ops scsiback_ops = { | |||
| 1990 | .fabric_make_nodeacl = scsiback_make_nodeacl, | 1991 | .fabric_make_nodeacl = scsiback_make_nodeacl, |
| 1991 | .fabric_drop_nodeacl = scsiback_drop_nodeacl, | 1992 | .fabric_drop_nodeacl = scsiback_drop_nodeacl, |
| 1992 | #endif | 1993 | #endif |
| 1993 | }; | ||
| 1994 | |||
| 1995 | static int scsiback_register_configfs(void) | ||
| 1996 | { | ||
| 1997 | struct target_fabric_configfs *fabric; | ||
| 1998 | int ret; | ||
| 1999 | 1994 | ||
| 2000 | pr_debug("xen-pvscsi: fabric module %s on %s/%s on "UTS_RELEASE"\n", | 1995 | .tfc_wwn_attrs = scsiback_wwn_attrs, |
| 2001 | VSCSI_VERSION, utsname()->sysname, utsname()->machine); | 1996 | .tfc_tpg_base_attrs = scsiback_tpg_attrs, |
| 2002 | /* | 1997 | .tfc_tpg_param_attrs = scsiback_param_attrs, |
| 2003 | * Register the top level struct config_item_type with TCM core | ||
| 2004 | */ | ||
| 2005 | fabric = target_fabric_configfs_init(THIS_MODULE, "xen-pvscsi"); | ||
| 2006 | if (IS_ERR(fabric)) | ||
| 2007 | return PTR_ERR(fabric); | ||
| 2008 | |||
| 2009 | /* | ||
| 2010 | * Setup fabric->tf_ops from our local scsiback_ops | ||
| 2011 | */ | ||
| 2012 | fabric->tf_ops = scsiback_ops; | ||
| 2013 | /* | ||
| 2014 | * Setup default attribute lists for various fabric->tf_cit_tmpl | ||
| 2015 | */ | ||
| 2016 | fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = scsiback_wwn_attrs; | ||
| 2017 | fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = scsiback_tpg_attrs; | ||
| 2018 | fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; | ||
| 2019 | fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = scsiback_param_attrs; | ||
| 2020 | fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; | ||
| 2021 | fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL; | ||
| 2022 | fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL; | ||
| 2023 | fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL; | ||
| 2024 | fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL; | ||
| 2025 | /* | ||
| 2026 | * Register the fabric for use within TCM | ||
| 2027 | */ | ||
| 2028 | ret = target_fabric_configfs_register(fabric); | ||
| 2029 | if (ret < 0) { | ||
| 2030 | target_fabric_configfs_free(fabric); | ||
| 2031 | return ret; | ||
| 2032 | } | ||
| 2033 | /* | ||
| 2034 | * Setup our local pointer to *fabric | ||
| 2035 | */ | ||
| 2036 | scsiback_fabric_configfs = fabric; | ||
| 2037 | pr_debug("xen-pvscsi: Set fabric -> scsiback_fabric_configfs\n"); | ||
| 2038 | return 0; | ||
| 2039 | }; | ||
| 2040 | |||
| 2041 | static void scsiback_deregister_configfs(void) | ||
| 2042 | { | ||
| 2043 | if (!scsiback_fabric_configfs) | ||
| 2044 | return; | ||
| 2045 | |||
| 2046 | target_fabric_configfs_deregister(scsiback_fabric_configfs); | ||
| 2047 | scsiback_fabric_configfs = NULL; | ||
| 2048 | pr_debug("xen-pvscsi: Cleared scsiback_fabric_configfs\n"); | ||
| 2049 | }; | 1998 | }; |
| 2050 | 1999 | ||
| 2051 | static const struct xenbus_device_id scsiback_ids[] = { | 2000 | static const struct xenbus_device_id scsiback_ids[] = { |
| @@ -2077,6 +2026,9 @@ static int __init scsiback_init(void) | |||
| 2077 | if (!xen_domain()) | 2026 | if (!xen_domain()) |
| 2078 | return -ENODEV; | 2027 | return -ENODEV; |
| 2079 | 2028 | ||
| 2029 | pr_debug("xen-pvscsi: fabric module %s on %s/%s on "UTS_RELEASE"\n", | ||
| 2030 | VSCSI_VERSION, utsname()->sysname, utsname()->machine); | ||
| 2031 | |||
| 2080 | scsiback_cachep = kmem_cache_create("vscsiif_cache", | 2032 | scsiback_cachep = kmem_cache_create("vscsiif_cache", |
| 2081 | sizeof(struct vscsibk_pend), 0, 0, scsiback_init_pend); | 2033 | sizeof(struct vscsibk_pend), 0, 0, scsiback_init_pend); |
| 2082 | if (!scsiback_cachep) | 2034 | if (!scsiback_cachep) |
| @@ -2086,7 +2038,7 @@ static int __init scsiback_init(void) | |||
| 2086 | if (ret) | 2038 | if (ret) |
| 2087 | goto out_cache_destroy; | 2039 | goto out_cache_destroy; |
| 2088 | 2040 | ||
| 2089 | ret = scsiback_register_configfs(); | 2041 | ret = target_register_template(&scsiback_ops); |
| 2090 | if (ret) | 2042 | if (ret) |
| 2091 | goto out_unregister_xenbus; | 2043 | goto out_unregister_xenbus; |
| 2092 | 2044 | ||
| @@ -2109,7 +2061,7 @@ static void __exit scsiback_exit(void) | |||
| 2109 | BUG(); | 2061 | BUG(); |
| 2110 | gnttab_free_pages(1, &page); | 2062 | gnttab_free_pages(1, &page); |
| 2111 | } | 2063 | } |
| 2112 | scsiback_deregister_configfs(); | 2064 | target_unregister_template(&scsiback_ops); |
| 2113 | xenbus_unregister_driver(&scsiback_driver); | 2065 | xenbus_unregister_driver(&scsiback_driver); |
| 2114 | kmem_cache_destroy(scsiback_cachep); | 2066 | kmem_cache_destroy(scsiback_cachep); |
| 2115 | } | 2067 | } |
