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.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
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>
31 #include <sys/thread.h>
33 #include <sys/fcntl.h>
35 #include <sys/fs/zfs.h>
36 #include <sys/zfs_znode.h>
37 #include <sys/zfs_dir.h>
38 #include <sys/zfs_acl.h>
39 #include <sys/zfs_fuid.h>
42 #include <sys/zfs_vnops.h>
43 #include <sys/byteorder.h>
47 #include <sys/atomic.h>
51 * Functions to replay ZFS intent log (ZIL) records
52 * The functions are called through a function vector (zfs_replay_vector)
53 * which is indexed by the transaction type.
57 zfs_init_iattr(struct iattr *attr, uint64_t mask, uint64_t mode,
58 uint64_t uid, uint64_t gid)
60 memset(attr, 0, sizeof(*attr));
61 attr->ia_valid = (uint_t)mask;
63 attr->ia_uid = (uid_t)(IS_EPHEMERAL(uid)) ? -1 : uid;
64 attr->ia_gid = (gid_t)(IS_EPHEMERAL(gid)) ? -1 : gid;
69 zfs_replay_error(zfs_sb_t *zsb, lr_t *lr, boolean_t byteswap)
76 zfs_replay_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
78 xoptattr_t *xoap = NULL;
85 xvap->xva_vattr.va_mask |= AT_XVATTR;
86 if ((xoap = xva_getxoptattr(xvap)) == NULL) {
87 xvap->xva_vattr.va_mask &= ~AT_XVATTR; /* shouldn't happen */
91 ASSERT(lrattr->lr_attr_masksize == xvap->xva_mapsize);
93 bitmap = &lrattr->lr_attr_bitmap;
94 for (i = 0; i != lrattr->lr_attr_masksize; i++, bitmap++)
95 xvap->xva_reqattrmap[i] = *bitmap;
97 attrs = (uint64_t *)(lrattr + lrattr->lr_attr_masksize - 1);
99 scanstamp = (caddr_t)(crtime + 2);
101 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN))
102 xoap->xoa_hidden = ((*attrs & XAT0_HIDDEN) != 0);
103 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM))
104 xoap->xoa_system = ((*attrs & XAT0_SYSTEM) != 0);
105 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE))
106 xoap->xoa_archive = ((*attrs & XAT0_ARCHIVE) != 0);
107 if (XVA_ISSET_REQ(xvap, XAT_READONLY))
108 xoap->xoa_readonly = ((*attrs & XAT0_READONLY) != 0);
109 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
110 xoap->xoa_immutable = ((*attrs & XAT0_IMMUTABLE) != 0);
111 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
112 xoap->xoa_nounlink = ((*attrs & XAT0_NOUNLINK) != 0);
113 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
114 xoap->xoa_appendonly = ((*attrs & XAT0_APPENDONLY) != 0);
115 if (XVA_ISSET_REQ(xvap, XAT_NODUMP))
116 xoap->xoa_nodump = ((*attrs & XAT0_NODUMP) != 0);
117 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE))
118 xoap->xoa_opaque = ((*attrs & XAT0_OPAQUE) != 0);
119 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
120 xoap->xoa_av_modified = ((*attrs & XAT0_AV_MODIFIED) != 0);
121 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED))
122 xoap->xoa_av_quarantined =
123 ((*attrs & XAT0_AV_QUARANTINED) != 0);
124 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
125 ZFS_TIME_DECODE(&xoap->xoa_createtime, crtime);
126 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
127 bcopy(scanstamp, xoap->xoa_av_scanstamp, AV_SCANSTAMP_SZ);
128 if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
129 xoap->xoa_reparse = ((*attrs & XAT0_REPARSE) != 0);
130 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE))
131 xoap->xoa_offline = ((*attrs & XAT0_OFFLINE) != 0);
132 if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
133 xoap->xoa_sparse = ((*attrs & XAT0_SPARSE) != 0);
135 #endif /* HAVE_XVATTR */
138 zfs_replay_domain_cnt(uint64_t uid, uint64_t gid)
144 uid_idx = FUID_INDEX(uid);
145 gid_idx = FUID_INDEX(gid);
148 if (gid_idx > 0 && gid_idx != uid_idx)
155 zfs_replay_fuid_domain_common(zfs_fuid_info_t *fuid_infop, void *start,
160 for (i = 0; i != domcnt; i++) {
161 fuid_infop->z_domain_table[i] = start;
162 start = (caddr_t)start + strlen(start) + 1;
169 * Set the uid/gid in the fuid_info structure.
172 zfs_replay_fuid_ugid(zfs_fuid_info_t *fuid_infop, uint64_t uid, uint64_t gid)
175 * If owner or group are log specific FUIDs then slurp up
176 * domain information and build zfs_fuid_info_t
178 if (IS_EPHEMERAL(uid))
179 fuid_infop->z_fuid_owner = uid;
181 if (IS_EPHEMERAL(gid))
182 fuid_infop->z_fuid_group = gid;
186 * Load fuid domains into fuid_info_t
188 static zfs_fuid_info_t *
189 zfs_replay_fuid_domain(void *buf, void **end, uint64_t uid, uint64_t gid)
193 zfs_fuid_info_t *fuid_infop;
195 fuid_infop = zfs_fuid_info_alloc();
197 domcnt = zfs_replay_domain_cnt(uid, gid);
202 fuid_infop->z_domain_table =
203 kmem_zalloc(domcnt * sizeof (char **), KM_SLEEP);
205 zfs_replay_fuid_ugid(fuid_infop, uid, gid);
207 fuid_infop->z_domain_cnt = domcnt;
208 *end = zfs_replay_fuid_domain_common(fuid_infop, buf, domcnt);
213 * load zfs_fuid_t's and fuid_domains into fuid_info_t
215 static zfs_fuid_info_t *
216 zfs_replay_fuids(void *start, void **end, int idcnt, int domcnt, uint64_t uid,
219 uint64_t *log_fuid = (uint64_t *)start;
220 zfs_fuid_info_t *fuid_infop;
223 fuid_infop = zfs_fuid_info_alloc();
224 fuid_infop->z_domain_cnt = domcnt;
226 fuid_infop->z_domain_table =
227 kmem_zalloc(domcnt * sizeof (char **), KM_SLEEP);
229 for (i = 0; i != idcnt; i++) {
232 zfuid = kmem_alloc(sizeof (zfs_fuid_t), KM_SLEEP);
233 zfuid->z_logfuid = *log_fuid;
236 list_insert_tail(&fuid_infop->z_fuids, zfuid);
240 zfs_replay_fuid_ugid(fuid_infop, uid, gid);
242 *end = zfs_replay_fuid_domain_common(fuid_infop, log_fuid, domcnt);
247 zfs_replay_swap_attrs(lr_attr_t *lrattr)
249 /* swap the lr_attr structure */
250 byteswap_uint32_array(lrattr, sizeof (*lrattr));
251 /* swap the bitmap */
252 byteswap_uint32_array(lrattr + 1, (lrattr->lr_attr_masksize - 1) *
254 /* swap the attributes, create time + 64 bit word for attributes */
255 byteswap_uint64_array((caddr_t)(lrattr + 1) + (sizeof (uint32_t) *
256 (lrattr->lr_attr_masksize - 1)), 3 * sizeof (uint64_t));
260 * Replay file create with optional ACL, xvattr information as well
261 * as option FUID information.
264 zfs_replay_create_acl(zfs_sb_t *zsb, lr_acl_create_t *lracl, boolean_t byteswap)
266 char *name = NULL; /* location determined later */
267 lr_create_t *lr = (lr_create_t *)lracl;
269 struct inode *ip = NULL;
272 vsecattr_t vsec = { 0 };
273 #endif /* HAVE_XVATTR */
282 txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
284 byteswap_uint64_array(lracl, sizeof (*lracl));
285 if (txtype == TX_CREATE_ACL_ATTR ||
286 txtype == TX_MKDIR_ACL_ATTR) {
287 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
288 zfs_replay_swap_attrs(lrattr);
289 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
292 aclstart = (caddr_t)(lracl + 1) + xvatlen;
293 zfs_ace_byteswap(aclstart, lracl->lr_acl_bytes, B_FALSE);
295 if (lracl->lr_fuidcnt) {
296 byteswap_uint64_array((caddr_t)aclstart +
297 ZIL_ACE_LENGTH(lracl->lr_acl_bytes),
298 lracl->lr_fuidcnt * sizeof (uint64_t));
302 if ((error = zfs_zget(zsb, lr->lr_doid, &dzp)) != 0)
307 zfs_init_iattr(&xva.xva_vattr, ATTR_MODE | ATTR_UID | ATTR_GID,
308 lr->lr_mode, lr->lr_uid, lr->lr_gid, /*lr->lr_rdev, lr->lr_foid*/);
311 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
312 * eventually end up in zfs_mknode(), which assigns the object's
313 * creation time and generation number. The generic zfs_create()
314 * doesn't have either concept, so we smuggle the values inside
315 * the vattr's otherwise unused va_ctime and va_nblocks fields.
317 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
318 xva.xva_vattr.va_nblocks = lr->lr_gen;
319 #endif /* HAVE_XVATTR */
321 error = dmu_object_info(zsb->z_os, lr->lr_foid, NULL);
325 if (lr->lr_common.lrc_txtype & TX_CI)
329 aclstart = (caddr_t)(lracl + 1);
330 fuidstart = (caddr_t)aclstart +
331 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
332 zsb->z_fuid_replay = zfs_replay_fuids(fuidstart,
333 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
334 lr->lr_uid, lr->lr_gid);
336 case TX_CREATE_ACL_ATTR:
339 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
340 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
341 xva.xva_vattr.va_mask |= AT_XVATTR;
342 zfs_replay_xvattr(lrattr, &xva);
344 vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
345 vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
346 vsec.vsa_aclcnt = lracl->lr_aclcnt;
347 vsec.vsa_aclentsz = lracl->lr_acl_bytes;
348 vsec.vsa_aclflags = lracl->lr_acl_flags;
349 if (zsb->z_fuid_replay == NULL) {
350 fuidstart = (caddr_t)(lracl + 1) + xvatlen +
351 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
353 zfs_replay_fuids(fuidstart,
354 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
355 lr->lr_uid, lr->lr_gid);
358 error = zfs_create(ZTOI(dzp), name, &xva.xva_vattr,
359 0, 0, &ip, kcred, vflg, NULL, &vsec);
360 #endif /* HAVE_XVATTR */
363 aclstart = (caddr_t)(lracl + 1);
364 fuidstart = (caddr_t)aclstart +
365 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
366 zsb->z_fuid_replay = zfs_replay_fuids(fuidstart,
367 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
368 lr->lr_uid, lr->lr_gid);
370 case TX_MKDIR_ACL_ATTR:
373 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
374 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
375 zfs_replay_xvattr(lrattr, &xva);
377 vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
378 vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
379 vsec.vsa_aclcnt = lracl->lr_aclcnt;
380 vsec.vsa_aclentsz = lracl->lr_acl_bytes;
381 vsec.vsa_aclflags = lracl->lr_acl_flags;
382 if (zsb->z_fuid_replay == NULL) {
383 fuidstart = (caddr_t)(lracl + 1) + xvatlen +
384 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
386 zfs_replay_fuids(fuidstart,
387 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
388 lr->lr_uid, lr->lr_gid);
390 error = zfs_mkdir(ZTOI(dzp), name, &xva.xva_vattr,
391 &ip, kcred, NULL, vflg, &vsec);
392 #endif /* HAVE_XVATTR */
399 if (error == 0 && ip != NULL)
404 if (zsb->z_fuid_replay)
405 zfs_fuid_info_free(zsb->z_fuid_replay);
406 zsb->z_fuid_replay = NULL;
412 zfs_replay_create(zfs_sb_t *zsb, lr_create_t *lr, boolean_t byteswap)
414 char *name = NULL; /* location determined later */
415 char *link; /* symlink content follows name */
417 struct inode *ip = NULL;
421 size_t lrsize = sizeof (lr_create_t);
424 #endif /* HAVE_XVATTR */
429 txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
431 byteswap_uint64_array(lr, sizeof (*lr));
432 if (txtype == TX_CREATE_ATTR || txtype == TX_MKDIR_ATTR)
433 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
437 if ((error = zfs_zget(zsb, lr->lr_doid, &dzp)) != 0)
442 zfs_init_iattr(&xva.xva_vattr, ATTR_MODE | ATTR_UID | ATTR_GID,
443 lr->lr_mode, lr->lr_uid, lr->lr_gid, /*lr->lr_rdev, lr->lr_foid*/);
446 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
447 * eventually end up in zfs_mknode(), which assigns the object's
448 * creation time and generation number. The generic zfs_create()
449 * doesn't have either concept, so we smuggle the values inside
450 * the vattr's otherwise unused va_ctime and va_nblocks fields.
452 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
453 xva.xva_vattr.va_nblocks = lr->lr_gen;
454 #endif /* HAVE_XVATTR */
456 error = dmu_object_info(zsb->z_os, lr->lr_foid, NULL);
460 if (lr->lr_common.lrc_txtype & TX_CI)
464 * Symlinks don't have fuid info, and CIFS never creates
467 * The _ATTR versions will grab the fuid info in their subcases.
469 if ((int)lr->lr_common.lrc_txtype != TX_SYMLINK &&
470 (int)lr->lr_common.lrc_txtype != TX_MKDIR_ATTR &&
471 (int)lr->lr_common.lrc_txtype != TX_CREATE_ATTR) {
474 zfs_replay_fuid_domain(start, &start,
475 lr->lr_uid, lr->lr_gid);
481 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
482 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
483 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
484 start = (caddr_t)(lr + 1) + xvatlen;
486 zfs_replay_fuid_domain(start, &start,
487 lr->lr_uid, lr->lr_gid);
488 name = (char *)start;
489 #endif /* HAVE_XVATTR */
494 name = (char *)start;
496 error = zfs_create(ZTOI(dzp), name, &xva.xva_vattr,
497 0, 0, &ip, kcred, vflg, NULL);
501 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
502 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
503 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
504 start = (caddr_t)(lr + 1) + xvatlen;
506 zfs_replay_fuid_domain(start, &start,
507 lr->lr_uid, lr->lr_gid);
508 name = (char *)start;
509 #endif /* HAVE_XVATTR */
514 name = (char *)(lr + 1);
516 error = zfs_mkdir(ZTOI(dzp), name, &xva.xva_vattr,
517 &ip, kcred, vflg, NULL);
520 error = zfs_make_xattrdir(dzp, &xva.xva_vattr, &ip, kcred);
523 name = (char *)(lr + 1);
524 link = name + strlen(name) + 1;
525 error = zfs_symlink(ZTOI(dzp), name, &xva.xva_vattr,
526 link, &ip, kcred, vflg);
533 if (error == 0 && ip != NULL)
538 if (zsb->z_fuid_replay)
539 zfs_fuid_info_free(zsb->z_fuid_replay);
540 zsb->z_fuid_replay = NULL;
545 zfs_replay_remove(zfs_sb_t *zsb, lr_remove_t *lr, boolean_t byteswap)
547 char *name = (char *)(lr + 1); /* name follows lr_remove_t */
553 byteswap_uint64_array(lr, sizeof (*lr));
555 if ((error = zfs_zget(zsb, lr->lr_doid, &dzp)) != 0)
559 if (lr->lr_common.lrc_txtype & TX_CI)
563 switch ((int)lr->lr_common.lrc_txtype) {
565 error = zfs_remove(ZTOI(dzp), name, kcred);
568 error = zfs_rmdir(ZTOI(dzp), name, NULL, kcred, vflg);
580 zfs_replay_link(zfs_sb_t *zsb, lr_link_t *lr, boolean_t byteswap)
582 char *name = (char *)(lr + 1); /* name follows lr_link_t */
587 byteswap_uint64_array(lr, sizeof (*lr));
589 if ((error = zfs_zget(zsb, lr->lr_doid, &dzp)) != 0)
592 if ((error = zfs_zget(zsb, lr->lr_link_obj, &zp)) != 0) {
598 if (lr->lr_common.lrc_txtype & TX_CI)
602 error = zfs_link(ZTOI(dzp), ZTOI(zp), name, kcred);
611 zfs_replay_rename(zfs_sb_t *zsb, lr_rename_t *lr, boolean_t byteswap)
613 char *sname = (char *)(lr + 1); /* sname and tname follow lr_rename_t */
614 char *tname = sname + strlen(sname) + 1;
615 znode_t *sdzp, *tdzp;
620 byteswap_uint64_array(lr, sizeof (*lr));
622 if ((error = zfs_zget(zsb, lr->lr_sdoid, &sdzp)) != 0)
625 if ((error = zfs_zget(zsb, lr->lr_tdoid, &tdzp)) != 0) {
630 if (lr->lr_common.lrc_txtype & TX_CI)
633 error = zfs_rename(ZTOI(sdzp), sname, ZTOI(tdzp), tname, kcred, vflg);
642 zfs_replay_write(zfs_sb_t *zsb, lr_write_t *lr, boolean_t byteswap)
645 char *data = (char *)(lr + 1); /* data follows lr_write_t */
649 uint64_t eod, offset, length;
652 byteswap_uint64_array(lr, sizeof (*lr));
654 if ((error = zfs_zget(zsb, lr->lr_foid, &zp)) != 0) {
656 * As we can log writes out of order, it's possible the
657 * file has been removed. In this case just drop the write
658 * and return success.
665 offset = lr->lr_offset;
666 length = lr->lr_length;
667 eod = offset + length; /* end of data for this write */
670 * This may be a write from a dmu_sync() for a whole block,
671 * and may extend beyond the current end of the file.
672 * We can't just replay what was written for this TX_WRITE as
673 * a future TX_WRITE2 may extend the eof and the data for that
674 * write needs to be there. So we write the whole block and
675 * reduce the eof. This needs to be done within the single dmu
676 * transaction created within vn_rdwr -> zfs_write. So a possible
677 * new end of file is passed through in zsb->z_replay_eof
680 zsb->z_replay_eof = 0; /* 0 means don't change end of file */
682 /* If it's a dmu_sync() block, write the whole block */
683 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
684 uint64_t blocksize = BP_GET_LSIZE(&lr->lr_blkptr);
685 if (length < blocksize) {
686 offset -= offset % blocksize;
689 if (zp->z_size < eod)
690 zsb->z_replay_eof = eod;
694 * XXX: Use zfs_write() once uio types are removed
697 error = vn_rdwr(UIO_WRITE, ZTOI(zp), data, length, offset,
698 UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
702 zsb->z_replay_eof = 0; /* safety */
708 * TX_WRITE2 are only generated when dmu_sync() returns EALREADY
709 * meaning the pool block is already being synced. So now that we always write
710 * out full blocks, all we have to do is expand the eof if
714 zfs_replay_write2(zfs_sb_t *zsb, lr_write_t *lr, boolean_t byteswap)
721 byteswap_uint64_array(lr, sizeof (*lr));
723 if ((error = zfs_zget(zsb, lr->lr_foid, &zp)) != 0)
727 end = lr->lr_offset + lr->lr_length;
728 if (end > zp->z_size) {
729 dmu_tx_t *tx = dmu_tx_create(zsb->z_os);
732 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
733 error = dmu_tx_assign(tx, TXG_WAIT);
736 if (error == ERESTART) {
744 (void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zsb),
745 (void *)&zp->z_size, sizeof (uint64_t), tx);
747 /* Ensure the replayed seq is updated */
748 (void) zil_replaying(zsb->z_log, tx);
759 zfs_replay_truncate(zfs_sb_t *zsb, lr_truncate_t *lr, boolean_t byteswap)
766 byteswap_uint64_array(lr, sizeof (*lr));
768 if ((error = zfs_zget(zsb, lr->lr_foid, &zp)) != 0)
771 bzero(&fl, sizeof (fl));
774 fl.l_start = lr->lr_offset;
775 fl.l_len = lr->lr_length;
777 error = zfs_space(ZTOI(zp), F_FREESP, &fl, FWRITE | FOFFMAX,
778 lr->lr_offset, kcred);
786 zfs_replay_setattr(zfs_sb_t *zsb, lr_setattr_t *lr, boolean_t byteswap)
791 #endif /* HAVE_XATTR */
798 #endif /* HAVE_XVATTR */
800 byteswap_uint64_array(lr, sizeof (*lr));
803 if ((lr->lr_mask & AT_XVATTR) &&
804 zsb->z_version >= ZPL_VERSION_INITIAL)
805 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
806 #endif /* HAVE_XVATTR */
809 if ((error = zfs_zget(zsb, lr->lr_foid, &zp)) != 0)
812 zfs_init_iattr(&attr, lr->lr_mask, lr->lr_mode, lr->lr_uid, lr->lr_gid);
814 attr.ia_size = lr->lr_size;
815 ZFS_TIME_DECODE(&attr.ia_atime, lr->lr_atime);
816 ZFS_TIME_DECODE(&attr.ia_mtime, lr->lr_mtime);
819 * Fill in xvattr_t portions if necessary.
822 start = (lr_setattr_t *)(lr + 1);
824 if (iattr->ia_mask & AT_XVATTR) {
825 zfs_replay_xvattr((lr_attr_t *)start, &xva);
826 start = (caddr_t)start +
827 ZIL_XVAT_SIZE(((lr_attr_t *)start)->lr_attr_masksize);
829 xva.xva_vattr.va_mask &= ~AT_XVATTR;
830 #endif /* HAVE_XVATTR */
832 zsb->z_fuid_replay = zfs_replay_fuid_domain(start, &start,
833 lr->lr_uid, lr->lr_gid);
835 error = zfs_setattr(ZTOI(zp), &attr, 0, kcred);
837 zfs_fuid_info_free(zsb->z_fuid_replay);
838 zsb->z_fuid_replay = NULL;
845 zfs_replay_acl_v0(zfs_sb_t *zsb, lr_acl_v0_t *lr, boolean_t byteswap)
847 ace_t *ace = (ace_t *)(lr + 1); /* ace array follows lr_acl_t */
853 byteswap_uint64_array(lr, sizeof (*lr));
854 zfs_oldace_byteswap(ace, lr->lr_aclcnt);
857 if ((error = zfs_zget(zsb, lr->lr_foid, &zp)) != 0)
860 bzero(&vsa, sizeof (vsa));
861 vsa.vsa_mask = VSA_ACE | VSA_ACECNT;
862 vsa.vsa_aclcnt = lr->lr_aclcnt;
863 vsa.vsa_aclentsz = sizeof (ace_t) * vsa.vsa_aclcnt;
864 vsa.vsa_aclflags = 0;
865 vsa.vsa_aclentp = ace;
867 error = zfs_setsecattr(ZTOI(zp), &vsa, 0, kcred);
875 * Replaying ACLs is complicated by FUID support.
876 * The log record may contain some optional data
877 * to be used for replaying FUID's. These pieces
878 * are the actual FUIDs that were created initially.
879 * The FUID table index may no longer be valid and
880 * during zfs_create() a new index may be assigned.
881 * Because of this the log will contain the original
882 * doman+rid in order to create a new FUID.
884 * The individual ACEs may contain an ephemeral uid/gid which is no
885 * longer valid and will need to be replaced with an actual FUID.
889 zfs_replay_acl(zfs_sb_t *zsb, lr_acl_t *lr, boolean_t byteswap)
891 ace_t *ace = (ace_t *)(lr + 1);
897 byteswap_uint64_array(lr, sizeof (*lr));
898 zfs_ace_byteswap(ace, lr->lr_acl_bytes, B_FALSE);
899 if (lr->lr_fuidcnt) {
900 byteswap_uint64_array((caddr_t)ace +
901 ZIL_ACE_LENGTH(lr->lr_acl_bytes),
902 lr->lr_fuidcnt * sizeof (uint64_t));
906 if ((error = zfs_zget(zsb, lr->lr_foid, &zp)) != 0)
909 bzero(&vsa, sizeof (vsa));
910 vsa.vsa_mask = VSA_ACE | VSA_ACECNT | VSA_ACE_ACLFLAGS;
911 vsa.vsa_aclcnt = lr->lr_aclcnt;
912 vsa.vsa_aclentp = ace;
913 vsa.vsa_aclentsz = lr->lr_acl_bytes;
914 vsa.vsa_aclflags = lr->lr_acl_flags;
916 if (lr->lr_fuidcnt) {
917 void *fuidstart = (caddr_t)ace +
918 ZIL_ACE_LENGTH(lr->lr_acl_bytes);
921 zfs_replay_fuids(fuidstart, &fuidstart,
922 lr->lr_fuidcnt, lr->lr_domcnt, 0, 0);
925 error = zfs_setsecattr(ZTOI(zp), &vsa, 0, kcred);
927 if (zsb->z_fuid_replay)
928 zfs_fuid_info_free(zsb->z_fuid_replay);
930 zsb->z_fuid_replay = NULL;
937 * Callback vectors for replaying records
939 zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE] = {
940 (zil_replay_func_t *)zfs_replay_error, /* no such type */
941 (zil_replay_func_t *)zfs_replay_create, /* TX_CREATE */
942 (zil_replay_func_t *)zfs_replay_create, /* TX_MKDIR */
943 (zil_replay_func_t *)zfs_replay_create, /* TX_MKXATTR */
944 (zil_replay_func_t *)zfs_replay_create, /* TX_SYMLINK */
945 (zil_replay_func_t *)zfs_replay_remove, /* TX_REMOVE */
946 (zil_replay_func_t *)zfs_replay_remove, /* TX_RMDIR */
947 (zil_replay_func_t *)zfs_replay_link, /* TX_LINK */
948 (zil_replay_func_t *)zfs_replay_rename, /* TX_RENAME */
949 (zil_replay_func_t *)zfs_replay_write, /* TX_WRITE */
950 (zil_replay_func_t *)zfs_replay_truncate, /* TX_TRUNCATE */
951 (zil_replay_func_t *)zfs_replay_setattr, /* TX_SETATTR */
952 (zil_replay_func_t *)zfs_replay_acl_v0, /* TX_ACL_V0 */
953 (zil_replay_func_t *)zfs_replay_acl, /* TX_ACL */
954 (zil_replay_func_t *)zfs_replay_create_acl, /* TX_CREATE_ACL */
955 (zil_replay_func_t *)zfs_replay_create, /* TX_CREATE_ATTR */
956 (zil_replay_func_t *)zfs_replay_create_acl, /* TX_CREATE_ACL_ATTR */
957 (zil_replay_func_t *)zfs_replay_create_acl, /* TX_MKDIR_ACL */
958 (zil_replay_func_t *)zfs_replay_create, /* TX_MKDIR_ATTR */
959 (zil_replay_func_t *)zfs_replay_create_acl, /* TX_MKDIR_ACL_ATTR */
960 (zil_replay_func_t *)zfs_replay_write2, /* TX_WRITE2 */