/[gentoo-x86]/sys-fs/zfs/files/zfs-0.6.0_rc9-range-lock-caller-allocate.patch
Gentoo

Diff of /sys-fs/zfs/files/zfs-0.6.0_rc9-range-lock-caller-allocate.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.3
1commit 4bbb86db6d6da5c05c452a810f20ffb19d6918de 1From fc1f1d3940f4d2e5b1b85481d900d8198cf4b6f3 Mon Sep 17 00:00:00 2001
2Author: Richard Yao <ryao@cs.stonybrook.edu> 2From: Richard Yao <ryao@cs.stonybrook.edu>
3Date: Sun Jun 24 20:11:40 2012 -0400 3Date: Mon, 25 Jun 2012 14:41:30 -0400
4Subject: [PATCH] Make callers responsible for memory allocation in
5 zfs_range_lock()
4 6
5 Make callers responsible for memory allocation in zfs_range_lock()
6
7 zfs_range_lock() is used in zvols, and previously, it could deadlock due 7zfs_range_lock() is used in zvols, and previously, it could deadlock due
8 to an allocation using KM_SLEEP. We avoid this by moving responsibility 8to an allocation using KM_SLEEP. We avoid this by moving responsibility
9 the memory allocation from zfs_range_lock() to the caller. This enables 9the memory allocation from zfs_range_lock() to the caller. This enables
10 us to avoid such deadlocks and use stack allocations, which are more 10us to avoid such deadlocks and use stack allocations, which are more
11 efficient and prevents deadlocks. The contexts in which stack 11efficient and prevents deadlocks. The contexts in which stack
12 allocations are done do not appear to be stack heavy, so we do not risk 12allocations are done do not appear to be stack heavy, so we do not risk
13 overflowing the stack from doing this. 13overflowing the stack from doing this.
14 14
15 Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu> 15Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
16 16
17 Conflicts: 17Conflicts:
18 18
19 module/zfs/zvol.c 19 module/zfs/zvol.c
20---
21 cmd/ztest/ztest.c | 32 +++++++++++++++++---------------
22 include/sys/zfs_rlock.h | 2 +-
23 module/zfs/zfs_rlock.c | 15 +++++++--------
24 module/zfs/zfs_vnops.c | 30 ++++++++++++++++--------------
25 module/zfs/zfs_znode.c | 30 +++++++++++++++---------------
26 module/zfs/zvol.c | 24 +++++++++++++-----------
27 6 files changed, 69 insertions(+), 64 deletions(-)
20 28
21diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c 29diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c
22index 72d511b..c5dd0c2 100644 30index 72d511b..c5dd0c2 100644
23--- a/cmd/ztest/ztest.c 31--- a/cmd/ztest/ztest.c
24+++ b/cmd/ztest/ztest.c 32+++ b/cmd/ztest/ztest.c
25@@ -973,12 +973,11 @@ ztest_object_unlock(ztest_ds_t *zd, uint64_t object) 33@@ -973,12 +973,11 @@ enum ztest_object {
26 } 34 }
27 35
28 static rl_t * 36 static rl_t *
29-ztest_range_lock(ztest_ds_t *zd, uint64_t object, uint64_t offset, 37-ztest_range_lock(ztest_ds_t *zd, uint64_t object, uint64_t offset,
30+ztest_range_lock(rl_t *rl, ztest_ds_t *zd, uint64_t object, uint64_t offset, 38+ztest_range_lock(rl_t *rl, ztest_ds_t *zd, uint64_t object, uint64_t offset,
34 rll_t *rll = &zd->zd_range_lock[hash & (ZTEST_RANGE_LOCKS - 1)]; 42 rll_t *rll = &zd->zd_range_lock[hash & (ZTEST_RANGE_LOCKS - 1)];
35- rl_t *rl; 43- rl_t *rl;
36 44
37 rl = umem_alloc(sizeof (*rl), UMEM_NOFAIL); 45 rl = umem_alloc(sizeof (*rl), UMEM_NOFAIL);
38 rl->rl_object = object; 46 rl->rl_object = object;
39@@ -1389,7 +1388,7 @@ ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap) 47@@ -1389,7 +1388,7 @@ enum ztest_object {
40 dmu_tx_t *tx; 48 dmu_tx_t *tx;
41 dmu_buf_t *db; 49 dmu_buf_t *db;
42 arc_buf_t *abuf = NULL; 50 arc_buf_t *abuf = NULL;
43- rl_t *rl; 51- rl_t *rl;
44+ rl_t rl; 52+ rl_t rl;
45 53
46 if (byteswap) 54 if (byteswap)
47 byteswap_uint64_array(lr, sizeof (*lr)); 55 byteswap_uint64_array(lr, sizeof (*lr));
48@@ -1413,7 +1412,7 @@ ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap) 56@@ -1413,7 +1412,7 @@ enum ztest_object {
49 bt = NULL; 57 bt = NULL;
50 58
51 ztest_object_lock(zd, lr->lr_foid, RL_READER); 59 ztest_object_lock(zd, lr->lr_foid, RL_READER);
52- rl = ztest_range_lock(zd, lr->lr_foid, offset, length, RL_WRITER); 60- rl = ztest_range_lock(zd, lr->lr_foid, offset, length, RL_WRITER);
53+ ztest_range_lock(&rl, zd, lr->lr_foid, offset, length, RL_WRITER); 61+ ztest_range_lock(&rl, zd, lr->lr_foid, offset, length, RL_WRITER);
54 62
55 VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db)); 63 VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
56 64
57@@ -1438,7 +1437,7 @@ ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap) 65@@ -1438,7 +1437,7 @@ enum ztest_object {
58 if (abuf != NULL) 66 if (abuf != NULL)
59 dmu_return_arcbuf(abuf); 67 dmu_return_arcbuf(abuf);
60 dmu_buf_rele(db, FTAG); 68 dmu_buf_rele(db, FTAG);
61- ztest_range_unlock(rl); 69- ztest_range_unlock(rl);
62+ ztest_range_unlock(&rl); 70+ ztest_range_unlock(&rl);
63 ztest_object_unlock(zd, lr->lr_foid); 71 ztest_object_unlock(zd, lr->lr_foid);
64 return (ENOSPC); 72 return (ENOSPC);
65 } 73 }
66@@ -1495,7 +1494,7 @@ ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap) 74@@ -1495,7 +1494,7 @@ enum ztest_object {
67 75
68 dmu_tx_commit(tx); 76 dmu_tx_commit(tx);
69 77
70- ztest_range_unlock(rl); 78- ztest_range_unlock(rl);
71+ ztest_range_unlock(&rl); 79+ ztest_range_unlock(&rl);
72 ztest_object_unlock(zd, lr->lr_foid); 80 ztest_object_unlock(zd, lr->lr_foid);
73 81
74 return (0); 82 return (0);
75@@ -1507,13 +1506,13 @@ ztest_replay_truncate(ztest_ds_t *zd, lr_truncate_t *lr, boolean_t byteswap) 83@@ -1507,13 +1506,13 @@ enum ztest_object {
76 objset_t *os = zd->zd_os; 84 objset_t *os = zd->zd_os;
77 dmu_tx_t *tx; 85 dmu_tx_t *tx;
78 uint64_t txg; 86 uint64_t txg;
79- rl_t *rl; 87- rl_t *rl;
80+ rl_t rl; 88+ rl_t rl;
86- rl = ztest_range_lock(zd, lr->lr_foid, lr->lr_offset, lr->lr_length, 94- rl = ztest_range_lock(zd, lr->lr_foid, lr->lr_offset, lr->lr_length,
87+ ztest_range_lock(&rl, zd, lr->lr_foid, lr->lr_offset, lr->lr_length, 95+ ztest_range_lock(&rl, zd, lr->lr_foid, lr->lr_offset, lr->lr_length,
88 RL_WRITER); 96 RL_WRITER);
89 97
90 tx = dmu_tx_create(os); 98 tx = dmu_tx_create(os);
91@@ -1522,7 +1521,7 @@ ztest_replay_truncate(ztest_ds_t *zd, lr_truncate_t *lr, boolean_t byteswap) 99@@ -1522,7 +1521,7 @@ enum ztest_object {
92 100
93 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG); 101 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
94 if (txg == 0) { 102 if (txg == 0) {
95- ztest_range_unlock(rl); 103- ztest_range_unlock(rl);
96+ ztest_range_unlock(&rl); 104+ ztest_range_unlock(&rl);
97 ztest_object_unlock(zd, lr->lr_foid); 105 ztest_object_unlock(zd, lr->lr_foid);
98 return (ENOSPC); 106 return (ENOSPC);
99 } 107 }
100@@ -1534,7 +1533,7 @@ ztest_replay_truncate(ztest_ds_t *zd, lr_truncate_t *lr, boolean_t byteswap) 108@@ -1534,7 +1533,7 @@ enum ztest_object {
101 109
102 dmu_tx_commit(tx); 110 dmu_tx_commit(tx);
103 111
104- ztest_range_unlock(rl); 112- ztest_range_unlock(rl);
105+ ztest_range_unlock(&rl); 113+ ztest_range_unlock(&rl);
106 ztest_object_unlock(zd, lr->lr_foid); 114 ztest_object_unlock(zd, lr->lr_foid);
107 115
108 return (0); 116 return (0);
109@@ -1670,6 +1669,8 @@ ztest_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) 117@@ -1670,6 +1669,8 @@ enum ztest_object {
110 dmu_object_info_t doi; 118 dmu_object_info_t doi;
111 dmu_buf_t *db; 119 dmu_buf_t *db;
112 zgd_t *zgd; 120 zgd_t *zgd;
113+ rl_t rl; 121+ rl_t rl;
114+ 122+
115 int error; 123 int error;
116 124
117 ztest_object_lock(zd, object, RL_READER); 125 ztest_object_lock(zd, object, RL_READER);
118@@ -1694,9 +1695,10 @@ ztest_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) 126@@ -1694,9 +1695,10 @@ enum ztest_object {
119 zgd = umem_zalloc(sizeof (*zgd), UMEM_NOFAIL); 127 zgd = umem_zalloc(sizeof (*zgd), UMEM_NOFAIL);
120 zgd->zgd_zilog = zd->zd_zilog; 128 zgd->zgd_zilog = zd->zd_zilog;
121 zgd->zgd_private = zd; 129 zgd->zgd_private = zd;
122+ zgd->zgd_rl = &rl; 130+ zgd->zgd_rl = &rl;
123 131
125- zgd->zgd_rl = ztest_range_lock(zd, object, offset, size, 133- zgd->zgd_rl = ztest_range_lock(zd, object, offset, size,
126+ ztest_range_lock(zgd->zgd_rl, zd, object, offset, size, 134+ ztest_range_lock(zgd->zgd_rl, zd, object, offset, size,
127 RL_READER); 135 RL_READER);
128 136
129 error = dmu_read(os, object, offset, size, buf, 137 error = dmu_read(os, object, offset, size, buf,
130@@ -1711,7 +1713,7 @@ ztest_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) 138@@ -1711,7 +1713,7 @@ enum ztest_object {
131 offset = 0; 139 offset = 0;
132 } 140 }
133 141
134- zgd->zgd_rl = ztest_range_lock(zd, object, offset, size, 142- zgd->zgd_rl = ztest_range_lock(zd, object, offset, size,
135+ ztest_range_lock(zgd->zgd_rl, zd, object, offset, size, 143+ ztest_range_lock(zgd->zgd_rl, zd, object, offset, size,
136 RL_READER); 144 RL_READER);
137 145
138 error = dmu_buf_hold(os, object, offset, zgd, &db, 146 error = dmu_buf_hold(os, object, offset, zgd, &db,
139@@ -1953,12 +1955,12 @@ ztest_prealloc(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size) 147@@ -1953,12 +1955,12 @@ enum ztest_object {
140 objset_t *os = zd->zd_os; 148 objset_t *os = zd->zd_os;
141 dmu_tx_t *tx; 149 dmu_tx_t *tx;
142 uint64_t txg; 150 uint64_t txg;
143- rl_t *rl; 151- rl_t *rl;
144+ rl_t rl; 152+ rl_t rl;
149- rl = ztest_range_lock(zd, object, offset, size, RL_WRITER); 157- rl = ztest_range_lock(zd, object, offset, size, RL_WRITER);
150+ ztest_range_lock(&rl, zd, object, offset, size, RL_WRITER); 158+ ztest_range_lock(&rl, zd, object, offset, size, RL_WRITER);
151 159
152 tx = dmu_tx_create(os); 160 tx = dmu_tx_create(os);
153 161
154@@ -1974,7 +1976,7 @@ ztest_prealloc(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size) 162@@ -1974,7 +1976,7 @@ enum ztest_object {
155 (void) dmu_free_long_range(os, object, offset, size); 163 (void) dmu_free_long_range(os, object, offset, size);
156 } 164 }
157 165
158- ztest_range_unlock(rl); 166- ztest_range_unlock(rl);
159+ ztest_range_unlock(&rl); 167+ ztest_range_unlock(&rl);
162 170
163diff --git a/include/sys/zfs_rlock.h b/include/sys/zfs_rlock.h 171diff --git a/include/sys/zfs_rlock.h b/include/sys/zfs_rlock.h
164index da18b1f..85dc16a 100644 172index da18b1f..85dc16a 100644
165--- a/include/sys/zfs_rlock.h 173--- a/include/sys/zfs_rlock.h
166+++ b/include/sys/zfs_rlock.h 174+++ b/include/sys/zfs_rlock.h
167@@ -63,7 +63,7 @@ typedef struct rl { 175@@ -63,7 +63,7 @@
168 * is converted to WRITER that specified to lock from the start of the 176 * is converted to WRITER that specified to lock from the start of the
169 * end of file. zfs_range_lock() returns the range lock structure. 177 * end of file. zfs_range_lock() returns the range lock structure.
170 */ 178 */
171-rl_t *zfs_range_lock(znode_t *zp, uint64_t off, uint64_t len, rl_type_t type); 179-rl_t *zfs_range_lock(znode_t *zp, uint64_t off, uint64_t len, rl_type_t type);
172+rl_t *zfs_range_lock(rl_t *rl, znode_t *zp, uint64_t off, uint64_t len, rl_type_t type); 180+rl_t *zfs_range_lock(rl_t *rl, znode_t *zp, uint64_t off, uint64_t len, rl_type_t type);
173 181
174 /* 182 /*
175 * Unlock range and destroy range lock structure. 183 * Unlock range and destroy range lock structure.
176diff --git a/module/zfs/zfs_rlock.c b/module/zfs/zfs_rlock.c 184diff --git a/module/zfs/zfs_rlock.c b/module/zfs/zfs_rlock.c
177index f3ada17..6e9afc0 100644 185index f3ada17..eb81777 100644
178--- a/module/zfs/zfs_rlock.c 186--- a/module/zfs/zfs_rlock.c
179+++ b/module/zfs/zfs_rlock.c 187+++ b/module/zfs/zfs_rlock.c
180@@ -31,9 +31,9 @@ 188@@ -31,9 +31,9 @@
181 * Interface 189 * Interface
182 * --------- 190 * ---------
188+ * zfs_range_unlock(&rl); 196+ * zfs_range_unlock(&rl);
189+ * zfs_range_reduce(&rl, off, len); 197+ * zfs_range_reduce(&rl, off, len);
190 * 198 *
191 * AVL tree 199 * AVL tree
192 * -------- 200 * --------
193@@ -420,13 +420,11 @@ got_lock: 201@@ -420,13 +420,11 @@
194 * previously locked as RL_WRITER). 202 * previously locked as RL_WRITER).
195 */ 203 */
196 rl_t * 204 rl_t *
197-zfs_range_lock(znode_t *zp, uint64_t off, uint64_t len, rl_type_t type) 205-zfs_range_lock(znode_t *zp, uint64_t off, uint64_t len, rl_type_t type)
198+zfs_range_lock(rl_t *new, znode_t *zp, uint64_t off, uint64_t len, rl_type_t type) 206+zfs_range_lock(rl_t *new, znode_t *zp, uint64_t off, uint64_t len, rl_type_t type)
203 211
204- new = kmem_alloc(sizeof (rl_t), KM_SLEEP); 212- new = kmem_alloc(sizeof (rl_t), KM_SLEEP);
205 new->r_zp = zp; 213 new->r_zp = zp;
206 new->r_off = off; 214 new->r_off = off;
207 if (len + off < off) /* overflow */ 215 if (len + off < off) /* overflow */
216@@ -531,7 +529,6 @@
217 }
218
219 mutex_exit(&zp->z_range_lock);
220- kmem_free(remove, sizeof (rl_t));
221 }
222 }
223
224@@ -572,7 +569,9 @@
225
226 while ((free_rl = list_head(&free_list)) != NULL) {
227 list_remove(&free_list, free_rl);
228- zfs_range_free(free_rl);
229+ /* Freeing rl is the caller's responsibility */
230+ if (free_rl != rl)
231+ zfs_range_free(free_rl);
232 }
233
234 list_destroy(&free_list);
208diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c 235diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c
209index 2da5fec..039269a 100644 236index 2da5fec..c8ca7c5 100644
210--- a/module/zfs/zfs_vnops.c 237--- a/module/zfs/zfs_vnops.c
211+++ b/module/zfs/zfs_vnops.c 238+++ b/module/zfs/zfs_vnops.c
212@@ -370,7 +370,7 @@ zfs_read(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr) 239@@ -370,7 +370,7 @@
213 objset_t *os; 240 objset_t *os;
214 ssize_t n, nbytes; 241 ssize_t n, nbytes;
215 int error = 0; 242 int error = 0;
216- rl_t *rl; 243- rl_t *rl;
217+ rl_t rl; 244+ rl_t rl;
218 #ifdef HAVE_UIO_ZEROCOPY 245 #ifdef HAVE_UIO_ZEROCOPY
219 xuio_t *xuio = NULL; 246 xuio_t *xuio = NULL;
220 #endif /* HAVE_UIO_ZEROCOPY */ 247 #endif /* HAVE_UIO_ZEROCOPY */
221@@ -418,7 +418,7 @@ zfs_read(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr) 248@@ -418,7 +418,7 @@
222 /* 249 /*
223 * Lock the range against changes. 250 * Lock the range against changes.
224 */ 251 */
225- rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER); 252- rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
226+ zfs_range_lock(&rl, zp, uio->uio_loffset, uio->uio_resid, RL_READER); 253+ zfs_range_lock(&rl, zp, uio->uio_loffset, uio->uio_resid, RL_READER);
227 254
228 /* 255 /*
229 * If we are reading past end-of-file we can skip 256 * If we are reading past end-of-file we can skip
230@@ -482,7 +482,7 @@ zfs_read(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr) 257@@ -482,7 +482,7 @@
231 n -= nbytes; 258 n -= nbytes;
232 } 259 }
233 out: 260 out:
234- zfs_range_unlock(rl); 261- zfs_range_unlock(rl);
235+ zfs_range_unlock(&rl); 262+ zfs_range_unlock(&rl);
236 263
237 ZFS_ACCESSTIME_STAMP(zsb, zp); 264 ZFS_ACCESSTIME_STAMP(zsb, zp);
238 zfs_inode_update(zp); 265 zfs_inode_update(zp);
239@@ -524,7 +524,7 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr) 266@@ -524,7 +524,7 @@
240 zilog_t *zilog; 267 zilog_t *zilog;
241 offset_t woff; 268 offset_t woff;
242 ssize_t n, nbytes; 269 ssize_t n, nbytes;
243- rl_t *rl; 270- rl_t *rl;
244+ rl_t rl; 271+ rl_t rl;
245 int max_blksz = zsb->z_max_blksz; 272 int max_blksz = zsb->z_max_blksz;
246 int error = 0; 273 int error = 0;
247 arc_buf_t *abuf; 274 arc_buf_t *abuf;
248@@ -608,9 +608,9 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr) 275@@ -608,9 +608,9 @@
249 * Obtain an appending range lock to guarantee file append 276 * Obtain an appending range lock to guarantee file append
250 * semantics. We reset the write offset once we have the lock. 277 * semantics. We reset the write offset once we have the lock.
251 */ 278 */
252- rl = zfs_range_lock(zp, 0, n, RL_APPEND); 279- rl = zfs_range_lock(zp, 0, n, RL_APPEND);
253- woff = rl->r_off; 280- woff = rl->r_off;
256+ woff = rl.r_off; 283+ woff = rl.r_off;
257+ if (rl.r_len == UINT64_MAX) { 284+ if (rl.r_len == UINT64_MAX) {
258 /* 285 /*
259 * We overlocked the file because this write will cause 286 * We overlocked the file because this write will cause
260 * the file block size to increase. 287 * the file block size to increase.
261@@ -625,11 +625,11 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr) 288@@ -625,11 +625,11 @@
262 * this write, then this range lock will lock the entire file 289 * this write, then this range lock will lock the entire file
263 * so that we can re-write the block safely. 290 * so that we can re-write the block safely.
264 */ 291 */
265- rl = zfs_range_lock(zp, woff, n, RL_WRITER); 292- rl = zfs_range_lock(zp, woff, n, RL_WRITER);
266+ zfs_range_lock(&rl, zp, woff, n, RL_WRITER); 293+ zfs_range_lock(&rl, zp, woff, n, RL_WRITER);
270- zfs_range_unlock(rl); 297- zfs_range_unlock(rl);
271+ zfs_range_unlock(&rl); 298+ zfs_range_unlock(&rl);
272 ZFS_EXIT(zsb); 299 ZFS_EXIT(zsb);
273 return (EFBIG); 300 return (EFBIG);
274 } 301 }
275@@ -719,7 +719,7 @@ again: 302@@ -719,7 +719,7 @@
276 * on the first iteration since zfs_range_reduce() will 303 * on the first iteration since zfs_range_reduce() will
277 * shrink down r_len to the appropriate size. 304 * shrink down r_len to the appropriate size.
278 */ 305 */
279- if (rl->r_len == UINT64_MAX) { 306- if (rl->r_len == UINT64_MAX) {
280+ if (rl.r_len == UINT64_MAX) { 307+ if (rl.r_len == UINT64_MAX) {
281 uint64_t new_blksz; 308 uint64_t new_blksz;
282 309
283 if (zp->z_blksz > max_blksz) { 310 if (zp->z_blksz > max_blksz) {
284@@ -729,7 +729,7 @@ again: 311@@ -729,7 +729,7 @@
285 new_blksz = MIN(end_size, max_blksz); 312 new_blksz = MIN(end_size, max_blksz);
286 } 313 }
287 zfs_grow_blocksize(zp, new_blksz, tx); 314 zfs_grow_blocksize(zp, new_blksz, tx);
288- zfs_range_reduce(rl, woff, n); 315- zfs_range_reduce(rl, woff, n);
289+ zfs_range_reduce(&rl, woff, n); 316+ zfs_range_reduce(&rl, woff, n);
290 } 317 }
291 318
292 /* 319 /*
293@@ -842,7 +842,7 @@ again: 320@@ -842,7 +842,7 @@
294 uio_prefaultpages(MIN(n, max_blksz), uio); 321 uio_prefaultpages(MIN(n, max_blksz), uio);
295 } 322 }
296 323
297- zfs_range_unlock(rl); 324- zfs_range_unlock(rl);
298+ zfs_range_unlock(&rl); 325+ zfs_range_unlock(&rl);
299 326
300 /* 327 /*
301 * If we're in replay mode, or we made no progress, return error. 328 * If we're in replay mode, or we made no progress, return error.
302@@ -946,7 +946,7 @@ zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) 329@@ -915,6 +915,7 @@
330 blkptr_t *bp = &lr->lr_blkptr;
331 dmu_buf_t *db;
332 zgd_t *zgd;
333+ rl_t rl;
334 int error = 0;
335
336 ASSERT(zio != NULL);
337@@ -935,6 +936,7 @@
338 }
339
340 zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
341+ zgd->zgd_rl = &rl;
342 zgd->zgd_zilog = zsb->z_log;
343 zgd->zgd_private = zp;
344
345@@ -946,7 +948,7 @@
303 * we don't have to write the data twice. 346 * we don't have to write the data twice.
304 */ 347 */
305 if (buf != NULL) { /* immediate write */ 348 if (buf != NULL) { /* immediate write */
306- zgd->zgd_rl = zfs_range_lock(zp, offset, size, RL_READER); 349- zgd->zgd_rl = zfs_range_lock(zp, offset, size, RL_READER);
307+ zfs_range_lock(zgd->zgd_rl, zp, offset, size, RL_READER); 350+ zfs_range_lock(zgd->zgd_rl, zp, offset, size, RL_READER);
308 /* test for truncation needs to be done while range locked */ 351 /* test for truncation needs to be done while range locked */
309 if (offset >= zp->z_size) { 352 if (offset >= zp->z_size) {
310 error = ENOENT; 353 error = ENOENT;
311@@ -967,7 +967,7 @@ zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) 354@@ -967,7 +969,7 @@
312 size = zp->z_blksz; 355 size = zp->z_blksz;
313 blkoff = ISP2(size) ? P2PHASE(offset, size) : offset; 356 blkoff = ISP2(size) ? P2PHASE(offset, size) : offset;
314 offset -= blkoff; 357 offset -= blkoff;
315- zgd->zgd_rl = zfs_range_lock(zp, offset, size, 358- zgd->zgd_rl = zfs_range_lock(zp, offset, size,
316+ zfs_range_lock(zgd->zgd_rl, zp, offset, size, 359+ zfs_range_lock(zgd->zgd_rl, zp, offset, size,
319 break; 362 break;
320diff --git a/module/zfs/zfs_znode.c b/module/zfs/zfs_znode.c 363diff --git a/module/zfs/zfs_znode.c b/module/zfs/zfs_znode.c
321index 3a6872f..e363839 100644 364index 3a6872f..e363839 100644
322--- a/module/zfs/zfs_znode.c 365--- a/module/zfs/zfs_znode.c
323+++ b/module/zfs/zfs_znode.c 366+++ b/module/zfs/zfs_znode.c
324@@ -1158,20 +1158,20 @@ zfs_extend(znode_t *zp, uint64_t end) 367@@ -1158,20 +1158,20 @@
325 { 368 {
326 zfs_sb_t *zsb = ZTOZSB(zp); 369 zfs_sb_t *zsb = ZTOZSB(zp);
327 dmu_tx_t *tx; 370 dmu_tx_t *tx;
328- rl_t *rl; 371- rl_t *rl;
329+ rl_t rl; 372+ rl_t rl;
343- zfs_range_unlock(rl); 386- zfs_range_unlock(rl);
344+ zfs_range_unlock(&rl); 387+ zfs_range_unlock(&rl);
345 return (0); 388 return (0);
346 } 389 }
347 top: 390 top:
348@@ -1202,7 +1202,7 @@ top: 391@@ -1202,7 +1202,7 @@
349 goto top; 392 goto top;
350 } 393 }
351 dmu_tx_abort(tx); 394 dmu_tx_abort(tx);
352- zfs_range_unlock(rl); 395- zfs_range_unlock(rl);
353+ zfs_range_unlock(&rl); 396+ zfs_range_unlock(&rl);
354 return (error); 397 return (error);
355 } 398 }
356 399
357@@ -1214,7 +1214,7 @@ top: 400@@ -1214,7 +1214,7 @@
358 VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(ZTOZSB(zp)), 401 VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(ZTOZSB(zp)),
359 &zp->z_size, sizeof (zp->z_size), tx)); 402 &zp->z_size, sizeof (zp->z_size), tx));
360 403
361- zfs_range_unlock(rl); 404- zfs_range_unlock(rl);
362+ zfs_range_unlock(&rl); 405+ zfs_range_unlock(&rl);
363 406
364 dmu_tx_commit(tx); 407 dmu_tx_commit(tx);
365 408
366@@ -1235,19 +1235,19 @@ static int 409@@ -1235,19 +1235,19 @@
367 zfs_free_range(znode_t *zp, uint64_t off, uint64_t len) 410 zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
368 { 411 {
369 zfs_sb_t *zsb = ZTOZSB(zp); 412 zfs_sb_t *zsb = ZTOZSB(zp);
370- rl_t *rl; 413- rl_t *rl;
371+ rl_t rl; 414+ rl_t rl;
384- zfs_range_unlock(rl); 427- zfs_range_unlock(rl);
385+ zfs_range_unlock(&rl); 428+ zfs_range_unlock(&rl);
386 return (0); 429 return (0);
387 } 430 }
388 431
389@@ -1256,7 +1256,7 @@ zfs_free_range(znode_t *zp, uint64_t off, uint64_t len) 432@@ -1256,7 +1256,7 @@
390 433
391 error = dmu_free_long_range(zsb->z_os, zp->z_id, off, len); 434 error = dmu_free_long_range(zsb->z_os, zp->z_id, off, len);
392 435
393- zfs_range_unlock(rl); 436- zfs_range_unlock(rl);
394+ zfs_range_unlock(&rl); 437+ zfs_range_unlock(&rl);
395 438
396 return (error); 439 return (error);
397 } 440 }
398@@ -1275,7 +1275,7 @@ zfs_trunc(znode_t *zp, uint64_t end) 441@@ -1275,7 +1275,7 @@
399 { 442 {
400 zfs_sb_t *zsb = ZTOZSB(zp); 443 zfs_sb_t *zsb = ZTOZSB(zp);
401 dmu_tx_t *tx; 444 dmu_tx_t *tx;
402- rl_t *rl; 445- rl_t *rl;
403+ rl_t rl; 446+ rl_t rl;
404 int error; 447 int error;
405 sa_bulk_attr_t bulk[2]; 448 sa_bulk_attr_t bulk[2];
406 int count = 0; 449 int count = 0;
407@@ -1283,19 +1283,19 @@ zfs_trunc(znode_t *zp, uint64_t end) 450@@ -1283,19 +1283,19 @@
408 /* 451 /*
409 * We will change zp_size, lock the whole file. 452 * We will change zp_size, lock the whole file.
410 */ 453 */
411- rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER); 454- rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
412+ zfs_range_lock(&rl, zp, 0, UINT64_MAX, RL_WRITER); 455+ zfs_range_lock(&rl, zp, 0, UINT64_MAX, RL_WRITER);
425- zfs_range_unlock(rl); 468- zfs_range_unlock(rl);
426+ zfs_range_unlock(&rl); 469+ zfs_range_unlock(&rl);
427 return (error); 470 return (error);
428 } 471 }
429 top: 472 top:
430@@ -1310,7 +1310,7 @@ top: 473@@ -1310,7 +1310,7 @@
431 goto top; 474 goto top;
432 } 475 }
433 dmu_tx_abort(tx); 476 dmu_tx_abort(tx);
434- zfs_range_unlock(rl); 477- zfs_range_unlock(rl);
435+ zfs_range_unlock(&rl); 478+ zfs_range_unlock(&rl);
436 return (error); 479 return (error);
437 } 480 }
438 481
439@@ -1327,7 +1327,7 @@ top: 482@@ -1327,7 +1327,7 @@
440 483
441 dmu_tx_commit(tx); 484 dmu_tx_commit(tx);
442 485
443- zfs_range_unlock(rl); 486- zfs_range_unlock(rl);
444+ zfs_range_unlock(&rl); 487+ zfs_range_unlock(&rl);
445 488
446 return (0); 489 return (0);
447 } 490 }
448diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c 491diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c
449index 125d58d..5cae597 100644 492index 125d58d..bbe53d9 100644
450--- a/module/zfs/zvol.c 493--- a/module/zfs/zvol.c
451+++ b/module/zfs/zvol.c 494+++ b/module/zfs/zvol.c
452@@ -537,7 +537,7 @@ zvol_write(void *arg) 495@@ -537,7 +537,7 @@
453 uint64_t size = blk_rq_bytes(req); 496 uint64_t size = blk_rq_bytes(req);
454 int error = 0; 497 int error = 0;
455 dmu_tx_t *tx; 498 dmu_tx_t *tx;
456- rl_t *rl; 499- rl_t *rl;
457+ rl_t rl; 500+ rl_t rl;
458 501
459 if (req->cmd_flags & VDEV_REQ_FLUSH) 502 if (req->cmd_flags & VDEV_REQ_FLUSH)
460 zil_commit(zv->zv_zilog, ZVOL_OBJ); 503 zil_commit(zv->zv_zilog, ZVOL_OBJ);
461@@ -550,7 +550,7 @@ zvol_write(void *arg) 504@@ -550,7 +550,7 @@
462 return; 505 return;
463 } 506 }
464 507
465- rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_WRITER); 508- rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_WRITER);
466+ zfs_range_lock(&rl, &zv->zv_znode, offset, size, RL_WRITER); 509+ zfs_range_lock(&rl, &zv->zv_znode, offset, size, RL_WRITER);
467 510
468 tx = dmu_tx_create(zv->zv_objset); 511 tx = dmu_tx_create(zv->zv_objset);
469 dmu_tx_hold_write(tx, ZVOL_OBJ, offset, size); 512 dmu_tx_hold_write(tx, ZVOL_OBJ, offset, size);
470@@ -559,7 +559,7 @@ zvol_write(void *arg) 513@@ -559,7 +559,7 @@
471 error = dmu_tx_assign(tx, TXG_WAIT); 514 error = dmu_tx_assign(tx, TXG_WAIT);
472 if (error) { 515 if (error) {
473 dmu_tx_abort(tx); 516 dmu_tx_abort(tx);
474- zfs_range_unlock(rl); 517- zfs_range_unlock(rl);
475+ zfs_range_unlock(&rl); 518+ zfs_range_unlock(&rl);
476 blk_end_request(req, -error, size); 519 blk_end_request(req, -error, size);
477 return; 520 return;
478 } 521 }
479@@ -570,7 +570,7 @@ zvol_write(void *arg) 522@@ -570,7 +570,7 @@
480 req->cmd_flags & VDEV_REQ_FUA); 523 req->cmd_flags & VDEV_REQ_FUA);
481 524
482 dmu_tx_commit(tx); 525 dmu_tx_commit(tx);
483- zfs_range_unlock(rl); 526- zfs_range_unlock(rl);
484+ zfs_range_unlock(&rl); 527+ zfs_range_unlock(&rl);
485 528
486 if ((req->cmd_flags & VDEV_REQ_FUA) || 529 if ((req->cmd_flags & VDEV_REQ_FUA) ||
487 zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS) 530 zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS)
488@@ -589,7 +589,7 @@ zvol_discard(void *arg) 531@@ -589,7 +589,7 @@
489 uint64_t offset = blk_rq_pos(req) << 9; 532 uint64_t offset = blk_rq_pos(req) << 9;
490 uint64_t size = blk_rq_bytes(req); 533 uint64_t size = blk_rq_bytes(req);
491 int error; 534 int error;
492- rl_t *rl; 535- rl_t *rl;
493+ rl_t rl; 536+ rl_t rl;
494 537
495 if (offset + size > zv->zv_volsize) { 538 if (offset + size > zv->zv_volsize) {
496 blk_end_request(req, -EIO, size); 539 blk_end_request(req, -EIO, size);
497@@ -601,7 +601,7 @@ zvol_discard(void *arg) 540@@ -601,7 +601,7 @@
498 return; 541 return;
499 } 542 }
500 543
501- rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_WRITER); 544- rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_WRITER);
502+ zfs_range_lock(&rl, &zv->zv_znode, offset, size, RL_WRITER); 545+ zfs_range_lock(&rl, &zv->zv_znode, offset, size, RL_WRITER);
503 546
504 error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, offset, size); 547 error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, offset, size);
505 548
506@@ -609,7 +609,7 @@ zvol_discard(void *arg) 549@@ -609,7 +609,7 @@
507 * TODO: maybe we should add the operation to the log. 550 * TODO: maybe we should add the operation to the log.
508 */ 551 */
509 552
510- zfs_range_unlock(rl); 553- zfs_range_unlock(rl);
511+ zfs_range_unlock(&rl); 554+ zfs_range_unlock(&rl);
512 555
513 blk_end_request(req, -error, size); 556 blk_end_request(req, -error, size);
514 } 557 }
515@@ -630,18 +630,18 @@ zvol_read(void *arg) 558@@ -630,18 +630,18 @@
516 uint64_t offset = blk_rq_pos(req) << 9; 559 uint64_t offset = blk_rq_pos(req) << 9;
517 uint64_t size = blk_rq_bytes(req); 560 uint64_t size = blk_rq_bytes(req);
518 int error; 561 int error;
519- rl_t *rl; 562- rl_t *rl;
520+ rl_t rl; 563+ rl_t rl;
532- zfs_range_unlock(rl); 575- zfs_range_unlock(rl);
533+ zfs_range_unlock(&rl); 576+ zfs_range_unlock(&rl);
534 577
535 /* convert checksum errors into IO errors */ 578 /* convert checksum errors into IO errors */
536 if (error == ECKSUM) 579 if (error == ECKSUM)
537@@ -744,6 +744,7 @@ zvol_get_done(zgd_t *zgd, int error) 580@@ -744,6 +744,7 @@
538 if (error == 0 && zgd->zgd_bp) 581 if (error == 0 && zgd->zgd_bp)
539 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp); 582 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
540 583
541+ kmem_free(zgd->zgd_rl, sizeof(rl_t)); 584+ kmem_free(zgd->zgd_rl, sizeof (rl_t));
542 kmem_free(zgd, sizeof (zgd_t)); 585 kmem_free(zgd, sizeof (zgd_t));
543 } 586 }
544 587
545@@ -766,7 +767,8 @@ zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) 588@@ -766,7 +767,8 @@
546 589
547 zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP); 590 zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
548 zgd->zgd_zilog = zv->zv_zilog; 591 zgd->zgd_zilog = zv->zv_zilog;
549- zgd->zgd_rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_READER); 592- zgd->zgd_rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_READER);
550+ zgd->zgd_rl = kmem_alloc(sizeof (rl_t), KM_SLEEP); 593+ zgd->zgd_rl = kmem_alloc(sizeof (rl_t), KM_SLEEP);
551+ zfs_range_lock(zgd->zgd_rl, &zv->zv_znode, offset, size, RL_READER); 594+ zfs_range_lock(zgd->zgd_rl, &zv->zv_znode, offset, size, RL_READER);
552 595
553 /* 596 /*
554 * Write records come in two flavors: immediate and indirect. 597 * Write records come in two flavors: immediate and indirect.
598--
5991.7.10
600

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.20