]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - zfs/include/sys/zfs_rlock.h
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 #ifndef _SYS_FS_ZFS_RLOCK_H
27 #define _SYS_FS_ZFS_RLOCK_H
37 #include <sys/condvar.h>
45 typedef struct zfs_rlock
{
46 kmutex_t zr_mutex
; /* protects changes to zr_avl */
47 avl_tree_t zr_avl
; /* avl tree of range locks */
48 uint64_t *zr_size
; /* points to znode->z_size */
49 uint_t
*zr_blksz
; /* points to znode->z_blksz */
50 uint64_t *zr_max_blksz
; /* points to zsb->z_max_blksz */
55 avl_node_t r_node
; /* avl node link */
56 uint64_t r_off
; /* file range offset */
57 uint64_t r_len
; /* file range length */
58 uint_t r_cnt
; /* range reference count in tree */
59 rl_type_t r_type
; /* range type */
60 kcondvar_t r_wr_cv
; /* cv for waiting writers */
61 kcondvar_t r_rd_cv
; /* cv for waiting readers */
62 uint8_t r_proxy
; /* acting for original range */
63 uint8_t r_write_wanted
; /* writer wants to lock this range */
64 uint8_t r_read_wanted
; /* reader wants to lock this range */
65 list_node_t rl_node
; /* used for deferred release */
69 * Lock a range (offset, length) as either shared (RL_READER)
70 * or exclusive (RL_WRITER or RL_APPEND). RL_APPEND is a special type that
71 * is converted to RL_WRITER that specified to lock from the start of the
72 * end of file. Returns the range lock structure.
74 rl_t
*zfs_range_lock(zfs_rlock_t
*zrl
, uint64_t off
, uint64_t len
,
77 /* Unlock range and destroy range lock structure. */
78 void zfs_range_unlock(rl_t
*rl
);
81 * Reduce range locked as RW_WRITER from whole file to specified range.
82 * Asserts the whole file was previously locked.
84 void zfs_range_reduce(rl_t
*rl
, uint64_t off
, uint64_t len
);
87 * AVL comparison function used to order range locks
88 * Locks are ordered on the start offset of the range.
90 int zfs_range_compare(const void *arg1
, const void *arg2
);
93 zfs_rlock_init(zfs_rlock_t
*zrl
)
95 mutex_init(&zrl
->zr_mutex
, NULL
, MUTEX_DEFAULT
, NULL
);
96 avl_create(&zrl
->zr_avl
, zfs_range_compare
,
97 sizeof (rl_t
), offsetof(rl_t
, r_node
));
100 zrl
->zr_max_blksz
= NULL
;
104 zfs_rlock_destroy(zfs_rlock_t
*zrl
)
106 avl_destroy(&zrl
->zr_avl
);
107 mutex_destroy(&zrl
->zr_mutex
);
115 #endif /* _SYS_FS_ZFS_RLOCK_H */