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.
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>
33 #include <sys/thread.h>
35 #include <sys/fcntl.h>
37 #include <sys/fs/zfs.h>
38 #include <sys/zfs_znode.h>
39 #include <sys/zfs_dir.h>
40 #include <sys/zfs_acl.h>
41 #include <sys/zfs_fuid.h>
44 #include <sys/zfs_vnops.h>
45 #include <sys/byteorder.h>
49 #include <sys/atomic.h>
53 * Functions to replay ZFS intent log (ZIL) records
54 * The functions are called through a function vector (zfs_replay_vector)
55 * which is indexed by the transaction type.
59 zfs_init_vattr(vattr_t *vap, uint64_t mask, uint64_t mode,
60 uint64_t uid, uint64_t gid, uint64_t rdev, uint64_t nodeid)
62 bzero(vap, sizeof (*vap));
63 vap->va_mask = (uint_t)mask;
64 vap->va_type = IFTOVT(mode);
65 vap->va_mode = mode & MODEMASK;
66 vap->va_uid = (uid_t)(IS_EPHEMERAL(uid)) ? -1 : uid;
67 vap->va_gid = (gid_t)(IS_EPHEMERAL(gid)) ? -1 : gid;
68 vap->va_rdev = zfs_cmpldev(rdev);
69 vap->va_nodeid = nodeid;
74 zfs_replay_error(zfsvfs_t *zfsvfs, lr_t *lr, boolean_t byteswap)
80 zfs_replay_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
82 xoptattr_t *xoap = NULL;
89 xvap->xva_vattr.va_mask |= AT_XVATTR;
90 if ((xoap = xva_getxoptattr(xvap)) == NULL) {
91 xvap->xva_vattr.va_mask &= ~AT_XVATTR; /* shouldn't happen */
95 ASSERT(lrattr->lr_attr_masksize == xvap->xva_mapsize);
97 bitmap = &lrattr->lr_attr_bitmap;
98 for (i = 0; i != lrattr->lr_attr_masksize; i++, bitmap++)
99 xvap->xva_reqattrmap[i] = *bitmap;
101 attrs = (uint64_t *)(lrattr + lrattr->lr_attr_masksize - 1);
103 scanstamp = (caddr_t)(crtime + 2);
105 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN))
106 xoap->xoa_hidden = ((*attrs & XAT0_HIDDEN) != 0);
107 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM))
108 xoap->xoa_system = ((*attrs & XAT0_SYSTEM) != 0);
109 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE))
110 xoap->xoa_archive = ((*attrs & XAT0_ARCHIVE) != 0);
111 if (XVA_ISSET_REQ(xvap, XAT_READONLY))
112 xoap->xoa_readonly = ((*attrs & XAT0_READONLY) != 0);
113 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
114 xoap->xoa_immutable = ((*attrs & XAT0_IMMUTABLE) != 0);
115 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
116 xoap->xoa_nounlink = ((*attrs & XAT0_NOUNLINK) != 0);
117 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
118 xoap->xoa_appendonly = ((*attrs & XAT0_APPENDONLY) != 0);
119 if (XVA_ISSET_REQ(xvap, XAT_NODUMP))
120 xoap->xoa_nodump = ((*attrs & XAT0_NODUMP) != 0);
121 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE))
122 xoap->xoa_opaque = ((*attrs & XAT0_OPAQUE) != 0);
123 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
124 xoap->xoa_av_modified = ((*attrs & XAT0_AV_MODIFIED) != 0);
125 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED))
126 xoap->xoa_av_quarantined =
127 ((*attrs & XAT0_AV_QUARANTINED) != 0);
128 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
129 ZFS_TIME_DECODE(&xoap->xoa_createtime, crtime);
130 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
131 bcopy(scanstamp, xoap->xoa_av_scanstamp, AV_SCANSTAMP_SZ);
132 if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
133 xoap->xoa_reparse = ((*attrs & XAT0_REPARSE) != 0);
134 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE))
135 xoap->xoa_offline = ((*attrs & XAT0_OFFLINE) != 0);
136 if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
137 xoap->xoa_sparse = ((*attrs & XAT0_SPARSE) != 0);
141 zfs_replay_domain_cnt(uint64_t uid, uint64_t gid)
147 uid_idx = FUID_INDEX(uid);
148 gid_idx = FUID_INDEX(gid);
151 if (gid_idx > 0 && gid_idx != uid_idx)
158 zfs_replay_fuid_domain_common(zfs_fuid_info_t *fuid_infop, void *start,
163 for (i = 0; i != domcnt; i++) {
164 fuid_infop->z_domain_table[i] = start;
165 start = (caddr_t)start + strlen(start) + 1;
172 * Set the uid/gid in the fuid_info structure.
175 zfs_replay_fuid_ugid(zfs_fuid_info_t *fuid_infop, uint64_t uid, uint64_t gid)
178 * If owner or group are log specific FUIDs then slurp up
179 * domain information and build zfs_fuid_info_t
181 if (IS_EPHEMERAL(uid))
182 fuid_infop->z_fuid_owner = uid;
184 if (IS_EPHEMERAL(gid))
185 fuid_infop->z_fuid_group = gid;
189 * Load fuid domains into fuid_info_t
191 static zfs_fuid_info_t *
192 zfs_replay_fuid_domain(void *buf, void **end, uint64_t uid, uint64_t gid)
196 zfs_fuid_info_t *fuid_infop;
198 fuid_infop = zfs_fuid_info_alloc();
200 domcnt = zfs_replay_domain_cnt(uid, gid);
205 fuid_infop->z_domain_table =
206 kmem_zalloc(domcnt * sizeof (char **), KM_SLEEP);
208 zfs_replay_fuid_ugid(fuid_infop, uid, gid);
210 fuid_infop->z_domain_cnt = domcnt;
211 *end = zfs_replay_fuid_domain_common(fuid_infop, buf, domcnt);
216 * load zfs_fuid_t's and fuid_domains into fuid_info_t
218 static zfs_fuid_info_t *
219 zfs_replay_fuids(void *start, void **end, int idcnt, int domcnt, uint64_t uid,
222 uint64_t *log_fuid = (uint64_t *)start;
223 zfs_fuid_info_t *fuid_infop;
226 fuid_infop = zfs_fuid_info_alloc();
227 fuid_infop->z_domain_cnt = domcnt;
229 fuid_infop->z_domain_table =
230 kmem_zalloc(domcnt * sizeof (char **), KM_SLEEP);
232 for (i = 0; i != idcnt; i++) {
235 zfuid = kmem_alloc(sizeof (zfs_fuid_t), KM_SLEEP);
236 zfuid->z_logfuid = *log_fuid;
239 list_insert_tail(&fuid_infop->z_fuids, zfuid);
243 zfs_replay_fuid_ugid(fuid_infop, uid, gid);
245 *end = zfs_replay_fuid_domain_common(fuid_infop, log_fuid, domcnt);
250 zfs_replay_swap_attrs(lr_attr_t *lrattr)
252 /* swap the lr_attr structure */
253 byteswap_uint32_array(lrattr, sizeof (*lrattr));
254 /* swap the bitmap */
255 byteswap_uint32_array(lrattr + 1, (lrattr->lr_attr_masksize - 1) *
257 /* swap the attributes, create time + 64 bit word for attributes */
258 byteswap_uint64_array((caddr_t)(lrattr + 1) + (sizeof (uint32_t) *
259 (lrattr->lr_attr_masksize - 1)), 3 * sizeof (uint64_t));
263 * Replay file create with optional ACL, xvattr information as well
264 * as option FUID information.
267 zfs_replay_create_acl(zfsvfs_t *zfsvfs,
268 lr_acl_create_t *lracl, boolean_t byteswap)
270 char *name = NULL; /* location determined later */
271 lr_create_t *lr = (lr_create_t *)lracl;
276 vsecattr_t vsec = { 0 };
284 txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
286 byteswap_uint64_array(lracl, sizeof (*lracl));
287 if (txtype == TX_CREATE_ACL_ATTR ||
288 txtype == TX_MKDIR_ACL_ATTR) {
289 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
290 zfs_replay_swap_attrs(lrattr);
291 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
294 aclstart = (caddr_t)(lracl + 1) + xvatlen;
295 zfs_ace_byteswap(aclstart, lracl->lr_acl_bytes, B_FALSE);
297 if (lracl->lr_fuidcnt) {
298 byteswap_uint64_array((caddr_t)aclstart +
299 ZIL_ACE_LENGTH(lracl->lr_acl_bytes),
300 lracl->lr_fuidcnt * sizeof (uint64_t));
304 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
308 zfs_init_vattr(&xva.xva_vattr, AT_TYPE | AT_MODE | AT_UID | AT_GID,
309 lr->lr_mode, lr->lr_uid, lr->lr_gid, lr->lr_rdev, lr->lr_foid);
312 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
313 * eventually end up in zfs_mknode(), which assigns the object's
314 * creation time and generation number. The generic zfs_create()
315 * doesn't have either concept, so we smuggle the values inside
316 * the vattr's otherwise unused va_ctime and va_nblocks fields.
318 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
319 xva.xva_vattr.va_nblocks = lr->lr_gen;
321 error = dmu_object_info(zfsvfs->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 zfsvfs->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:
338 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
339 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
340 xva.xva_vattr.va_mask |= AT_XVATTR;
341 zfs_replay_xvattr(lrattr, &xva);
343 vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
344 vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
345 vsec.vsa_aclcnt = lracl->lr_aclcnt;
346 vsec.vsa_aclentsz = lracl->lr_acl_bytes;
347 vsec.vsa_aclflags = lracl->lr_acl_flags;
348 if (zfsvfs->z_fuid_replay == NULL) {
349 fuidstart = (caddr_t)(lracl + 1) + xvatlen +
350 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
351 zfsvfs->z_fuid_replay =
352 zfs_replay_fuids(fuidstart,
353 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
354 lr->lr_uid, lr->lr_gid);
357 error = zfs_create(ZTOV(dzp), name, &xva.xva_vattr,
358 0, 0, &vp, kcred, vflg, NULL, &vsec);
361 aclstart = (caddr_t)(lracl + 1);
362 fuidstart = (caddr_t)aclstart +
363 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
364 zfsvfs->z_fuid_replay = zfs_replay_fuids(fuidstart,
365 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
366 lr->lr_uid, lr->lr_gid);
368 case TX_MKDIR_ACL_ATTR:
370 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
371 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
372 zfs_replay_xvattr(lrattr, &xva);
374 vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
375 vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
376 vsec.vsa_aclcnt = lracl->lr_aclcnt;
377 vsec.vsa_aclentsz = lracl->lr_acl_bytes;
378 vsec.vsa_aclflags = lracl->lr_acl_flags;
379 if (zfsvfs->z_fuid_replay == NULL) {
380 fuidstart = (caddr_t)(lracl + 1) + xvatlen +
381 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
382 zfsvfs->z_fuid_replay =
383 zfs_replay_fuids(fuidstart,
384 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
385 lr->lr_uid, lr->lr_gid);
387 error = zfs_mkdir(ZTOV(dzp), name, &xva.xva_vattr,
388 &vp, kcred, NULL, vflg, &vsec);
395 if (error == 0 && vp != NULL)
400 if (zfsvfs->z_fuid_replay)
401 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
402 zfsvfs->z_fuid_replay = NULL;
408 zfs_replay_create(zfsvfs_t *zfsvfs, lr_create_t *lr, boolean_t byteswap)
410 char *name = NULL; /* location determined later */
411 char *link; /* symlink content follows name */
416 size_t lrsize = sizeof (lr_create_t);
423 txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
425 byteswap_uint64_array(lr, sizeof (*lr));
426 if (txtype == TX_CREATE_ATTR || txtype == TX_MKDIR_ATTR)
427 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
431 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
435 zfs_init_vattr(&xva.xva_vattr, AT_TYPE | AT_MODE | AT_UID | AT_GID,
436 lr->lr_mode, lr->lr_uid, lr->lr_gid, lr->lr_rdev, lr->lr_foid);
439 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
440 * eventually end up in zfs_mknode(), which assigns the object's
441 * creation time and generation number. The generic zfs_create()
442 * doesn't have either concept, so we smuggle the values inside
443 * the vattr's otherwise unused va_ctime and va_nblocks fields.
445 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
446 xva.xva_vattr.va_nblocks = lr->lr_gen;
448 error = dmu_object_info(zfsvfs->z_os, lr->lr_foid, NULL);
452 if (lr->lr_common.lrc_txtype & TX_CI)
456 * Symlinks don't have fuid info, and CIFS never creates
459 * The _ATTR versions will grab the fuid info in their subcases.
461 if ((int)lr->lr_common.lrc_txtype != TX_SYMLINK &&
462 (int)lr->lr_common.lrc_txtype != TX_MKDIR_ATTR &&
463 (int)lr->lr_common.lrc_txtype != TX_CREATE_ATTR) {
465 zfsvfs->z_fuid_replay =
466 zfs_replay_fuid_domain(start, &start,
467 lr->lr_uid, lr->lr_gid);
472 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
473 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
474 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
475 start = (caddr_t)(lr + 1) + xvatlen;
476 zfsvfs->z_fuid_replay =
477 zfs_replay_fuid_domain(start, &start,
478 lr->lr_uid, lr->lr_gid);
479 name = (char *)start;
484 name = (char *)start;
486 error = zfs_create(ZTOV(dzp), name, &xva.xva_vattr,
487 0, 0, &vp, kcred, vflg, NULL, NULL);
490 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
491 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
492 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
493 start = (caddr_t)(lr + 1) + xvatlen;
494 zfsvfs->z_fuid_replay =
495 zfs_replay_fuid_domain(start, &start,
496 lr->lr_uid, lr->lr_gid);
497 name = (char *)start;
502 name = (char *)(lr + 1);
504 error = zfs_mkdir(ZTOV(dzp), name, &xva.xva_vattr,
505 &vp, kcred, NULL, vflg, NULL);
508 error = zfs_make_xattrdir(dzp, &xva.xva_vattr, &vp, kcred);
511 name = (char *)(lr + 1);
512 link = name + strlen(name) + 1;
513 error = zfs_symlink(ZTOV(dzp), name, &xva.xva_vattr,
514 link, kcred, NULL, vflg);
521 if (error == 0 && vp != NULL)
526 if (zfsvfs->z_fuid_replay)
527 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
528 zfsvfs->z_fuid_replay = NULL;
533 zfs_replay_remove(zfsvfs_t *zfsvfs, lr_remove_t *lr, boolean_t byteswap)
535 char *name = (char *)(lr + 1); /* name follows lr_remove_t */
541 byteswap_uint64_array(lr, sizeof (*lr));
543 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
546 if (lr->lr_common.lrc_txtype & TX_CI)
549 switch ((int)lr->lr_common.lrc_txtype) {
551 error = zfs_remove(ZTOV(dzp), name, kcred, NULL, vflg);
554 error = zfs_rmdir(ZTOV(dzp), name, NULL, kcred, NULL, vflg);
566 zfs_replay_link(zfsvfs_t *zfsvfs, lr_link_t *lr, boolean_t byteswap)
568 char *name = (char *)(lr + 1); /* name follows lr_link_t */
574 byteswap_uint64_array(lr, sizeof (*lr));
576 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
579 if ((error = zfs_zget(zfsvfs, lr->lr_link_obj, &zp)) != 0) {
584 if (lr->lr_common.lrc_txtype & TX_CI)
587 error = zfs_link(ZTOV(dzp), ZTOV(zp), name, kcred, NULL, vflg);
596 zfs_replay_rename(zfsvfs_t *zfsvfs, lr_rename_t *lr, boolean_t byteswap)
598 char *sname = (char *)(lr + 1); /* sname and tname follow lr_rename_t */
599 char *tname = sname + strlen(sname) + 1;
600 znode_t *sdzp, *tdzp;
605 byteswap_uint64_array(lr, sizeof (*lr));
607 if ((error = zfs_zget(zfsvfs, lr->lr_sdoid, &sdzp)) != 0)
610 if ((error = zfs_zget(zfsvfs, lr->lr_tdoid, &tdzp)) != 0) {
615 if (lr->lr_common.lrc_txtype & TX_CI)
618 error = zfs_rename(ZTOV(sdzp), sname, ZTOV(tdzp), tname, kcred,
628 zfs_replay_write(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap)
630 char *data = (char *)(lr + 1); /* data follows lr_write_t */
634 uint64_t eod, offset, length;
637 byteswap_uint64_array(lr, sizeof (*lr));
639 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
641 * As we can log writes out of order, it's possible the
642 * file has been removed. In this case just drop the write
643 * and return success.
650 offset = lr->lr_offset;
651 length = lr->lr_length;
652 eod = offset + length; /* end of data for this write */
655 * This may be a write from a dmu_sync() for a whole block,
656 * and may extend beyond the current end of the file.
657 * We can't just replay what was written for this TX_WRITE as
658 * a future TX_WRITE2 may extend the eof and the data for that
659 * write needs to be there. So we write the whole block and
660 * reduce the eof. This needs to be done within the single dmu
661 * transaction created within vn_rdwr -> zfs_write. So a possible
662 * new end of file is passed through in zfsvfs->z_replay_eof
665 zfsvfs->z_replay_eof = 0; /* 0 means don't change end of file */
667 /* If it's a dmu_sync() block, write the whole block */
668 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
669 uint64_t blocksize = BP_GET_LSIZE(&lr->lr_blkptr);
670 if (length < blocksize) {
671 offset -= offset % blocksize;
674 if (zp->z_size < eod)
675 zfsvfs->z_replay_eof = eod;
678 error = vn_rdwr(UIO_WRITE, ZTOV(zp), data, length, offset,
679 UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
682 zfsvfs->z_replay_eof = 0; /* safety */
688 * TX_WRITE2 are only generated when dmu_sync() returns EALREADY
689 * meaning the pool block is already being synced. So now that we always write
690 * out full blocks, all we have to do is expand the eof if
694 zfs_replay_write2(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap)
701 byteswap_uint64_array(lr, sizeof (*lr));
703 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
707 end = lr->lr_offset + lr->lr_length;
708 if (end > zp->z_size) {
709 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
712 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
713 error = dmu_tx_assign(tx, TXG_WAIT);
716 if (error == ERESTART) {
724 (void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
725 (void *)&zp->z_size, sizeof (uint64_t), tx);
727 /* Ensure the replayed seq is updated */
728 (void) zil_replaying(zfsvfs->z_log, tx);
739 zfs_replay_truncate(zfsvfs_t *zfsvfs, lr_truncate_t *lr, boolean_t byteswap)
746 byteswap_uint64_array(lr, sizeof (*lr));
748 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
751 bzero(&fl, sizeof (fl));
754 fl.l_start = lr->lr_offset;
755 fl.l_len = lr->lr_length;
757 error = zfs_space(ZTOV(zp), F_FREESP, &fl, FWRITE | FOFFMAX,
758 lr->lr_offset, kcred, NULL);
766 zfs_replay_setattr(zfsvfs_t *zfsvfs, lr_setattr_t *lr, boolean_t byteswap)
770 vattr_t *vap = &xva.xva_vattr;
776 byteswap_uint64_array(lr, sizeof (*lr));
778 if ((lr->lr_mask & AT_XVATTR) &&
779 zfsvfs->z_version >= ZPL_VERSION_INITIAL)
780 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
783 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
786 zfs_init_vattr(vap, lr->lr_mask, lr->lr_mode,
787 lr->lr_uid, lr->lr_gid, 0, lr->lr_foid);
789 vap->va_size = lr->lr_size;
790 ZFS_TIME_DECODE(&vap->va_atime, lr->lr_atime);
791 ZFS_TIME_DECODE(&vap->va_mtime, lr->lr_mtime);
794 * Fill in xvattr_t portions if necessary.
797 start = (lr_setattr_t *)(lr + 1);
798 if (vap->va_mask & AT_XVATTR) {
799 zfs_replay_xvattr((lr_attr_t *)start, &xva);
800 start = (caddr_t)start +
801 ZIL_XVAT_SIZE(((lr_attr_t *)start)->lr_attr_masksize);
803 xva.xva_vattr.va_mask &= ~AT_XVATTR;
805 zfsvfs->z_fuid_replay = zfs_replay_fuid_domain(start, &start,
806 lr->lr_uid, lr->lr_gid);
808 error = zfs_setattr(ZTOV(zp), vap, 0, kcred, NULL);
810 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
811 zfsvfs->z_fuid_replay = NULL;
818 zfs_replay_acl_v0(zfsvfs_t *zfsvfs, lr_acl_v0_t *lr, boolean_t byteswap)
820 ace_t *ace = (ace_t *)(lr + 1); /* ace array follows lr_acl_t */
826 byteswap_uint64_array(lr, sizeof (*lr));
827 zfs_oldace_byteswap(ace, lr->lr_aclcnt);
830 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
833 bzero(&vsa, sizeof (vsa));
834 vsa.vsa_mask = VSA_ACE | VSA_ACECNT;
835 vsa.vsa_aclcnt = lr->lr_aclcnt;
836 vsa.vsa_aclentsz = sizeof (ace_t) * vsa.vsa_aclcnt;
837 vsa.vsa_aclflags = 0;
838 vsa.vsa_aclentp = ace;
840 error = zfs_setsecattr(ZTOV(zp), &vsa, 0, kcred, NULL);
848 * Replaying ACLs is complicated by FUID support.
849 * The log record may contain some optional data
850 * to be used for replaying FUID's. These pieces
851 * are the actual FUIDs that were created initially.
852 * The FUID table index may no longer be valid and
853 * during zfs_create() a new index may be assigned.
854 * Because of this the log will contain the original
855 * doman+rid in order to create a new FUID.
857 * The individual ACEs may contain an ephemeral uid/gid which is no
858 * longer valid and will need to be replaced with an actual FUID.
862 zfs_replay_acl(zfsvfs_t *zfsvfs, lr_acl_t *lr, boolean_t byteswap)
864 ace_t *ace = (ace_t *)(lr + 1);
870 byteswap_uint64_array(lr, sizeof (*lr));
871 zfs_ace_byteswap(ace, lr->lr_acl_bytes, B_FALSE);
872 if (lr->lr_fuidcnt) {
873 byteswap_uint64_array((caddr_t)ace +
874 ZIL_ACE_LENGTH(lr->lr_acl_bytes),
875 lr->lr_fuidcnt * sizeof (uint64_t));
879 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
882 bzero(&vsa, sizeof (vsa));
883 vsa.vsa_mask = VSA_ACE | VSA_ACECNT | VSA_ACE_ACLFLAGS;
884 vsa.vsa_aclcnt = lr->lr_aclcnt;
885 vsa.vsa_aclentp = ace;
886 vsa.vsa_aclentsz = lr->lr_acl_bytes;
887 vsa.vsa_aclflags = lr->lr_acl_flags;
889 if (lr->lr_fuidcnt) {
890 void *fuidstart = (caddr_t)ace +
891 ZIL_ACE_LENGTH(lr->lr_acl_bytes);
893 zfsvfs->z_fuid_replay =
894 zfs_replay_fuids(fuidstart, &fuidstart,
895 lr->lr_fuidcnt, lr->lr_domcnt, 0, 0);
898 error = zfs_setsecattr(ZTOV(zp), &vsa, 0, kcred, NULL);
900 if (zfsvfs->z_fuid_replay)
901 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
903 zfsvfs->z_fuid_replay = NULL;
910 * Callback vectors for replaying records
912 zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE] = {
913 zfs_replay_error, /* 0 no such transaction type */
914 zfs_replay_create, /* TX_CREATE */
915 zfs_replay_create, /* TX_MKDIR */
916 zfs_replay_create, /* TX_MKXATTR */
917 zfs_replay_create, /* TX_SYMLINK */
918 zfs_replay_remove, /* TX_REMOVE */
919 zfs_replay_remove, /* TX_RMDIR */
920 zfs_replay_link, /* TX_LINK */
921 zfs_replay_rename, /* TX_RENAME */
922 zfs_replay_write, /* TX_WRITE */
923 zfs_replay_truncate, /* TX_TRUNCATE */
924 zfs_replay_setattr, /* TX_SETATTR */
925 zfs_replay_acl_v0, /* TX_ACL_V0 */
926 zfs_replay_acl, /* TX_ACL */
927 zfs_replay_create_acl, /* TX_CREATE_ACL */
928 zfs_replay_create, /* TX_CREATE_ATTR */
929 zfs_replay_create_acl, /* TX_CREATE_ACL_ATTR */
930 zfs_replay_create_acl, /* TX_MKDIR_ACL */
931 zfs_replay_create, /* TX_MKDIR_ATTR */
932 zfs_replay_create_acl, /* TX_MKDIR_ACL_ATTR */
933 zfs_replay_write2, /* TX_WRITE2 */
935 #endif /* HAVE_ZPL */