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