sharetab.c revision ecd6cf800b63704be73fb264c3f5b6e0dafc068d
a237e38e9161f0acd6451439d4a7dd597e66291dth * CDDL HEADER START
a237e38e9161f0acd6451439d4a7dd597e66291dth * The contents of this file are subject to the terms of the
a237e38e9161f0acd6451439d4a7dd597e66291dth * Common Development and Distribution License (the "License").
a237e38e9161f0acd6451439d4a7dd597e66291dth * You may not use this file except in compliance with the License.
a237e38e9161f0acd6451439d4a7dd597e66291dth * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a237e38e9161f0acd6451439d4a7dd597e66291dth * See the License for the specific language governing permissions
a237e38e9161f0acd6451439d4a7dd597e66291dth * and limitations under the License.
a237e38e9161f0acd6451439d4a7dd597e66291dth * When distributing Covered Code, include this CDDL HEADER in each
a237e38e9161f0acd6451439d4a7dd597e66291dth * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a237e38e9161f0acd6451439d4a7dd597e66291dth * If applicable, add the following below this CDDL HEADER, with the
a237e38e9161f0acd6451439d4a7dd597e66291dth * fields enclosed by brackets "[]" replaced with your own identifying
a237e38e9161f0acd6451439d4a7dd597e66291dth * information: Portions Copyright [yyyy] [name of copyright owner]
a237e38e9161f0acd6451439d4a7dd597e66291dth * CDDL HEADER END
a237e38e9161f0acd6451439d4a7dd597e66291dth * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Use is subject to license terms.
a237e38e9161f0acd6451439d4a7dd597e66291dth#pragma ident "%Z%%M% %I% %E% SMI"
a237e38e9161f0acd6451439d4a7dd597e66291dth * A macro to avoid cut-and-paste errors on getting a string field
a237e38e9161f0acd6451439d4a7dd597e66291dth * from user-land.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Need to remove 1 because copyinstr() counts the NUL. \
a237e38e9161f0acd6451439d4a7dd597e66291dthsharetab_t *sharefs_sharetab = NULL; /* The incore sharetab. */
a237e38e9161f0acd6451439d4a7dd597e66291dthkrwlock_t sharetab_lock; /* lock to protect the cached sharetab */
a237e38e9161f0acd6451439d4a7dd597e66291dthkrwlock_t sharefs_lock; /* lock to protect the vnode ops */
a237e38e9161f0acd6451439d4a7dd597e66291dthuint_t sharetab_generation; /* Only increments and wraps! */
a237e38e9161f0acd6451439d4a7dd597e66291dth * Initialize table in pseudo-random fashion
a237e38e9161f0acd6451439d4a7dd597e66291dth * for use in Pearson's string hash algorithm.
a237e38e9161f0acd6451439d4a7dd597e66291dth * See: Communications of the ACM, June 1990 Vol 33 pp 677-680
a237e38e9161f0acd6451439d4a7dd597e66291dth * http://www.acm.org/pubs/citations/journals/cacm/1990-33-6/p677-pearson
a237e38e9161f0acd6451439d4a7dd597e66291dthstatic void
a237e38e9161f0acd6451439d4a7dd597e66291dth int k = 7;
a237e38e9161f0acd6451439d4a7dd597e66291dth for (i = 0; i < SHARETAB_HASHES; i++)
a237e38e9161f0acd6451439d4a7dd597e66291dth for (j = 0; j < 4; j++) {
a237e38e9161f0acd6451439d4a7dd597e66291dth for (i = 0; i < SHARETAB_HASHES; i++) {
a237e38e9161f0acd6451439d4a7dd597e66291dth * Take care of cleaning up a share.
a237e38e9161f0acd6451439d4a7dd597e66291dth * If passed in a length array, use it to determine how much
a237e38e9161f0acd6451439d4a7dd597e66291dth * space to clean up. Else, figure that out.
a237e38e9161f0acd6451439d4a7dd597e66291dthstatic void
a237e38e9161f0acd6451439d4a7dd597e66291dth * If there is no error, then this function is responsible for
a237e38e9161f0acd6451439d4a7dd597e66291dth * cleaning up the memory associated with the share argument.
a237e38e9161f0acd6451439d4a7dd597e66291dth for (sht = sharefs_sharetab; sht != NULL; sht = sht->s_next) {
a237e38e9161f0acd6451439d4a7dd597e66291dth * There does not exist a fstype in memory which
a237e38e9161f0acd6451439d4a7dd597e66291dth * matches the share passed in.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Now walk down the hash table and find the entry to free!
a237e38e9161f0acd6451439d4a7dd597e66291dth * We need exact matches.
a237e38e9161f0acd6451439d4a7dd597e66291dth * We need to free the share for the caller.
a237e38e9161f0acd6451439d4a7dd597e66291dth return (0);
a237e38e9161f0acd6451439d4a7dd597e66291dth * The caller must have allocated memory for us to use.
a237e38e9161f0acd6451439d4a7dd597e66291dth * We need to find the hash buckets for the fstype.
a237e38e9161f0acd6451439d4a7dd597e66291dth for (sht = sharefs_sharetab; sht != NULL; sht = sht->s_next) {
a237e38e9161f0acd6451439d4a7dd597e66291dth * Did not exist, so allocate one and add it to the
a237e38e9161f0acd6451439d4a7dd597e66291dth * sharetab.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Now we need to find where we have to add the entry.
a237e38e9161f0acd6451439d4a7dd597e66291dth * We need to account for field seperators and
a237e38e9161f0acd6451439d4a7dd597e66291dth * the EOL.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Now walk down the hash table and add the new entry!
a237e38e9161f0acd6451439d4a7dd597e66291dth * We need exact matches.
a237e38e9161f0acd6451439d4a7dd597e66291dth * We found a matching path. Either we have a
a237e38e9161f0acd6451439d4a7dd597e66291dth * duplicate path in a share command or we are
a237e38e9161f0acd6451439d4a7dd597e66291dth * being asked to replace an existing entry.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Get rid of the old node.
a237e38e9161f0acd6451439d4a7dd597e66291dth return (0);
a237e38e9161f0acd6451439d4a7dd597e66291dth * Okay, we have gone through the entire hash chain and not
a237e38e9161f0acd6451439d4a7dd597e66291dth * found a match. We just need to add this node.
a237e38e9161f0acd6451439d4a7dd597e66291dth return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkssharefs_impl(enum sharefs_sys_op opcode, share_t *sh_in, uint32_t iMaxLen)
a237e38e9161f0acd6451439d4a7dd597e66291dth * Before we do anything, lets make sure we have
a237e38e9161f0acd6451439d4a7dd597e66291dth * a sharetab in memory if we need one.
a237e38e9161f0acd6451439d4a7dd597e66291dth switch (opcode) {
a237e38e9161f0acd6451439d4a7dd597e66291dth * Initialize the data pointers.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (copyin(sh_in, STRUCT_BUF(u_sh), STRUCT_SIZE(u_sh))) {
a237e38e9161f0acd6451439d4a7dd597e66291dth * Get the share.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Get some storage for copying in the strings.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Only grab these two until we know what we want.
a237e38e9161f0acd6451439d4a7dd597e66291dth switch (opcode) {
a237e38e9161f0acd6451439d4a7dd597e66291dth * If there is no error, then we have stashed the structure
a237e38e9161f0acd6451439d4a7dd597e66291dth * away in the sharetab hash table or have deleted it.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Either way, the only reason to blow away the data is if
a237e38e9161f0acd6451439d4a7dd597e66291dth * there was an error.
a237e38e9161f0acd6451439d4a7dd597e66291dth if (error != 0) {