2 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2006 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_file_ids.h>
49 #define FILE_ID OSM_FILE_SERVICE_C
50 #include <opensm/osm_service.h>
51 #include <opensm/osm_opensm.h>
53 void osm_svcr_delete(IN osm_svcr_t * p_svcr)
58 void osm_svcr_init(IN osm_svcr_t * p_svcr,
59 IN const ib_service_record_t * p_svc_rec)
63 p_svcr->modified_time = cl_get_time_stamp_sec();
65 /* We track the time left for this service in
66 an external field to avoid extra cl_ntoh/hton
67 required for working with the MAD field */
68 p_svcr->lease_period = cl_ntoh32(p_svc_rec->service_lease);
69 p_svcr->service_record = *p_svc_rec;
72 osm_svcr_t *osm_svcr_new(IN const ib_service_record_t * p_svc_rec)
78 p_svcr = (osm_svcr_t *) malloc(sizeof(*p_svcr));
80 memset(p_svcr, 0, sizeof(*p_svcr));
81 osm_svcr_init(p_svcr, p_svc_rec);
87 static cl_status_t match_rid_of_svc_rec(IN const cl_list_item_t * p_list_item,
90 ib_service_record_t *p_svc_rec = (ib_service_record_t *) context;
91 osm_svcr_t *p_svcr = (osm_svcr_t *) p_list_item;
93 if (memcmp(&p_svcr->service_record, p_svc_rec,
94 sizeof(p_svc_rec->service_id) +
95 sizeof(p_svc_rec->service_gid) +
96 sizeof(p_svc_rec->service_pkey)))
102 osm_svcr_t *osm_svcr_get_by_rid(IN osm_subn_t const *p_subn,
103 IN osm_log_t * p_log,
104 IN ib_service_record_t * p_svc_rec)
106 cl_list_item_t *p_list_item;
108 OSM_LOG_ENTER(p_log);
110 p_list_item = cl_qlist_find_from_head(&p_subn->sa_sr_list,
111 match_rid_of_svc_rec, p_svc_rec);
112 if (p_list_item == cl_qlist_end(&p_subn->sa_sr_list))
116 return (osm_svcr_t *) p_list_item;
119 void osm_svcr_insert_to_db(IN osm_subn_t * p_subn, IN osm_log_t * p_log,
120 IN osm_svcr_t * p_svcr)
122 OSM_LOG_ENTER(p_log);
124 OSM_LOG(p_log, OSM_LOG_DEBUG,
125 "Inserting new Service Record into Database\n");
127 cl_qlist_insert_head(&p_subn->sa_sr_list, &p_svcr->list_item);
128 p_subn->p_osm->sa.dirty = TRUE;
133 void osm_svcr_remove_from_db(IN osm_subn_t * p_subn, IN osm_log_t * p_log,
134 IN osm_svcr_t * p_svcr)
136 OSM_LOG_ENTER(p_log);
138 OSM_LOG(p_log, OSM_LOG_DEBUG,
139 "Removing Service Record Name:%s ID:0x%016" PRIx64
140 " from Database\n", p_svcr->service_record.service_name,
141 cl_ntoh64(p_svcr->service_record.service_id));
143 cl_qlist_remove_item(&p_subn->sa_sr_list, &p_svcr->list_item);
144 p_subn->p_osm->sa.dirty = TRUE;