]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_log.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.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  * zfs_log_create() is used to handle TX_CREATE, TX_CREATE_ATTR, TX_MKDIR,
220  * TX_MKDIR_ATTR and TX_MKXATTR
221  * transactions.
222  *
223  * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID
224  * domain information appended prior to the name.  In this case the
225  * uid/gid in the log record will be a log centric FUID.
226  *
227  * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that
228  * may contain attributes, ACL and optional fuid information.
229  *
230  * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify
231  * and ACL and normal users/groups in the ACEs.
232  *
233  * There may be an optional xvattr attribute information similar
234  * to zfs_log_setattr.
235  *
236  * Also, after the file name "domain" strings may be appended.
237  */
238 void
239 zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
240     znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp,
241     zfs_fuid_info_t *fuidp, vattr_t *vap)
242 {
243         itx_t *itx;
244         lr_create_t *lr;
245         lr_acl_create_t *lracl;
246         size_t aclsize;
247         size_t xvatsize = 0;
248         size_t txsize;
249         xvattr_t *xvap = (xvattr_t *)vap;
250         void *end;
251         size_t lrsize;
252         size_t namesize = strlen(name) + 1;
253         size_t fuidsz = 0;
254
255         if (zil_replaying(zilog, tx))
256                 return;
257
258         /*
259          * If we have FUIDs present then add in space for
260          * domains and ACE fuid's if any.
261          */
262         if (fuidp) {
263                 fuidsz += fuidp->z_domain_str_sz;
264                 fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t);
265         }
266
267         if (vap->va_mask & AT_XVATTR)
268                 xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize);
269
270         if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
271             (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR ||
272             (int)txtype == TX_MKXATTR) {
273                 txsize = sizeof (*lr) + namesize + fuidsz + xvatsize;
274                 lrsize = sizeof (*lr);
275         } else {
276                 aclsize = (vsecp) ? vsecp->vsa_aclentsz : 0;
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  * zfs_log_remove() 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  * zfs_log_link() 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  * zfs_log_symlink() 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  * zfs_log_rename() 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  * zfs_log_write() 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         itx_wr_state_t write_state;
463         boolean_t slogging;
464         uintptr_t fsync_cnt;
465         ssize_t immediate_write_sz;
466
467         if (zil_replaying(zilog, tx) || zp->z_unlinked)
468                 return;
469
470         immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
471             ? 0 : zfs_immediate_write_sz;
472
473         slogging = spa_has_slogs(zilog->zl_spa) &&
474             (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
475         if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
476                 write_state = WR_INDIRECT;
477         else if (ioflag & (FSYNC | FDSYNC))
478                 write_state = WR_COPIED;
479         else
480                 write_state = WR_NEED_COPY;
481
482         if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) {
483                 (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1));
484         }
485
486         while (resid) {
487                 itx_t *itx;
488                 lr_write_t *lr;
489                 ssize_t len;
490
491                 /*
492                  * If the write would overflow the largest block then split it.
493                  */
494                 if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
495                         len = SPA_MAXBLOCKSIZE >> 1;
496                 else
497                         len = resid;
498
499                 itx = zil_itx_create(txtype, sizeof (*lr) +
500                     (write_state == WR_COPIED ? len : 0));
501                 lr = (lr_write_t *)&itx->itx_lr;
502                 if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
503                     zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
504                         zil_itx_destroy(itx);
505                         itx = zil_itx_create(txtype, sizeof (*lr));
506                         lr = (lr_write_t *)&itx->itx_lr;
507                         write_state = WR_NEED_COPY;
508                 }
509
510                 itx->itx_wr_state = write_state;
511                 if (write_state == WR_NEED_COPY)
512                         itx->itx_sod += len;
513                 lr->lr_foid = zp->z_id;
514                 lr->lr_offset = off;
515                 lr->lr_length = len;
516                 lr->lr_blkoff = 0;
517                 BP_ZERO(&lr->lr_blkptr);
518
519                 itx->itx_private = zp->z_zfsvfs;
520
521                 if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
522                     (fsync_cnt == 0))
523                         itx->itx_sync = B_FALSE;
524
525                 zil_itx_assign(zilog, itx, tx);
526
527                 off += len;
528                 resid -= len;
529         }
530 }
531
532 /*
533  * zfs_log_truncate() handles TX_TRUNCATE transactions.
534  */
535 void
536 zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
537         znode_t *zp, uint64_t off, uint64_t len)
538 {
539         itx_t *itx;
540         lr_truncate_t *lr;
541
542         if (zil_replaying(zilog, tx) || zp->z_unlinked)
543                 return;
544
545         itx = zil_itx_create(txtype, sizeof (*lr));
546         lr = (lr_truncate_t *)&itx->itx_lr;
547         lr->lr_foid = zp->z_id;
548         lr->lr_offset = off;
549         lr->lr_length = len;
550
551         itx->itx_sync = (zp->z_sync_cnt != 0);
552         zil_itx_assign(zilog, itx, tx);
553 }
554
555 /*
556  * zfs_log_setattr() handles TX_SETATTR transactions.
557  */
558 void
559 zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
560         znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp)
561 {
562         itx_t           *itx;
563         lr_setattr_t    *lr;
564         xvattr_t        *xvap = (xvattr_t *)vap;
565         size_t          recsize = sizeof (lr_setattr_t);
566         void            *start;
567
568         if (zil_replaying(zilog, tx) || zp->z_unlinked)
569                 return;
570
571         /*
572          * If XVATTR set, then log record size needs to allow
573          * for lr_attr_t + xvattr mask, mapsize and create time
574          * plus actual attribute values
575          */
576         if (vap->va_mask & AT_XVATTR)
577                 recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
578
579         if (fuidp)
580                 recsize += fuidp->z_domain_str_sz;
581
582         itx = zil_itx_create(txtype, recsize);
583         lr = (lr_setattr_t *)&itx->itx_lr;
584         lr->lr_foid = zp->z_id;
585         lr->lr_mask = (uint64_t)mask_applied;
586         lr->lr_mode = (uint64_t)vap->va_mode;
587         if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid))
588                 lr->lr_uid = fuidp->z_fuid_owner;
589         else
590                 lr->lr_uid = (uint64_t)vap->va_uid;
591
592         if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid))
593                 lr->lr_gid = fuidp->z_fuid_group;
594         else
595                 lr->lr_gid = (uint64_t)vap->va_gid;
596
597         lr->lr_size = (uint64_t)vap->va_size;
598         ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime);
599         ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime);
600         start = (lr_setattr_t *)(lr + 1);
601         if (vap->va_mask & AT_XVATTR) {
602                 zfs_log_xvattr((lr_attr_t *)start, xvap);
603                 start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
604         }
605
606         /*
607          * Now stick on domain information if any on end
608          */
609
610         if (fuidp)
611                 (void) zfs_log_fuid_domains(fuidp, start);
612
613         itx->itx_sync = (zp->z_sync_cnt != 0);
614         zil_itx_assign(zilog, itx, tx);
615 }
616
617 /*
618  * zfs_log_acl() handles TX_ACL transactions.
619  */
620 void
621 zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
622     vsecattr_t *vsecp, zfs_fuid_info_t *fuidp)
623 {
624         itx_t *itx;
625         lr_acl_v0_t *lrv0;
626         lr_acl_t *lr;
627         int txtype;
628         int lrsize;
629         size_t txsize;
630         size_t aclbytes = vsecp->vsa_aclentsz;
631
632         if (zil_replaying(zilog, tx) || zp->z_unlinked)
633                 return;
634
635         txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
636             TX_ACL_V0 : TX_ACL;
637
638         if (txtype == TX_ACL)
639                 lrsize = sizeof (*lr);
640         else
641                 lrsize = sizeof (*lrv0);
642
643         txsize = lrsize +
644             ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) +
645             (fuidp ? fuidp->z_domain_str_sz : 0) +
646             sizeof (uint64_t) * (fuidp ? fuidp->z_fuid_cnt : 0);
647
648         itx = zil_itx_create(txtype, txsize);
649
650         lr = (lr_acl_t *)&itx->itx_lr;
651         lr->lr_foid = zp->z_id;
652         if (txtype == TX_ACL) {
653                 lr->lr_acl_bytes = aclbytes;
654                 lr->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
655                 lr->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
656                 if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS)
657                         lr->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
658                 else
659                         lr->lr_acl_flags = 0;
660         }
661         lr->lr_aclcnt = (uint64_t)vsecp->vsa_aclcnt;
662
663         if (txtype == TX_ACL_V0) {
664                 lrv0 = (lr_acl_v0_t *)lr;
665                 bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes);
666         } else {
667                 void *start = (ace_t *)(lr + 1);
668
669                 bcopy(vsecp->vsa_aclentp, start, aclbytes);
670
671                 start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes);
672
673                 if (fuidp) {
674                         start = zfs_log_fuid_ids(fuidp, start);
675                         (void) zfs_log_fuid_domains(fuidp, start);
676                 }
677         }
678
679         itx->itx_sync = (zp->z_sync_cnt != 0);
680         zil_itx_assign(zilog, itx, tx);
681 }