1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved. 3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. 4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 5219820Sjeff * 6219820Sjeff * This software is available to you under a choice of one of two 7219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 8219820Sjeff * General Public License (GPL) Version 2, available from the file 9219820Sjeff * COPYING in the main directory of this source tree, or the 10219820Sjeff * OpenIB.org BSD license below: 11219820Sjeff * 12219820Sjeff * Redistribution and use in source and binary forms, with or 13219820Sjeff * without modification, are permitted provided that the following 14219820Sjeff * conditions are met: 15219820Sjeff * 16219820Sjeff * - Redistributions of source code must retain the above 17219820Sjeff * copyright notice, this list of conditions and the following 18219820Sjeff * disclaimer. 19219820Sjeff * 20219820Sjeff * - Redistributions in binary form must reproduce the above 21219820Sjeff * copyright notice, this list of conditions and the following 22219820Sjeff * disclaimer in the documentation and/or other materials 23219820Sjeff * provided with the distribution. 24219820Sjeff * 25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32219820Sjeff * SOFTWARE. 33219820Sjeff * 34219820Sjeff */ 35219820Sjeff 36219820Sjeff/* 37219820Sjeff * Abstract: 38219820Sjeff * Implementation of service record functions. 39219820Sjeff */ 40219820Sjeff 41219820Sjeff#if HAVE_CONFIG_H 42219820Sjeff# include <config.h> 43219820Sjeff#endif /* HAVE_CONFIG_H */ 44219820Sjeff 45219820Sjeff#include <stdlib.h> 46219820Sjeff#include <complib/cl_debug.h> 47219820Sjeff#include <complib/cl_timer.h> 48219820Sjeff#include <opensm/osm_service.h> 49219820Sjeff 50219820Sjeff/********************************************************************** 51219820Sjeff **********************************************************************/ 52219820Sjeffvoid osm_svcr_delete(IN osm_svcr_t * const p_svcr) 53219820Sjeff{ 54219820Sjeff free(p_svcr); 55219820Sjeff} 56219820Sjeff 57219820Sjeff/********************************************************************** 58219820Sjeff **********************************************************************/ 59219820Sjeffvoid 60219820Sjeffosm_svcr_init(IN osm_svcr_t * const p_svcr, 61219820Sjeff IN const ib_service_record_t * p_svc_rec) 62219820Sjeff{ 63219820Sjeff CL_ASSERT(p_svcr); 64219820Sjeff 65219820Sjeff p_svcr->modified_time = cl_get_time_stamp_sec(); 66219820Sjeff 67219820Sjeff /* We track the time left for this service in 68219820Sjeff an external field to avoid extra cl_ntoh/hton 69219820Sjeff required for working with the MAD field */ 70219820Sjeff p_svcr->lease_period = cl_ntoh32(p_svc_rec->service_lease); 71219820Sjeff p_svcr->service_record = *p_svc_rec; 72219820Sjeff} 73219820Sjeff 74219820Sjeff/********************************************************************** 75219820Sjeff **********************************************************************/ 76219820Sjeffosm_svcr_t *osm_svcr_new(IN const ib_service_record_t * p_svc_rec) 77219820Sjeff{ 78219820Sjeff osm_svcr_t *p_svcr; 79219820Sjeff 80219820Sjeff CL_ASSERT(p_svc_rec); 81219820Sjeff 82219820Sjeff p_svcr = (osm_svcr_t *) malloc(sizeof(*p_svcr)); 83219820Sjeff if (p_svcr) { 84219820Sjeff memset(p_svcr, 0, sizeof(*p_svcr)); 85219820Sjeff osm_svcr_init(p_svcr, p_svc_rec); 86219820Sjeff } 87219820Sjeff 88219820Sjeff return (p_svcr); 89219820Sjeff} 90219820Sjeff 91219820Sjeff/********************************************************************** 92219820Sjeff **********************************************************************/ 93219820Sjeffstatic 94219820Sjeff cl_status_t 95219820Sjeff__match_rid_of_svc_rec(IN const cl_list_item_t * const p_list_item, 96219820Sjeff IN void *context) 97219820Sjeff{ 98219820Sjeff ib_service_record_t *p_svc_rec = (ib_service_record_t *) context; 99219820Sjeff osm_svcr_t *p_svcr = (osm_svcr_t *) p_list_item; 100219820Sjeff int32_t count; 101219820Sjeff 102219820Sjeff count = memcmp(&p_svcr->service_record, 103219820Sjeff p_svc_rec, 104219820Sjeff sizeof(p_svc_rec->service_id) + 105219820Sjeff sizeof(p_svc_rec->service_gid) + 106219820Sjeff sizeof(p_svc_rec->service_pkey)); 107219820Sjeff 108219820Sjeff if (count == 0) 109219820Sjeff return CL_SUCCESS; 110219820Sjeff else 111219820Sjeff return CL_NOT_FOUND; 112219820Sjeff 113219820Sjeff} 114219820Sjeff 115219820Sjeff/********************************************************************** 116219820Sjeff **********************************************************************/ 117219820Sjeffosm_svcr_t *osm_svcr_get_by_rid(IN osm_subn_t const *p_subn, 118219820Sjeff IN osm_log_t * p_log, 119219820Sjeff IN ib_service_record_t * const p_svc_rec) 120219820Sjeff{ 121219820Sjeff cl_list_item_t *p_list_item; 122219820Sjeff 123219820Sjeff OSM_LOG_ENTER(p_log); 124219820Sjeff 125219820Sjeff p_list_item = cl_qlist_find_from_head(&p_subn->sa_sr_list, 126219820Sjeff __match_rid_of_svc_rec, 127219820Sjeff p_svc_rec); 128219820Sjeff 129219820Sjeff if (p_list_item == cl_qlist_end(&p_subn->sa_sr_list)) 130219820Sjeff p_list_item = NULL; 131219820Sjeff 132219820Sjeff OSM_LOG_EXIT(p_log); 133219820Sjeff return (osm_svcr_t *) p_list_item; 134219820Sjeff} 135219820Sjeff 136219820Sjeff/********************************************************************** 137219820Sjeff **********************************************************************/ 138219820Sjeffvoid 139219820Sjeffosm_svcr_insert_to_db(IN osm_subn_t * p_subn, 140219820Sjeff IN osm_log_t * p_log, IN osm_svcr_t * p_svcr) 141219820Sjeff{ 142219820Sjeff OSM_LOG_ENTER(p_log); 143219820Sjeff 144219820Sjeff OSM_LOG(p_log, OSM_LOG_DEBUG, 145219820Sjeff "Inserting new Service Record into Database\n"); 146219820Sjeff 147219820Sjeff cl_qlist_insert_head(&p_subn->sa_sr_list, &p_svcr->list_item); 148219820Sjeff 149219820Sjeff OSM_LOG_EXIT(p_log); 150219820Sjeff} 151219820Sjeff 152219820Sjeffvoid 153219820Sjeffosm_svcr_remove_from_db(IN osm_subn_t * p_subn, 154219820Sjeff IN osm_log_t * p_log, IN osm_svcr_t * p_svcr) 155219820Sjeff{ 156219820Sjeff OSM_LOG_ENTER(p_log); 157219820Sjeff 158219820Sjeff OSM_LOG(p_log, OSM_LOG_DEBUG, 159219820Sjeff "Removing Service Record Name:%s ID:0x%016" PRIx64 160219820Sjeff " from Database\n", p_svcr->service_record.service_name, 161219820Sjeff p_svcr->service_record.service_id); 162219820Sjeff 163219820Sjeff cl_qlist_remove_item(&p_subn->sa_sr_list, &p_svcr->list_item); 164219820Sjeff 165219820Sjeff OSM_LOG_EXIT(p_log); 166219820Sjeff} 167