1669
|
1 |
/*
|
|
2 |
* CDDL HEADER START
|
|
3 |
*
|
|
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.
|
|
7 |
*
|
|
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.
|
|
12 |
*
|
|
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]
|
|
18 |
*
|
|
19 |
* CDDL HEADER END
|
|
20 |
*/
|
|
21 |
/*
|
|
22 |
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
|
|
23 |
* Use is subject to license terms.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#ifndef _SYS_FS_ZFS_RLOCK_H
|
|
27 |
#define _SYS_FS_ZFS_RLOCK_H
|
|
28 |
|
|
29 |
#pragma ident "%Z%%M% %I% %E% SMI"
|
|
30 |
|
|
31 |
#ifdef __cplusplus
|
|
32 |
extern "C" {
|
|
33 |
#endif
|
|
34 |
|
|
35 |
#ifdef _KERNEL
|
|
36 |
|
|
37 |
#include <sys/zfs_znode.h>
|
|
38 |
|
|
39 |
typedef enum {
|
|
40 |
RL_READER,
|
|
41 |
RL_WRITER,
|
|
42 |
RL_APPEND
|
|
43 |
} rl_type_t;
|
|
44 |
|
|
45 |
typedef struct rl {
|
|
46 |
avl_node_t r_node; /* avl node link */
|
|
47 |
uint64_t r_off; /* file range offset */
|
|
48 |
uint64_t r_len; /* file range length */
|
|
49 |
uint_t r_cnt; /* range reference count in tree */
|
|
50 |
rl_type_t r_type; /* range type */
|
|
51 |
kcondvar_t r_wr_cv; /* cv for waiting writers */
|
|
52 |
kcondvar_t r_rd_cv; /* cv for waiting readers */
|
|
53 |
uint8_t r_proxy; /* acting for original range */
|
|
54 |
uint8_t r_write_wanted; /* writer wants to lock this range */
|
|
55 |
uint8_t r_read_wanted; /* reader wants to lock this range */
|
|
56 |
} rl_t;
|
|
57 |
|
|
58 |
/*
|
|
59 |
* Lock a range (offset, length) as either shared (READER)
|
|
60 |
* or exclusive (WRITER or APPEND). APPEND is a special type that
|
|
61 |
* is converted to WRITER that specified to lock from the start of the
|
|
62 |
* end of file. zfs_range_lock() returns the range lock structure.
|
|
63 |
*/
|
|
64 |
rl_t *zfs_range_lock(znode_t *zp, uint64_t off, uint64_t len, rl_type_t type);
|
|
65 |
|
|
66 |
/*
|
|
67 |
* Unlock range and destroy range lock structure.
|
|
68 |
*/
|
|
69 |
void zfs_range_unlock(znode_t *zp, rl_t *rl);
|
|
70 |
|
|
71 |
/*
|
|
72 |
* Reduce range locked as RW_WRITER from whole file to specified range.
|
|
73 |
* Asserts the whole file was previously locked.
|
|
74 |
*/
|
|
75 |
void zfs_range_reduce(znode_t *zp, rl_t *rl, uint64_t off, uint64_t len);
|
|
76 |
|
|
77 |
/*
|
|
78 |
* AVL comparison function used to compare range locks
|
|
79 |
*/
|
|
80 |
int zfs_range_compare(const void *arg1, const void *arg2);
|
|
81 |
|
|
82 |
#endif /* _KERNEL */
|
|
83 |
|
|
84 |
#ifdef __cplusplus
|
|
85 |
}
|
|
86 |
#endif
|
|
87 |
|
|
88 |
#endif /* _SYS_FS_ZFS_RLOCK_H */
|