b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER START
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The contents of this file are subject to the terms of the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Common Development and Distribution License (the "License").
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You may not use this file except in compliance with the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * See the License for the specific language governing permissions
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * and limitations under the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * When distributing Covered Code, include this CDDL HEADER in each
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If applicable, add the following below this CDDL HEADER, with the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * fields enclosed by brackets "[]" replaced with your own identifying
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * information: Portions Copyright [yyyy] [name of copyright owner]
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER END
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Use is subject to license terms.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Utility routines and top-level conflict detection code for NBMAND
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Enter the critical region for synchronizing I/O requests with lock/share
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * requests. "mode" specifies whether the caller intends to update
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * lock/share state (as opposed to just query it).
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Leave the critical region.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Return non-zero if some thread is in the critical region.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Note that this is appropriate for use in ASSERT()s only.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Returns non-zero if we need to look further for an NBMAND lock or
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * share conflict.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/* ARGSUSED */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Currently we only check if NBMAND locks/shares are allowed on
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * the filesystem. An option for the future would be to have a
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * flag on the vnode, though the locking for that can get tricky.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* (vp->v_vfsp) && (vp->v_vfsp->vfs_flag & VFS_NBMAND)) */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Top-level conflict detection routine. The arguments describe the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * operation that is being attempted. If the operation conflicts with an
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * existing lock or share reservation, a non-zero value is returned. If
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * the operation is allowed, zero is returned. Note that there is an
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * implicit argument, which is the process ID of the requester.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * svmand indicates that the file has System V mandatory locking enabled,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * so we should look at all record locks, not just NBMAND record locks.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * (This is to avoid a deadlock between a process making an I/O request and
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * a process trying to release a lock. Instead of letting the first
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * process block in the filesystem code, we flag a conflict here.)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross ASSERT(op == NBL_READ || op == NBL_WRITE || op == NBL_RENAME ||
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If this is not an I/O request, there's no need to check against
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * the locks on the file.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (nbl_lock_conflict(vp, op, offset, length, svmand, ct));
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Determine if the given file has mode bits for System V mandatory locks.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If there was an error, the errno value is returned. Otherwise, zero is
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * returned and *svp is set appropriately (non-zero for mandatory locks,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * zero for no mandatory locks).
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The kernel handles this for us when we actually try I/O.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/* ARGSUSED */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossnbl_share_conflict(vnode_t *vp, nbl_op_t op, caller_context_t *ct)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The kernel handles this for us when we actually try I/O.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/* ARGSUSED */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossnbl_lock_conflict(vnode_t *vp, nbl_op_t op, u_offset_t offset,