1d6b92ffaSHans Petter Selasky /*
2d6b92ffaSHans Petter Selasky * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3d6b92ffaSHans Petter Selasky * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved.
4d6b92ffaSHans Petter Selasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5d6b92ffaSHans Petter Selasky *
6d6b92ffaSHans Petter Selasky * This software is available to you under a choice of one of two
7d6b92ffaSHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU
8d6b92ffaSHans Petter Selasky * General Public License (GPL) Version 2, available from the file
9d6b92ffaSHans Petter Selasky * COPYING in the main directory of this source tree, or the
10d6b92ffaSHans Petter Selasky * OpenIB.org BSD license below:
11d6b92ffaSHans Petter Selasky *
12d6b92ffaSHans Petter Selasky * Redistribution and use in source and binary forms, with or
13d6b92ffaSHans Petter Selasky * without modification, are permitted provided that the following
14d6b92ffaSHans Petter Selasky * conditions are met:
15d6b92ffaSHans Petter Selasky *
16d6b92ffaSHans Petter Selasky * - Redistributions of source code must retain the above
17d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following
18d6b92ffaSHans Petter Selasky * disclaimer.
19d6b92ffaSHans Petter Selasky *
20d6b92ffaSHans Petter Selasky * - Redistributions in binary form must reproduce the above
21d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following
22d6b92ffaSHans Petter Selasky * disclaimer in the documentation and/or other materials
23d6b92ffaSHans Petter Selasky * provided with the distribution.
24d6b92ffaSHans Petter Selasky *
25d6b92ffaSHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26d6b92ffaSHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27d6b92ffaSHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28d6b92ffaSHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29d6b92ffaSHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30d6b92ffaSHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31d6b92ffaSHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32d6b92ffaSHans Petter Selasky * SOFTWARE.
33d6b92ffaSHans Petter Selasky *
34d6b92ffaSHans Petter Selasky */
35d6b92ffaSHans Petter Selasky
36d6b92ffaSHans Petter Selasky /*
37d6b92ffaSHans Petter Selasky * Abstract:
38d6b92ffaSHans Petter Selasky * Implementation of service record functions.
39d6b92ffaSHans Petter Selasky */
40d6b92ffaSHans Petter Selasky
41d6b92ffaSHans Petter Selasky #if HAVE_CONFIG_H
42d6b92ffaSHans Petter Selasky # include <config.h>
43d6b92ffaSHans Petter Selasky #endif /* HAVE_CONFIG_H */
44d6b92ffaSHans Petter Selasky
45d6b92ffaSHans Petter Selasky #include <stdlib.h>
46d6b92ffaSHans Petter Selasky #include <complib/cl_debug.h>
47d6b92ffaSHans Petter Selasky #include <complib/cl_timer.h>
48d6b92ffaSHans Petter Selasky #include <opensm/osm_file_ids.h>
49d6b92ffaSHans Petter Selasky #define FILE_ID OSM_FILE_SERVICE_C
50d6b92ffaSHans Petter Selasky #include <opensm/osm_service.h>
51d6b92ffaSHans Petter Selasky #include <opensm/osm_opensm.h>
52d6b92ffaSHans Petter Selasky
osm_svcr_delete(IN osm_svcr_t * p_svcr)53d6b92ffaSHans Petter Selasky void osm_svcr_delete(IN osm_svcr_t * p_svcr)
54d6b92ffaSHans Petter Selasky {
55d6b92ffaSHans Petter Selasky free(p_svcr);
56d6b92ffaSHans Petter Selasky }
57d6b92ffaSHans Petter Selasky
osm_svcr_init(IN osm_svcr_t * p_svcr,IN const ib_service_record_t * p_svc_rec)58d6b92ffaSHans Petter Selasky void osm_svcr_init(IN osm_svcr_t * p_svcr,
59d6b92ffaSHans Petter Selasky IN const ib_service_record_t * p_svc_rec)
60d6b92ffaSHans Petter Selasky {
61d6b92ffaSHans Petter Selasky CL_ASSERT(p_svcr);
62d6b92ffaSHans Petter Selasky
63d6b92ffaSHans Petter Selasky p_svcr->modified_time = cl_get_time_stamp_sec();
64d6b92ffaSHans Petter Selasky
65d6b92ffaSHans Petter Selasky /* We track the time left for this service in
66d6b92ffaSHans Petter Selasky an external field to avoid extra cl_ntoh/hton
67d6b92ffaSHans Petter Selasky required for working with the MAD field */
68d6b92ffaSHans Petter Selasky p_svcr->lease_period = cl_ntoh32(p_svc_rec->service_lease);
69d6b92ffaSHans Petter Selasky p_svcr->service_record = *p_svc_rec;
70d6b92ffaSHans Petter Selasky }
71d6b92ffaSHans Petter Selasky
osm_svcr_new(IN const ib_service_record_t * p_svc_rec)72d6b92ffaSHans Petter Selasky osm_svcr_t *osm_svcr_new(IN const ib_service_record_t * p_svc_rec)
73d6b92ffaSHans Petter Selasky {
74d6b92ffaSHans Petter Selasky osm_svcr_t *p_svcr;
75d6b92ffaSHans Petter Selasky
76d6b92ffaSHans Petter Selasky CL_ASSERT(p_svc_rec);
77d6b92ffaSHans Petter Selasky
78d6b92ffaSHans Petter Selasky p_svcr = (osm_svcr_t *) malloc(sizeof(*p_svcr));
79d6b92ffaSHans Petter Selasky if (p_svcr) {
80d6b92ffaSHans Petter Selasky memset(p_svcr, 0, sizeof(*p_svcr));
81d6b92ffaSHans Petter Selasky osm_svcr_init(p_svcr, p_svc_rec);
82d6b92ffaSHans Petter Selasky }
83d6b92ffaSHans Petter Selasky
84d6b92ffaSHans Petter Selasky return p_svcr;
85d6b92ffaSHans Petter Selasky }
86d6b92ffaSHans Petter Selasky
match_rid_of_svc_rec(IN const cl_list_item_t * p_list_item,IN void * context)87d6b92ffaSHans Petter Selasky static cl_status_t match_rid_of_svc_rec(IN const cl_list_item_t * p_list_item,
88d6b92ffaSHans Petter Selasky IN void *context)
89d6b92ffaSHans Petter Selasky {
90d6b92ffaSHans Petter Selasky ib_service_record_t *p_svc_rec = (ib_service_record_t *) context;
91d6b92ffaSHans Petter Selasky osm_svcr_t *p_svcr = (osm_svcr_t *) p_list_item;
92d6b92ffaSHans Petter Selasky
93d6b92ffaSHans Petter Selasky if (memcmp(&p_svcr->service_record, p_svc_rec,
94d6b92ffaSHans Petter Selasky sizeof(p_svc_rec->service_id) +
95d6b92ffaSHans Petter Selasky sizeof(p_svc_rec->service_gid) +
96d6b92ffaSHans Petter Selasky sizeof(p_svc_rec->service_pkey)))
97d6b92ffaSHans Petter Selasky return CL_NOT_FOUND;
98d6b92ffaSHans Petter Selasky else
99d6b92ffaSHans Petter Selasky return CL_SUCCESS;
100d6b92ffaSHans Petter Selasky }
101d6b92ffaSHans Petter Selasky
osm_svcr_get_by_rid(IN osm_subn_t const * p_subn,IN osm_log_t * p_log,IN ib_service_record_t * p_svc_rec)102d6b92ffaSHans Petter Selasky osm_svcr_t *osm_svcr_get_by_rid(IN osm_subn_t const *p_subn,
103d6b92ffaSHans Petter Selasky IN osm_log_t * p_log,
104d6b92ffaSHans Petter Selasky IN ib_service_record_t * p_svc_rec)
105d6b92ffaSHans Petter Selasky {
106d6b92ffaSHans Petter Selasky cl_list_item_t *p_list_item;
107d6b92ffaSHans Petter Selasky
108d6b92ffaSHans Petter Selasky OSM_LOG_ENTER(p_log);
109d6b92ffaSHans Petter Selasky
110d6b92ffaSHans Petter Selasky p_list_item = cl_qlist_find_from_head(&p_subn->sa_sr_list,
111d6b92ffaSHans Petter Selasky match_rid_of_svc_rec, p_svc_rec);
112d6b92ffaSHans Petter Selasky if (p_list_item == cl_qlist_end(&p_subn->sa_sr_list))
113d6b92ffaSHans Petter Selasky p_list_item = NULL;
114d6b92ffaSHans Petter Selasky
115d6b92ffaSHans Petter Selasky OSM_LOG_EXIT(p_log);
116d6b92ffaSHans Petter Selasky return (osm_svcr_t *) p_list_item;
117d6b92ffaSHans Petter Selasky }
118d6b92ffaSHans Petter Selasky
osm_svcr_insert_to_db(IN osm_subn_t * p_subn,IN osm_log_t * p_log,IN osm_svcr_t * p_svcr)119d6b92ffaSHans Petter Selasky void osm_svcr_insert_to_db(IN osm_subn_t * p_subn, IN osm_log_t * p_log,
120d6b92ffaSHans Petter Selasky IN osm_svcr_t * p_svcr)
121d6b92ffaSHans Petter Selasky {
122d6b92ffaSHans Petter Selasky OSM_LOG_ENTER(p_log);
123d6b92ffaSHans Petter Selasky
124d6b92ffaSHans Petter Selasky OSM_LOG(p_log, OSM_LOG_DEBUG,
125d6b92ffaSHans Petter Selasky "Inserting new Service Record into Database\n");
126d6b92ffaSHans Petter Selasky
127d6b92ffaSHans Petter Selasky cl_qlist_insert_head(&p_subn->sa_sr_list, &p_svcr->list_item);
128d6b92ffaSHans Petter Selasky p_subn->p_osm->sa.dirty = TRUE;
129d6b92ffaSHans Petter Selasky
130d6b92ffaSHans Petter Selasky OSM_LOG_EXIT(p_log);
131d6b92ffaSHans Petter Selasky }
132d6b92ffaSHans Petter Selasky
osm_svcr_remove_from_db(IN osm_subn_t * p_subn,IN osm_log_t * p_log,IN osm_svcr_t * p_svcr)133d6b92ffaSHans Petter Selasky void osm_svcr_remove_from_db(IN osm_subn_t * p_subn, IN osm_log_t * p_log,
134d6b92ffaSHans Petter Selasky IN osm_svcr_t * p_svcr)
135d6b92ffaSHans Petter Selasky {
136d6b92ffaSHans Petter Selasky OSM_LOG_ENTER(p_log);
137d6b92ffaSHans Petter Selasky
138d6b92ffaSHans Petter Selasky OSM_LOG(p_log, OSM_LOG_DEBUG,
139d6b92ffaSHans Petter Selasky "Removing Service Record Name:%s ID:0x%016" PRIx64
140d6b92ffaSHans Petter Selasky " from Database\n", p_svcr->service_record.service_name,
141d6b92ffaSHans Petter Selasky cl_ntoh64(p_svcr->service_record.service_id));
142d6b92ffaSHans Petter Selasky
143d6b92ffaSHans Petter Selasky cl_qlist_remove_item(&p_subn->sa_sr_list, &p_svcr->list_item);
144d6b92ffaSHans Petter Selasky p_subn->p_osm->sa.dirty = TRUE;
145d6b92ffaSHans Petter Selasky
146d6b92ffaSHans Petter Selasky OSM_LOG_EXIT(p_log);
147d6b92ffaSHans Petter Selasky }
148