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

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

  ViewVC Help
Powered by ViewVC 1.1.20