Add linux kernel disk support
[zfs.git] / module / 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 #ifdef HAVE_ZPL
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  * zfs_log_create() is used to handle TX_CREATE, TX_CREATE_ATTR, TX_MKDIR,
217  * TX_MKDIR_ATTR and TX_MKXATTR
218  * transactions.
219  *
220  * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID
221  * domain information appended prior to the name.  In this case the
222  * uid/gid in the log record will be a log centric FUID.
223  *
224  * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that
225  * may contain attributes, ACL and optional fuid information.
226  *
227  * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify
228  * and ACL and normal users/groups in the ACEs.
229  *
230  * There may be an optional xvattr attribute information similar
231  * to zfs_log_setattr.
232  *
233  * Also, after the file name "domain" strings may be appended.
234  */
235 void
236 zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
237     znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp,
238     zfs_fuid_info_t *fuidp, vattr_t *vap)
239 {
240         itx_t *itx;
241         lr_create_t *lr;
242         lr_acl_create_t *lracl;
243         size_t aclsize;
244         size_t xvatsize = 0;
245         size_t txsize;
246         xvattr_t *xvap = (xvattr_t *)vap;
247         void *end;
248         size_t lrsize;
249         size_t namesize = strlen(name) + 1;
250         size_t fuidsz = 0;
251
252         if (zil_replaying(zilog, tx))
253                 return;
254
255         /*
256          * If we have FUIDs present then add in space for
257          * domains and ACE fuid's if any.
258          */
259         if (fuidp) {
260                 fuidsz += fuidp->z_domain_str_sz;
261                 fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t);
262         }
263
264         if (vap->va_mask & AT_XVATTR)
265                 xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize);
266
267         if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
268             (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR ||
269             (int)txtype == TX_MKXATTR) {
270                 txsize = sizeof (*lr) + namesize + fuidsz + xvatsize;
271                 lrsize = sizeof (*lr);
272         } else {
273                 aclsize = (vsecp) ? vsecp->vsa_aclentsz : 0;
274                 txsize =
275                     sizeof (lr_acl_create_t) + namesize + fuidsz +
276                     ZIL_ACE_LENGTH(aclsize) + xvatsize;
277                 lrsize = sizeof (lr_acl_create_t);
278         }
279
280         itx = zil_itx_create(txtype, txsize);
281
282         lr = (lr_create_t *)&itx->itx_lr;
283         lr->lr_doid = dzp->z_id;
284         lr->lr_foid = zp->z_id;
285         lr->lr_mode = zp->z_mode;
286         if (!IS_EPHEMERAL(zp->z_uid)) {
287                 lr->lr_uid = (uint64_t)zp->z_uid;
288         } else {
289                 lr->lr_uid = fuidp->z_fuid_owner;
290         }
291         if (!IS_EPHEMERAL(zp->z_gid)) {
292                 lr->lr_gid = (uint64_t)zp->z_gid;
293         } else {
294                 lr->lr_gid = fuidp->z_fuid_group;
295         }
296         (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
297             sizeof (uint64_t));
298         (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
299             lr->lr_crtime, sizeof (uint64_t) * 2);
300
301         if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zp->z_zfsvfs), &lr->lr_rdev,
302             sizeof (lr->lr_rdev)) != 0)
303                 lr->lr_rdev = 0;
304
305         /*
306          * Fill in xvattr info if any
307          */
308         if (vap->va_mask & AT_XVATTR) {
309                 zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap);
310                 end = (caddr_t)lr + lrsize + xvatsize;
311         } else {
312                 end = (caddr_t)lr + lrsize;
313         }
314
315         /* Now fill in any ACL info */
316
317         if (vsecp) {
318                 lracl = (lr_acl_create_t *)&itx->itx_lr;
319                 lracl->lr_aclcnt = vsecp->vsa_aclcnt;
320                 lracl->lr_acl_bytes = aclsize;
321                 lracl->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
322                 lracl->lr_fuidcnt  = fuidp ? fuidp->z_fuid_cnt : 0;
323                 if (vsecp->vsa_aclflags & VSA_ACE_ACLFLAGS)
324                         lracl->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
325                 else
326                         lracl->lr_acl_flags = 0;
327
328                 bcopy(vsecp->vsa_aclentp, end, aclsize);
329                 end = (caddr_t)end + ZIL_ACE_LENGTH(aclsize);
330         }
331
332         /* drop in FUID info */
333         if (fuidp) {
334                 end = zfs_log_fuid_ids(fuidp, end);
335                 end = zfs_log_fuid_domains(fuidp, end);
336         }
337         /*
338          * Now place file name in log record
339          */
340         bcopy(name, end, namesize);
341
342         zil_itx_assign(zilog, itx, tx);
343 }
344
345 /*
346  * zfs_log_remove() handles both TX_REMOVE and TX_RMDIR transactions.
347  */
348 void
349 zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
350         znode_t *dzp, char *name, uint64_t foid)
351 {
352         itx_t *itx;
353         lr_remove_t *lr;
354         size_t namesize = strlen(name) + 1;
355
356         if (zil_replaying(zilog, tx))
357                 return;
358
359         itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
360         lr = (lr_remove_t *)&itx->itx_lr;
361         lr->lr_doid = dzp->z_id;
362         bcopy(name, (char *)(lr + 1), namesize);
363
364         itx->itx_oid = foid;
365
366         zil_itx_assign(zilog, itx, tx);
367 }
368
369 /*
370  * zfs_log_link() handles TX_LINK transactions.
371  */
372 void
373 zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
374         znode_t *dzp, znode_t *zp, char *name)
375 {
376         itx_t *itx;
377         lr_link_t *lr;
378         size_t namesize = strlen(name) + 1;
379
380         if (zil_replaying(zilog, tx))
381                 return;
382
383         itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
384         lr = (lr_link_t *)&itx->itx_lr;
385         lr->lr_doid = dzp->z_id;
386         lr->lr_link_obj = zp->z_id;
387         bcopy(name, (char *)(lr + 1), namesize);
388
389         zil_itx_assign(zilog, itx, tx);
390 }
391
392 /*
393  * zfs_log_symlink() handles TX_SYMLINK transactions.
394  */
395 void
396 zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
397     znode_t *dzp, znode_t *zp, char *name, char *link)
398 {
399         itx_t *itx;
400         lr_create_t *lr;
401         size_t namesize = strlen(name) + 1;
402         size_t linksize = strlen(link) + 1;
403
404         if (zil_replaying(zilog, tx))
405                 return;
406
407         itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
408         lr = (lr_create_t *)&itx->itx_lr;
409         lr->lr_doid = dzp->z_id;
410         lr->lr_foid = zp->z_id;
411         lr->lr_uid = zp->z_uid;
412         lr->lr_gid = zp->z_gid;
413         lr->lr_mode = zp->z_mode;
414         (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
415             sizeof (uint64_t));
416         (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
417             lr->lr_crtime, sizeof (uint64_t) * 2);
418         bcopy(name, (char *)(lr + 1), namesize);
419         bcopy(link, (char *)(lr + 1) + namesize, linksize);
420
421         zil_itx_assign(zilog, itx, tx);
422 }
423
424 /*
425  * zfs_log_rename() handles TX_RENAME transactions.
426  */
427 void
428 zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
429         znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
430 {
431         itx_t *itx;
432         lr_rename_t *lr;
433         size_t snamesize = strlen(sname) + 1;
434         size_t dnamesize = strlen(dname) + 1;
435
436         if (zil_replaying(zilog, tx))
437                 return;
438
439         itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
440         lr = (lr_rename_t *)&itx->itx_lr;
441         lr->lr_sdoid = sdzp->z_id;
442         lr->lr_tdoid = tdzp->z_id;
443         bcopy(sname, (char *)(lr + 1), snamesize);
444         bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
445         itx->itx_oid = szp->z_id;
446
447         zil_itx_assign(zilog, itx, tx);
448 }
449
450 /*
451  * zfs_log_write() handles TX_WRITE transactions.
452  */
453 ssize_t zfs_immediate_write_sz = 32768;
454
455 void
456 zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
457         znode_t *zp, offset_t off, ssize_t resid, int ioflag)
458 {
459         itx_wr_state_t write_state;
460         boolean_t slogging;
461         uintptr_t fsync_cnt;
462         ssize_t immediate_write_sz;
463
464         if (zil_replaying(zilog, tx) || zp->z_unlinked)
465                 return;
466
467         immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
468             ? 0 : zfs_immediate_write_sz;
469
470         slogging = spa_has_slogs(zilog->zl_spa) &&
471             (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
472         if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
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                 ssize_t len;
487
488                 /*
489                  * If the write would overflow the largest block then split it.
490                  */
491                 if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
492                         len = SPA_MAXBLOCKSIZE >> 1;
493                 else
494                         len = resid;
495
496                 itx = zil_itx_create(txtype, sizeof (*lr) +
497                     (write_state == WR_COPIED ? len : 0));
498                 lr = (lr_write_t *)&itx->itx_lr;
499                 if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
500                     zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
501                         zil_itx_destroy(itx);
502                         itx = zil_itx_create(txtype, sizeof (*lr));
503                         lr = (lr_write_t *)&itx->itx_lr;
504                         write_state = WR_NEED_COPY;
505                 }
506
507                 itx->itx_wr_state = write_state;
508                 if (write_state == WR_NEED_COPY)
509                         itx->itx_sod += len;
510                 lr->lr_foid = zp->z_id;
511                 lr->lr_offset = off;
512                 lr->lr_length = len;
513                 lr->lr_blkoff = 0;
514                 BP_ZERO(&lr->lr_blkptr);
515
516                 itx->itx_private = zp->z_zfsvfs;
517
518                 if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
519                     (fsync_cnt == 0))
520                         itx->itx_sync = B_FALSE;
521
522                 zil_itx_assign(zilog, itx, tx);
523
524                 off += len;
525                 resid -= len;
526         }
527 }
528
529 /*
530  * zfs_log_truncate() handles TX_TRUNCATE transactions.
531  */
532 void
533 zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
534         znode_t *zp, uint64_t off, uint64_t len)
535 {
536         itx_t *itx;
537         lr_truncate_t *lr;
538
539         if (zil_replaying(zilog, tx) || zp->z_unlinked)
540                 return;
541
542         itx = zil_itx_create(txtype, sizeof (*lr));
543         lr = (lr_truncate_t *)&itx->itx_lr;
544         lr->lr_foid = zp->z_id;
545         lr->lr_offset = off;
546         lr->lr_length = len;
547
548         itx->itx_sync = (zp->z_sync_cnt != 0);
549         zil_itx_assign(zilog, itx, tx);
550 }
551
552 /*
553  * zfs_log_setattr() handles TX_SETATTR transactions.
554  */
555 void
556 zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
557         znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp)
558 {
559         itx_t           *itx;
560         lr_setattr_t    *lr;
561         xvattr_t        *xvap = (xvattr_t *)vap;
562         size_t          recsize = sizeof (lr_setattr_t);
563         void            *start;
564
565         if (zil_replaying(zilog, tx) || zp->z_unlinked)
566                 return;
567
568         /*
569          * If XVATTR set, then log record size needs to allow
570          * for lr_attr_t + xvattr mask, mapsize and create time
571          * plus actual attribute values
572          */
573         if (vap->va_mask & AT_XVATTR)
574                 recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
575
576         if (fuidp)
577                 recsize += fuidp->z_domain_str_sz;
578
579         itx = zil_itx_create(txtype, recsize);
580         lr = (lr_setattr_t *)&itx->itx_lr;
581         lr->lr_foid = zp->z_id;
582         lr->lr_mask = (uint64_t)mask_applied;
583         lr->lr_mode = (uint64_t)vap->va_mode;
584         if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid))
585                 lr->lr_uid = fuidp->z_fuid_owner;
586         else
587                 lr->lr_uid = (uint64_t)vap->va_uid;
588
589         if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid))
590                 lr->lr_gid = fuidp->z_fuid_group;
591         else
592                 lr->lr_gid = (uint64_t)vap->va_gid;
593
594         lr->lr_size = (uint64_t)vap->va_size;
595         ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime);
596         ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime);
597         start = (lr_setattr_t *)(lr + 1);
598         if (vap->va_mask & AT_XVATTR) {
599                 zfs_log_xvattr((lr_attr_t *)start, xvap);
600                 start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
601         }
602
603         /*
604          * Now stick on domain information if any on end
605          */
606
607         if (fuidp)
608                 (void) zfs_log_fuid_domains(fuidp, start);
609
610         itx->itx_sync = (zp->z_sync_cnt != 0);
611         zil_itx_assign(zilog, itx, tx);
612 }
613
614 /*
615  * zfs_log_acl() handles TX_ACL transactions.
616  */
617 void
618 zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
619     vsecattr_t *vsecp, zfs_fuid_info_t *fuidp)
620 {
621         itx_t *itx;
622         lr_acl_v0_t *lrv0;
623         lr_acl_t *lr;
624         int txtype;
625         int lrsize;
626         size_t txsize;
627         size_t aclbytes = vsecp->vsa_aclentsz;
628
629         if (zil_replaying(zilog, tx) || zp->z_unlinked)
630                 return;
631
632         txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
633             TX_ACL_V0 : TX_ACL;
634
635         if (txtype == TX_ACL)
636                 lrsize = sizeof (*lr);
637         else
638                 lrsize = sizeof (*lrv0);
639
640         txsize = lrsize +
641             ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) +
642             (fuidp ? fuidp->z_domain_str_sz : 0) +
643             sizeof (uint64_t) * (fuidp ? fuidp->z_fuid_cnt : 0);
644
645         itx = zil_itx_create(txtype, txsize);
646
647         lr = (lr_acl_t *)&itx->itx_lr;
648         lr->lr_foid = zp->z_id;
649         if (txtype == TX_ACL) {
650                 lr->lr_acl_bytes = aclbytes;
651                 lr->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
652                 lr->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
653                 if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS)
654                         lr->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
655                 else
656                         lr->lr_acl_flags = 0;
657         }
658         lr->lr_aclcnt = (uint64_t)vsecp->vsa_aclcnt;
659
660         if (txtype == TX_ACL_V0) {
661                 lrv0 = (lr_acl_v0_t *)lr;
662                 bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes);
663         } else {
664                 void *start = (ace_t *)(lr + 1);
665
666                 bcopy(vsecp->vsa_aclentp, start, aclbytes);
667
668                 start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes);
669
670                 if (fuidp) {
671                         start = zfs_log_fuid_ids(fuidp, start);
672                         (void) zfs_log_fuid_domains(fuidp, start);
673                 }
674         }
675
676         itx->itx_sync = (zp->z_sync_cnt != 0);
677         zil_itx_assign(zilog, itx, tx);
678 }
679
680 #endif /* HAVE_ZPL */