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_log.c
+++ new/usr/src/uts/common/fs/zfs/zfs_log.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) 2005, 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/systm.h>
28 28 #include <sys/sysmacros.h>
29 29 #include <sys/cmn_err.h>
30 30 #include <sys/kmem.h>
31 31 #include <sys/thread.h>
32 32 #include <sys/file.h>
33 33 #include <sys/vfs.h>
34 34 #include <sys/zfs_znode.h>
35 35 #include <sys/zfs_dir.h>
36 36 #include <sys/zil.h>
37 37 #include <sys/zil_impl.h>
38 38 #include <sys/byteorder.h>
39 39 #include <sys/policy.h>
40 40 #include <sys/stat.h>
41 41 #include <sys/mode.h>
42 42 #include <sys/acl.h>
43 43 #include <sys/dmu.h>
44 44 #include <sys/spa.h>
45 45 #include <sys/zfs_fuid.h>
46 46 #include <sys/ddi.h>
47 47 #include <sys/dsl_dataset.h>
48 48
49 49 /*
50 50 * These zfs_log_* functions must be called within a dmu tx, in one
51 51 * of 2 contexts depending on zilog->z_replay:
52 52 *
53 53 * Non replay mode
54 54 * ---------------
55 55 * We need to record the transaction so that if it is committed to
56 56 * the Intent Log then it can be replayed. An intent log transaction
57 57 * structure (itx_t) is allocated and all the information necessary to
58 58 * possibly replay the transaction is saved in it. The itx is then assigned
59 59 * a sequence number and inserted in the in-memory list anchored in the zilog.
60 60 *
61 61 * Replay mode
62 62 * -----------
63 63 * We need to mark the intent log record as replayed in the log header.
64 64 * This is done in the same transaction as the replay so that they
65 65 * commit atomically.
66 66 */
67 67
68 68 int
69 69 zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
70 70 {
71 71 int isxvattr = (vap->va_mask & AT_XVATTR);
72 72 switch (type) {
73 73 case Z_FILE:
74 74 if (vsecp == NULL && !isxvattr)
75 75 return (TX_CREATE);
76 76 if (vsecp && isxvattr)
77 77 return (TX_CREATE_ACL_ATTR);
78 78 if (vsecp)
79 79 return (TX_CREATE_ACL);
80 80 else
81 81 return (TX_CREATE_ATTR);
82 82 /*NOTREACHED*/
83 83 case Z_DIR:
84 84 if (vsecp == NULL && !isxvattr)
85 85 return (TX_MKDIR);
86 86 if (vsecp && isxvattr)
87 87 return (TX_MKDIR_ACL_ATTR);
88 88 if (vsecp)
89 89 return (TX_MKDIR_ACL);
90 90 else
91 91 return (TX_MKDIR_ATTR);
92 92 case Z_XATTRDIR:
93 93 return (TX_MKXATTR);
94 94 }
95 95 ASSERT(0);
96 96 return (TX_MAX_TYPE);
97 97 }
98 98
99 99 /*
100 100 * build up the log data necessary for logging xvattr_t
101 101 * First lr_attr_t is initialized. following the lr_attr_t
102 102 * is the mapsize and attribute bitmap copied from the xvattr_t.
103 103 * Following the bitmap and bitmapsize two 64 bit words are reserved
104 104 * for the create time which may be set. Following the create time
105 105 * records a single 64 bit integer which has the bits to set on
106 106 * replay for the xvattr.
107 107 */
108 108 static void
109 109 zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
110 110 {
111 111 uint32_t *bitmap;
112 112 uint64_t *attrs;
113 113 uint64_t *crtime;
114 114 xoptattr_t *xoap;
115 115 void *scanstamp;
116 116 int i;
117 117
118 118 xoap = xva_getxoptattr(xvap);
119 119 ASSERT(xoap);
120 120
121 121 lrattr->lr_attr_masksize = xvap->xva_mapsize;
122 122 bitmap = &lrattr->lr_attr_bitmap;
123 123 for (i = 0; i != xvap->xva_mapsize; i++, bitmap++) {
124 124 *bitmap = xvap->xva_reqattrmap[i];
125 125 }
126 126
127 127 /* Now pack the attributes up in a single uint64_t */
128 128 attrs = (uint64_t *)bitmap;
129 129 crtime = attrs + 1;
130 130 scanstamp = (caddr_t)(crtime + 2);
131 131 *attrs = 0;
132 132 if (XVA_ISSET_REQ(xvap, XAT_READONLY))
133 133 *attrs |= (xoap->xoa_readonly == 0) ? 0 :
134 134 XAT0_READONLY;
135 135 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN))
136 136 *attrs |= (xoap->xoa_hidden == 0) ? 0 :
137 137 XAT0_HIDDEN;
138 138 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM))
139 139 *attrs |= (xoap->xoa_system == 0) ? 0 :
140 140 XAT0_SYSTEM;
141 141 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE))
142 142 *attrs |= (xoap->xoa_archive == 0) ? 0 :
143 143 XAT0_ARCHIVE;
144 144 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
145 145 *attrs |= (xoap->xoa_immutable == 0) ? 0 :
146 146 XAT0_IMMUTABLE;
147 147 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
148 148 *attrs |= (xoap->xoa_nounlink == 0) ? 0 :
149 149 XAT0_NOUNLINK;
150 150 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
151 151 *attrs |= (xoap->xoa_appendonly == 0) ? 0 :
152 152 XAT0_APPENDONLY;
153 153 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE))
154 154 *attrs |= (xoap->xoa_opaque == 0) ? 0 :
155 155 XAT0_APPENDONLY;
156 156 if (XVA_ISSET_REQ(xvap, XAT_NODUMP))
157 157 *attrs |= (xoap->xoa_nodump == 0) ? 0 :
158 158 XAT0_NODUMP;
159 159 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED))
160 160 *attrs |= (xoap->xoa_av_quarantined == 0) ? 0 :
161 161 XAT0_AV_QUARANTINED;
162 162 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
163 163 *attrs |= (xoap->xoa_av_modified == 0) ? 0 :
164 164 XAT0_AV_MODIFIED;
165 165 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
166 166 ZFS_TIME_ENCODE(&xoap->xoa_createtime, crtime);
167 167 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
168 168 bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ);
169 169 if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
170 170 *attrs |= (xoap->xoa_reparse == 0) ? 0 :
171 171 XAT0_REPARSE;
172 172 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE))
173 173 *attrs |= (xoap->xoa_offline == 0) ? 0 :
174 174 XAT0_OFFLINE;
175 175 if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
176 176 *attrs |= (xoap->xoa_sparse == 0) ? 0 :
177 177 XAT0_SPARSE;
178 178 }
179 179
180 180 static void *
181 181 zfs_log_fuid_ids(zfs_fuid_info_t *fuidp, void *start)
182 182 {
183 183 zfs_fuid_t *zfuid;
184 184 uint64_t *fuidloc = start;
185 185
186 186 /* First copy in the ACE FUIDs */
187 187 for (zfuid = list_head(&fuidp->z_fuids); zfuid;
188 188 zfuid = list_next(&fuidp->z_fuids, zfuid)) {
189 189 *fuidloc++ = zfuid->z_logfuid;
190 190 }
191 191 return (fuidloc);
192 192 }
193 193
194 194
195 195 static void *
196 196 zfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start)
197 197 {
198 198 zfs_fuid_domain_t *zdomain;
199 199
200 200 /* now copy in the domain info, if any */
201 201 if (fuidp->z_domain_str_sz != 0) {
202 202 for (zdomain = list_head(&fuidp->z_domains); zdomain;
203 203 zdomain = list_next(&fuidp->z_domains, zdomain)) {
↓ open down ↓ |
203 lines elided |
↑ open up ↑ |
204 204 bcopy((void *)zdomain->z_domain, start,
205 205 strlen(zdomain->z_domain) + 1);
206 206 start = (caddr_t)start +
207 207 strlen(zdomain->z_domain) + 1;
208 208 }
209 209 }
210 210 return (start);
211 211 }
212 212
213 213 /*
214 - * zfs_log_create() is used to handle TX_CREATE, TX_CREATE_ATTR, TX_MKDIR,
215 - * TX_MKDIR_ATTR and TX_MKXATTR
216 - * transactions.
214 + * Handles TX_CREATE, TX_CREATE_ATTR, TX_MKDIR, TX_MKDIR_ATTR and
215 + * TK_MKXATTR transactions.
217 216 *
218 217 * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID
219 218 * domain information appended prior to the name. In this case the
220 219 * uid/gid in the log record will be a log centric FUID.
221 220 *
222 221 * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that
223 222 * may contain attributes, ACL and optional fuid information.
224 223 *
225 224 * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify
226 225 * and ACL and normal users/groups in the ACEs.
227 226 *
228 227 * There may be an optional xvattr attribute information similar
229 228 * to zfs_log_setattr.
230 229 *
231 230 * Also, after the file name "domain" strings may be appended.
232 231 */
233 232 void
234 233 zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
235 234 znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp,
236 235 zfs_fuid_info_t *fuidp, vattr_t *vap)
237 236 {
238 237 itx_t *itx;
239 238 lr_create_t *lr;
240 239 lr_acl_create_t *lracl;
241 240 size_t aclsize = (vsecp != NULL) ? vsecp->vsa_aclentsz : 0;
242 241 size_t xvatsize = 0;
243 242 size_t txsize;
244 243 xvattr_t *xvap = (xvattr_t *)vap;
245 244 void *end;
246 245 size_t lrsize;
247 246 size_t namesize = strlen(name) + 1;
248 247 size_t fuidsz = 0;
249 248
250 249 if (zil_replaying(zilog, tx))
251 250 return;
252 251
253 252 /*
254 253 * If we have FUIDs present then add in space for
255 254 * domains and ACE fuid's if any.
256 255 */
257 256 if (fuidp) {
258 257 fuidsz += fuidp->z_domain_str_sz;
259 258 fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t);
260 259 }
261 260
262 261 if (vap->va_mask & AT_XVATTR)
263 262 xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize);
264 263
265 264 if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
266 265 (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR ||
267 266 (int)txtype == TX_MKXATTR) {
268 267 txsize = sizeof (*lr) + namesize + fuidsz + xvatsize;
269 268 lrsize = sizeof (*lr);
270 269 } else {
271 270 txsize =
272 271 sizeof (lr_acl_create_t) + namesize + fuidsz +
273 272 ZIL_ACE_LENGTH(aclsize) + xvatsize;
274 273 lrsize = sizeof (lr_acl_create_t);
275 274 }
276 275
277 276 itx = zil_itx_create(txtype, txsize);
278 277
279 278 lr = (lr_create_t *)&itx->itx_lr;
280 279 lr->lr_doid = dzp->z_id;
281 280 lr->lr_foid = zp->z_id;
282 281 lr->lr_mode = zp->z_mode;
283 282 if (!IS_EPHEMERAL(zp->z_uid)) {
284 283 lr->lr_uid = (uint64_t)zp->z_uid;
285 284 } else {
286 285 lr->lr_uid = fuidp->z_fuid_owner;
287 286 }
288 287 if (!IS_EPHEMERAL(zp->z_gid)) {
289 288 lr->lr_gid = (uint64_t)zp->z_gid;
290 289 } else {
291 290 lr->lr_gid = fuidp->z_fuid_group;
292 291 }
293 292 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
294 293 sizeof (uint64_t));
295 294 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
296 295 lr->lr_crtime, sizeof (uint64_t) * 2);
297 296
298 297 if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zp->z_zfsvfs), &lr->lr_rdev,
299 298 sizeof (lr->lr_rdev)) != 0)
300 299 lr->lr_rdev = 0;
301 300
302 301 /*
303 302 * Fill in xvattr info if any
304 303 */
305 304 if (vap->va_mask & AT_XVATTR) {
306 305 zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap);
307 306 end = (caddr_t)lr + lrsize + xvatsize;
308 307 } else {
309 308 end = (caddr_t)lr + lrsize;
310 309 }
311 310
312 311 /* Now fill in any ACL info */
313 312
314 313 if (vsecp) {
315 314 lracl = (lr_acl_create_t *)&itx->itx_lr;
316 315 lracl->lr_aclcnt = vsecp->vsa_aclcnt;
317 316 lracl->lr_acl_bytes = aclsize;
318 317 lracl->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
319 318 lracl->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
320 319 if (vsecp->vsa_aclflags & VSA_ACE_ACLFLAGS)
321 320 lracl->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
322 321 else
323 322 lracl->lr_acl_flags = 0;
324 323
325 324 bcopy(vsecp->vsa_aclentp, end, aclsize);
326 325 end = (caddr_t)end + ZIL_ACE_LENGTH(aclsize);
327 326 }
328 327
329 328 /* drop in FUID info */
330 329 if (fuidp) {
331 330 end = zfs_log_fuid_ids(fuidp, end);
332 331 end = zfs_log_fuid_domains(fuidp, end);
↓ open down ↓ |
106 lines elided |
↑ open up ↑ |
333 332 }
334 333 /*
335 334 * Now place file name in log record
336 335 */
337 336 bcopy(name, end, namesize);
338 337
339 338 zil_itx_assign(zilog, itx, tx);
340 339 }
341 340
342 341 /*
343 - * zfs_log_remove() handles both TX_REMOVE and TX_RMDIR transactions.
342 + * Handles both TX_REMOVE and TX_RMDIR transactions.
344 343 */
345 344 void
346 345 zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
347 346 znode_t *dzp, char *name, uint64_t foid)
348 347 {
349 348 itx_t *itx;
350 349 lr_remove_t *lr;
351 350 size_t namesize = strlen(name) + 1;
352 351
353 352 if (zil_replaying(zilog, tx))
354 353 return;
355 354
356 355 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
357 356 lr = (lr_remove_t *)&itx->itx_lr;
358 357 lr->lr_doid = dzp->z_id;
359 358 bcopy(name, (char *)(lr + 1), namesize);
360 359
361 360 itx->itx_oid = foid;
362 361
363 362 zil_itx_assign(zilog, itx, tx);
364 363 }
365 364
366 365 /*
367 - * zfs_log_link() handles TX_LINK transactions.
366 + * Handles TX_LINK transactions.
368 367 */
369 368 void
370 369 zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
371 370 znode_t *dzp, znode_t *zp, char *name)
372 371 {
373 372 itx_t *itx;
374 373 lr_link_t *lr;
375 374 size_t namesize = strlen(name) + 1;
376 375
377 376 if (zil_replaying(zilog, tx))
378 377 return;
379 378
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
380 379 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
381 380 lr = (lr_link_t *)&itx->itx_lr;
382 381 lr->lr_doid = dzp->z_id;
383 382 lr->lr_link_obj = zp->z_id;
384 383 bcopy(name, (char *)(lr + 1), namesize);
385 384
386 385 zil_itx_assign(zilog, itx, tx);
387 386 }
388 387
389 388 /*
390 - * zfs_log_symlink() handles TX_SYMLINK transactions.
389 + * Handles TX_SYMLINK transactions.
391 390 */
392 391 void
393 392 zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
394 393 znode_t *dzp, znode_t *zp, char *name, char *link)
395 394 {
396 395 itx_t *itx;
397 396 lr_create_t *lr;
398 397 size_t namesize = strlen(name) + 1;
399 398 size_t linksize = strlen(link) + 1;
400 399
401 400 if (zil_replaying(zilog, tx))
402 401 return;
403 402
404 403 itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
405 404 lr = (lr_create_t *)&itx->itx_lr;
406 405 lr->lr_doid = dzp->z_id;
407 406 lr->lr_foid = zp->z_id;
408 407 lr->lr_uid = zp->z_uid;
409 408 lr->lr_gid = zp->z_gid;
410 409 lr->lr_mode = zp->z_mode;
411 410 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
412 411 sizeof (uint64_t));
413 412 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
414 413 lr->lr_crtime, sizeof (uint64_t) * 2);
415 414 bcopy(name, (char *)(lr + 1), namesize);
416 415 bcopy(link, (char *)(lr + 1) + namesize, linksize);
417 416
418 417 zil_itx_assign(zilog, itx, tx);
419 418 }
420 419
421 420 /*
422 - * zfs_log_rename() handles TX_RENAME transactions.
421 + * Handles TX_RENAME transactions.
423 422 */
424 423 void
425 424 zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
426 425 znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
427 426 {
428 427 itx_t *itx;
429 428 lr_rename_t *lr;
430 429 size_t snamesize = strlen(sname) + 1;
431 430 size_t dnamesize = strlen(dname) + 1;
432 431
433 432 if (zil_replaying(zilog, tx))
434 433 return;
435 434
436 435 itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
437 436 lr = (lr_rename_t *)&itx->itx_lr;
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
438 437 lr->lr_sdoid = sdzp->z_id;
439 438 lr->lr_tdoid = tdzp->z_id;
440 439 bcopy(sname, (char *)(lr + 1), snamesize);
441 440 bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
442 441 itx->itx_oid = szp->z_id;
443 442
444 443 zil_itx_assign(zilog, itx, tx);
445 444 }
446 445
447 446 /*
448 - * zfs_log_write() handles TX_WRITE transactions.
447 + * Handles TX_WRITE transactions.
449 448 */
450 449 ssize_t zfs_immediate_write_sz = 32768;
451 450
452 451 void
453 452 zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
454 453 znode_t *zp, offset_t off, ssize_t resid, int ioflag)
455 454 {
456 455 itx_wr_state_t write_state;
457 456 boolean_t slogging;
458 457 uintptr_t fsync_cnt;
459 458 ssize_t immediate_write_sz;
460 459
461 460 if (zil_replaying(zilog, tx) || zp->z_unlinked)
462 461 return;
463 462
464 463 immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
465 464 ? 0 : zfs_immediate_write_sz;
466 465
467 466 slogging = spa_has_slogs(zilog->zl_spa) &&
468 467 (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
469 468 if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
470 469 write_state = WR_INDIRECT;
471 470 else if (ioflag & (FSYNC | FDSYNC))
472 471 write_state = WR_COPIED;
473 472 else
474 473 write_state = WR_NEED_COPY;
475 474
476 475 if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) {
477 476 (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1));
478 477 }
479 478
480 479 while (resid) {
481 480 itx_t *itx;
482 481 lr_write_t *lr;
483 482 ssize_t len;
484 483
485 484 /*
486 485 * If the write would overflow the largest block then split it.
487 486 */
488 487 if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
489 488 len = SPA_MAXBLOCKSIZE >> 1;
490 489 else
491 490 len = resid;
492 491
493 492 itx = zil_itx_create(txtype, sizeof (*lr) +
494 493 (write_state == WR_COPIED ? len : 0));
495 494 lr = (lr_write_t *)&itx->itx_lr;
496 495 if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
497 496 zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
498 497 zil_itx_destroy(itx);
499 498 itx = zil_itx_create(txtype, sizeof (*lr));
500 499 lr = (lr_write_t *)&itx->itx_lr;
501 500 write_state = WR_NEED_COPY;
502 501 }
503 502
504 503 itx->itx_wr_state = write_state;
505 504 if (write_state == WR_NEED_COPY)
506 505 itx->itx_sod += len;
507 506 lr->lr_foid = zp->z_id;
508 507 lr->lr_offset = off;
509 508 lr->lr_length = len;
510 509 lr->lr_blkoff = 0;
511 510 BP_ZERO(&lr->lr_blkptr);
512 511
513 512 itx->itx_private = zp->z_zfsvfs;
514 513
515 514 if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
516 515 (fsync_cnt == 0))
↓ open down ↓ |
58 lines elided |
↑ open up ↑ |
517 516 itx->itx_sync = B_FALSE;
518 517
519 518 zil_itx_assign(zilog, itx, tx);
520 519
521 520 off += len;
522 521 resid -= len;
523 522 }
524 523 }
525 524
526 525 /*
527 - * zfs_log_truncate() handles TX_TRUNCATE transactions.
526 + * Handles TX_TRUNCATE transactions.
528 527 */
529 528 void
530 529 zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
531 530 znode_t *zp, uint64_t off, uint64_t len)
532 531 {
533 532 itx_t *itx;
534 533 lr_truncate_t *lr;
535 534
536 535 if (zil_replaying(zilog, tx) || zp->z_unlinked)
537 536 return;
538 537
539 538 itx = zil_itx_create(txtype, sizeof (*lr));
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
540 539 lr = (lr_truncate_t *)&itx->itx_lr;
541 540 lr->lr_foid = zp->z_id;
542 541 lr->lr_offset = off;
543 542 lr->lr_length = len;
544 543
545 544 itx->itx_sync = (zp->z_sync_cnt != 0);
546 545 zil_itx_assign(zilog, itx, tx);
547 546 }
548 547
549 548 /*
550 - * zfs_log_setattr() handles TX_SETATTR transactions.
549 + * Handles TX_SETATTR transactions.
551 550 */
552 551 void
553 552 zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
554 553 znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp)
555 554 {
556 555 itx_t *itx;
557 556 lr_setattr_t *lr;
558 557 xvattr_t *xvap = (xvattr_t *)vap;
559 558 size_t recsize = sizeof (lr_setattr_t);
560 559 void *start;
561 560
562 561 if (zil_replaying(zilog, tx) || zp->z_unlinked)
563 562 return;
564 563
565 564 /*
566 565 * If XVATTR set, then log record size needs to allow
567 566 * for lr_attr_t + xvattr mask, mapsize and create time
568 567 * plus actual attribute values
569 568 */
570 569 if (vap->va_mask & AT_XVATTR)
571 570 recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
572 571
573 572 if (fuidp)
574 573 recsize += fuidp->z_domain_str_sz;
575 574
576 575 itx = zil_itx_create(txtype, recsize);
577 576 lr = (lr_setattr_t *)&itx->itx_lr;
578 577 lr->lr_foid = zp->z_id;
579 578 lr->lr_mask = (uint64_t)mask_applied;
580 579 lr->lr_mode = (uint64_t)vap->va_mode;
581 580 if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid))
582 581 lr->lr_uid = fuidp->z_fuid_owner;
583 582 else
584 583 lr->lr_uid = (uint64_t)vap->va_uid;
585 584
586 585 if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid))
587 586 lr->lr_gid = fuidp->z_fuid_group;
588 587 else
589 588 lr->lr_gid = (uint64_t)vap->va_gid;
590 589
591 590 lr->lr_size = (uint64_t)vap->va_size;
592 591 ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime);
593 592 ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime);
594 593 start = (lr_setattr_t *)(lr + 1);
595 594 if (vap->va_mask & AT_XVATTR) {
596 595 zfs_log_xvattr((lr_attr_t *)start, xvap);
597 596 start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
598 597 }
599 598
600 599 /*
601 600 * Now stick on domain information if any on end
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
602 601 */
603 602
604 603 if (fuidp)
605 604 (void) zfs_log_fuid_domains(fuidp, start);
606 605
607 606 itx->itx_sync = (zp->z_sync_cnt != 0);
608 607 zil_itx_assign(zilog, itx, tx);
609 608 }
610 609
611 610 /*
612 - * zfs_log_acl() handles TX_ACL transactions.
611 + * Handles TX_ACL transactions.
613 612 */
614 613 void
615 614 zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
616 615 vsecattr_t *vsecp, zfs_fuid_info_t *fuidp)
617 616 {
618 617 itx_t *itx;
619 618 lr_acl_v0_t *lrv0;
620 619 lr_acl_t *lr;
621 620 int txtype;
622 621 int lrsize;
623 622 size_t txsize;
624 623 size_t aclbytes = vsecp->vsa_aclentsz;
625 624
626 625 if (zil_replaying(zilog, tx) || zp->z_unlinked)
627 626 return;
628 627
629 628 txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
630 629 TX_ACL_V0 : TX_ACL;
631 630
632 631 if (txtype == TX_ACL)
633 632 lrsize = sizeof (*lr);
634 633 else
635 634 lrsize = sizeof (*lrv0);
636 635
637 636 txsize = lrsize +
638 637 ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) +
639 638 (fuidp ? fuidp->z_domain_str_sz : 0) +
640 639 sizeof (uint64_t) * (fuidp ? fuidp->z_fuid_cnt : 0);
641 640
642 641 itx = zil_itx_create(txtype, txsize);
643 642
644 643 lr = (lr_acl_t *)&itx->itx_lr;
645 644 lr->lr_foid = zp->z_id;
646 645 if (txtype == TX_ACL) {
647 646 lr->lr_acl_bytes = aclbytes;
648 647 lr->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
649 648 lr->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
650 649 if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS)
651 650 lr->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
652 651 else
653 652 lr->lr_acl_flags = 0;
654 653 }
655 654 lr->lr_aclcnt = (uint64_t)vsecp->vsa_aclcnt;
656 655
657 656 if (txtype == TX_ACL_V0) {
658 657 lrv0 = (lr_acl_v0_t *)lr;
659 658 bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes);
660 659 } else {
661 660 void *start = (ace_t *)(lr + 1);
662 661
663 662 bcopy(vsecp->vsa_aclentp, start, aclbytes);
664 663
665 664 start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes);
666 665
667 666 if (fuidp) {
668 667 start = zfs_log_fuid_ids(fuidp, start);
669 668 (void) zfs_log_fuid_domains(fuidp, start);
670 669 }
671 670 }
672 671
673 672 itx->itx_sync = (zp->z_sync_cnt != 0);
674 673 zil_itx_assign(zilog, itx, tx);
675 674 }
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX