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
37 #define rangelock_init zfs_rangelock_init
38 #define rangelock_fini zfs_rangelock_fini
49 typedef void (rangelock_cb_t)(struct locked_range *, void *);
52 typedef struct zfs_rangelock {
54 typedef struct rangelock {
56 avl_tree_t rl_tree; /* contains locked_range_t */
58 rangelock_cb_t *rl_cb;
62 typedef struct locked_range {
63 rangelock_t *lr_rangelock; /* rangelock that this lock applies to */
64 avl_node_t lr_node; /* avl node link */
65 uint64_t lr_offset; /* file range offset */
66 uint64_t lr_length; /* file range length */
67 uint_t lr_count; /* range reference count in tree */
68 rangelock_type_t lr_type; /* range type */
69 kcondvar_t lr_write_cv; /* cv for waiting writers */
70 kcondvar_t lr_read_cv; /* cv for waiting readers */
71 uint8_t lr_proxy; /* acting for original range */
72 uint8_t lr_write_wanted; /* writer wants to lock this range */
73 uint8_t lr_read_wanted; /* reader wants to lock this range */
76 void rangelock_init(rangelock_t *, rangelock_cb_t *, void *);
77 void rangelock_fini(rangelock_t *);
79 locked_range_t *rangelock_enter(rangelock_t *,
80 uint64_t, uint64_t, rangelock_type_t);
81 void rangelock_exit(locked_range_t *);
82 void rangelock_reduce(locked_range_t *, uint64_t, uint64_t);
88 #endif /* _SYS_FS_ZFS_RLOCK_H */