4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright (c) 2018 by Delphix. All rights reserved.
29 #ifndef _SYS_FS_ZFS_RLOCK_H
30 #define _SYS_FS_ZFS_RLOCK_H
46 typedef void (rangelock_cb_t)(struct locked_range *, void *);
48 typedef struct rangelock {
49 avl_tree_t rl_tree; /* contains locked_range_t */
51 rangelock_cb_t *rl_cb;
55 typedef struct locked_range {
56 rangelock_t *lr_rangelock; /* rangelock that this lock applies to */
57 avl_node_t lr_node; /* avl node link */
58 uint64_t lr_offset; /* file range offset */
59 uint64_t lr_length; /* file range length */
60 uint_t lr_count; /* range reference count in tree */
61 rangelock_type_t lr_type; /* range type */
62 kcondvar_t lr_write_cv; /* cv for waiting writers */
63 kcondvar_t lr_read_cv; /* cv for waiting readers */
64 uint8_t lr_proxy; /* acting for original range */
65 uint8_t lr_write_wanted; /* writer wants to lock this range */
66 uint8_t lr_read_wanted; /* reader wants to lock this range */
69 void rangelock_init(rangelock_t *, rangelock_cb_t *, void *);
70 void rangelock_fini(rangelock_t *);
72 locked_range_t *rangelock_enter(rangelock_t *,
73 uint64_t, uint64_t, rangelock_type_t);
74 void rangelock_exit(locked_range_t *);
75 void rangelock_reduce(locked_range_t *, uint64_t, uint64_t);
81 #endif /* _SYS_FS_ZFS_RLOCK_H */