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