fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global variables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * local variables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic pthread_mutex_t stw_mtx = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic pthread_mutex_t idl_mtx = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic pthread_cond_t idl_cond = PTHREAD_COND_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * external variables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern const int UID_ATTR_INDEX[MAX_OBJ_TYPE_FOR_SIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * local functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *esi_monitor(void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * new_esi_portal:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Make a new portal for ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the portal object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ip6 - the portal IPv6 format IP address.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port - the portal port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * esip - the ESI port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the new ESI portal.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = (esi_portal_t *)malloc(sizeof (esi_portal_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free_esi_portal:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free a list of portal of one ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI portal.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (p != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Make a new ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the Entity object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * eid - the Entity object name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * len - the length of the name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialization time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cb_portal_uids:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Callback function which makes a copy of the portal child object
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * UIDs from a Network Entity object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p1 - the Network Entity object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p2 - the lookup control data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the number of portal object UIDs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr = &obj->attrs[ATTR_INDEX_ENTITY(ISNS_ENTITY_REG_PERIOD_ATTR_ID)];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* just one second before the end of the world */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cb_esi_portal:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Callback function which gets ESI port number and ESI interval
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from a portal object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p1 - the Portal object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p2 - the lookup control data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the ESI interval.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((int)intval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * extract_esi_portal:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Extract a list of portal which have an ESI port for an Entity.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the Entity object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * intval - the ESI interval for returnning.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the list of portals.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prepare for looking up entity object */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the array of the portal uid(s) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_of_portal = (uint32_t)cache_lookup(&lc, NULL, cb_portal_uids);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prepare for looking up portal object(s) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free up the portal uid array */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add an ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ev - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * init - 0: initialization time, otherwise not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the portal(s) which are registered for ESI monitoring */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* and the second interval for ESI or registration expiration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* avoid running everything at the same time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* generate random number within range (0, 1] */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no portal is registered for ESI monitoring, make */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* an entry for entity registration expiration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* schedule the event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The signal handler for SIGALRM, the ESI proc uses the SIGALRM
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for waking up to perform the client status inquery.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sig - the signal.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wake up the idle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Load an ESI event from data store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the Entity object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * eid - the Entity object name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * len - the length of the name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make a new event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put the new event to the list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * verify_esi_portal:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Verify ESI port and add the ESI entries after the ESI are loaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* add each event from the list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add a new ESI event when a new Entity is registered.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the Entity object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * eid - the Entity object name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * len - the length of the name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make a new event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* interrupt idle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * esi_remove:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove an ESI event immediately.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the Entity object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - always successful.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * esi_remove_obj:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Update an ESI event when a Entity object or a Portal object is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * removed from server. If the object is being removed because of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ESI failure, the ESI event will be removed with a pending time,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise, the ESI will be removed immediately.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * obj - the object being removed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pending - the pending flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - always successful.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get_stopwatch:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the stopwatch. It might need to signal the condition to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wake up the idle so the stopwatch gets updated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - wake up flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the stopwatch.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not re-schedule, wake up idle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get most current time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ev_intval:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the time interval of an ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the time interval.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check the ESI event maching an Entity object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the Entity object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 1: match, otherwise not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ev_remove:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove a portal or an ESI event. If all of ESI portal has been
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * removed, the ESI event will be marked as removal pending, which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will result in removing the Entity object after the pending time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portal_uid - the Portal object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - 0: the ESI is currently in use, otherwise it is scheduled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pending - flag for the ESI removal pending.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: the ESI is physically removed, otherwise not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove one portal only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* found the match portal */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mark it as removed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not in use, remove it physically */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* one or more esi portals are available */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no portal available */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mark the event as removed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s [%d] is marked as removed.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* physically remove the event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mark the event as removal pending */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s [%d] is marked as removal pending.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "ev_remove", "%s [%d] removed portal %d.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free an ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free up all of portals */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s [%d] is physically removed.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free the event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check the initial flag of an ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: not initial, otherwise yes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * evf_again:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check the again flag of an ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (this flag might be eliminated and use the init flag.)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: not again, otherwise yes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * evf_wakeup:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check the wakeup flag of an ESI event. The idle might need to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wake up before the event is scheduled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: no wakeup, otherwise yes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check the removal flag of an ESI event. The ESI entry might be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * marked as removal.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: not removed, otherwise yes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * evf_rem_pending:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check the removal pending flag of an ESI event. The ESI entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * might be marked as removal pending. If it is, we will switch the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * event type and change the time interval.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: not removal pending, otherwise yes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s [%d] is changed to REG_EXP.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Reset the event flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not acutally clear it, need to set again flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* and keep the removal pending flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ev->flags = EV_FLAG_AGAIN | (ev->flags & EV_FLAG_REM_P);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * evl_append:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Append an ESI event to the list, the list contains all of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ESI events which are being processed at present.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * evl_strip:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Strip off an ESI event from the list after the event is being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * processed, it will be scheduled in the scheduler.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ev == p) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * evl_remove:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove an ESI event or a portal of an ESI event from the event list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * id1 - the Entity object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * id2 - the Portal object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pending - the pending flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 1: found a match event, otherwise not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* found it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock the event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mark it as removed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unlock the event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* tell caller removal is done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not found it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Idle for certain amount of time or a wakeup signal is recieved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * t - the idle time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the time that idle left.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* hold the mutex for stopwatch update */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start alarm */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* hold the mutex for idle condition */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait on condition variable to wake up idle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (wakeup == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clean wakeup flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release the mutex for idle condition */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* stop alarm */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* seconds actually slept */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (t > 0 && idl_int == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increate the stopwatch by the actually slept time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release the mutex after stopwatch is updated */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return the amount of time which is not slept */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Execute an event. To inquiry the client status or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * perform registration expiration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ev - the event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "ev_ex", "pthread_create() failed.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reschedule for next occurence */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increase the thread ref count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_set(sys_q, REG_EXP, (void *)ev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ESI thread entry, which:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1: fetch an event from schedule,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2: idle for some time,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3: execute the event or re-schedule it,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 4: repeat from step 1 before server is being shutdown.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * arg - the thread argument.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* caculate the idle time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* block for a certain amount of time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "idle for %d seconds.", t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "idle interrupted after idle for "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not naturally waken up */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reschedule current event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* excute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "excute the cron job[%d].",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Ping the client with the ESI retry threshold for status inquiry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so - the socket descriptor.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pdu - the ESI packet.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pl - the length of packet.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 1: status inquired, otherwise not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* retry after 1 second */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * esi_monitor:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Child thread for client status mornitoring.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * arg - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock the event for esi monitoring */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* timestamp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate ESI PDU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TIMESTAMP_ATTR_ID, 8, (void *)&t, 1) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_EID_ATTR_ID, ev->eid_len, (void *)ev->eid, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no memory, will retry later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set pdu head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* keep the current lenght of the playload */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (p != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p->ref != 0 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* skip IPv6 portal */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* connect once */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* p->so = so; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cannot connect, portal is dead */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "ESI ping failed.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)p->ref);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unlock the event after esi monitoring is done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clean up pdu */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set reschedule flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reschedule for next occurence */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* decrease the thread ref count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portal_dies:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Handles the dead portal that ESI detected.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid - the Portal object UID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prepare the lookup control for deregistration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock the cache for object deregistration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* deregister the portal */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unlock cache and sync with data store */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portal_dies:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Handles the Entity registration expiration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * p - the ESI event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prepare the lookup control for deregistration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock the cache for object deregistration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* deregister the entity */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unlock cache and sync with data store */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ec == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* successfuk, mark ev as removed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* failed, retry after 3 mintues */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dereg failed, retry after 3 mintues.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ev is marked as removed, no need to dereg */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reschedule it for next occurence */