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