Print this page
5056 ZFS deadlock on db_mtx and dn_holds
Reviewed by: Will Andrews <willa@spectralogic.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Dan McDonald <danmcd@omniti.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/zfs_sa.c
+++ new/usr/src/uts/common/fs/zfs/zfs_sa.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 -#include <sys/types.h>
26 -#include <sys/param.h>
25 +#include <sys/zfs_context.h>
27 26 #include <sys/vnode.h>
28 27 #include <sys/sa.h>
29 28 #include <sys/zfs_acl.h>
30 29 #include <sys/zfs_sa.h>
31 30
32 31 /*
33 32 * ZPL attribute registration table.
34 33 * Order of attributes doesn't matter
35 34 * a unique value will be assigned for each
36 35 * attribute that is file system specific
37 36 *
38 37 * This is just the set of ZPL attributes that this
39 38 * version of ZFS deals with natively. The file system
40 39 * could have other attributes stored in files, but they will be
41 40 * ignored. The SA framework will preserve them, just that
42 41 * this version of ZFS won't change or delete them.
43 42 */
44 43
45 44 sa_attr_reg_t zfs_attr_table[ZPL_END+1] = {
46 45 {"ZPL_ATIME", sizeof (uint64_t) * 2, SA_UINT64_ARRAY, 0},
47 46 {"ZPL_MTIME", sizeof (uint64_t) * 2, SA_UINT64_ARRAY, 1},
48 47 {"ZPL_CTIME", sizeof (uint64_t) * 2, SA_UINT64_ARRAY, 2},
49 48 {"ZPL_CRTIME", sizeof (uint64_t) * 2, SA_UINT64_ARRAY, 3},
50 49 {"ZPL_GEN", sizeof (uint64_t), SA_UINT64_ARRAY, 4},
51 50 {"ZPL_MODE", sizeof (uint64_t), SA_UINT64_ARRAY, 5},
52 51 {"ZPL_SIZE", sizeof (uint64_t), SA_UINT64_ARRAY, 6},
53 52 {"ZPL_PARENT", sizeof (uint64_t), SA_UINT64_ARRAY, 7},
54 53 {"ZPL_LINKS", sizeof (uint64_t), SA_UINT64_ARRAY, 8},
55 54 {"ZPL_XATTR", sizeof (uint64_t), SA_UINT64_ARRAY, 9},
56 55 {"ZPL_RDEV", sizeof (uint64_t), SA_UINT64_ARRAY, 10},
57 56 {"ZPL_FLAGS", sizeof (uint64_t), SA_UINT64_ARRAY, 11},
58 57 {"ZPL_UID", sizeof (uint64_t), SA_UINT64_ARRAY, 12},
59 58 {"ZPL_GID", sizeof (uint64_t), SA_UINT64_ARRAY, 13},
60 59 {"ZPL_PAD", sizeof (uint64_t) * 4, SA_UINT64_ARRAY, 14},
61 60 {"ZPL_ZNODE_ACL", 88, SA_UINT8_ARRAY, 15},
62 61 {"ZPL_DACL_COUNT", sizeof (uint64_t), SA_UINT64_ARRAY, 0},
63 62 {"ZPL_SYMLINK", 0, SA_UINT8_ARRAY, 0},
64 63 {"ZPL_SCANSTAMP", 32, SA_UINT8_ARRAY, 0},
65 64 {"ZPL_DACL_ACES", 0, SA_ACL, 0},
66 65 {NULL, 0, 0, 0}
67 66 };
68 67
69 68 #ifdef _KERNEL
70 69
71 70 int
72 71 zfs_sa_readlink(znode_t *zp, uio_t *uio)
73 72 {
74 73 dmu_buf_t *db = sa_get_db(zp->z_sa_hdl);
75 74 size_t bufsz;
76 75 int error;
77 76
78 77 bufsz = zp->z_size;
79 78 if (bufsz + ZFS_OLD_ZNODE_PHYS_SIZE <= db->db_size) {
80 79 error = uiomove((caddr_t)db->db_data +
81 80 ZFS_OLD_ZNODE_PHYS_SIZE,
82 81 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
83 82 } else {
84 83 dmu_buf_t *dbp;
85 84 if ((error = dmu_buf_hold(zp->z_zfsvfs->z_os, zp->z_id,
86 85 0, FTAG, &dbp, DMU_READ_NO_PREFETCH)) == 0) {
87 86 error = uiomove(dbp->db_data,
88 87 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
89 88 dmu_buf_rele(dbp, FTAG);
90 89 }
91 90 }
92 91 return (error);
93 92 }
94 93
95 94 void
96 95 zfs_sa_symlink(znode_t *zp, char *link, int len, dmu_tx_t *tx)
97 96 {
98 97 dmu_buf_t *db = sa_get_db(zp->z_sa_hdl);
99 98
100 99 if (ZFS_OLD_ZNODE_PHYS_SIZE + len <= dmu_bonus_max()) {
101 100 VERIFY(dmu_set_bonus(db,
102 101 len + ZFS_OLD_ZNODE_PHYS_SIZE, tx) == 0);
103 102 if (len) {
104 103 bcopy(link, (caddr_t)db->db_data +
105 104 ZFS_OLD_ZNODE_PHYS_SIZE, len);
106 105 }
107 106 } else {
108 107 dmu_buf_t *dbp;
109 108
110 109 zfs_grow_blocksize(zp, len, tx);
111 110 VERIFY(0 == dmu_buf_hold(zp->z_zfsvfs->z_os,
112 111 zp->z_id, 0, FTAG, &dbp, DMU_READ_NO_PREFETCH));
113 112
114 113 dmu_buf_will_dirty(dbp, tx);
115 114
116 115 ASSERT3U(len, <=, dbp->db_size);
117 116 bcopy(link, dbp->db_data, len);
118 117 dmu_buf_rele(dbp, FTAG);
119 118 }
120 119 }
121 120
122 121 void
123 122 zfs_sa_get_scanstamp(znode_t *zp, xvattr_t *xvap)
124 123 {
125 124 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
126 125 xoptattr_t *xoap;
127 126
128 127 ASSERT(MUTEX_HELD(&zp->z_lock));
129 128 VERIFY((xoap = xva_getxoptattr(xvap)) != NULL);
130 129 if (zp->z_is_sa) {
131 130 if (sa_lookup(zp->z_sa_hdl, SA_ZPL_SCANSTAMP(zfsvfs),
132 131 &xoap->xoa_av_scanstamp,
133 132 sizeof (xoap->xoa_av_scanstamp)) != 0)
134 133 return;
135 134 } else {
136 135 dmu_object_info_t doi;
137 136 dmu_buf_t *db = sa_get_db(zp->z_sa_hdl);
138 137 int len;
139 138
140 139 if (!(zp->z_pflags & ZFS_BONUS_SCANSTAMP))
141 140 return;
142 141
143 142 sa_object_info(zp->z_sa_hdl, &doi);
144 143 len = sizeof (xoap->xoa_av_scanstamp) +
145 144 ZFS_OLD_ZNODE_PHYS_SIZE;
146 145
147 146 if (len <= doi.doi_bonus_size) {
148 147 (void) memcpy(xoap->xoa_av_scanstamp,
149 148 (caddr_t)db->db_data + ZFS_OLD_ZNODE_PHYS_SIZE,
150 149 sizeof (xoap->xoa_av_scanstamp));
151 150 }
152 151 }
153 152 XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
154 153 }
155 154
156 155 void
157 156 zfs_sa_set_scanstamp(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
158 157 {
159 158 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
160 159 xoptattr_t *xoap;
161 160
162 161 ASSERT(MUTEX_HELD(&zp->z_lock));
163 162 VERIFY((xoap = xva_getxoptattr(xvap)) != NULL);
164 163 if (zp->z_is_sa)
165 164 VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_SCANSTAMP(zfsvfs),
166 165 &xoap->xoa_av_scanstamp,
167 166 sizeof (xoap->xoa_av_scanstamp), tx));
168 167 else {
169 168 dmu_object_info_t doi;
170 169 dmu_buf_t *db = sa_get_db(zp->z_sa_hdl);
171 170 int len;
172 171
173 172 sa_object_info(zp->z_sa_hdl, &doi);
174 173 len = sizeof (xoap->xoa_av_scanstamp) +
175 174 ZFS_OLD_ZNODE_PHYS_SIZE;
176 175 if (len > doi.doi_bonus_size)
177 176 VERIFY(dmu_set_bonus(db, len, tx) == 0);
178 177 (void) memcpy((caddr_t)db->db_data + ZFS_OLD_ZNODE_PHYS_SIZE,
179 178 xoap->xoa_av_scanstamp, sizeof (xoap->xoa_av_scanstamp));
180 179
181 180 zp->z_pflags |= ZFS_BONUS_SCANSTAMP;
182 181 VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs),
183 182 &zp->z_pflags, sizeof (uint64_t), tx));
184 183 }
185 184 }
186 185
187 186 /*
188 187 * I'm not convinced we should do any of this upgrade.
189 188 * since the SA code can read both old/new znode formats
190 189 * with probably little to no performance difference.
191 190 *
192 191 * All new files will be created with the new format.
193 192 */
194 193
195 194 void
196 195 zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
197 196 {
198 197 dmu_buf_t *db = sa_get_db(hdl);
199 198 znode_t *zp = sa_get_userdata(hdl);
200 199 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
201 200 sa_bulk_attr_t bulk[20];
202 201 int count = 0;
203 202 sa_bulk_attr_t sa_attrs[20] = { 0 };
204 203 zfs_acl_locator_cb_t locate = { 0 };
205 204 uint64_t uid, gid, mode, rdev, xattr, parent;
206 205 uint64_t crtime[2], mtime[2], ctime[2];
207 206 zfs_acl_phys_t znode_acl;
208 207 char scanstamp[AV_SCANSTAMP_SZ];
209 208 boolean_t drop_lock = B_FALSE;
210 209
211 210 /*
212 211 * No upgrade if ACL isn't cached
213 212 * since we won't know which locks are held
214 213 * and ready the ACL would require special "locked"
215 214 * interfaces that would be messy
216 215 */
217 216 if (zp->z_acl_cached == NULL || ZTOV(zp)->v_type == VLNK)
218 217 return;
219 218
220 219 /*
221 220 * If the z_lock is held and we aren't the owner
222 221 * the just return since we don't want to deadlock
223 222 * trying to update the status of z_is_sa. This
224 223 * file can then be upgraded at a later time.
225 224 *
226 225 * Otherwise, we know we are doing the
227 226 * sa_update() that caused us to enter this function.
228 227 */
229 228 if (mutex_owner(&zp->z_lock) != curthread) {
230 229 if (mutex_tryenter(&zp->z_lock) == 0)
231 230 return;
232 231 else
233 232 drop_lock = B_TRUE;
234 233 }
235 234
236 235 /* First do a bulk query of the attributes that aren't cached */
237 236 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
238 237 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
239 238 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CRTIME(zfsvfs), NULL, &crtime, 16);
240 239 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL, &mode, 8);
241 240 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL, &parent, 8);
242 241 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_XATTR(zfsvfs), NULL, &xattr, 8);
243 242 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_RDEV(zfsvfs), NULL, &rdev, 8);
244 243 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL, &uid, 8);
245 244 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL, &gid, 8);
246 245 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ZNODE_ACL(zfsvfs), NULL,
247 246 &znode_acl, 88);
248 247
249 248 if (sa_bulk_lookup_locked(hdl, bulk, count) != 0)
250 249 goto done;
251 250
252 251
253 252 /*
254 253 * While the order here doesn't matter its best to try and organize
255 254 * it is such a way to pick up an already existing layout number
256 255 */
257 256 count = 0;
258 257 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_MODE(zfsvfs), NULL, &mode, 8);
259 258 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_SIZE(zfsvfs), NULL,
260 259 &zp->z_size, 8);
261 260 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_GEN(zfsvfs),
262 261 NULL, &zp->z_gen, 8);
263 262 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_UID(zfsvfs), NULL, &uid, 8);
264 263 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_GID(zfsvfs), NULL, &gid, 8);
265 264 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_PARENT(zfsvfs),
266 265 NULL, &parent, 8);
267 266 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_FLAGS(zfsvfs), NULL,
268 267 &zp->z_pflags, 8);
269 268 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_ATIME(zfsvfs), NULL,
270 269 zp->z_atime, 16);
271 270 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_MTIME(zfsvfs), NULL,
272 271 &mtime, 16);
273 272 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_CTIME(zfsvfs), NULL,
274 273 &ctime, 16);
275 274 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_CRTIME(zfsvfs), NULL,
276 275 &crtime, 16);
277 276 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_LINKS(zfsvfs), NULL,
278 277 &zp->z_links, 8);
279 278 if (zp->z_vnode->v_type == VBLK || zp->z_vnode->v_type == VCHR)
280 279 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_RDEV(zfsvfs), NULL,
281 280 &rdev, 8);
282 281 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_DACL_COUNT(zfsvfs), NULL,
283 282 &zp->z_acl_cached->z_acl_count, 8);
284 283
285 284 if (zp->z_acl_cached->z_version < ZFS_ACL_VERSION_FUID)
286 285 zfs_acl_xform(zp, zp->z_acl_cached, CRED());
287 286
288 287 locate.cb_aclp = zp->z_acl_cached;
289 288 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_DACL_ACES(zfsvfs),
290 289 zfs_acl_data_locator, &locate, zp->z_acl_cached->z_acl_bytes);
291 290
292 291 if (xattr)
293 292 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_XATTR(zfsvfs),
294 293 NULL, &xattr, 8);
295 294
296 295 /* if scanstamp then add scanstamp */
297 296
298 297 if (zp->z_pflags & ZFS_BONUS_SCANSTAMP) {
299 298 bcopy((caddr_t)db->db_data + ZFS_OLD_ZNODE_PHYS_SIZE,
300 299 scanstamp, AV_SCANSTAMP_SZ);
301 300 SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_SCANSTAMP(zfsvfs),
302 301 NULL, scanstamp, AV_SCANSTAMP_SZ);
303 302 zp->z_pflags &= ~ZFS_BONUS_SCANSTAMP;
304 303 }
305 304
306 305 VERIFY(dmu_set_bonustype(db, DMU_OT_SA, tx) == 0);
307 306 VERIFY(sa_replace_all_by_template_locked(hdl, sa_attrs,
308 307 count, tx) == 0);
309 308 if (znode_acl.z_acl_extern_obj)
310 309 VERIFY(0 == dmu_object_free(zfsvfs->z_os,
311 310 znode_acl.z_acl_extern_obj, tx));
312 311
313 312 zp->z_is_sa = B_TRUE;
314 313 done:
315 314 if (drop_lock)
316 315 mutex_exit(&zp->z_lock);
317 316 }
318 317
319 318 void
320 319 zfs_sa_upgrade_txholds(dmu_tx_t *tx, znode_t *zp)
321 320 {
322 321 if (!zp->z_zfsvfs->z_use_sa || zp->z_is_sa)
323 322 return;
324 323
325 324
326 325 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
327 326
328 327 if (zfs_external_acl(zp)) {
329 328 dmu_tx_hold_free(tx, zfs_external_acl(zp), 0,
330 329 DMU_OBJECT_END);
331 330 }
332 331 }
333 332
334 333 #endif
|
↓ open down ↓ |
298 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX