lockmap.c revision 4a19049349b8aa3a6f741b8303a0a60e1fa770c9
0N/A * The contents of this file are subject to the terms of the 0N/A * Common Development and Distribution License (the "License"). 0N/A * You may not use this file except in compliance with the License. 0N/A * See the License for the specific language governing permissions 0N/A * and limitations under the License. 0N/A * When distributing Covered Code, include this CDDL HEADER in each 0N/A * If applicable, add the following below this CDDL HEADER, with the 0N/A * fields enclosed by brackets "[]" replaced with your own identifying 0N/A * information: Portions Copyright [yyyy] [name of copyright owner] 0N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 0N/A * Use is subject to license terms. 1585N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1585N/A * These routines provide mutual exclusion between ypserv and ypxfr. 1585N/A * Mutual exclusion is needed so that ypxfr doesn't try to rename 1585N/A * dbm files while ypserv is trying to open them. After ypserv has 1585N/A * opened a dbm file, it is safe to rename it because ypserv still 1585N/A * has access to the file through its file descriptor. 1585N/A * Cross-process robust mutex locks. 1585N/A * Provide synchronization between YP processes 1585N/A * by implementing an exclusive locking mechanism 1585N/A * via a memory-mapped file. 1629N/A * Hash functions, used for by the locking mechanism. 1585N/A * - hash() is the front-end function that gets called. 1585N/A * - get_map_id() returns a unique int value per map. 1585N/A * It is used in N2L mode only. 1585N/A * It is called by hash() in N2L mode. 1629N/A * Local references to hash table for map lists 1629N/A * and to max number of maps 1585N/A /* initializes map_list_p & max_map */ 1585N/A ", giving max_map value (%d)",
1585N/A * max_map does not match any map id, hence 1311N/A * will not trigger any lock collision 0N/A * with existing maps. 0N/A * Needed for yp regular locking mechanism. 907N/A for (i =
1; *s; i +=
10, s++) {
907N/A * Initialize cross-process locks in memory-mapped file. 907N/A "init_locks_mem():mutex_init():error=%d",
907N/A * EBUSY for all locks OK, it means another process 907N/A * has already initialized locks. 907N/A * Locking file initialization algorithm, with recovery mechanism. 907N/A * This mechanism has been devised to ensure proper creation 907N/A * of a memory-mapped lock file containing mutexes for robust, 907N/A * inter-process communication. 907N/A * Try to open the file. If file doesn't exist, or size is too small, 907N/A * If file exists and size is at least large enough, assume it's a 907N/A * good file, and m-map the lock structure directly to it. 0N/A * Recovery from inconsistent state is easy - simply delete the file 0N/A * and restart NIS (YP). 342N/A "write(%s) => %d!=%d: wrong number of bytes written.",
1585N/A * File exists with correct size, is open, and we're holding 0N/A * If we wrote zeroes to the file, we also need to initialize 0N/A "remove(%s) => errno=%d: Please delete file.",
342N/A "lockf(%s,F_ULOCK) => errno=%d",
0N/A * FUNCTION : lock_map() 1311N/A * DESCRIPTION: Front end to the lock routine taking map name as argument. 541N/A * RETURNS : Same as lock_core 0N/A * DESCRIPTION: The core map locking function 0N/A * Robust, cross-process lock implementation 0N/A * Previows lock owner died, resetting lock 0N/A * to recover from error. 0N/A "mutex_init(): error=%d",
rc);
0N/A "mutex_unlock(): error=%d",
rc);
907N/A * Unrecoverable problem - nothing to do 907N/A * but exit YP and delete lock file. 0N/A "mutex_lock(): error=%d",
rc);
541N/A "remove(%s) => errno=%d: Please delete file.",
0N/A * FUNCTION : unlock_map() 1311N/A * DESCRIPTION: Front end to the unlock routine taking map name as argument. 0N/A * RETURNS : Same as unlock_core 1558N/A * DESCRIPTION: The core map locking function 1558N/A "remove(%s) => errno=%d: Please delete file.",