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