2 * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 * Implementation of service record functions.
43 #endif /* HAVE_CONFIG_H */
46 #include <complib/cl_debug.h>
47 #include <complib/cl_timer.h>
48 #include <opensm/osm_service.h>
50 /**********************************************************************
51 **********************************************************************/
52 void osm_svcr_delete(IN osm_svcr_t * const p_svcr)
57 /**********************************************************************
58 **********************************************************************/
60 osm_svcr_init(IN osm_svcr_t * const p_svcr,
61 IN const ib_service_record_t * p_svc_rec)
65 p_svcr->modified_time = cl_get_time_stamp_sec();
67 /* We track the time left for this service in
68 an external field to avoid extra cl_ntoh/hton
69 required for working with the MAD field */
70 p_svcr->lease_period = cl_ntoh32(p_svc_rec->service_lease);
71 p_svcr->service_record = *p_svc_rec;
74 /**********************************************************************
75 **********************************************************************/
76 osm_svcr_t *osm_svcr_new(IN const ib_service_record_t * p_svc_rec)
82 p_svcr = (osm_svcr_t *) malloc(sizeof(*p_svcr));
84 memset(p_svcr, 0, sizeof(*p_svcr));
85 osm_svcr_init(p_svcr, p_svc_rec);
91 /**********************************************************************
92 **********************************************************************/
95 __match_rid_of_svc_rec(IN const cl_list_item_t * const p_list_item,
98 ib_service_record_t *p_svc_rec = (ib_service_record_t *) context;
99 osm_svcr_t *p_svcr = (osm_svcr_t *) p_list_item;
102 count = memcmp(&p_svcr->service_record,
104 sizeof(p_svc_rec->service_id) +
105 sizeof(p_svc_rec->service_gid) +
106 sizeof(p_svc_rec->service_pkey));
115 /**********************************************************************
116 **********************************************************************/
117 osm_svcr_t *osm_svcr_get_by_rid(IN osm_subn_t const *p_subn,
118 IN osm_log_t * p_log,
119 IN ib_service_record_t * const p_svc_rec)
121 cl_list_item_t *p_list_item;
123 OSM_LOG_ENTER(p_log);
125 p_list_item = cl_qlist_find_from_head(&p_subn->sa_sr_list,
126 __match_rid_of_svc_rec,
129 if (p_list_item == cl_qlist_end(&p_subn->sa_sr_list))
133 return (osm_svcr_t *) p_list_item;
136 /**********************************************************************
137 **********************************************************************/
139 osm_svcr_insert_to_db(IN osm_subn_t * p_subn,
140 IN osm_log_t * p_log, IN osm_svcr_t * p_svcr)
142 OSM_LOG_ENTER(p_log);
144 OSM_LOG(p_log, OSM_LOG_DEBUG,
145 "Inserting new Service Record into Database\n");
147 cl_qlist_insert_head(&p_subn->sa_sr_list, &p_svcr->list_item);
153 osm_svcr_remove_from_db(IN osm_subn_t * p_subn,
154 IN osm_log_t * p_log, IN osm_svcr_t * p_svcr)
156 OSM_LOG_ENTER(p_log);
158 OSM_LOG(p_log, OSM_LOG_DEBUG,
159 "Removing Service Record Name:%s ID:0x%016" PRIx64
160 " from Database\n", p_svcr->service_record.service_name,
161 p_svcr->service_record.service_id);
163 cl_qlist_remove_item(&p_subn->sa_sr_list, &p_svcr->list_item);