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