xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/zfs_rlock.h (revision 2237:45affe88ed99)
11669Sperrin /*
21669Sperrin  * CDDL HEADER START
31669Sperrin  *
41669Sperrin  * The contents of this file are subject to the terms of the
51669Sperrin  * Common Development and Distribution License (the "License").
61669Sperrin  * You may not use this file except in compliance with the License.
71669Sperrin  *
81669Sperrin  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91669Sperrin  * or http://www.opensolaris.org/os/licensing.
101669Sperrin  * See the License for the specific language governing permissions
111669Sperrin  * and limitations under the License.
121669Sperrin  *
131669Sperrin  * When distributing Covered Code, include this CDDL HEADER in each
141669Sperrin  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151669Sperrin  * If applicable, add the following below this CDDL HEADER, with the
161669Sperrin  * fields enclosed by brackets "[]" replaced with your own identifying
171669Sperrin  * information: Portions Copyright [yyyy] [name of copyright owner]
181669Sperrin  *
191669Sperrin  * CDDL HEADER END
201669Sperrin  */
211669Sperrin /*
221669Sperrin  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
231669Sperrin  * Use is subject to license terms.
241669Sperrin  */
251669Sperrin 
261669Sperrin #ifndef	_SYS_FS_ZFS_RLOCK_H
271669Sperrin #define	_SYS_FS_ZFS_RLOCK_H
281669Sperrin 
291669Sperrin #pragma ident	"%Z%%M%	%I%	%E% SMI"
301669Sperrin 
311669Sperrin #ifdef	__cplusplus
321669Sperrin extern "C" {
331669Sperrin #endif
341669Sperrin 
351669Sperrin #ifdef _KERNEL
361669Sperrin 
371669Sperrin #include <sys/zfs_znode.h>
381669Sperrin 
391669Sperrin typedef enum {
401669Sperrin 	RL_READER,
411669Sperrin 	RL_WRITER,
421669Sperrin 	RL_APPEND
431669Sperrin } rl_type_t;
441669Sperrin 
451669Sperrin typedef struct rl {
46*2237Smaybee 	znode_t *r_zp;		/* znode this lock applies to */
471669Sperrin 	avl_node_t r_node;	/* avl node link */
481669Sperrin 	uint64_t r_off;		/* file range offset */
491669Sperrin 	uint64_t r_len;		/* file range length */
501669Sperrin 	uint_t r_cnt;		/* range reference count in tree */
511669Sperrin 	rl_type_t r_type;	/* range type */
521669Sperrin 	kcondvar_t r_wr_cv;	/* cv for waiting writers */
531669Sperrin 	kcondvar_t r_rd_cv;	/* cv for waiting readers */
541669Sperrin 	uint8_t r_proxy;	/* acting for original range */
551669Sperrin 	uint8_t r_write_wanted;	/* writer wants to lock this range */
561669Sperrin 	uint8_t r_read_wanted;	/* reader wants to lock this range */
571669Sperrin } rl_t;
581669Sperrin 
591669Sperrin /*
601669Sperrin  * Lock a range (offset, length) as either shared (READER)
611669Sperrin  * or exclusive (WRITER or APPEND). APPEND is a special type that
621669Sperrin  * is converted to WRITER that specified to lock from the start of the
631669Sperrin  * end of file.  zfs_range_lock() returns the range lock structure.
641669Sperrin  */
651669Sperrin rl_t *zfs_range_lock(znode_t *zp, uint64_t off, uint64_t len, rl_type_t type);
661669Sperrin 
671669Sperrin /*
681669Sperrin  * Unlock range and destroy range lock structure.
691669Sperrin  */
70*2237Smaybee void zfs_range_unlock(rl_t *rl);
711669Sperrin 
721669Sperrin /*
731669Sperrin  * Reduce range locked as RW_WRITER from whole file to specified range.
741669Sperrin  * Asserts the whole file was previously locked.
751669Sperrin  */
76*2237Smaybee void zfs_range_reduce(rl_t *rl, uint64_t off, uint64_t len);
771669Sperrin 
781669Sperrin /*
791669Sperrin  * AVL comparison function used to compare range locks
801669Sperrin  */
811669Sperrin int zfs_range_compare(const void *arg1, const void *arg2);
821669Sperrin 
831669Sperrin #endif /* _KERNEL */
841669Sperrin 
851669Sperrin #ifdef	__cplusplus
861669Sperrin }
871669Sperrin #endif
881669Sperrin 
891669Sperrin #endif	/* _SYS_FS_ZFS_RLOCK_H */
90