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