From patchwork Tue Dec 7 00:22:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arlin Davis X-Patchwork-Id: 380802 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oB70MuJ2020452 for ; Tue, 7 Dec 2010 00:23:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753234Ab0LGAXY (ORCPT ); Mon, 6 Dec 2010 19:23:24 -0500 Received: from mga11.intel.com ([192.55.52.93]:21391 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753039Ab0LGAXX convert rfc822-to-8bit (ORCPT ); Mon, 6 Dec 2010 19:23:23 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 06 Dec 2010 16:23:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.59,308,1288594800"; d="scan'208";a="865203726" Received: from orsmsx604.amr.corp.intel.com ([10.22.226.87]) by fmsmga001.fm.intel.com with ESMTP; 06 Dec 2010 16:23:00 -0800 Received: from orsmsx506.amr.corp.intel.com ([10.22.226.44]) by orsmsx604.amr.corp.intel.com ([10.250.113.17]) with mapi; Mon, 6 Dec 2010 16:23:00 -0800 From: "Davis, Arlin R" To: linux-rdma , "ofw@lists.openfabrics.org" CC: "Smith, Stan" , "King, Perry E." Date: Mon, 6 Dec 2010 16:22:53 -0800 Subject: [PATCH] libdat v2.0: static provider entries created for local SR database not freed Thread-Topic: [PATCH] libdat v2.0: static provider entries created for local SR database not freed Thread-Index: AcuVpOOlzKzJKhwMRPSWs9uFgKPhKw== Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 07 Dec 2010 00:23:24 +0000 (UTC) diff --git a/dat/common/dat_sr.c b/dat/common/dat_sr.c index 95b9333..e86c5dc 100755 --- a/dat/common/dat_sr.c +++ b/dat/common/dat_sr.c @@ -94,6 +94,11 @@ extern DAT_RETURN dat_sr_fini(void) { DAT_RETURN status; + status = dat_sr_remove_all(g_sr_dictionary); + if (DAT_SUCCESS != status) { + return status; + } + status = dat_os_lock_destroy(&g_sr_lock); if (DAT_SUCCESS != status) { return status; @@ -116,9 +121,7 @@ dat_sr_insert(IN const DAT_PROVIDER_INFO * info, IN DAT_SR_ENTRY * entry) { DAT_RETURN status; DAT_SR_ENTRY *data; - DAT_OS_SIZE lib_path_size; DAT_OS_SIZE lib_path_len; - DAT_OS_SIZE ia_params_size; DAT_OS_SIZE ia_params_len; DAT_DICTIONARY_ENTRY dict_entry; DAT_DICTIONARY_DATA prev_data; @@ -132,9 +135,9 @@ dat_sr_insert(IN const DAT_PROVIDER_INFO * info, IN DAT_SR_ENTRY * entry) dat_os_memset(data, '\0', sizeof(DAT_SR_ENTRY)); lib_path_len = strlen(entry->lib_path); - lib_path_size = (lib_path_len + 1) * sizeof(char); + data->lib_path_size = (lib_path_len + 1) * sizeof(char); - if (NULL == (data->lib_path = dat_os_alloc(lib_path_size))) { + if (NULL == (data->lib_path = dat_os_alloc(data->lib_path_size))) { status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES, DAT_RESOURCE_MEMORY); goto bail; @@ -144,9 +147,9 @@ dat_sr_insert(IN const DAT_PROVIDER_INFO * info, IN DAT_SR_ENTRY * entry) data->lib_path[lib_path_len] = '\0'; ia_params_len = strlen(entry->ia_params); - ia_params_size = (ia_params_len + 1) * sizeof(char); + data->ia_params_size = (ia_params_len + 1) * sizeof(char); - if (NULL == (data->ia_params = dat_os_alloc(ia_params_size))) { + if (NULL == (data->ia_params = dat_os_alloc(data->ia_params_size))) { status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES, DAT_RESOURCE_MEMORY); goto bail; @@ -197,11 +200,11 @@ dat_sr_insert(IN const DAT_PROVIDER_INFO * info, IN DAT_SR_ENTRY * entry) if (DAT_SUCCESS != status) { if (NULL != data) { if (NULL != data->lib_path) { - dat_os_free(data->lib_path, lib_path_size); + dat_os_free(data->lib_path, data->lib_path_size); } if (NULL != data->ia_params) { - dat_os_free(data->ia_params, ia_params_size); + dat_os_free(data->ia_params, data->ia_params_size); } dat_os_free(data, sizeof(DAT_SR_ENTRY)); @@ -218,6 +221,42 @@ dat_sr_insert(IN const DAT_PROVIDER_INFO * info, IN DAT_SR_ENTRY * entry) //*********************************************************************** // Function: dat_sr_size //*********************************************************************** +extern DAT_RETURN dat_sr_remove(IN const DAT_PROVIDER_INFO *info) +{ + DAT_DICTIONARY_ENTRY dict_entry = NULL; + DAT_RETURN status = DAT_ERROR(DAT_PROVIDER_IN_USE, 0); + DAT_SR_ENTRY *data; + + dat_os_lock(&g_sr_lock); + status = dat_dictionary_search(g_sr_dictionary, info, + (DAT_DICTIONARY_DATA)&data); + if (DAT_SUCCESS != status) + goto bail; + + if (0 != ((DAT_SR_ENTRY *) data)->ref_count) + goto bail; + + status = dat_dictionary_remove(g_sr_dictionary, + &dict_entry, info, + (DAT_DICTIONARY_DATA)&data); + if (DAT_SUCCESS != status) + goto bail; + + dat_os_free(data->lib_path, data->lib_path_size); + dat_os_free(data->ia_params, data->ia_params_size); + dat_os_free(data, sizeof(DAT_SR_ENTRY)); +bail: + dat_os_unlock(&g_sr_lock); + + if (NULL != dict_entry) + (void)dat_dictionary_entry_destroy(dict_entry); + + return status; +} + +//*********************************************************************** +// Function: dat_sr_size +//*********************************************************************** extern DAT_RETURN dat_sr_size(OUT DAT_COUNT * size) { @@ -302,6 +341,62 @@ dat_sr_list(IN DAT_COUNT max_to_return, } //*********************************************************************** +// Function: dat_sr_remove_all() +//*********************************************************************** +extern DAT_RETURN dat_sr_remove_all(IN DAT_DICTIONARY *p_dictionary) +{ + int i; + DAT_RETURN status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES, DAT_RESOURCE_MEMORY); + DAT_COUNT entries = 0; + DAT_PROVIDER_INFO **plist; + + /* get provider count */ + dat_sr_size(&entries); + + /* need array of pointers to info */ + plist = dat_os_alloc(entries * sizeof(DAT_PROVIDER_INFO *)); + if (plist == NULL) + goto bail; + + dat_os_memset(plist, 0, entries * sizeof(DAT_PROVIDER_INFO *)); + for (i = 0; i < entries; i++ ) { + plist[i] = dat_os_alloc(sizeof(DAT_PROVIDER_INFO)); + if (plist[i] == NULL) + goto bail; + } + + /* remove and destroy each SR entry */ + status = dat_sr_list(entries, &entries, plist); + if (DAT_SUCCESS != status) + goto bail; + + for (i=0;iia_name); + goto bail; + } + dat_os_dbg_print(DAT_OS_DBG_TYPE_SR, + " libdat2 removed SR" + " provider: IA %s\n", + plist[i]->ia_name); + } +bail: + for (i = 0; i < entries; i++ ) { + if (plist[i] != NULL) + dat_os_free(plist[i], sizeof(DAT_PROVIDER_INFO)); + } + dat_os_free(plist, entries * sizeof(DAT_PROVIDER_INFO *)); + + return status; + +} + + +//*********************************************************************** // Function: dat_sr_provider_open //*********************************************************************** diff --git a/dat/common/dat_sr.h b/dat/common/dat_sr.h index 86be8a0..1990023 100644 --- a/dat/common/dat_sr.h +++ b/dat/common/dat_sr.h @@ -45,6 +45,7 @@ #include #include "dat_osd.h" +#include "dat_dictionary.h" /********************************************************************* * * @@ -57,6 +58,8 @@ typedef struct DAT_SR_ENTRY DAT_PROVIDER_INFO info; char * lib_path; char * ia_params; + DAT_OS_SIZE lib_path_size; + DAT_OS_SIZE ia_params_size; DAT_OS_LIBRARY_HANDLE lib_handle; DAT_PROVIDER_INIT_FUNC init_func; DAT_PROVIDER_FINI_FUNC fini_func; @@ -82,6 +85,9 @@ dat_sr_insert ( IN const DAT_PROVIDER_INFO *info, IN DAT_SR_ENTRY *entry ); +extern DAT_RETURN dat_sr_remove( + IN const DAT_PROVIDER_INFO *info); + extern DAT_RETURN dat_sr_size ( OUT DAT_COUNT *size); @@ -93,6 +99,10 @@ dat_sr_list ( OUT DAT_PROVIDER_INFO * (dat_provider_list[]) ); extern DAT_RETURN +dat_sr_remove_all( + IN DAT_DICTIONARY *p_dictionary); + +extern DAT_RETURN dat_sr_provider_open ( IN const DAT_PROVIDER_INFO *info );