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