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