2 * Copyright (c) 2004-2008 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 osm_sr_rcv_t.
39 * This object represents the ServiceRecord Receiver object.
40 * This object is part of the opensm family of objects.
45 #endif /* HAVE_CONFIG_H */
48 #include <iba/ib_types.h>
49 #include <complib/cl_qmap.h>
50 #include <complib/cl_passivelock.h>
51 #include <complib/cl_debug.h>
52 #include <complib/cl_qlist.h>
53 #include <vendor/osm_vendor_api.h>
54 #include <opensm/osm_port.h>
55 #include <opensm/osm_node.h>
56 #include <opensm/osm_switch.h>
57 #include <opensm/osm_helper.h>
58 #include <opensm/osm_sa.h>
59 #include <opensm/osm_service.h>
60 #include <opensm/osm_pkey.h>
62 typedef struct osm_sr_item {
63 cl_list_item_t list_item;
64 ib_service_record_t service_rec;
67 typedef struct osm_sr_match_item {
69 ib_service_record_t *p_service_rec;
72 } osm_sr_match_item_t;
74 typedef struct osm_sr_search_ctxt {
75 osm_sr_match_item_t *p_sr_item;
76 const osm_physp_t *p_req_physp;
77 } osm_sr_search_ctxt_t;
79 /**********************************************************************
80 **********************************************************************/
82 __match_service_pkey_with_ports_pkey(IN osm_sa_t * sa,
83 IN const osm_madw_t * const p_madw,
84 ib_service_record_t * const p_service_rec,
85 ib_net64_t const comp_mask)
87 boolean_t valid = TRUE;
88 osm_physp_t *p_req_physp;
89 ib_net64_t service_guid;
90 osm_port_t *service_port;
92 /* update the requester physical port. */
93 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log,
95 osm_madw_get_mad_addr_ptr
97 if (p_req_physp == NULL) {
98 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2404: "
99 "Cannot find requester physical port\n");
104 if ((comp_mask & IB_SR_COMPMASK_SPKEY) == IB_SR_COMPMASK_SPKEY) {
105 /* We have a ServiceP_Key - check matching on requester port, and
106 ServiceGid port (if such exists) */
107 /* Make sure it matches the p_req_physp */
108 if (!osm_physp_has_pkey
109 (sa->p_log, p_service_rec->service_pkey, p_req_physp)) {
114 /* Make sure it matches the port of the ServiceGid */
115 if ((comp_mask & IB_SR_COMPMASK_SGID) == IB_SR_COMPMASK_SGID) {
117 p_service_rec->service_gid.unicast.interface_id;
119 osm_get_port_by_guid(sa->p_subn, service_guid);
121 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2405: "
122 "No port object for port 0x%016" PRIx64
123 "\n", cl_ntoh64(service_guid));
127 /* check on the table of the default physical port of the service port */
128 if (!osm_physp_has_pkey(sa->p_log,
129 p_service_rec->service_pkey,
130 service_port->p_physp)) {
141 /**********************************************************************
142 **********************************************************************/
144 __match_name_to_key_association(IN osm_sa_t * sa,
145 ib_service_record_t * p_service_rec,
146 ib_net64_t comp_mask)
148 UNUSED_PARAM(p_service_rec);
151 if ((comp_mask & (IB_SR_COMPMASK_SKEY | IB_SR_COMPMASK_SNAME)) ==
152 (IB_SR_COMPMASK_SKEY | IB_SR_COMPMASK_SNAME)) {
153 /* For now, we are not maintaining the ServiceAssociation record
154 * so just return TRUE
162 /**********************************************************************
163 **********************************************************************/
165 __validate_sr(IN osm_sa_t * sa, IN const osm_madw_t * const p_madw)
167 boolean_t valid = TRUE;
168 ib_sa_mad_t *p_sa_mad;
169 ib_service_record_t *p_recvd_service_rec;
171 OSM_LOG_ENTER(sa->p_log);
173 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
174 p_recvd_service_rec =
175 (ib_service_record_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
177 valid = __match_service_pkey_with_ports_pkey(sa,
180 p_sa_mad->comp_mask);
183 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
184 "No Match for Service Pkey\n");
189 valid = __match_name_to_key_association(sa,
191 p_sa_mad->comp_mask);
194 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
195 "Service Record Name to key matching failed\n");
201 OSM_LOG_EXIT(sa->p_log);
205 /**********************************************************************
206 **********************************************************************/
208 __osm_sr_rcv_respond(IN osm_sa_t * sa,
209 IN osm_madw_t * const p_madw,
210 IN cl_qlist_t * const p_list)
212 /* p923 - The ServiceKey shall be set to 0, except in the case of
214 Note: In the mad controller we check that the SM_Key received on
215 the mad is valid. Meaning - is either zero or equal to the local
218 if (!osm_madw_get_sa_mad_ptr(p_madw)->sm_key) {
220 for (item = (osm_sr_item_t *) cl_qlist_head(p_list);
221 item != (osm_sr_item_t *) cl_qlist_end(p_list);
222 item = (osm_sr_item_t *)cl_qlist_next(&item->list_item))
223 memset(item->service_rec.service_key, 0,
224 sizeof(item->service_rec.service_key));
227 osm_sa_respond(sa, p_madw, sizeof(ib_service_record_t), p_list);
230 /**********************************************************************
231 **********************************************************************/
233 __get_matching_sr(IN cl_list_item_t * const p_list_item, IN void *context)
235 osm_sr_search_ctxt_t *const p_ctxt = (osm_sr_search_ctxt_t *) context;
236 osm_svcr_t *p_svcr = (osm_svcr_t *) p_list_item;
237 osm_sr_item_t *p_sr_pool_item;
238 osm_sr_match_item_t *p_sr_item = p_ctxt->p_sr_item;
239 ib_net64_t comp_mask = p_sr_item->comp_mask;
240 const osm_physp_t *p_req_physp = p_ctxt->p_req_physp;
242 if ((comp_mask & IB_SR_COMPMASK_SID) == IB_SR_COMPMASK_SID) {
243 if (p_sr_item->p_service_rec->service_id !=
244 p_svcr->service_record.service_id)
247 if ((comp_mask & IB_SR_COMPMASK_SGID) == IB_SR_COMPMASK_SGID) {
248 if (memcmp(&p_sr_item->p_service_rec->service_gid,
249 &p_svcr->service_record.service_gid,
250 sizeof(p_svcr->service_record.service_gid)) != 0)
253 if ((comp_mask & IB_SR_COMPMASK_SPKEY) == IB_SR_COMPMASK_SPKEY) {
254 if (p_sr_item->p_service_rec->service_pkey !=
255 p_svcr->service_record.service_pkey)
259 if ((comp_mask & IB_SR_COMPMASK_SKEY) == IB_SR_COMPMASK_SKEY) {
260 if (memcmp(p_sr_item->p_service_rec->service_key,
261 p_svcr->service_record.service_key,
262 16 * sizeof(uint8_t)))
265 if ((comp_mask & IB_SR_COMPMASK_SNAME) == IB_SR_COMPMASK_SNAME) {
266 if (memcmp(p_sr_item->p_service_rec->service_name,
267 p_svcr->service_record.service_name,
268 sizeof(p_svcr->service_record.service_name)) != 0)
271 if ((comp_mask & IB_SR_COMPMASK_SDATA8_0) == IB_SR_COMPMASK_SDATA8_0) {
272 if (p_sr_item->p_service_rec->service_data8[0] !=
273 p_svcr->service_record.service_data8[0])
277 if ((comp_mask & IB_SR_COMPMASK_SDATA8_1) == IB_SR_COMPMASK_SDATA8_1) {
278 if (p_sr_item->p_service_rec->service_data8[1] !=
279 p_svcr->service_record.service_data8[1])
282 if ((comp_mask & IB_SR_COMPMASK_SDATA8_2) == IB_SR_COMPMASK_SDATA8_2) {
283 if (p_sr_item->p_service_rec->service_data8[2] !=
284 p_svcr->service_record.service_data8[2])
287 if ((comp_mask & IB_SR_COMPMASK_SDATA8_3) == IB_SR_COMPMASK_SDATA8_3) {
288 if (p_sr_item->p_service_rec->service_data8[3] !=
289 p_svcr->service_record.service_data8[3])
292 if ((comp_mask & IB_SR_COMPMASK_SDATA8_4) == IB_SR_COMPMASK_SDATA8_4) {
293 if (p_sr_item->p_service_rec->service_data8[4] !=
294 p_svcr->service_record.service_data8[4])
297 if ((comp_mask & IB_SR_COMPMASK_SDATA8_5) == IB_SR_COMPMASK_SDATA8_5) {
298 if (p_sr_item->p_service_rec->service_data8[5] !=
299 p_svcr->service_record.service_data8[5])
302 if ((comp_mask & IB_SR_COMPMASK_SDATA8_6) == IB_SR_COMPMASK_SDATA8_6) {
303 if (p_sr_item->p_service_rec->service_data8[6] !=
304 p_svcr->service_record.service_data8[6])
308 if ((comp_mask & IB_SR_COMPMASK_SDATA8_7) == IB_SR_COMPMASK_SDATA8_7) {
309 if (p_sr_item->p_service_rec->service_data8[7] !=
310 p_svcr->service_record.service_data8[7])
314 if ((comp_mask & IB_SR_COMPMASK_SDATA8_8) == IB_SR_COMPMASK_SDATA8_8) {
315 if (p_sr_item->p_service_rec->service_data8[8] !=
316 p_svcr->service_record.service_data8[8])
320 if ((comp_mask & IB_SR_COMPMASK_SDATA8_9) == IB_SR_COMPMASK_SDATA8_9) {
321 if (p_sr_item->p_service_rec->service_data8[9] !=
322 p_svcr->service_record.service_data8[9])
326 if ((comp_mask & IB_SR_COMPMASK_SDATA8_10) == IB_SR_COMPMASK_SDATA8_10) {
327 if (p_sr_item->p_service_rec->service_data8[10] !=
328 p_svcr->service_record.service_data8[10])
332 if ((comp_mask & IB_SR_COMPMASK_SDATA8_11) == IB_SR_COMPMASK_SDATA8_11) {
333 if (p_sr_item->p_service_rec->service_data8[11] !=
334 p_svcr->service_record.service_data8[11])
338 if ((comp_mask & IB_SR_COMPMASK_SDATA8_12) == IB_SR_COMPMASK_SDATA8_12) {
339 if (p_sr_item->p_service_rec->service_data8[12] !=
340 p_svcr->service_record.service_data8[12])
343 if ((comp_mask & IB_SR_COMPMASK_SDATA8_13) == IB_SR_COMPMASK_SDATA8_13) {
344 if (p_sr_item->p_service_rec->service_data8[13] !=
345 p_svcr->service_record.service_data8[13])
348 if ((comp_mask & IB_SR_COMPMASK_SDATA8_14) == IB_SR_COMPMASK_SDATA8_14) {
349 if (p_sr_item->p_service_rec->service_data8[14] !=
350 p_svcr->service_record.service_data8[14])
353 if ((comp_mask & IB_SR_COMPMASK_SDATA8_15) == IB_SR_COMPMASK_SDATA8_15) {
354 if (p_sr_item->p_service_rec->service_data8[15] !=
355 p_svcr->service_record.service_data8[15])
358 if ((comp_mask & IB_SR_COMPMASK_SDATA16_0) == IB_SR_COMPMASK_SDATA16_0) {
359 if (p_sr_item->p_service_rec->service_data16[0] !=
360 p_svcr->service_record.service_data16[0])
363 if ((comp_mask & IB_SR_COMPMASK_SDATA16_1) == IB_SR_COMPMASK_SDATA16_1) {
364 if (p_sr_item->p_service_rec->service_data16[1] !=
365 p_svcr->service_record.service_data16[1])
368 if ((comp_mask & IB_SR_COMPMASK_SDATA16_2) == IB_SR_COMPMASK_SDATA16_2) {
369 if (p_sr_item->p_service_rec->service_data16[2] !=
370 p_svcr->service_record.service_data16[2])
373 if ((comp_mask & IB_SR_COMPMASK_SDATA16_3) == IB_SR_COMPMASK_SDATA16_3) {
374 if (p_sr_item->p_service_rec->service_data16[3] !=
375 p_svcr->service_record.service_data16[3])
378 if ((comp_mask & IB_SR_COMPMASK_SDATA16_4) == IB_SR_COMPMASK_SDATA16_4) {
379 if (p_sr_item->p_service_rec->service_data16[4] !=
380 p_svcr->service_record.service_data16[4])
383 if ((comp_mask & IB_SR_COMPMASK_SDATA16_5) == IB_SR_COMPMASK_SDATA16_5) {
384 if (p_sr_item->p_service_rec->service_data16[5] !=
385 p_svcr->service_record.service_data16[5])
388 if ((comp_mask & IB_SR_COMPMASK_SDATA16_6) == IB_SR_COMPMASK_SDATA16_6) {
389 if (p_sr_item->p_service_rec->service_data16[6] !=
390 p_svcr->service_record.service_data16[6])
393 if ((comp_mask & IB_SR_COMPMASK_SDATA16_7) == IB_SR_COMPMASK_SDATA16_7) {
394 if (p_sr_item->p_service_rec->service_data16[7] !=
395 p_svcr->service_record.service_data16[7])
398 if ((comp_mask & IB_SR_COMPMASK_SDATA32_0) == IB_SR_COMPMASK_SDATA32_0) {
399 if (p_sr_item->p_service_rec->service_data32[0] !=
400 p_svcr->service_record.service_data32[0])
403 if ((comp_mask & IB_SR_COMPMASK_SDATA32_1) == IB_SR_COMPMASK_SDATA32_1) {
404 if (p_sr_item->p_service_rec->service_data32[1] !=
405 p_svcr->service_record.service_data32[1])
408 if ((comp_mask & IB_SR_COMPMASK_SDATA32_2) == IB_SR_COMPMASK_SDATA32_2) {
409 if (p_sr_item->p_service_rec->service_data32[2] !=
410 p_svcr->service_record.service_data32[2])
413 if ((comp_mask & IB_SR_COMPMASK_SDATA32_3) == IB_SR_COMPMASK_SDATA32_3) {
414 if (p_sr_item->p_service_rec->service_data32[3] !=
415 p_svcr->service_record.service_data32[3])
419 if ((comp_mask & IB_SR_COMPMASK_SDATA64_0) == IB_SR_COMPMASK_SDATA64_0) {
420 if (p_sr_item->p_service_rec->service_data64[0] !=
421 p_svcr->service_record.service_data64[0])
424 if ((comp_mask & IB_SR_COMPMASK_SDATA64_1) == IB_SR_COMPMASK_SDATA64_1) {
425 if (p_sr_item->p_service_rec->service_data64[1] !=
426 p_svcr->service_record.service_data64[1])
430 /* Check that the requester port has the pkey which is the service_pkey.
431 If not - then it cannot receive this ServiceRecord. */
432 /* The check is relevant only if the service_pkey is valid */
433 if (!ib_pkey_is_invalid(p_svcr->service_record.service_pkey)) {
434 if (!osm_physp_has_pkey(p_sr_item->sa->p_log,
435 p_svcr->service_record.service_pkey,
437 OSM_LOG(p_sr_item->sa->p_log, OSM_LOG_VERBOSE,
438 "requester port doesn't have the service_pkey: 0x%X\n",
439 cl_ntoh16(p_svcr->service_record.service_pkey));
444 p_sr_pool_item = malloc(sizeof(*p_sr_pool_item));
445 if (p_sr_pool_item == NULL) {
446 OSM_LOG(p_sr_item->sa->p_log, OSM_LOG_ERROR, "ERR 2408: "
447 "Unable to acquire Service Record from pool\n");
451 p_sr_pool_item->service_rec = p_svcr->service_record;
453 cl_qlist_insert_tail(&p_sr_item->sr_list, &p_sr_pool_item->list_item);
459 /**********************************************************************
460 **********************************************************************/
462 osm_sr_rcv_process_get_method(IN osm_sa_t * sa,
463 IN osm_madw_t * const p_madw)
465 ib_sa_mad_t *p_sa_mad;
466 ib_service_record_t *p_recvd_service_rec;
467 osm_sr_match_item_t sr_match_item;
468 osm_sr_search_ctxt_t context;
469 osm_physp_t *p_req_physp;
471 OSM_LOG_ENTER(sa->p_log);
475 /* update the requester physical port. */
476 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log,
478 osm_madw_get_mad_addr_ptr
480 if (p_req_physp == NULL) {
481 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2409: "
482 "Cannot find requester physical port\n");
486 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
487 p_recvd_service_rec =
488 (ib_service_record_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
490 if (osm_log_is_active(sa->p_log, OSM_LOG_DEBUG))
491 osm_dump_service_record(sa->p_log, p_recvd_service_rec,
494 cl_qlist_init(&sr_match_item.sr_list);
495 sr_match_item.p_service_rec = p_recvd_service_rec;
496 sr_match_item.comp_mask = p_sa_mad->comp_mask;
497 sr_match_item.sa = sa;
499 context.p_sr_item = &sr_match_item;
500 context.p_req_physp = p_req_physp;
503 cl_plock_excl_acquire(sa->p_lock);
505 cl_qlist_apply_func(&sa->p_subn->sa_sr_list,
506 __get_matching_sr, &context);
508 cl_plock_release(sa->p_lock);
510 if (p_sa_mad->method == IB_MAD_METHOD_GET &&
511 cl_qlist_count(&sr_match_item.sr_list) == 0) {
512 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
513 "No records matched the Service Record query\n");
515 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_NO_RECORDS);
519 __osm_sr_rcv_respond(sa, p_madw, &sr_match_item.sr_list);
522 OSM_LOG_EXIT(sa->p_log);
526 /**********************************************************************
527 **********************************************************************/
529 osm_sr_rcv_process_set_method(IN osm_sa_t * sa,
530 IN osm_madw_t * const p_madw)
532 ib_sa_mad_t *p_sa_mad;
533 ib_service_record_t *p_recvd_service_rec;
534 ib_net64_t comp_mask;
536 osm_sr_item_t *p_sr_item;
539 OSM_LOG_ENTER(sa->p_log);
543 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
544 p_recvd_service_rec =
545 (ib_service_record_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
547 comp_mask = p_sa_mad->comp_mask;
549 if (osm_log_is_active(sa->p_log, OSM_LOG_DEBUG))
550 osm_dump_service_record(sa->p_log, p_recvd_service_rec,
553 if ((comp_mask & (IB_SR_COMPMASK_SID | IB_SR_COMPMASK_SGID)) !=
554 (IB_SR_COMPMASK_SID | IB_SR_COMPMASK_SGID)) {
555 OSM_LOG(sa->p_log, OSM_LOG_VERBOSE,
556 "Component Mask RID check failed for METHOD_SET\n");
557 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_REQ_INVALID);
561 /* if we were not provided with a service lease make it
563 if ((comp_mask & IB_SR_COMPMASK_SLEASE) != IB_SR_COMPMASK_SLEASE) {
564 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
565 "ServiceLease Component Mask not set - using infinite lease\n");
566 p_recvd_service_rec->service_lease = 0xFFFFFFFF;
570 cl_plock_excl_acquire(sa->p_lock);
572 /* If Record exists with matching RID */
573 p_svcr = osm_svcr_get_by_rid(sa->p_subn,
574 sa->p_log, p_recvd_service_rec);
576 if (p_svcr == NULL) {
577 /* Create the instance of the osm_svcr_t object */
578 p_svcr = osm_svcr_new(p_recvd_service_rec);
579 if (p_svcr == NULL) {
580 cl_plock_release(sa->p_lock);
582 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2411: "
583 "osm_svcr_get_by_rid failed\n");
585 osm_sa_send_error(sa, p_madw,
586 IB_SA_MAD_STATUS_NO_RESOURCES);
590 /* Add this new osm_svcr_t object to subnet object */
591 osm_svcr_insert_to_db(sa->p_subn, sa->p_log, p_svcr);
594 /* Update the old instance of the osm_svcr_t object */
595 osm_svcr_init(p_svcr, p_recvd_service_rec);
598 cl_plock_release(sa->p_lock);
600 if (p_recvd_service_rec->service_lease != 0xFFFFFFFF) {
602 cl_timer_trim(&sa->sr_timer,
603 p_recvd_service_rec->service_lease * 1000);
605 /* This was a bug since no check was made to see if too long */
606 /* just make sure the timer works - get a call back within a second */
607 cl_timer_trim(&sa->sr_timer, 1000);
608 p_svcr->modified_time = cl_get_time_stamp_sec();
611 p_sr_item = malloc(sizeof(*p_sr_item));
612 if (p_sr_item == NULL) {
613 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2412: "
614 "Unable to acquire Service record\n");
615 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_NO_RESOURCES);
619 if ((comp_mask & IB_SR_COMPMASK_SPKEY) != IB_SR_COMPMASK_SPKEY) {
620 /* Set the Default Service P_Key in the response */
621 p_recvd_service_rec->service_pkey = IB_DEFAULT_PKEY;
624 p_sr_item->service_rec = *p_recvd_service_rec;
625 cl_qlist_init(&sr_list);
627 cl_qlist_insert_tail(&sr_list, &p_sr_item->list_item);
629 __osm_sr_rcv_respond(sa, p_madw, &sr_list);
632 OSM_LOG_EXIT(sa->p_log);
635 /**********************************************************************
636 **********************************************************************/
638 osm_sr_rcv_process_delete_method(IN osm_sa_t * sa,
639 IN osm_madw_t * const p_madw)
641 ib_sa_mad_t *p_sa_mad;
642 ib_service_record_t *p_recvd_service_rec;
643 ib_net64_t comp_mask;
645 osm_sr_item_t *p_sr_item;
648 OSM_LOG_ENTER(sa->p_log);
652 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
653 p_recvd_service_rec =
654 (ib_service_record_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
656 comp_mask = p_sa_mad->comp_mask;
658 if (osm_log_is_active(sa->p_log, OSM_LOG_DEBUG))
659 osm_dump_service_record(sa->p_log, p_recvd_service_rec,
663 cl_plock_excl_acquire(sa->p_lock);
665 /* If Record exists with matching RID */
666 p_svcr = osm_svcr_get_by_rid(sa->p_subn,
667 sa->p_log, p_recvd_service_rec);
669 if (p_svcr == NULL) {
670 cl_plock_release(sa->p_lock);
671 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
672 "No records matched the RID\n");
673 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_NO_RECORDS);
676 osm_svcr_remove_from_db(sa->p_subn, sa->p_log, p_svcr);
679 cl_plock_release(sa->p_lock);
681 p_sr_item = malloc(sizeof(*p_sr_item));
682 if (p_sr_item == NULL) {
683 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2413: "
684 "Unable to acquire Service record\n");
685 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_NO_RESOURCES);
689 /* provide back the copy of the record */
690 p_sr_item->service_rec = p_svcr->service_record;
691 cl_qlist_init(&sr_list);
693 cl_qlist_insert_tail(&sr_list, &p_sr_item->list_item);
696 osm_svcr_delete(p_svcr);
698 __osm_sr_rcv_respond(sa, p_madw, &sr_list);
701 OSM_LOG_EXIT(sa->p_log);
705 /**********************************************************************
706 **********************************************************************/
707 void osm_sr_rcv_process(IN void *context, IN void *data)
709 osm_sa_t *sa = context;
710 osm_madw_t *p_madw = data;
711 ib_sa_mad_t *p_sa_mad;
714 OSM_LOG_ENTER(sa->p_log);
718 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
720 CL_ASSERT(p_sa_mad->attr_id == IB_MAD_ATTR_SERVICE_RECORD);
722 switch (p_sa_mad->method) {
723 case IB_MAD_METHOD_SET:
724 valid = __validate_sr(sa, p_madw);
726 OSM_LOG(sa->p_log, OSM_LOG_VERBOSE,
727 "Component Mask check failed for set request\n");
728 osm_sa_send_error(sa, p_madw,
729 IB_SA_MAD_STATUS_REQ_INVALID);
732 osm_sr_rcv_process_set_method(sa, p_madw);
734 case IB_MAD_METHOD_DELETE:
735 valid = __validate_sr(sa, p_madw);
737 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
738 "Component Mask check failed for delete request\n");
739 osm_sa_send_error(sa, p_madw,
740 IB_SA_MAD_STATUS_REQ_INVALID);
743 osm_sr_rcv_process_delete_method(sa, p_madw);
745 case IB_MAD_METHOD_GET:
746 case IB_MAD_METHOD_GETTABLE:
747 osm_sr_rcv_process_get_method(sa, p_madw);
750 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
751 "Unsupported Method (%s)\n",
752 ib_get_sa_method_str(p_sa_mad->method));
753 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
758 OSM_LOG_EXIT(sa->p_log);
761 /**********************************************************************
762 **********************************************************************/
763 void osm_sr_rcv_lease_cb(IN void *context)
765 osm_sa_t *sa = context;
766 cl_list_item_t *p_list_item;
767 cl_list_item_t *p_next_list_item;
770 uint32_t elapsed_time;
771 uint32_t trim_time = 20; /* maxiaml timer refresh is 20 seconds */
773 OSM_LOG_ENTER(sa->p_log);
775 cl_plock_excl_acquire(sa->p_lock);
777 p_list_item = cl_qlist_head(&sa->p_subn->sa_sr_list);
779 while (p_list_item != cl_qlist_end(&sa->p_subn->sa_sr_list)) {
780 p_svcr = (osm_svcr_t *) p_list_item;
782 if (p_svcr->service_record.service_lease == 0xFFFFFFFF) {
783 p_list_item = cl_qlist_next(p_list_item);
787 /* current time in seconds */
788 curr_time = cl_get_time_stamp_sec();
789 /* elapsed time from last modify */
790 elapsed_time = curr_time - p_svcr->modified_time;
791 /* but it can not be less then 1 */
792 if (elapsed_time < 1)
795 if (elapsed_time < p_svcr->lease_period) {
797 Just update the service lease period
798 note: for simplicity we work with a uint32_t field
799 external to the network order lease_period of the MAD
801 p_svcr->lease_period -= elapsed_time;
803 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
804 "Remaining time for Service Name:%s is:0x%X\n",
805 p_svcr->service_record.service_name,
806 p_svcr->lease_period);
808 p_svcr->modified_time = curr_time;
810 /* Update the trim timer */
811 if (trim_time > p_svcr->lease_period) {
812 trim_time = p_svcr->lease_period;
817 p_list_item = cl_qlist_next(p_list_item);
821 p_next_list_item = cl_qlist_next(p_list_item);
823 /* Remove the service Record */
824 osm_svcr_remove_from_db(sa->p_subn,
827 osm_svcr_delete(p_svcr);
829 p_list_item = p_next_list_item;
834 /* Release the Lock */
835 cl_plock_release(sa->p_lock);
837 if (trim_time != 0xFFFFFFFF) {
838 cl_timer_trim(&sa->sr_timer, trim_time * 1000); /* Convert to milli seconds */
841 OSM_LOG_EXIT(sa->p_log);