2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A * The list and the list lock are global for two external uses: 2N/A * 1) C_CloseAllSessions need to close the head (repeatedly, 2N/A * until no more sessions exist). 2N/A * 2) meta_object_find_by_handle needs to walk all sessions, 2N/A * searching each session object list for matching objects. 2N/A * The following 2 variables are used for tracking the number of 2N/A * sessions and number of read-write rw sessions that are currently open. 2N/A * meta_sessionManager_initialize 2N/A * Called from meta_Initialize. Initializes all the variables used 2N/A * by the session manager. 2N/A * meta_sessionManager_finalize 2N/A * Close all sessions, and destroy all the locks 2N/A * Close any remaining metasessions, can just simply call 2N/A * meta_CloseAllSessions. The METASLOT_SLOTID argument is 2N/A * not used, but need to be passed in. 2N/A * meta_handle2session 2N/A * Convert a CK_SESSION_HANDLE to the corresponding metasession. If 2N/A * successful, a write-lock on the session will be held to indicate 2N/A * that it's in use. Call REFRELEASE() when finished. 2N/A /* Check for bad args (eg CK_INVALID_HANDLE, which is 0/NULL). */ 2N/A * sessions can only be used by a single thread at a time. 2N/A * So, we need to get a write-lock. 2N/A /* Make sure this session is not in the process of being deleted */ 2N/A * meta_session_alloc 2N/A /* Allocate memory for the session. */ 2N/A * meta_session_activate 2N/A * Create and add a session to the list of active meta sessions. 2N/A /* Add session to the list of sessions. */ 2N/A * meta_session_deactivate 2N/A /* Safely resolve attempts of concurrent-close */ 2N/A /* Lost a delete race. */ 2N/A * Remove session from the session list. Once removed, it will not 2N/A * be possible for another thread to begin using the session. 2N/A /* Cleanup any in-progress operations. */ 2N/A /* Remove all the session metaobjects created in this session. */ 2N/A /* Basically, emulate C_DestroyObject, including safety h2s */ 2N/A /* Can only happen if someone else just closed it. */ 2N/A /* if C_Logout fails, just ignore the error */ 2N/A /* need to deactivate all the PRIVATE token objects */ 2N/A * meta_session_dealloc 2N/A * Release the resources held by a metasession. If the session has been 2N/A * activated, it must be deactivated first. 2N/A * If there were active operations, cleanup the slot session so that 2N/A * it can be reused (otherwise provider might complain that an 2N/A * operation is active). 2N/A /* Final object cleanup. */ 2N/A * This function adds the to-be-freed meta session to a linked list. 2N/A * When the number of sessions queued in the linked list reaches the 2N/A * maximum threshold MAX_SESSION_TO_BE_FREED, it will free the first 2N/A * session (FIFO) in the list. 2N/A /* Add the newly deleted session at the end of the list */ 2N/A * Free the first session in the list only if 2N/A * the total count reaches maximum threshold.